JcsxqdkController.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package com.zjrs.zwnw.sxgl.controller;
  2. import com.zjrs.zwnw.sxgl.bpo.JcsxqdkBPO;
  3. import com.zjrs.zwnw.sxgl.dto.SxExportQueryDTO;
  4. import com.zjrs.zwnw.sxgl.dto.SxpzxxXsUpdateDTO;
  5. import com.zjrs.zwnw.sxgl.dto.SxtempQueryDTO;
  6. import io.swagger.v3.oas.annotations.Operation;
  7. import io.swagger.v3.oas.annotations.tags.Tag;
  8. import jakarta.annotation.Resource;
  9. import jakarta.servlet.http.HttpServletRequest;
  10. import jakarta.servlet.http.HttpServletResponse;
  11. import jakarta.validation.Valid;
  12. import org.mohrss.leaf.core.framework.persistens.PageResult;
  13. import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. import org.springframework.util.StreamUtils;
  17. import org.springframework.web.bind.annotation.*;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import java.io.File;
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. import java.net.URLEncoder;
  23. import java.util.Map;
  24. @Tag(name = "基础事项清单库")
  25. @RestController
  26. @RequestMapping("/api/zwnw/sxgl/jcsxqdk")
  27. public class JcsxqdkController {
  28. private static final Logger LOG = LoggerFactory.getLogger(JcsxqdkController.class);
  29. @Resource
  30. private JcsxqdkBPO jcsxqdkBPO;
  31. @Operation(summary = "获取导入结果统计", description = "获取导入结果统计")
  32. @PostMapping("/getDrjgtj")
  33. public AjaxResponse getDrjgtj(@RequestBody @Valid SxtempQueryDTO dto) {
  34. LOG.info("获取导入结果统计开始");
  35. AjaxResponse ajaxResponse = new AjaxResponse();
  36. Integer pagenum = dto.getPagenum();
  37. Integer pagesize = dto.getPagesize();
  38. try {
  39. PageResult pageResult = this.jcsxqdkBPO.getDrjgtj(dto, pagenum, pagesize);
  40. ajaxResponse.setData("data", pageResult);
  41. ajaxResponse.setData("pagesize", pagesize);
  42. ajaxResponse.setData("pagenum", pagenum);
  43. } catch (Exception e) {
  44. LOG.error(e.getMessage());
  45. ajaxResponse.setAppcode("1");
  46. ajaxResponse.setErrorMsg("系统异常");
  47. }
  48. LOG.info("获取导入结果统计结束");
  49. return ajaxResponse;
  50. }
  51. @Operation(summary = "获取导入事项list", description = "获取导入事项list")
  52. @PostMapping("/getDrjgList")
  53. public AjaxResponse getDrjgList(@RequestBody @Valid SxtempQueryDTO dto) {
  54. LOG.info("获取导入事项列表开始");
  55. AjaxResponse ajaxResponse = new AjaxResponse();
  56. Integer pagenum = dto.getPagenum();
  57. Integer pagesize = dto.getPagesize();
  58. try {
  59. PageResult pageResult = this.jcsxqdkBPO.getDrjgList(dto, pagenum, pagesize);
  60. ajaxResponse.setData("data", pageResult);
  61. ajaxResponse.setData("pagesize", pagesize);
  62. ajaxResponse.setData("pagenum", pagenum);
  63. } catch (Exception e) {
  64. LOG.error(e.getMessage());
  65. ajaxResponse.setAppcode("1");
  66. ajaxResponse.setErrorMsg("系统异常");
  67. }
  68. LOG.info("获取导入事项列表结束");
  69. return ajaxResponse;
  70. }
  71. @Operation(summary = "导出事项列表", description = "导出事项列表")
  72. @PostMapping("/exportSx")
  73. public void exportSx(@RequestBody SxExportQueryDTO dto, HttpServletResponse res) throws IOException {
  74. LOG.info("导出事项列表开始");
  75. this.jcsxqdkBPO.exportSx(dto, res);
  76. LOG.info("导出事项列表结束");
  77. }
  78. @Operation(summary = "导入事项列表", description = "导入事项列表")
  79. @PostMapping("/importSx")
  80. @ResponseBody
  81. public AjaxResponse importSx(MultipartFile file, HttpServletRequest request) {
  82. LOG.info("导入事项列表开始");
  83. AjaxResponse ajaxResponse = new AjaxResponse();
  84. if (file == null) {
  85. ajaxResponse.setAppcode("1");
  86. ajaxResponse.setMsg("导入失败,导入的文件无效。");
  87. } else {
  88. try {
  89. String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
  90. if (!"xls".equals(suffix) && !"xlsx".equals(suffix)) {
  91. ajaxResponse.setAppcode("1");
  92. ajaxResponse.setMsg("导入失败,导入的文件无效,文件格式只能为:xls或xlsx。");
  93. } else if (file.getSize() > 2 * 1048576) {
  94. ajaxResponse.setAppcode("1");
  95. ajaxResponse.setMsg("导入失败,导入的文件大小不能超过2M。");
  96. } else {
  97. InputStream is = file.getInputStream();
  98. Map<String, String> resultMap = this.jcsxqdkBPO.importSx(is);
  99. ajaxResponse.setAppcode(resultMap.get("code"));
  100. ajaxResponse.setMsg(resultMap.get("msg"));
  101. ajaxResponse.setData("data", resultMap);
  102. }
  103. } catch (Exception e) {
  104. LOG.error(e.getMessage());
  105. ajaxResponse.setAppcode("1");
  106. ajaxResponse.setErrorMsg("导入失败,请检查导入文件是否正确。");
  107. }
  108. }
  109. LOG.info("导入事项列表结束");
  110. return ajaxResponse;
  111. }
  112. @Operation(summary = "下载导入模板", description = "下载导入模板")
  113. @GetMapping(value = "/downloadTemplate")
  114. public void downloadTemplate(HttpServletRequest request, HttpServletResponse res) throws IOException {
  115. LOG.info("下载导入模板开始");
  116. InputStream is = JcsxqdkController.class.getClassLoader()
  117. .getResourceAsStream("templates" + File.separator + "sxgl" + File.separator + "import.xls");
  118. res.setContentType("application/octet-stream; charset=UTF-8");
  119. res.setHeader("Content-disposition",
  120. "attachment;filename=" + URLEncoder.encode("事项导入模板.xls", "UTF-8"));
  121. try {
  122. StreamUtils.copy(is, res.getOutputStream());
  123. } catch (IOException e) {
  124. LOG.error(e.getMessage());
  125. } finally {
  126. if (is != null) {
  127. is.close();
  128. }
  129. if (res.getOutputStream() != null) {
  130. res.getOutputStream().close();
  131. }
  132. }
  133. LOG.info("下载导入模板结束");
  134. }
  135. @Operation(summary = "保存事项基本信息", description = "保存事项基本信息")
  136. @PostMapping("/saveSxjbxx")
  137. public AjaxResponse saveSxjbxx(@RequestBody SxpzxxXsUpdateDTO dto) {
  138. LOG.info("保存事项基本信息开始");
  139. AjaxResponse ajaxResponse = new AjaxResponse();
  140. try {
  141. Map<String, String> resultMap = this.jcsxqdkBPO.saveSxjbxx(dto);
  142. ajaxResponse.setAppcode(resultMap.get("code"));
  143. ajaxResponse.setMsg(resultMap.get("msg"));
  144. } catch (Exception e) {
  145. LOG.error(e.getMessage());
  146. ajaxResponse.setAppcode("1");
  147. ajaxResponse.setErrorMsg("系统异常");
  148. }
  149. LOG.info("保存事项基本信息结束");
  150. return ajaxResponse;
  151. }
  152. }