4408b4772defed35cf922b3de6363466f8822509.svn-base 20 KB

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