c69caddbd51802ead54fb7f2b9c03ea248671a92.svn-base 13 KB

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