3ecea76c1d106727825967defbff48304736d5eb.svn-base 14 KB

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