edd5f3acd722d7e6b62678cc36a12a69a037b700.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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.ChkSafeSelsProj;
  6. import cn.com.goldenwater.dcproj.model.ChkSafeSpvsEnforceLawStat;
  7. import cn.com.goldenwater.dcproj.param.ChkSafeSelsProjParam;
  8. import cn.com.goldenwater.dcproj.param.ChkSafeSpvsEnforceLawStatParam;
  9. import cn.com.goldenwater.dcproj.service.AttAdBaseService;
  10. import cn.com.goldenwater.dcproj.service.ChkSafeSelsProjService;
  11. import cn.com.goldenwater.dcproj.service.ChkSafeSpvsEnforceLawStatService;
  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/spvs/enforce/law/stat")
  47. public class ChkSafeSpvsEnforceLawStatController extends BaseController {
  48. private Logger logger = LoggerFactory.getLogger(getClass());
  49. /**
  50. * 成都市水务安全生产'护安'监管执法专项行动统计汇总 服务
  51. */
  52. @Autowired
  53. private ChkSafeSpvsEnforceLawStatService chkSafeSpvsEnforceLawStatService;
  54. /**
  55. * 项目类型
  56. */
  57. @Autowired
  58. private ChkSafeSelsProjService chkSafeSelsProjService;
  59. /**
  60. * 机构 区域 服务
  61. */
  62. @Autowired
  63. private OlBisInspOrgService olBisInspOrgService;
  64. @Autowired
  65. private AttAdBaseService attAdBaseService;
  66. @Value("${export.templatePath}")
  67. private String templatePath;
  68. /**
  69. * 上传模板名称
  70. * 监管执法专项行动 统计汇总表
  71. */
  72. private String templateName = "chkSafeSpvsEnforceLawStat.xls";
  73. /**
  74. * 新增/编辑成都市水务安全生产'护安'监管执法专项行动统计汇总单表
  75. */
  76. @ApiOperation(value = "修改")
  77. @RequestMapping(value = "/", method = RequestMethod.POST)
  78. public BaseResponse insert(@ApiParam(name = "chkSafeSpvsEnforceLawStat", value = "ChkSafeSpvsEnforceLawStat", required = true)
  79. @RequestBody ChkSafeSpvsEnforceLawStat chkSafeSpvsEnforceLawStat) {
  80. int ret = 0;
  81. if (StringUtils.isBlank(chkSafeSpvsEnforceLawStat.getId())) {
  82. chkSafeSpvsEnforceLawStat.setOrgId(getCurrentOrgId());
  83. chkSafeSpvsEnforceLawStat.setPersId(getCurrentPersId());
  84. chkSafeSpvsEnforceLawStat.setAdCode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  85. ret = chkSafeSpvsEnforceLawStatService.insert(chkSafeSpvsEnforceLawStat);
  86. } else {
  87. ret = chkSafeSpvsEnforceLawStatService.update(chkSafeSpvsEnforceLawStat);
  88. }
  89. return buildSuccessResponse(chkSafeSpvsEnforceLawStat);
  90. }
  91. /**
  92. * 删除成都市水务安全生产'护安'监管执法专项行动统计汇总 单表
  93. */
  94. @ApiOperation(value = "根据ID删除")
  95. @RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
  96. public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  97. int ret = chkSafeSpvsEnforceLawStatService.delete(id);
  98. return buildSuccessResponse();
  99. }
  100. @ApiOperation(value = "更新成都市水务安全生产'护安'监管执法专项行动统计汇总表")
  101. @RequestMapping(value = "/update", method = RequestMethod.POST)
  102. public BaseResponse<ChkSafeSpvsEnforceLawStat> update(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger", required = true) @RequestBody ChkSafeSpvsEnforceLawStat chkSafeSpvsEnforceLawStat) {
  103. Assert.notNull(chkSafeSpvsEnforceLawStat.getId(), "主键id为必填参数");
  104. int ret = chkSafeSpvsEnforceLawStatService.update(chkSafeSpvsEnforceLawStat);
  105. return buildSuccessResponse(chkSafeSpvsEnforceLawStat);
  106. }
  107. @ApiOperation(value = "批量上报 成都市水务安全生产'护安'监管执法专项行动统计汇总")
  108. @RequestMapping(value = "/report/batch", method = RequestMethod.POST)
  109. public BaseResponse<Integer> batchReport(@ApiParam(name = "ids", value = "ids", required = true) @RequestParam String[] ids) {
  110. Assert.notNull(ids, "主键id为必填参数");
  111. int ret = chkSafeSpvsEnforceLawStatService.batchReportByIds(ids);
  112. return buildSuccessResponse(ret);
  113. }
  114. /**
  115. * 查询成都市水务安全生产'护安'监管执法专项行动统计汇总单表
  116. */
  117. @ApiOperation(value = "根据ID获取单表")
  118. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  119. public BaseResponse<ChkSafeSpvsEnforceLawStat> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  120. ChkSafeSpvsEnforceLawStat chkSafeSpvsEnforceLawStat = chkSafeSpvsEnforceLawStatService.get(id);
  121. return buildSuccessResponse(chkSafeSpvsEnforceLawStat);
  122. }
  123. /**
  124. * 查询成都市水务安全生产'护安'监管执法专项行动统计汇总列表
  125. */
  126. @ApiOperation(value = "列表--分页")
  127. @RequestMapping(value = "/page", method = RequestMethod.POST)
  128. public BaseResponse<PageInfo> page(@ApiParam(name = "chkSafeSpvsEnforceLawStatParam", value = "chkSafeSpvsEnforceLawStatParam", required = true)
  129. @RequestBody ChkSafeSpvsEnforceLawStatParam chkSafeSpvsEnforceLawStatParam) {
  130. if (StringUtils.isBlank(chkSafeSpvsEnforceLawStatParam.getAdCode())) {
  131. chkSafeSpvsEnforceLawStatParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
  132. }
  133. AttAdBase attAdBase = attAdBaseService.getByAdcode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  134. // 2 省 3 市 4 县 5 乡镇 6 村
  135. if ("3".equals(attAdBase.getAdGrad())) {
  136. // 如果是市级的 只查询 上报的 1-新增; 2-上报
  137. chkSafeSpvsEnforceLawStatParam.setFillRepoStat("2");
  138. }
  139. return buildSuccessResponse(chkSafeSpvsEnforceLawStatService.findPageInfo(chkSafeSpvsEnforceLawStatParam));
  140. }
  141. /**
  142. * 导出成都市水务安全生产'护安'监管执法专项行动统计汇总列表
  143. */
  144. @ApiOperation(value = "根据条件导出成都市水务安全生产'护安'监管执法专项行动统计汇总")
  145. @RequestMapping(value = "/export", method = RequestMethod.POST)
  146. public void export(@ApiParam(name = "chkSafeSpvsEnforceLawStatParam", value = "chkSafeSpvsEnforceLawStatParam")
  147. @RequestBody(required = false) ChkSafeSpvsEnforceLawStatParam chkSafeSpvsEnforceLawStatParam,
  148. HttpServletResponse response) {
  149. if (StringUtils.isBlank(chkSafeSpvsEnforceLawStatParam.getAdCode())) {
  150. chkSafeSpvsEnforceLawStatParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
  151. }
  152. AttAdBase attAdBase = attAdBaseService.getByAdcode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  153. // 2 省 3 市 4 县 5 乡镇 6 村
  154. if ("3".equals(attAdBase.getAdGrad())) {
  155. // 如果是市级的 只查询 上报的 1-新增; 2-上报
  156. chkSafeSpvsEnforceLawStatParam.setFillRepoStat("2");
  157. }
  158. chkSafeSpvsEnforceLawStatService.export(chkSafeSpvsEnforceLawStatParam, response);
  159. }
  160. @ApiOperation(value = "下载模板")
  161. @RequestMapping(value = "/dowmTemplate", method = RequestMethod.GET)
  162. public BaseResponse dowmTemplate(HttpServletResponse response) {
  163. try {
  164. ExpAndImpUtil.downloadFile(response, templatePath + File.separator + templateName, "成都市水务安全生产”护安2023“监管执法专项行动统计汇总表");
  165. } catch (Exception e) {
  166. return buildFailResponse(e);
  167. }
  168. return buildSuccessResponse();
  169. }
  170. @ApiOperation("批量上报 上传xls导入数据")
  171. @RequestMapping(value = "/impExl", method = RequestMethod.POST)
  172. public BaseResponse<List<String>> impExl(@RequestParam("file") MultipartFile multfile) throws IOException, InvalidFormatException {
  173. // 获取文件名
  174. String fileName = multfile.getOriginalFilename();
  175. // 获取文件后缀
  176. String prefix = fileName.substring(fileName.lastIndexOf("."));
  177. // 用uuid作为文件名,防止生成的临时文件重复
  178. String uuid = UuidUtil.uuid();
  179. File file = File.createTempFile(uuid, prefix);
  180. // MultipartFile to File
  181. multfile.transferTo(Paths.get(file.getPath()));
  182. // 获取当前当前用户机构和行政区划
  183. String curOrgId = getCurrentOrgId();
  184. String curPersId = getCurrentPersId();
  185. List<String> resultList = new ArrayList<>();
  186. // 获取excle表格内容 忽略第1行
  187. String[][] data = ReadExcelUtil.getDataAll(file, 1, 0);
  188. try {
  189. if (data != null && data.length > 0) {
  190. Date curDate = new Date();
  191. List<ChkSafeSelsProj> projList = chkSafeSelsProjService.findList(new ChkSafeSelsProjParam());
  192. List<ChkSafeSpvsEnforceLawStat> safeSpvsEnforceLawStatList = new ArrayList<>(data.length);
  193. for (int i = 0; i < data.length; i++) {
  194. ChkSafeSpvsEnforceLawStat cssels = new ChkSafeSpvsEnforceLawStat(curDate, curPersId);
  195. if (org.apache.commons.lang3.StringUtils.isBlank(data[i][0])) {
  196. // 此行首列的 单元格为空 就认为 此行结束
  197. resultList.add("第" + (i + 2) + "行结束");
  198. break;
  199. }
  200. // 行政区域代码
  201. String adCode = data[i][0].substring(0, 12);
  202. cssels.setOrgId(curOrgId);
  203. cssels.setAdCode(adCode);
  204. // 报送单位
  205. cssels.setChkSubmitDept(data[i][4]);
  206. // 项目类型
  207. cssels.setChkProjType(formatProjType(data[i][5], projList));
  208. cssels.setChkProjSubType(formatProjType(data[i][6], projList));
  209. cssels.setChkGroupNum(formatNum(data[i][7]));
  210. cssels.setChkPersTime(formatNum(data[i][8]));
  211. cssels.setChkSafeExpertTime(formatNum(data[i][9]));
  212. cssels.setChkUnitNum(formatNum(data[i][10]));
  213. cssels.setChkFindDangerTotalNum(formatNum(data[i][11]));
  214. cssels.setChkFindDangerGeneralNum(formatNum(data[i][12]));
  215. cssels.setChkFindDangerMajorNum(formatNum(data[i][13]));
  216. cssels.setChkRectDangerTotalNum(formatNum(data[i][14]));
  217. cssels.setChkRectDangerGeneralNum(formatNum(data[i][15]));
  218. cssels.setChkRectDangerMajorNum(formatNum(data[i][16]));
  219. cssels.setSceneEmergencyDisposal(formatNum(data[i][17]));
  220. cssels.setPenaltyRecord(formatNum(data[i][18]));
  221. cssels.setPenaltyImposeFine(data[i][19]);
  222. cssels.setPenaltyShutProd(formatNum(data[i][20]));
  223. cssels.setPenaltySuspendLicense(formatNum(data[i][21]));
  224. cssels.setIssueEnforceLawWrit(formatNum(data[i][22]));
  225. cssels.setInformExposeFreq(formatNum(data[i][23]));
  226. cssels.setHandOverCaseGeneral(formatNum(data[i][24]));
  227. cssels.setHandOverCaseMajor(formatNum(data[i][25]));
  228. safeSpvsEnforceLawStatList.add(cssels);
  229. }
  230. // 批量导入
  231. this.chkSafeSpvsEnforceLawStatService.insertBatchFile(safeSpvsEnforceLawStatList);
  232. }
  233. } catch (Exception e) {
  234. logger.error(e.getMessage());
  235. return buildFailResponse();
  236. }
  237. return buildSuccessResponse(resultList);
  238. }
  239. private String formatProjType(String projType, List<ChkSafeSelsProj> projList) {
  240. try {
  241. if (StringUtils.isBlank(projType)) {
  242. return null;
  243. }
  244. String formatStr = projList.stream().filter(f -> projType.equals(f.getProjType())).map(m -> m.getId()).collect(Collectors.joining());
  245. return formatStr;
  246. } catch (Exception e) {
  247. return null;
  248. }
  249. }
  250. private Long formatNum(String cellVal) {
  251. if (StringUtils.isBlank(cellVal)) {
  252. return 0L;
  253. }
  254. try {
  255. return Long.parseLong(cellVal);
  256. } catch (NumberFormatException e) {
  257. return 0L;
  258. }
  259. }
  260. }