Search in sources :

Example 91 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project pmph by BCSquad.

the class FileDownLoadController method org.

/**
 * <pre>
 * 功能描述:导出已发布教材下的学校
 * 使用示范:
 *
 * &#64;param materialId 教材ID
 * &#64;param request
 * &#64;param response
 * </pre>
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "导出已发布教材下的学校")
@RequestMapping(value = "/excel/published/org", method = RequestMethod.GET)
public void org(@RequestParam("materialId") Long materialId, HttpServletRequest request, HttpServletResponse response) {
    Workbook workbook = null;
    List<OrgExclVO> orgList = null;
    try {
        orgList = materialOrgService.getOutPutExclOrgByMaterialId(materialId);
        if (orgList.isEmpty()) {
            orgList.add(new OrgExclVO());
        }
        workbook = excelHelper.fromBusinessObjectList(orgList, "学校信息");
    } catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
        logger.warn("数据表格化的时候失败");
    }
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/force-download");
    String materialName = null;
    if (CollectionUtil.isNotEmpty(orgList)) {
        // 教材名称
        materialName = orgList.get(0).getMaterialName();
    }
    if (StringUtil.isEmpty(materialName)) {
        materialName = "已发布学校";
    }
    String fileName = returnFileName(request, materialName + ".xls");
    response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
    try (OutputStream out = response.getOutputStream()) {
        workbook.write(out);
        out.flush();
        out.close();
    } catch (Exception e) {
        logger.warn("文件下载时出现IO异常:{}", e.getMessage());
        throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "文件在传输时中断");
    }
}
Also used : OrgExclVO(com.bc.pmpheep.back.vo.OrgExclVO) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Workbook(org.apache.poi.ss.usermodel.Workbook) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 92 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project pmph by BCSquad.

the class FileDownLoadController method progress.

/**
 * 功能描述:查询进度
 *
 * @param id
 * @return
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "查询word打包进度")
@RequestMapping(value = "/word/progress", method = RequestMethod.GET)
public ZipDownload progress(String id) {
    ZipDownload zipDownload = new ZipDownload();
    if (Const.WORD_EXPORT_MAP.containsKey(id)) {
        zipDownload.setId(Const.WORD_EXPORT_MAP.get(id).getId());
        zipDownload.setState(Const.WORD_EXPORT_MAP.get(id).getState());
        zipDownload.setDetail(Const.WORD_EXPORT_MAP.get(id).getDetail());
        zipDownload.setCreateTime(Const.WORD_EXPORT_MAP.get(id).getCreateTime());
    }
    return zipDownload;
}
Also used : ZipDownload(com.bc.pmpheep.general.bean.ZipDownload) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 93 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project pmph by BCSquad.

the class FileDownLoadController method exportTopic.

/**
 * Description:设置选题号页面导出选题号
 *
 * @author:lyc
 * @date:2018年1月23日下午6:18:41
 * @param
 * @return void
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "设置选题号页面导出选题号信息")
@RequestMapping(value = "/textbook/exportTopic", method = RequestMethod.GET)
public void exportTopic(Long materialId, HttpServletRequest request, HttpServletResponse response) {
    List<Textbook> list = textbookService.listTopicNumber(materialId);
    Workbook workbook = null;
    if (list.size() == 0) {
        list.add(new Textbook());
    }
    try {
        workbook = excelHelper.fromTextbookTopic(list, "选题号导出");
    } catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
        logger.warn("数据表格化的时候失败");
    }
    Material material = materialService.getMaterialById(materialId);
    String fileName = returnFileName(request, material.getMaterialName() + ".xls");
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/force-download");
    response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
    try (OutputStream out = response.getOutputStream()) {
        workbook.write(out);
        out.flush();
        out.close();
    } catch (Exception e) {
        logger.warn("文件下载时出现IO异常: {}", e.getMessage());
        throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "文件在传输时中断");
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) Textbook(com.bc.pmpheep.back.po.Textbook) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) Workbook(org.apache.poi.ss.usermodel.Workbook) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 94 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project topcom-cloud by 545314690.

the class AbbreviationController method update.

/**
 * 根据输入的实体对象信息,修改指定id的实体对象
 *
 * @param id
 * @param model
 * @return 实体对象
 */
@RequestMapping(value = "/getTree/{id}", method = RequestMethod.PUT, produces = "application/json", consumes = "application/json")
@ResponseBody
public Abbreviation update(@PathVariable int id, @RequestBody Abbreviation model) {
    Abbreviation abb = this.manager.findById(Long.valueOf(id));
    Unit unit = abb.getUnit();
    abb.setShortName(model.getShortName());
    unit.setUnitName(model.getUnit().getUnitName());
    abb.setFlag(model.getFlag());
    abb.setUnit(unit);
    this.model = this.manager.save(abb);
    return this.model;
}
Also used : Abbreviation(com.topcom.cms.domain.Abbreviation) Unit(com.topcom.cms.domain.Unit) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 95 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project topcom-cloud by 545314690.

the class SearchWordController method findByType.

/**
 * 热词查询 查询排名前 limit 的word
 * @return
 */
@RequestMapping(method = RequestMethod.GET, value = "/findByType", produces = "application/json")
@ResponseBody
public List<SearchWord> findByType(@CurrentUser User user, @ApiParam("limit") @RequestParam(required = true) Integer limit, @ApiParam("type") @RequestParam(required = true) Integer type) {
    Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "wordCount"));
    Pageable page = new PageRequest(0, limit, sort);
    User user1 = this.userManager.findById(user.getId());
    Set<Group> groups = user1.getGroups();
    String groupId = SearchWord.groupIdBySet(groups);
    List<String> groupIdList = new ArrayList<>();
    groupIdList.add(groupId);
    if (groupId.indexOf(",") != -1) {
        String[] split = groupId.split(",");
        for (String s : split) {
            groupIdList.add(s);
        }
    }
    Page<SearchWord> searchWords = this.searchWordManager.findByTypeAndGroupIdIn(page, type, groupIdList);
    return filterNull(searchWords);
}
Also used : Group(com.topcom.cms.domain.Group) CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) SearchWord(com.topcom.cms.domain.SearchWord) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1991 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1700 HashMap (java.util.HashMap)458 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)212 IOException (java.io.IOException)207 JSONObject (com.alibaba.fastjson.JSONObject)200 Map (java.util.Map)172 ApiOperation (io.swagger.annotations.ApiOperation)170 ArrayList (java.util.ArrayList)169 GetMapping (org.springframework.web.bind.annotation.GetMapping)112 ResponseEntity (org.springframework.http.ResponseEntity)102 ApiRest (build.dream.common.api.ApiRest)101 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)101 AuthPassport (com.ngtesting.platform.util.AuthPassport)99 PostMapping (org.springframework.web.bind.annotation.PostMapping)94 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)87 Date (java.util.Date)81 UserVo (com.ngtesting.platform.vo.UserVo)78 LogDetail (com.bc.pmpheep.annotation.LogDetail)71 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)65