7b62a8d704c267ed3ac6620d24794a5f35f49a47.svn-base 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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.ChkSafeProdLedger;
  6. import cn.com.goldenwater.dcproj.model.ChkSafeSelsProj;
  7. import cn.com.goldenwater.dcproj.param.ChkSafeSelsProjParam;
  8. import cn.com.goldenwater.dcproj.service.AttAdBaseService;
  9. import cn.com.goldenwater.dcproj.service.ChkSafeProdLedgerService;
  10. import cn.com.goldenwater.dcproj.service.ChkSafeSelsProjService;
  11. import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
  12. import cn.com.goldenwater.dcproj.util.ReadExcelUtil;
  13. import cn.com.goldenwater.dcproj.utils.AdLevelUtil;
  14. import cn.com.goldenwater.dcproj.utils.StringUtils;
  15. import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
  16. import cn.com.goldenwater.id.util.UuidUtil;
  17. import com.github.pagehelper.PageInfo;
  18. import io.swagger.annotations.Api;
  19. import io.swagger.annotations.ApiOperation;
  20. import io.swagger.annotations.ApiParam;
  21. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.beans.factory.annotation.Value;
  26. import org.springframework.util.Assert;
  27. import org.springframework.web.bind.annotation.*;
  28. import org.springframework.web.multipart.MultipartFile;
  29. import javax.servlet.http.HttpServletResponse;
  30. import java.io.File;
  31. import java.io.IOException;
  32. import java.nio.file.Paths;
  33. import java.text.ParseException;
  34. import java.time.LocalDateTime;
  35. import java.util.*;
  36. import java.util.stream.Collectors;
  37. /**
  38. * @author zyd
  39. * @date 2022-6-2
  40. */
  41. @Api(value = "成都市水务局安全生产监督检查台账", tags = "成都市水务局安全生产监督检查台账")
  42. @RestController
  43. @RequestMapping("/chk/safe/prod/ledger")
  44. public class ChkSafeProdLedgerController extends BaseController {
  45. private Logger logger = LoggerFactory.getLogger(getClass());
  46. @Autowired
  47. private ChkSafeProdLedgerService chkSafeProdLedgerService;
  48. @Autowired
  49. private OlBisInspOrgService olBisInspOrgService;
  50. @Autowired
  51. private AttAdBaseService attAdBaseService;
  52. /**
  53. * 项目类型
  54. */
  55. @Autowired
  56. private ChkSafeSelsProjService chkSafeSelsProjService;
  57. @Value("${export.templatePath}")
  58. private String templatePath;
  59. private String[] parsePatterns = {
  60. "yyyy-M", "yyyy-M-d", "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM-dd HH", "yyyy-MM", "yyyy",
  61. "yyyy/M", "yyyy/M/d", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy-MM-dd HH", "yyyy/MM", "HH:mm:ss",
  62. "yyyy.M", "yyyy.M.d", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy-MM-dd HH", "yyyy.MM", "HH:mm",
  63. "yyyy年MM月dd日", "yyyy年MM月dd日HH时mm分ss秒", "yyyy年MM月dd日HH时mm分", "yyyy年MM月dd日HH时", "yyyy年MM月", "HH时mm分",
  64. "yyyy年M月d日", "yyyy年M月d日H时m分s秒", "yyyy年M月d日H时m分", "yyyy年M月d日H时", "yyyy年M月", "H时m分"};
  65. /**
  66. * 上传模板名称
  67. * 安全生产监督检查台账
  68. */
  69. private String templateName = "chkSafeProdLedger.xls";
  70. @ApiOperation(value = "添加安全生产监督检查台账-基础表")
  71. @RequestMapping(value = "/", method = RequestMethod.POST)
  72. public BaseResponse<ChkSafeProdLedger> insert(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger", required = true) @RequestBody ChkSafeProdLedger chkSafeProdLedger) {
  73. if (StringUtils.isBlank(chkSafeProdLedger.getId())) {
  74. chkSafeProdLedger.setOrgId(getCurrentOrgId());
  75. chkSafeProdLedger.setPersId(getCurrentPersId());
  76. chkSafeProdLedger.setAdCode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  77. //填报状态 1新增 2上报
  78. chkSafeProdLedger.setFillRepoStat("1");
  79. int ret = chkSafeProdLedgerService.insert(chkSafeProdLedger);
  80. } else {
  81. int ret = chkSafeProdLedgerService.update(chkSafeProdLedger);
  82. }
  83. return buildSuccessResponse(chkSafeProdLedger);
  84. }
  85. @ApiOperation(value = "根据ID删除安全生产监督检查台账-基础表")
  86. @RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
  87. public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  88. int ret = chkSafeProdLedgerService.delete(id);
  89. return buildSuccessResponse();
  90. }
  91. @ApiOperation(value = "更新安全生产监督检查台账-基础表信息")
  92. @RequestMapping(value = "/update", method = RequestMethod.POST)
  93. public BaseResponse<ChkSafeProdLedger> update(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger", required = true) @RequestBody ChkSafeProdLedger chkSafeProdLedger) {
  94. Assert.notNull(chkSafeProdLedger.getId(), "主键id为必填参数");
  95. int ret = chkSafeProdLedgerService.update(chkSafeProdLedger);
  96. return buildSuccessResponse(chkSafeProdLedger);
  97. }
  98. @ApiOperation(value = "批量上报")
  99. @RequestMapping(value = "/report/batch", method = RequestMethod.POST)
  100. public BaseResponse<Integer> batchReport(@ApiParam(name = "ids", value = "ids", required = true) @RequestParam String[] ids) {
  101. Assert.notNull(ids, "主键id为必填参数");
  102. int ret = chkSafeProdLedgerService.batchReportByIds(ids);
  103. return buildSuccessResponse(ret);
  104. }
  105. @ApiOperation(value = "根据ID获取安全生产监督检查台账-基础表(单表)")
  106. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  107. public BaseResponse<ChkSafeProdLedger> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  108. ChkSafeProdLedger attRdwpgdBase = chkSafeProdLedgerService.get(id);
  109. return buildSuccessResponse(attRdwpgdBase);
  110. }
  111. @ApiOperation(value = "获取列表数据")
  112. @RequestMapping(value = "/page", method = RequestMethod.POST)
  113. public BaseResponse<PageInfo> findPcPage(@RequestBody ChkSafeProdLedger chkSafeProdLedger) {
  114. if (StringUtils.isBlank(chkSafeProdLedger.getAdCode())) {
  115. chkSafeProdLedger.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
  116. }
  117. AttAdBase attAdBase = attAdBaseService.getByAdcode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  118. // 2 省 3 市 4 县 5 乡镇 6 村
  119. if ("3".equals(attAdBase.getAdGrad())) {
  120. // 如果是市级的 只查询 上报的 1-新增; 2-上报
  121. chkSafeProdLedger.setFillRepoStat("2");
  122. }
  123. PageInfo<ChkSafeProdLedger> pageInfo = chkSafeProdLedgerService.findPageInfo(chkSafeProdLedger);
  124. return buildSuccessResponse(pageInfo);
  125. }
  126. @ApiOperation(value = "市级获取区/县列表数据")
  127. @RequestMapping(value = "/page/sub", method = RequestMethod.POST)
  128. public BaseResponse<PageInfo> findSubPcPage(@RequestBody ChkSafeProdLedger chkSafeProdLedger) {
  129. if (StringUtils.isBlank(chkSafeProdLedger.getAdCode())) {
  130. chkSafeProdLedger.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
  131. }
  132. // 市级的 只查询 上报的 1-新增; 2-上报
  133. chkSafeProdLedger.setFillRepoStat("2");
  134. PageInfo<ChkSafeProdLedger> pageInfo = chkSafeProdLedgerService.findPageInfo(chkSafeProdLedger);
  135. return buildSuccessResponse(pageInfo);
  136. }
  137. @ApiOperation(value = "获取市级汇总列表数据")
  138. @RequestMapping(value = "/page/summary", method = RequestMethod.POST)
  139. public BaseResponse<PageInfo> findPcCityPage(@RequestBody ChkSafeProdLedger chkSafeProdLedger) {
  140. chkSafeProdLedger.setOrgId(getCurrentOrgId());
  141. PageInfo<Map<String, Object>> pageInfo = chkSafeProdLedgerService.findSummaryPage(chkSafeProdLedger);
  142. return buildSuccessResponse(pageInfo);
  143. }
  144. @ApiOperation(value = "获取当前账户是否是县")
  145. @RequestMapping(value = "/getIsCounty", method = RequestMethod.GET)
  146. public BaseResponse<Boolean> getIsCounty() {
  147. AttAdBase attAdBase = attAdBaseService.getByAdcode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  148. // 2 省 3 市 4 县 5 乡镇 6 村
  149. if ("4".equals(attAdBase.getAdGrad())) {
  150. return buildSuccessResponse(true);
  151. }
  152. return buildSuccessResponse(false);
  153. }
  154. @ApiOperation(value = "下载模板")
  155. @RequestMapping(value = "/dowmTemplate", method = RequestMethod.GET)
  156. public BaseResponse dowmTemplate(HttpServletResponse response) {
  157. try {
  158. ExpAndImpUtil.downloadFile(response, templatePath + File.separator + templateName, "成都市水务局安全生产监督检查台账");
  159. } catch (Exception e) {
  160. return buildFailResponse(e);
  161. }
  162. return buildSuccessResponse();
  163. }
  164. @ApiOperation("批量上报 上传xls导入数据")
  165. @RequestMapping(value = "/impExl", method = RequestMethod.POST)
  166. public BaseResponse<List<String>> impExl(@RequestParam("file") MultipartFile multfile) throws IOException, InvalidFormatException {
  167. // 获取文件名
  168. String fileName = multfile.getOriginalFilename();
  169. // 获取文件后缀
  170. String prefix = fileName.substring(fileName.lastIndexOf("."));
  171. // 用uuid作为文件名,防止生成的临时文件重复
  172. String uuid = UuidUtil.uuid();
  173. File file = File.createTempFile(uuid, prefix);
  174. // MultipartFile to File
  175. multfile.transferTo(Paths.get(file.getPath()));
  176. // 获取当前当前用户机构和行政区划
  177. String curOrgId = getCurrentOrgId();
  178. String curPersId = getCurrentPersId();
  179. // 台账导入 默认当前用户的行政区域代码
  180. String adCode = olBisInspOrgService.getRlProvince(getCurrentOrgId());
  181. List<String> resultList = new ArrayList<>();
  182. // 获取excle表格内容 忽略第1行
  183. String[][] data = ReadExcelUtil.getDataAll(file, 1, 0);
  184. try {
  185. if (data != null && data.length > 0) {
  186. // 填报单位
  187. String submitDept = data[0][4];
  188. if (StringUtils.isBlank(submitDept)) {
  189. logger.error("填报单位为空");
  190. resultList.add("第" + (2) + "行填报单位不能为空");
  191. return buildSuccessResponse(resultList);
  192. }
  193. submitDept = submitDept.trim();
  194. // 报送月份 填报日期 不需要了
  195. Calendar newTime = Calendar.getInstance();
  196. // 项目类型
  197. List<ChkSafeSelsProj> projList = this.chkSafeSelsProjService.queryLedgerSelectOptions(null);
  198. List<ChkSafeProdLedger> prodLedgerList = new ArrayList<>(data.length);
  199. for (int i = 2; i < data.length; i++) {
  200. newTime.add(Calendar.SECOND, 10);
  201. ChkSafeProdLedger chkSafeProdLedger = new ChkSafeProdLedger(curOrgId, adCode, submitDept, newTime.getTime(), curPersId);
  202. if (org.apache.commons.lang3.StringUtils.isBlank(data[i][0])) {
  203. // 此行首列的 单元格为空 就认为 此行结束
  204. resultList.add("第" + (i + 2) + "行结束");
  205. break;
  206. }
  207. // 检查日期 必填
  208. chkSafeProdLedger.setChkDttm(parseDate(data[i][1], null));
  209. // 检查单位 必填
  210. chkSafeProdLedger.setLeadDep(data[i][2]);
  211. // 检查单位负责人 必填
  212. chkSafeProdLedger.setLeadDepRespPers(data[i][3]);
  213. // 项目类型 必填
  214. chkSafeProdLedger.setChkProjType(formatProjType(data[i][4], projList));
  215. // 被检查单位(项目)必填
  216. chkSafeProdLedger.setChkOrg(data[i][5]);
  217. // 被检查单位负责人 非必填
  218. chkSafeProdLedger.setChkOrgRespPers(data[i][6]);
  219. // 被检查单位负责人电话 非必填
  220. chkSafeProdLedger.setChkOrgRespPersMobi(data[i][7]);
  221. // 检查结果 必填
  222. chkSafeProdLedger.setChkResult(formatChkResult(data[i][8]));
  223. // 隐患问题 检查结果--未发现隐患 无需填报 非必填
  224. chkSafeProdLedger.setChkDgerPblm(data[i][9]);
  225. // 处理意见 检查结果--未发现隐患 无需填报 非必填
  226. chkSafeProdLedger.setChkHandSugg(data[i][10]);
  227. // 整改时限 检查结果--未发现隐患 无需填报 非必填
  228. chkSafeProdLedger.setChkHandEdtm(parseDate(data[i][11], null));
  229. // 整改落实情况 检查结果--未发现隐患 无需填报 非必填
  230. chkSafeProdLedger.setChkRectImplInfo(formatChkRectImplInfo(data[i][12]));
  231. // 整改落实情况说明 检查结果--未发现隐患 无需填报 非必填
  232. chkSafeProdLedger.setChkRectImplInfoDesc(data[i][13]);
  233. // 整改验收时间 检查结果--未发现隐患 无需填报 非必填
  234. chkSafeProdLedger.setChkAcceTm(parseDate(data[i][14], null));
  235. // 整改验收人 检查结果--未发现隐患 无需填报 非必填
  236. chkSafeProdLedger.setChkAccePers(data[i][15]);
  237. // 报送单位
  238. chkSafeProdLedger.setChkFillUnit(data[i][16]);
  239. prodLedgerList.add(chkSafeProdLedger);
  240. }
  241. // 批量导入
  242. this.chkSafeProdLedgerService.insertBatchFile(prodLedgerList);
  243. }
  244. } catch (Exception e) {
  245. logger.error(e.getMessage());
  246. return buildFailResponse();
  247. }
  248. return buildSuccessResponse(resultList);
  249. }
  250. private String formatProjType(String projType, List<ChkSafeSelsProj> projList) {
  251. try {
  252. if (StringUtils.isBlank(projType)) {
  253. return null;
  254. }
  255. String formatStr = projList.stream().filter(f -> projType.equals(f.getProjType())).map(m -> m.getId()).collect(Collectors.joining());
  256. return formatStr;
  257. } catch (Exception e) {
  258. return null;
  259. }
  260. }
  261. private String formatChkRectImplInfo(String chkRectImplInfo) {
  262. switch (chkRectImplInfo) {
  263. case "未整改":
  264. chkRectImplInfo = "0";
  265. break;
  266. case "正在整改":
  267. chkRectImplInfo = "1";
  268. break;
  269. case "完成整改":
  270. chkRectImplInfo = "2";
  271. break;
  272. default:
  273. break;
  274. }
  275. return chkRectImplInfo;
  276. }
  277. private String formatChkResult(String chkResult) {
  278. switch (chkResult) {
  279. case "无隐患":
  280. chkResult = "0";
  281. break;
  282. case "有隐患":
  283. chkResult = "1";
  284. break;
  285. default:
  286. break;
  287. }
  288. return chkResult;
  289. }
  290. /**
  291. * 导出成都市水务局安全生产监督检查台账
  292. */
  293. @ApiOperation(value = "根据条件导出成都市水务局安全生产监督检查台账")
  294. @RequestMapping(value = "/export", method = RequestMethod.POST)
  295. public void export(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger")
  296. @RequestBody(required = false) ChkSafeProdLedger chkSafeProdLedger,
  297. HttpServletResponse response) {
  298. if (StringUtils.isBlank(chkSafeProdLedger.getAdCode())) {
  299. chkSafeProdLedger.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
  300. }
  301. AttAdBase attAdBase = attAdBaseService.getByAdcode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  302. // 2 省 3 市 4 县 5 乡镇 6 村
  303. if ("3".equals(attAdBase.getAdGrad())) {
  304. // 如果是市级的 只查询 上报的 1-新增; 2-上报
  305. chkSafeProdLedger.setFillRepoStat("2");
  306. }
  307. chkSafeProdLedgerService.export(chkSafeProdLedger, response);
  308. }
  309. /**
  310. * 导出成都市水务局安全生产监督检查台账
  311. * 市级账号 导出 区县数据
  312. */
  313. @ApiOperation(value = "根据条件导出成都市水务局安全生产监督检查台账")
  314. @RequestMapping(value = "/export/sub", method = RequestMethod.POST)
  315. public void exportSub(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger")
  316. @RequestBody(required = false) ChkSafeProdLedger chkSafeProdLedger,
  317. HttpServletResponse response) {
  318. if (StringUtils.isBlank(chkSafeProdLedger.getAdCode())) {
  319. chkSafeProdLedger.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
  320. }
  321. chkSafeProdLedger.setFillRepoStat("2");
  322. chkSafeProdLedgerService.export(chkSafeProdLedger, response);
  323. }
  324. /**
  325. * 导出成都市水务局安全生产监督检查台账
  326. */
  327. @ApiOperation(value = "根据条件导出成都市水务局安全生产监督检查台账")
  328. @RequestMapping(value = "/export/summary", method = RequestMethod.POST)
  329. public void exportSummary(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger")
  330. @RequestBody(required = false) ChkSafeProdLedger chkSafeProdLedger,
  331. HttpServletResponse response) {
  332. String curOrgId = getCurrentOrgId();
  333. chkSafeProdLedger.setOrgId(curOrgId);
  334. chkSafeProdLedgerService.exportSummary(chkSafeProdLedger, response);
  335. }
  336. /**
  337. * 日期型字符串转化为日期 格式
  338. */
  339. private Date parseDate(Object str, String... curParsePatterns) {
  340. if (str == null || StringUtils.isBlank(str.toString())) {
  341. return null;
  342. }
  343. try {
  344. if (null == curParsePatterns) {
  345. return org.apache.commons.lang3.time.DateUtils.parseDate(str.toString(), parsePatterns);
  346. } else {
  347. return org.apache.commons.lang3.time.DateUtils.parseDate(str.toString(), curParsePatterns);
  348. }
  349. } catch (ParseException e) {
  350. return null;
  351. }
  352. }
  353. private LocalDateTime convertDateToLocalDateTime(Date date) {
  354. Calendar calendar = Calendar.getInstance();
  355. calendar.setTime(date);
  356. LocalDateTime localDateTime = LocalDateTime.of(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
  357. return localDateTime;
  358. }
  359. /**
  360. * 查询 安全生产监督检查台账的 项目类型
  361. */
  362. @ApiOperation(value = "下来框列表")
  363. @RequestMapping(value = "/proj/type/selectOptions", method = RequestMethod.POST)
  364. public BaseResponse<List<ChkSafeSelsProj>> querySelectOptions(@ApiParam(name = "chkSafeSelsProjParam", value = "chkSafeSelsProjParam", required = false)
  365. @RequestBody(required = false) ChkSafeSelsProjParam chkSafeSelsProjParam) {
  366. return buildSuccessResponse(chkSafeSelsProjService.queryLedgerSelectOptions(chkSafeSelsProjParam));
  367. }
  368. }