911feb7bd6c43ee937980d881a96fed618d4ea4e.svn-base 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package cn.com.goldenwater.dcproj.controller.ducha;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.core.web.BaseResponse;
  4. import cn.com.goldenwater.dcproj.model.BisInspPlanChk;
  5. import cn.com.goldenwater.dcproj.param.BisInspPlanChkParam;
  6. import cn.com.goldenwater.dcproj.service.BisInspPlanChkService;
  7. import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
  8. import cn.com.goldenwater.dcproj.util.ReadExcelUtil;
  9. import cn.com.goldenwater.dcproj.utils.AdLevelUtil;
  10. import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
  11. import cn.com.goldenwater.id.util.UuidUtil;
  12. import com.github.pagehelper.PageInfo;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiOperation;
  15. import io.swagger.annotations.ApiParam;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  18. import org.slf4j.Logger;
  19. import org.slf4j.LoggerFactory;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.web.bind.annotation.*;
  23. import org.springframework.web.multipart.MultipartFile;
  24. import javax.servlet.http.HttpServletResponse;
  25. import java.io.File;
  26. import java.io.IOException;
  27. import java.nio.file.Paths;
  28. import java.util.HashMap;
  29. import java.util.Map;
  30. /**
  31. * @author lhc
  32. * @date 2021-4-1
  33. */
  34. @Api(value = "年度计划方案-年度督查检查计划管理", tags = "年度计划方案-年度督查检查计划管理")
  35. @RestController
  36. @RequestMapping("/bis/insp/plan/chk")
  37. public class BisInspPlanChkController extends BaseController {
  38. private Logger logger = LoggerFactory.getLogger(getClass());
  39. @Value("${export.templatePath}")
  40. private String templatePath;
  41. @Autowired
  42. private BisInspPlanChkService bisInspPlanChkService;
  43. @Autowired
  44. private OlBisInspOrgService olBisInspOrgService;
  45. @ApiOperation(value = "修改年度计划方案-年度督查检查计划")
  46. @RequestMapping(value = "", method = RequestMethod.POST)
  47. public BaseResponse<BisInspPlanChk> insert(@ApiParam(name = "bisInspPlanChk", value = "BisInspPlanChk", required = true)
  48. @RequestBody BisInspPlanChk bisInspPlanChk) {
  49. int ret = 0;
  50. if (StringUtils.isBlank(bisInspPlanChk.getId())) {
  51. bisInspPlanChk.setAdCode(olBisInspOrgService.getProvince(getCurrentOrgId()));
  52. bisInspPlanChk.setPersId(getCurrentPersId());
  53. ret = bisInspPlanChkService.insert(bisInspPlanChk);
  54. } else {
  55. ret = bisInspPlanChkService.update(bisInspPlanChk);
  56. }
  57. return buildSuccessResponse(bisInspPlanChk);
  58. }
  59. @ApiOperation(value = "根据ID删除年度计划方案-年度督查检查计划")
  60. @RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
  61. public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  62. int ret = bisInspPlanChkService.delete(id);
  63. return buildSuccessResponse();
  64. }
  65. @ApiOperation(value = "根据ID获取年度计划方案-年度督查检查计划(单表)")
  66. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  67. public BaseResponse<BisInspPlanChk> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  68. BisInspPlanChk bisInspPlanChk = bisInspPlanChkService.get(id);
  69. return buildSuccessResponse(bisInspPlanChk);
  70. }
  71. @ApiOperation(value = "根据ID获取年度计划方案-年度督查检查计划(单表)")
  72. @RequestMapping(value = "/listOfPage", method = RequestMethod.POST)
  73. public BaseResponse<PageInfo<BisInspPlanChk>> listOfPage(@ApiParam(name = "bisInspPlanChkcc", value = "bisInspPlanChkcc", required = true)
  74. @RequestBody BisInspPlanChkParam bisInspPlanChk) {
  75. bisInspPlanChk.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())));
  76. return buildSuccessResponse(bisInspPlanChkService.findPageInfo(bisInspPlanChk));
  77. }
  78. @ApiOperation(value = "导出检查表")
  79. @RequestMapping(value = "/export/checkList", method = RequestMethod.POST)
  80. public void exportCheckList(HttpServletResponse response, @RequestBody BisInspPlanChkParam bisInspPlanChkParam) {
  81. bisInspPlanChkService.exportCheckList(response, bisInspPlanChkParam);
  82. }
  83. @ApiOperation("获取导入模板")
  84. @GetMapping(value = "/getExl")
  85. public BaseResponse getExl(HttpServletResponse response) {
  86. String path = templatePath + File.separator + "chk_plan.xls";
  87. try {
  88. ExpAndImpUtil.downloadFile(response, path, "年度检查表");
  89. } catch (Exception e) {
  90. logger.error(e.getMessage(), e);
  91. }
  92. return buildSuccessResponse();
  93. }
  94. @ApiOperation("上传 xls 导入数据")
  95. @RequestMapping(value = "/impExl", method = RequestMethod.POST)
  96. public BaseResponse<Map<String, Object>> impExl(@RequestParam("file") MultipartFile multfile) throws IOException, InvalidFormatException {
  97. // 获取文件名
  98. String fileName = multfile.getOriginalFilename();
  99. // 获取文件后缀
  100. String prefix = fileName.substring(fileName.lastIndexOf("."));
  101. // 用uuid作为文件名,防止生成的临时文件重复
  102. String uuid = UuidUtil.uuid();
  103. File file = File.createTempFile(uuid, prefix);
  104. // MultipartFile to File
  105. multfile.transferTo(Paths.get(file.getPath()));
  106. Map<String, Object> map = new HashMap<>(2);
  107. int shu = 0;
  108. int success = 0;
  109. String[][] data = ReadExcelUtil.getData(file, 3);
  110. if (data.length > 0) {
  111. for (String[] datum : data) {
  112. if (StringUtils.isBlank(datum[1])) {
  113. continue;
  114. }
  115. try {
  116. BisInspPlanChk planChk = new BisInspPlanChk();
  117. planChk.setChkYear(Long.parseLong(datum[1]));
  118. planChk.setChkItem(datum[2]);
  119. planChk.setChkMatter(datum[3]);
  120. planChk.setChkBatch(datum[4]);
  121. planChk.setChkTm(datum[5]);
  122. planChk.setChkCity(datum[6]);
  123. planChk.setChkCounty(datum[7]);
  124. planChk.setChkContent(datum[8]);
  125. planChk.setChkDep(datum[9]);
  126. planChk.setChkType(datum[10]);
  127. insert(planChk);
  128. success++;
  129. } catch (Exception e) {
  130. logger.error(e.getMessage(), e);
  131. shu++;
  132. }
  133. }
  134. }
  135. map.put("false", shu);
  136. map.put("success", success);
  137. return buildSuccessResponse(map);
  138. }
  139. }