use of org.springframework.web.bind.annotation.ResponseBody in project pmph by BCSquad.
the class FileDownLoadController method org.
/**
* <pre>
* 功能描述:导出已发布教材下的学校
* 使用示范:
*
* @param materialId 教材ID
* @param request
* @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, "文件在传输时中断");
}
}
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;
}
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, "文件在传输时中断");
}
}
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;
}
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);
}
Aggregations