dc92493892e7822b30eef1ee00f8d36637820571.svn-base 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. package cn.com.goldenwater.dcproj.controller.safeprod;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.core.web.BaseResponse;
  4. import cn.com.goldenwater.dcproj.model.AttAdBase;
  5. import cn.com.goldenwater.dcproj.model.ChkSafeStatList;
  6. import cn.com.goldenwater.dcproj.model.ChkSafeStatListIndustry;
  7. import cn.com.goldenwater.dcproj.param.ChkSafeStatListIndustryParam;
  8. import cn.com.goldenwater.dcproj.param.ChkSafeStatListParam;
  9. import cn.com.goldenwater.dcproj.service.AttAdBaseService;
  10. import cn.com.goldenwater.dcproj.service.ChkSafeStatListIndustryService;
  11. import cn.com.goldenwater.dcproj.service.ChkSafeStatListService;
  12. import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
  13. import cn.com.goldenwater.dcproj.util.ReadExcelUtil;
  14. import cn.com.goldenwater.dcproj.utils.AdLevelUtil;
  15. import cn.com.goldenwater.dcproj.utils.StringUtils;
  16. import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
  17. import cn.com.goldenwater.id.util.UuidUtil;
  18. import com.github.pagehelper.PageInfo;
  19. import io.swagger.annotations.Api;
  20. import io.swagger.annotations.ApiOperation;
  21. import io.swagger.annotations.ApiParam;
  22. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  23. import org.slf4j.Logger;
  24. import org.slf4j.LoggerFactory;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.beans.factory.annotation.Value;
  27. import org.springframework.util.Assert;
  28. import org.springframework.web.bind.annotation.*;
  29. import org.springframework.web.multipart.MultipartFile;
  30. import javax.servlet.http.HttpServletResponse;
  31. import java.io.File;
  32. import java.io.IOException;
  33. import java.nio.file.Paths;
  34. import java.util.ArrayList;
  35. import java.util.Date;
  36. import java.util.List;
  37. import java.util.stream.Collectors;
  38. /**
  39. * 成都市水务行业安全大检查情况统计Controller
  40. *
  41. * @author ruoyi
  42. * @date 2023-02-22
  43. */
  44. @Api(value = "成都市水务行业安全大检查情况统计表", tags = "成都市水务行业安全大检查情况统计表")
  45. @RestController
  46. @RequestMapping("/chk/safe/stat/record")
  47. public class ChkSafeStatListController extends BaseController {
  48. private Logger logger = LoggerFactory.getLogger(getClass());
  49. /**
  50. * 成都市水务行业安全大检查情况统计 服务
  51. */
  52. @Autowired
  53. private ChkSafeStatListService chkSafeStatListService;
  54. /**
  55. * 成都市水务行业安全大检查行业(领域) 服务
  56. */
  57. @Autowired
  58. private ChkSafeStatListIndustryService chkSafeStatListIndustryService;
  59. @Value("${export.templatePath}")
  60. private String templatePath;
  61. /**
  62. * 上传模板名称
  63. * 水务行业安全大检查情况表
  64. */
  65. private String templateName = "chkSafeStatList.xls";
  66. /**
  67. * 机构 区域 服务
  68. */
  69. @Autowired
  70. private OlBisInspOrgService olBisInspOrgService;
  71. @Autowired
  72. private AttAdBaseService attAdBaseService;
  73. /**
  74. * 新增/编辑成都市水务行业安全大检查情况统计单表
  75. */
  76. @ApiOperation(value = "修改")
  77. @RequestMapping(value = "/", method = RequestMethod.POST)
  78. public BaseResponse insert(@ApiParam(name = "chkSafeStatList", value = "ChkSafeStatList", required = true)
  79. @RequestBody ChkSafeStatList chkSafeStatList) {
  80. int ret = 0;
  81. if (StringUtils.isBlank(chkSafeStatList.getId())) {
  82. chkSafeStatList.setOrgId(getCurrentOrgId());
  83. chkSafeStatList.setPersId(getCurrentPersId());
  84. chkSafeStatList.setAdCode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  85. //填报状态 1新增 2上报
  86. chkSafeStatList.setFillRepoStat("1");
  87. ret = chkSafeStatListService.insert(chkSafeStatList);
  88. } else {
  89. ret = chkSafeStatListService.update(chkSafeStatList);
  90. }
  91. return buildSuccessResponse(chkSafeStatList);
  92. }
  93. /**
  94. * 删除成都市水务行业安全大检查情况统计 单表
  95. */
  96. @ApiOperation(value = "根据ID删除")
  97. @RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
  98. public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  99. int ret = chkSafeStatListService.delete(id);
  100. return buildSuccessResponse();
  101. }
  102. @ApiOperation(value = "更新成都市水务行业安全大检查情况统计表")
  103. @RequestMapping(value = "/update", method = RequestMethod.POST)
  104. public BaseResponse<ChkSafeStatList> update(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger", required = true) @RequestBody ChkSafeStatList chkSafeStatList) {
  105. Assert.notNull(chkSafeStatList.getId(), "主键id为必填参数");
  106. int ret = chkSafeStatListService.update(chkSafeStatList);
  107. return buildSuccessResponse(chkSafeStatList);
  108. }
  109. @ApiOperation(value = "批量上报 成都市水务行业安全大检查情况统计")
  110. @RequestMapping(value = "/report/batch", method = RequestMethod.POST)
  111. public BaseResponse<Integer> batchReport(@ApiParam(name = "ids", value = "ids", required = true) @RequestParam String[] ids) {
  112. Assert.notNull(ids, "主键id为必填参数");
  113. int ret = chkSafeStatListService.batchReportByIds(ids);
  114. return buildSuccessResponse(ret);
  115. }
  116. /**
  117. * 查询成都市水务行业安全大检查情况统计单表
  118. */
  119. @ApiOperation(value = "根据ID获取单表")
  120. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  121. public BaseResponse<ChkSafeStatList> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  122. ChkSafeStatList chkSafeStatList = chkSafeStatListService.get(id);
  123. return buildSuccessResponse(chkSafeStatList);
  124. }
  125. /**
  126. * 查询成都市水务行业安全大检查情况统计列表
  127. */
  128. @ApiOperation(value = "列表--分页")
  129. @RequestMapping(value = "/page", method = RequestMethod.POST)
  130. public BaseResponse<PageInfo> page(@ApiParam(name = "chkSafeStatListParam", value = "chkSafeStatListParam", required = true)
  131. @RequestBody ChkSafeStatListParam chkSafeStatListParam) {
  132. if (StringUtils.isBlank(chkSafeStatListParam.getAdCode())) {
  133. chkSafeStatListParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
  134. }
  135. AttAdBase attAdBase = attAdBaseService.getByAdcode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  136. // 2 省 3 市 4 县 5 乡镇 6 村
  137. if ("3".equals(attAdBase.getAdGrad())) {
  138. // 如果是市级的 只查询 上报的 1-新增; 2-上报
  139. chkSafeStatListParam.setFillRepoStat("2");
  140. }
  141. return buildSuccessResponse(chkSafeStatListService.findPageInfo(chkSafeStatListParam));
  142. }
  143. /**
  144. * 导出成都市水务行业安全大检查情况统计列表
  145. */
  146. @ApiOperation(value = "根据条件导出成都市水务行业安全大检查情况统计")
  147. @RequestMapping(value = "/export", method = RequestMethod.POST)
  148. public void export(@ApiParam(name = "chkSafeStatListParam", value = "chkSafeStatListParam")
  149. @RequestBody(required = false) ChkSafeStatListParam chkSafeStatListParam, HttpServletResponse response) {
  150. if (StringUtils.isBlank(chkSafeStatListParam.getAdCode())) {
  151. chkSafeStatListParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
  152. }
  153. AttAdBase attAdBase = attAdBaseService.getByAdcode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  154. // 2 省 3 市 4 县 5 乡镇 6 村
  155. if ("3".equals(attAdBase.getAdGrad())) {
  156. // 如果是市级的 只查询 上报的 1-新增; 2-上报
  157. chkSafeStatListParam.setFillRepoStat("2");
  158. }
  159. chkSafeStatListService.export(chkSafeStatListParam, response);
  160. }
  161. @ApiOperation(value = "下载模板")
  162. @RequestMapping(value = "/dowmTemplate", method = RequestMethod.GET)
  163. public BaseResponse dowmTemplate(HttpServletResponse response) {
  164. try {
  165. ExpAndImpUtil.downloadFile(response, templatePath + File.separator + templateName, "成都市安全生产大检查行动检查情况统计表");
  166. } catch (Exception e) {
  167. return buildFailResponse(e);
  168. }
  169. return buildSuccessResponse();
  170. }
  171. @ApiOperation("批量上报 上传xls导入数据")
  172. @RequestMapping(value = "/impExl", method = RequestMethod.POST)
  173. public BaseResponse<List<String>> impExl(@RequestParam("file") MultipartFile multfile) throws IOException, InvalidFormatException {
  174. // 获取文件名
  175. String fileName = multfile.getOriginalFilename();
  176. // 获取文件后缀
  177. String prefix = fileName.substring(fileName.lastIndexOf("."));
  178. // 用uuid作为文件名,防止生成的临时文件重复
  179. String uuid = UuidUtil.uuid();
  180. File file = File.createTempFile(uuid, prefix);
  181. // MultipartFile to File
  182. multfile.transferTo(Paths.get(file.getPath()));
  183. // 获取当前当前用户机构和行政区划
  184. String curOrgId = getCurrentOrgId();
  185. String curPersId = getCurrentPersId();
  186. List<String> resultList = new ArrayList<>();
  187. // 获取excle表格内容 忽略第1行
  188. String[][] data = ReadExcelUtil.getDataAll(file, 1, 0);
  189. try {
  190. if (data != null && data.length > 0) {
  191. Date curDate = new Date();
  192. List<ChkSafeStatListIndustry> industryList = chkSafeStatListIndustryService.findList(new ChkSafeStatListIndustryParam());
  193. List<ChkSafeStatList> safeStatLists = new ArrayList<>(data.length);
  194. for (int i = 0; i < data.length; i++) {
  195. ChkSafeStatList safeStat = new ChkSafeStatList(curDate, curPersId);
  196. if (org.apache.commons.lang3.StringUtils.isBlank(data[i][0])) {
  197. // 此行首列的 单元格为空 就认为 此行结束
  198. resultList.add("第" + (i + 2) + "行结束");
  199. break;
  200. }
  201. // 行政区域代码
  202. String adCode = data[i][0].substring(0, 12);
  203. safeStat.setOrgId(curOrgId);
  204. safeStat.setAdCode(adCode);
  205. // 报送单位
  206. safeStat.setChkSubmitDept(data[i][4]);
  207. // 行业(领域)
  208. safeStat.setChkIndustry(formatIndustryType(data[i][5], industryList));
  209. safeStat.setChkGroupNum(formatNum(data[i][6]));
  210. safeStat.setChkGroupNumUndercover(formatNum(data[i][7]));
  211. safeStat.setChkPointNum(formatNum(data[i][8]));
  212. safeStat.setInspGeneralChk(formatNum(data[i][9]));
  213. safeStat.setInspGeneralRepair(formatNum(data[i][10]));
  214. safeStat.setInspMajorChk(formatNum(data[i][11]));
  215. safeStat.setInspMajorRepair(formatNum(data[i][12]));
  216. safeStat.setDangerRectFund(data[i][13]);
  217. safeStat.setCrackDownIllegalAction(formatNum(data[i][14]));
  218. safeStat.setRepairViolateRuleAction(formatNum(data[i][15]));
  219. safeStat.setStopProdRect(formatNum(data[i][16]));
  220. safeStat.setSuspendLicense(formatNum(data[i][17]));
  221. safeStat.setShutClampDown(formatNum(data[i][18]));
  222. safeStat.setPenaltyFine(data[i][19]);
  223. safeStat.setActbExpsUnit(formatNum(data[i][20]));
  224. safeStat.setJoinPunishTrustBreakEntp(formatNum(data[i][21]));
  225. // 报送月份
  226. safeStatLists.add(safeStat);
  227. }
  228. // 批量导入
  229. this.chkSafeStatListService.insertBatchFile(safeStatLists);
  230. }
  231. } catch (Exception e) {
  232. logger.error(e.getMessage());
  233. return buildFailResponse();
  234. }
  235. return buildSuccessResponse(resultList);
  236. }
  237. private String formatIndustryType(String industryType, List<ChkSafeStatListIndustry> industryList) {
  238. try {
  239. if (StringUtils.isBlank(industryType)) {
  240. return null;
  241. }
  242. String formatStr = industryList.stream().filter(f -> industryType.equals(f.getIndustryType())).map(m -> m.getId()).collect(Collectors.joining());
  243. return formatStr;
  244. } catch (Exception e) {
  245. return null;
  246. }
  247. }
  248. private Long formatNum(String cellVal) {
  249. if (StringUtils.isBlank(cellVal)) {
  250. return 0L;
  251. }
  252. try {
  253. return Long.parseLong(cellVal);
  254. } catch (NumberFormatException e) {
  255. return 0L;
  256. }
  257. }
  258. }