6e8b771300a5d6b5d1e79ea3ee8d6ac7ad3a6a11.svn-base 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. package cn.com.goldenwater.dcproj.controller.pblm;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.core.web.BaseResponse;
  4. import cn.com.goldenwater.dcproj.dao.ObjInspPblmsDao;
  5. import cn.com.goldenwater.dcproj.dto.ObjInspPblmsDto;
  6. import cn.com.goldenwater.dcproj.model.ObjInspPblms;
  7. import cn.com.goldenwater.dcproj.model.ObjTypeCheck;
  8. import cn.com.goldenwater.dcproj.model.OlBisInspOrg;
  9. import cn.com.goldenwater.dcproj.param.ObjInspPblmsParam;
  10. import cn.com.goldenwater.dcproj.param.ObjInspPblmsParams;
  11. import cn.com.goldenwater.dcproj.param.WagaPblm;
  12. import cn.com.goldenwater.dcproj.service.BisInspPblmPService;
  13. import cn.com.goldenwater.dcproj.service.ObjInspPblmsService;
  14. import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
  15. import cn.com.goldenwater.dcproj.util.ReadExcelUtil;
  16. import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
  17. import cn.com.goldenwater.id.util.UuidUtil;
  18. import cn.com.goldenwater.target.CheckException;
  19. import io.swagger.annotations.Api;
  20. import io.swagger.annotations.ApiOperation;
  21. import io.swagger.annotations.ApiParam;
  22. import org.apache.commons.lang3.StringUtils;
  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.util.Assert;
  29. import org.springframework.web.bind.annotation.*;
  30. import org.springframework.web.multipart.MultipartFile;
  31. import javax.servlet.http.HttpServletRequest;
  32. import javax.servlet.http.HttpServletResponse;
  33. import java.io.File;
  34. import java.io.IOException;
  35. import java.nio.file.Paths;
  36. import java.util.*;
  37. import static cn.com.goldenwater.dcproj.util.CheckUtil.check;
  38. /**
  39. * @author lune
  40. * @date 2019-2-18
  41. */
  42. @Api(value = "小水库督查问题分类标准库", tags = "小水库督查问题分类标准库")
  43. @RestController
  44. @RequestMapping("/dc/insp/pblms")
  45. public class ObjInspPblmsController extends BaseController {
  46. private Logger logger = LoggerFactory.getLogger(getClass());
  47. @Value("${export.templatePath}")
  48. private String templatePath;
  49. @Autowired
  50. private ObjInspPblmsService objInspPblmsService;
  51. @Autowired
  52. private OlBisInspOrgService olBisInspOrgService;
  53. @Autowired
  54. private BisInspPblmPService bisInspPblmPService;
  55. @ApiOperation(value = "添加问题分类标准库")
  56. @RequestMapping(value = "", method = RequestMethod.POST)
  57. public BaseResponse<String> insert(@ApiParam(name = "objInspPblms", value = "ObjInspPblms", required = true) @RequestBody ObjInspPblms objInspPblms) {
  58. if (StringUtils.isBlank(objInspPblms.getType()) || StringUtils.isBlank(objInspPblms.getInspPblmsName())) {
  59. return buildFailResponse("请选择问题类别或填写问题名称!!");
  60. }
  61. String uuid = UuidUtil.uuid();
  62. objInspPblms.setGuid(uuid);
  63. if (StringUtils.isBlank(objInspPblms.getPguid())) {
  64. objInspPblms.setPguid("00000000000000000000000000000000");
  65. }
  66. objInspPblms.setAttach("1");
  67. objInspPblms.setSnClass("1");
  68. int ret = objInspPblmsService.insert(objInspPblms);
  69. return buildSuccessResponse(uuid);
  70. }
  71. @ApiOperation(value = "获取问题类别")
  72. @RequestMapping(value = "/getPblmType", method = {RequestMethod.GET, RequestMethod.POST})
  73. public BaseResponse<List<ObjInspPblms>> getPblmType(ObjInspPblmsParam objInspPblmsParam) {
  74. if (StringUtils.isBlank(objInspPblmsParam.getType()) &&
  75. StringUtils.isBlank(objInspPblmsParam.getPguid())) {
  76. return buildSuccessResponse(objInspPblmsService.findList(null));
  77. }
  78. String orgId = getCurrentOrgId();
  79. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(orgId);
  80. Optional.ofNullable(olBisInspOrg).orElseThrow(() -> new CheckException("当前机构不存在!!"));
  81. if ("1".equals(olBisInspOrg.getPblmLogo()) && "1".equals(objInspPblmsParam.getType())) {
  82. objInspPblmsParam.setOrgId(olBisInspOrg.getQuoteOrgId());
  83. } else if ("22".equals(objInspPblmsParam.getType())) {
  84. objInspPblmsParam.setPguid(null);
  85. objInspPblmsParam.setOrgId(null);
  86. // if ("063".equals(orgId)) {
  87. // objInspPblmsParam.setOrgId(orgId);
  88. // }
  89. } else {
  90. objInspPblmsParam.setOrgId(null);
  91. }
  92. List<ObjInspPblms> objInspPblms;
  93. objInspPblms = objInspPblmsService.findList(objInspPblmsParam);
  94. //如果没找到问题清单,则设置通用问题清单
  95. if (objInspPblms.size() == 0) {
  96. ObjInspPblmsParam objInspPblmsParam1 = new ObjInspPblmsParam();
  97. objInspPblmsParam1.setType("111");
  98. objInspPblms = objInspPblmsService.findList(objInspPblmsParam1);
  99. for (ObjInspPblms item : objInspPblms) {
  100. item.setType(objInspPblmsParam.getType());
  101. }
  102. }
  103. return buildSuccessResponse(objInspPblms);
  104. }
  105. @ApiOperation(value = "获取问题类别")
  106. @GetMapping("/listByRgstr/{rgstrId}")
  107. public BaseResponse<List<ObjInspPblms>> listByRgstr(@PathVariable String rgstrId) {
  108. String type = bisInspPblmPService.getIdByRgstrId(rgstrId);
  109. Optional.ofNullable(type).orElseThrow(() -> new CheckException("当前注册单不存在!!"));
  110. ObjInspPblmsParam objInspPblmsParam = new ObjInspPblmsParam();
  111. objInspPblmsParam.setType(type);
  112. return getPblmType(objInspPblmsParam);
  113. }
  114. @ApiOperation(value = "获取问题类别")
  115. @GetMapping("/listByObjId/{objId}")
  116. public BaseResponse<List<ObjInspPblms>> listByObjId(@PathVariable String objId) {
  117. String type = bisInspPblmPService.getIdByObjId(objId);
  118. Optional.ofNullable(type).orElseThrow(() -> new CheckException("当前注册单不存在!!"));
  119. ObjInspPblmsParam objInspPblmsParam = new ObjInspPblmsParam();
  120. objInspPblmsParam.setType(type);
  121. return getPblmType(objInspPblmsParam);
  122. }
  123. @ApiOperation(value = "获取根据附件表问题类别")
  124. @RequestMapping(value = "/getPblmTypeInAttach", method = {RequestMethod.POST})
  125. public BaseResponse<List<ObjInspPblms>> getPblmTypeInAttach(@RequestBody ObjInspPblmsParams objInspPblms) {
  126. List<ObjInspPblms> obj = new ArrayList<>();
  127. try {
  128. obj = objInspPblmsService.getPblmTypeInAttach(objInspPblms);
  129. } catch (Exception e) {
  130. e.printStackTrace();
  131. logger.error(e.getMessage());
  132. return buildFailResponse(e.getMessage());
  133. }
  134. return buildSuccessResponse(obj);
  135. }
  136. @ApiOperation(value = "根据ID删除问题分类标准库")
  137. @RequestMapping(value = "/{id}", method = RequestMethod.POST)
  138. public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  139. int ret = objInspPblmsService.delete(id);
  140. return buildSuccessResponse();
  141. }
  142. @ApiOperation(value = "根据ID删除问题分类标准库")
  143. @RequestMapping(value = "/delete", method = RequestMethod.POST)
  144. public BaseResponse deletes(@ApiParam(name = "id", value = "id", required = true) @RequestParam String id) {
  145. if (StringUtils.isBlank(id)) {
  146. return buildFailResponse("请选择要删除的问题!");
  147. }
  148. String[] ids = id.split(",");
  149. for (String item : ids) {
  150. objInspPblmsService.delete(item);
  151. }
  152. return buildSuccessResponse();
  153. }
  154. @ApiOperation(value = "更新问题分类标准库信息")
  155. @RequestMapping(value = "/update", method = RequestMethod.POST)
  156. public BaseResponse update(@ApiParam(name = "objInspPblms", value = "ObjInspPblms", required = true) @RequestBody ObjInspPblms objInspPblms) {
  157. Assert.notNull(objInspPblms.getGuid(), "主键id为必填参数");
  158. int ret = objInspPblmsService.update(objInspPblms);
  159. return buildSuccessResponse();
  160. }
  161. @ApiOperation(value = "根据ID获取问题分类标准库(单表)")
  162. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  163. public BaseResponse<ObjInspPblms> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  164. ObjInspPblms objInspPblms = objInspPblmsService.get(id);
  165. return buildSuccessResponse(objInspPblms);
  166. }
  167. @ApiOperation(value = "获取整个标准库数据")
  168. @RequestMapping(value = "/findAll", method = RequestMethod.GET)
  169. public BaseResponse<List<ObjInspPblms>> findAll() {
  170. List<ObjInspPblms> pblmsList = objInspPblmsService.findList(null);
  171. return buildSuccessResponse(pblmsList);
  172. }
  173. @ApiOperation(value = "获取所有数据类型")
  174. @RequestMapping(value = "/getPblmsType", method = {RequestMethod.GET})
  175. public BaseResponse<List<String>> getPblmsType() {
  176. List<String> pblmsType = objInspPblmsService.findPblmsName(getCurrentOrgId());
  177. return buildSuccessResponse(pblmsType);
  178. }
  179. @ApiOperation(value = "获取所有的问题名称,去重")
  180. @RequestMapping(value = "/getPblmNames", method = RequestMethod.GET)
  181. public BaseResponse<List<String>> getPblmNames(ObjInspPblmsParam objInspPblmsParam) {
  182. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(getCurrentOrgId());
  183. if (olBisInspOrg == null) {
  184. throw new CheckException("当前机构不存在!!");
  185. }
  186. if ("1".equals(olBisInspOrg.getPblmLogo()) && "1".equals(objInspPblmsParam.getType())) {
  187. objInspPblmsParam.setOrgId(olBisInspOrg.getQuoteOrgId());
  188. } else {
  189. objInspPblmsParam.setOrgId("");
  190. }
  191. List<String> pblmNames = objInspPblmsService.getPblmNames(objInspPblmsParam);
  192. return buildSuccessResponse(pblmNames);
  193. }
  194. @ApiOperation(value = "获取所有数据检查项")
  195. @RequestMapping(value = "/getCheckPoints", method = {RequestMethod.POST})
  196. public BaseResponse<List<String>> getPblmsType(@RequestBody ObjInspPblmsParam objInspPblmsParam) {
  197. if (StringUtils.isBlank(objInspPblmsParam.getType())) {
  198. objInspPblmsParam.setType("1");
  199. }
  200. List<String> pblmsType = objInspPblmsService.findPblmsCheckPoints(objInspPblmsParam, getCurrentOrgId());
  201. return buildSuccessResponse(pblmsType);
  202. }
  203. @ApiOperation(value = "获取所有问题描述信息")
  204. @RequestMapping(value = "/getPblmsDesc", method = {RequestMethod.POST})
  205. public BaseResponse<List<String>> getPblmsDesc(@RequestBody ObjInspPblmsParam objInspPblmsParam) {
  206. if (StringUtils.isBlank(objInspPblmsParam.getType())) {
  207. objInspPblmsParam.setType("1");
  208. }
  209. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(getCurrentOrgId());
  210. if (olBisInspOrg == null) {
  211. throw new CheckException("当前机构不存在!!");
  212. }
  213. Map<String, String> params = new HashMap<>();
  214. params.put("type", objInspPblmsParam.getType());
  215. params.put("inspPblmsName", objInspPblmsParam.getInspPblmsName());
  216. params.put("checkPoint", objInspPblmsParam.getCheckPoint());
  217. if ("1".equals(olBisInspOrg.getPblmLogo()) && "1".equals(objInspPblmsParam.getType())) {
  218. params.put("orgId", olBisInspOrg.getQuoteOrgId());
  219. }
  220. List<String> pblmsType = objInspPblmsService.findPblmsDesc(params);
  221. return buildSuccessResponse(pblmsType);
  222. }
  223. @ApiOperation(value = "获取标准表单个信息")
  224. @RequestMapping(value = "/getByPblms", method = {RequestMethod.POST})
  225. public BaseResponse<ObjInspPblms> getByPblms(@RequestBody ObjInspPblmsParam objInspPblmsParam) {
  226. check(StringUtils.isNotBlank(objInspPblmsParam.getType()), "type.no");
  227. Map<String, String> params = new HashMap<>(6);
  228. params.put("inspPblmsName", objInspPblmsParam.getInspPblmsName());
  229. params.put("checkPoint", objInspPblmsParam.getCheckPoint());
  230. params.put("pblmDesc", objInspPblmsParam.getPblmDesc());
  231. params.put("type", objInspPblmsParam.getType());
  232. params.put("guid", objInspPblmsParam.getGuid());
  233. String orgId = getCurrentOrgId();
  234. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(orgId);
  235. if ("1".equals(olBisInspOrg.getPblmLogo()) && "1".equals(objInspPblmsParam.getType())) {
  236. params.put("orgId", olBisInspOrg.getQuoteOrgId());
  237. } else {
  238. params.put("orgId", "");
  239. }
  240. ObjInspPblms pblmsType = objInspPblmsService.getByPblms(params);
  241. return buildSuccessResponse(pblmsType);
  242. }
  243. @ApiOperation(value = "获取标准表单个信息")
  244. @RequestMapping(value = "/getPblmsByType", method = {RequestMethod.POST})
  245. public BaseResponse<ObjInspPblms> getPblmsByType(@RequestBody ObjInspPblmsParam objInspPblmsParam) {
  246. String orgId = getCurrentOrgId();
  247. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(orgId);
  248. if (olBisInspOrg == null) {
  249. throw new CheckException("当前机构不存在!!");
  250. }
  251. if ("1".equals(olBisInspOrg.getPblmLogo()) && "1".equals(objInspPblmsParam.getType())) {
  252. objInspPblmsParam.setOrgId(olBisInspOrg.getQuoteOrgId());
  253. } else {
  254. objInspPblmsParam.setOrgId(null);
  255. }
  256. ObjInspPblms pblmsType = objInspPblmsService.getPblmsByType(objInspPblmsParam);
  257. return buildSuccessResponse(pblmsType);
  258. }
  259. @Autowired
  260. private ObjInspPblmsDao objInspPblmsDao;
  261. @ApiOperation(value = "获取标准表单个信息(未启用)")
  262. @RequestMapping(value = "/getByWagaPblm", method = {RequestMethod.POST})
  263. public BaseResponse<Map<String, Object>> getByPblms(@RequestBody WagaPblm wagaPblm) {
  264. String sn = wagaPblm.getSn();
  265. if (StringUtils.isNotBlank(sn)) {
  266. sn = sn.replace("至", "-");
  267. sn = sn.replace("到", "-");
  268. StringBuffer buffer = new StringBuffer();
  269. if (sn.contains(",")) {
  270. String[] arrays = sn.split(",");
  271. for (String array : arrays) {
  272. if (array.contains("-")) {
  273. String[] startAndEnd = array.split("-");
  274. if (startAndEnd.length == 2) {
  275. int start = Integer.parseInt(startAndEnd[0]);
  276. int end = Integer.parseInt(startAndEnd[1]);
  277. for (int i = start; i <= end; i++) {
  278. buffer.append(i + ",");
  279. }
  280. } else {
  281. buffer.append(startAndEnd[0] + ",");
  282. }
  283. } else {
  284. buffer.append(array + ",");
  285. }
  286. }
  287. } else if (sn.contains("-")) {
  288. String[] startAndEnd = sn.split("-");
  289. if (startAndEnd.length == 2) {
  290. int start = Integer.parseInt(startAndEnd[0]);
  291. int end = Integer.parseInt(startAndEnd[1]);
  292. for (int i = start; i <= end; i++) {
  293. buffer.append(i + ",");
  294. }
  295. } else {
  296. buffer.append(startAndEnd[0] + ",");
  297. }
  298. } else {
  299. buffer.append(sn);
  300. }
  301. String snStr = buffer.toString();
  302. if (snStr.endsWith(",")) {
  303. snStr = snStr.substring(0, snStr.length() - 1);
  304. }
  305. wagaPblm.setSn(snStr);
  306. List<ObjInspPblms> inspPblms = objInspPblmsDao.findWagaPblm(wagaPblm.getSn(), wagaPblm.getAttach(), getCurrentOrgId());
  307. Map<String, Object> retMap = new HashMap<>();
  308. List<String> pblmNames = new ArrayList<>();
  309. for (ObjInspPblms pblms : inspPblms) {
  310. if (!pblmNames.contains(pblms.getInspPblmsName())) {
  311. pblmNames.add(pblms.getInspPblmsName());
  312. }
  313. }
  314. retMap.put("pblms", pblmNames);
  315. retMap.put("datas", inspPblms);
  316. return buildSuccessResponse(retMap);
  317. }
  318. return buildSuccessResponse(null);
  319. }
  320. @ApiOperation(value = "根据规则id和类型获取对应的描述信息")
  321. @RequestMapping(value = "/getPblmsByQuesNum/{id}/{type}", method = {RequestMethod.GET})
  322. public BaseResponse<List<ObjTypeCheck>> getPblmsByQuesNum(@ApiParam(name = "id", value = "规则id", required = true) @PathVariable String id,
  323. @ApiParam(name = "type", value = "类型", required = true) @PathVariable String type) {
  324. // 1. 跟id取出对应的 规则(问题标准 0:全国标准,1:自定义标准)
  325. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(getCurrentOrgId());
  326. if (olBisInspOrg == null) {
  327. throw new CheckException("当前机构不存在!!");
  328. }
  329. List<ObjTypeCheck> bisInspItemQuesNumDtoList = objInspPblmsService.getPblmsByQuesNum(id, type, olBisInspOrg);
  330. return buildSuccessResponse(bisInspItemQuesNumDtoList);
  331. }
  332. @ApiOperation(value = "根据督查类型获取所有的问题标准的分类、检查项和描述信息")
  333. @RequestMapping(value = "/getAllPblmsByType/{type}", method = {RequestMethod.GET})
  334. public BaseResponse getAllPblmsByType(@ApiParam(name = "type", value = "类型", required = true)
  335. @PathVariable String type) {
  336. return buildSuccessResponse(objInspPblmsService.getAllPblmsByType(type, getCurrentOrgId()));
  337. }
  338. @ApiOperation(value = "获取小水库(水闸)标准数据tree类型:type=1水库,type=6水闸")
  339. @RequestMapping(value = "/getPblmsRverTree/{type}", method = {RequestMethod.GET})
  340. public BaseResponse<List<ObjInspPblmsDto>> getPblmsRverTree(@PathVariable(required = true) String type, HttpServletRequest request) {
  341. //第一节点
  342. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(getCurrentOrgId());
  343. String orgId = "";
  344. if ("1".equals(olBisInspOrg.getPblmLogo()) && "1".equals(type)) {
  345. orgId = olBisInspOrg.getQuoteOrgId();
  346. }
  347. String pblmsName = request.getParameter("pblmsName");
  348. String sort1 = request.getParameter("sort1");
  349. List<ObjInspPblmsDto> pblmsType = new ArrayList<>();
  350. List<ObjInspPblmsDto> pblmsList = new ArrayList<>();
  351. pblmsType = objInspPblmsService.findPblmsDtoName(type, pblmsName, orgId, sort1);
  352. pblmsList = objInspPblmsService.findPblmsDTO(type, pblmsName, orgId, sort1);
  353. Set<ObjInspPblmsDto> secondList = new HashSet<>();
  354. if (pblmsList == null) {
  355. throw new CheckException("未查到任何数据!!");
  356. }
  357. for (ObjInspPblmsDto pblm : pblmsList) {
  358. ObjInspPblmsDto secChild = new ObjInspPblmsDto();
  359. secChild.setCheckPoint(pblm.getCheckPoint());
  360. secChild.setInspPblmsName(pblm.getInspPblmsName());
  361. secondList.add(secChild);
  362. }
  363. for (ObjInspPblmsDto pblm : pblmsType) {
  364. List<ObjInspPblmsDto> chlist = new ArrayList<>();
  365. for (ObjInspPblmsDto sec : secondList) {
  366. if (pblm.getInspPblmsName().equals(sec.getInspPblmsName())) {
  367. chlist.add(sec);
  368. }
  369. }
  370. pblm.setChildren(chlist);
  371. }
  372. for (ObjInspPblmsDto sec : secondList) {
  373. List<ObjInspPblmsDto> chlist = new ArrayList<>();
  374. for (ObjInspPblmsDto pblm : pblmsList) {
  375. if (sec.getInspPblmsName().equals(pblm.getInspPblmsName()) && sec.getCheckPoint().equals(pblm.getCheckPoint())) {
  376. chlist.add(pblm);
  377. }
  378. }
  379. sec.setChildren(chlist);
  380. }
  381. return buildSuccessResponse(pblmsType);
  382. }
  383. @ApiOperation("获取导入模板")
  384. @GetMapping(value = "/getExl")
  385. public void getExl(HttpServletResponse response) {
  386. String path = templatePath + File.separator + "objInspPblms.xlsx";
  387. try {
  388. ExpAndImpUtil.downloadFile(response, path, "问题清单表");
  389. } catch (Exception e) {
  390. logger.error(e.getMessage(), e);
  391. }
  392. }
  393. private List<String> sort1List = new ArrayList<>();
  394. private int sort1Index = 1;
  395. private List<String> sort2List = new ArrayList<>();
  396. private int sort2Index = 1;
  397. @ApiOperation("上传 xls 导入数据")
  398. @RequestMapping(value = "/impExl/{type}", method = RequestMethod.POST)
  399. public BaseResponse<Map<String, Object>> impExl(@PathVariable String type, @RequestParam("file") MultipartFile multfile) throws IOException, InvalidFormatException {
  400. // 获取文件名
  401. String fileName = multfile.getOriginalFilename();
  402. // 获取文件后缀
  403. String prefix = fileName.substring(fileName.lastIndexOf("."));
  404. // 用uuid作为文件名,防止生成的临时文件重复
  405. String uuid = UuidUtil.uuid();
  406. File file = File.createTempFile(uuid, prefix);
  407. // MultipartFile to File
  408. multfile.transferTo(Paths.get(file.getPath()));
  409. Map<String, Object> map = new HashMap<>(2);
  410. int shu = 0;
  411. int success = 0;
  412. String[][] data = ReadExcelUtil.getData(file, 1);
  413. try {
  414. if (data != null && data.length > 0) {
  415. for (int i = 0; i < data.length; i++) {
  416. ObjInspPblms objInspPblms = new ObjInspPblms();
  417. objInspPblms.setType(type);
  418. objInspPblms.setGuid(UuidUtil.uuid());
  419. objInspPblms.setPguid("00000000000000000000000000000000");
  420. objInspPblms.setAttach("1");
  421. objInspPblms.setSnClass("1");
  422. objInspPblms.setSn(data[i][0]);
  423. objInspPblms.setInspPblmsName(data[i][1]);
  424. objInspPblms.setCheckPoint(data[i][2]);
  425. objInspPblms.setPblmDesc(data[i][3]);
  426. objInspPblms.setSort1(generateSort1(data[i][1])); // Sort1是一级排序
  427. objInspPblms.setSort2(generateSort2(data[i][2])); // Sort2是二级排序
  428. objInspPblms.setInspPblmCate("0");
  429. insert(objInspPblms);
  430. success++;
  431. }
  432. }
  433. } catch (Exception e) {
  434. shu++;
  435. logger.error(e.getMessage(), e);
  436. }
  437. map.put("false", shu);
  438. map.put("success", success);
  439. return buildSuccessResponse(map);
  440. }
  441. /**
  442. * 根据一级分类名称和顺序生成一级排序值
  443. *
  444. * @param inspPblmsName 一级分类名称
  445. * @return 排序值,长度不超过2位
  446. */
  447. private String generateSort1(String inspPblmsName) {
  448. if (sort1List.contains(inspPblmsName)) {
  449. for (int i = 0; i < sort1List.size(); i++) {
  450. if (inspPblmsName.equals(sort1List.get(i))) {
  451. return String.valueOf(i + 1);
  452. }
  453. }
  454. } else {
  455. sort1List.add(inspPblmsName);
  456. return String.valueOf(sort1Index++);
  457. }
  458. return null;
  459. }
  460. /**
  461. * 根据二级分类名称和顺序生成二级排序值
  462. *
  463. * @param checkPoint 二级分类名称
  464. * @return 排序值,长度不超过2位
  465. */
  466. private String generateSort2(String checkPoint) {
  467. if (sort2List.contains(checkPoint)) {
  468. for (int i = 0; i < sort2List.size(); i++) {
  469. if (checkPoint.equals(sort2List.get(i))) {
  470. return String.valueOf(i + 1);
  471. }
  472. }
  473. } else {
  474. sort2List.add(checkPoint);
  475. return String.valueOf(sort2Index++);
  476. }
  477. return null;
  478. }
  479. }