a7ad80e6f247f22320e4e8fbb44b07be7e071583.svn-base 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. @RequestMapping(value = "/getPblmTypeInAttach", method = {RequestMethod.POST})
  116. public BaseResponse<List<ObjInspPblms>> getPblmTypeInAttach(@RequestBody ObjInspPblmsParams objInspPblms) {
  117. List<ObjInspPblms> obj = new ArrayList<>();
  118. try {
  119. obj = objInspPblmsService.getPblmTypeInAttach(objInspPblms);
  120. } catch (Exception e) {
  121. e.printStackTrace();
  122. logger.error(e.getMessage());
  123. return buildFailResponse(e.getMessage());
  124. }
  125. return buildSuccessResponse(obj);
  126. }
  127. @ApiOperation(value = "根据ID删除问题分类标准库")
  128. @RequestMapping(value = "/{id}", method = RequestMethod.POST)
  129. public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  130. int ret = objInspPblmsService.delete(id);
  131. return buildSuccessResponse();
  132. }
  133. @ApiOperation(value = "根据ID删除问题分类标准库")
  134. @RequestMapping(value = "/delete", method = RequestMethod.POST)
  135. public BaseResponse deletes(@ApiParam(name = "id", value = "id", required = true) @RequestParam String id) {
  136. if (StringUtils.isBlank(id)) {
  137. return buildFailResponse("请选择要删除的问题!");
  138. }
  139. String[] ids = id.split(",");
  140. for (String item : ids) {
  141. objInspPblmsService.delete(item);
  142. }
  143. return buildSuccessResponse();
  144. }
  145. @ApiOperation(value = "更新问题分类标准库信息")
  146. @RequestMapping(value = "/update", method = RequestMethod.POST)
  147. public BaseResponse update(@ApiParam(name = "objInspPblms", value = "ObjInspPblms", required = true) @RequestBody ObjInspPblms objInspPblms) {
  148. Assert.notNull(objInspPblms.getGuid(), "主键id为必填参数");
  149. int ret = objInspPblmsService.update(objInspPblms);
  150. return buildSuccessResponse();
  151. }
  152. @ApiOperation(value = "根据ID获取问题分类标准库(单表)")
  153. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  154. public BaseResponse<ObjInspPblms> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  155. ObjInspPblms objInspPblms = objInspPblmsService.get(id);
  156. return buildSuccessResponse(objInspPblms);
  157. }
  158. @ApiOperation(value = "获取整个标准库数据")
  159. @RequestMapping(value = "/findAll", method = RequestMethod.GET)
  160. public BaseResponse<List<ObjInspPblms>> findAll() {
  161. List<ObjInspPblms> pblmsList = objInspPblmsService.findList(null);
  162. return buildSuccessResponse(pblmsList);
  163. }
  164. @ApiOperation(value = "获取所有数据类型")
  165. @RequestMapping(value = "/getPblmsType", method = {RequestMethod.GET})
  166. public BaseResponse<List<String>> getPblmsType() {
  167. List<String> pblmsType = objInspPblmsService.findPblmsName(getCurrentOrgId());
  168. return buildSuccessResponse(pblmsType);
  169. }
  170. @ApiOperation(value = "获取所有的问题名称,去重")
  171. @RequestMapping(value = "/getPblmNames", method = RequestMethod.GET)
  172. public BaseResponse<List<String>> getPblmNames(ObjInspPblmsParam objInspPblmsParam) {
  173. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(getCurrentOrgId());
  174. if (olBisInspOrg == null) {
  175. throw new CheckException("当前机构不存在!!");
  176. }
  177. if ("1".equals(olBisInspOrg.getPblmLogo()) && "1".equals(objInspPblmsParam.getType())) {
  178. objInspPblmsParam.setOrgId(olBisInspOrg.getQuoteOrgId());
  179. } else {
  180. objInspPblmsParam.setOrgId("");
  181. }
  182. List<String> pblmNames = objInspPblmsService.getPblmNames(objInspPblmsParam);
  183. return buildSuccessResponse(pblmNames);
  184. }
  185. @ApiOperation(value = "获取所有数据检查项")
  186. @RequestMapping(value = "/getCheckPoints", method = {RequestMethod.POST})
  187. public BaseResponse<List<String>> getPblmsType(@RequestBody ObjInspPblmsParam objInspPblmsParam) {
  188. if (StringUtils.isBlank(objInspPblmsParam.getType())) {
  189. objInspPblmsParam.setType("1");
  190. }
  191. List<String> pblmsType = objInspPblmsService.findPblmsCheckPoints(objInspPblmsParam, getCurrentOrgId());
  192. return buildSuccessResponse(pblmsType);
  193. }
  194. @ApiOperation(value = "获取所有问题描述信息")
  195. @RequestMapping(value = "/getPblmsDesc", method = {RequestMethod.POST})
  196. public BaseResponse<List<String>> getPblmsDesc(@RequestBody ObjInspPblmsParam objInspPblmsParam) {
  197. if (StringUtils.isBlank(objInspPblmsParam.getType())) {
  198. objInspPblmsParam.setType("1");
  199. }
  200. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(getCurrentOrgId());
  201. if (olBisInspOrg == null) {
  202. throw new CheckException("当前机构不存在!!");
  203. }
  204. Map<String, String> params = new HashMap<>();
  205. params.put("type", objInspPblmsParam.getType());
  206. params.put("inspPblmsName", objInspPblmsParam.getInspPblmsName());
  207. params.put("checkPoint", objInspPblmsParam.getCheckPoint());
  208. if ("1".equals(olBisInspOrg.getPblmLogo()) && "1".equals(objInspPblmsParam.getType())) {
  209. params.put("orgId", olBisInspOrg.getQuoteOrgId());
  210. }
  211. List<String> pblmsType = objInspPblmsService.findPblmsDesc(params);
  212. return buildSuccessResponse(pblmsType);
  213. }
  214. @ApiOperation(value = "获取标准表单个信息")
  215. @RequestMapping(value = "/getByPblms", method = {RequestMethod.POST})
  216. public BaseResponse<ObjInspPblms> getByPblms(@RequestBody ObjInspPblmsParam objInspPblmsParam) {
  217. check(StringUtils.isNotBlank(objInspPblmsParam.getType()), "type.no");
  218. Map<String, String> params = new HashMap<>(6);
  219. params.put("inspPblmsName", objInspPblmsParam.getInspPblmsName());
  220. params.put("checkPoint", objInspPblmsParam.getCheckPoint());
  221. params.put("pblmDesc", objInspPblmsParam.getPblmDesc());
  222. params.put("type", objInspPblmsParam.getType());
  223. params.put("guid", objInspPblmsParam.getGuid());
  224. String orgId = getCurrentOrgId();
  225. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(orgId);
  226. if ("1".equals(olBisInspOrg.getPblmLogo()) && "1".equals(objInspPblmsParam.getType())) {
  227. params.put("orgId", olBisInspOrg.getQuoteOrgId());
  228. } else {
  229. params.put("orgId", "");
  230. }
  231. ObjInspPblms pblmsType = objInspPblmsService.getByPblms(params);
  232. return buildSuccessResponse(pblmsType);
  233. }
  234. @ApiOperation(value = "获取标准表单个信息")
  235. @RequestMapping(value = "/getPblmsByType", method = {RequestMethod.POST})
  236. public BaseResponse<ObjInspPblms> getPblmsByType(@RequestBody ObjInspPblmsParam objInspPblmsParam) {
  237. String orgId = getCurrentOrgId();
  238. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(orgId);
  239. if (olBisInspOrg == null) {
  240. throw new CheckException("当前机构不存在!!");
  241. }
  242. if ("1".equals(olBisInspOrg.getPblmLogo()) && "1".equals(objInspPblmsParam.getType())) {
  243. objInspPblmsParam.setOrgId(olBisInspOrg.getQuoteOrgId());
  244. } else {
  245. objInspPblmsParam.setOrgId(null);
  246. }
  247. ObjInspPblms pblmsType = objInspPblmsService.getPblmsByType(objInspPblmsParam);
  248. return buildSuccessResponse(pblmsType);
  249. }
  250. @Autowired
  251. private ObjInspPblmsDao objInspPblmsDao;
  252. @ApiOperation(value = "获取标准表单个信息(未启用)")
  253. @RequestMapping(value = "/getByWagaPblm", method = {RequestMethod.POST})
  254. public BaseResponse<Map<String, Object>> getByPblms(@RequestBody WagaPblm wagaPblm) {
  255. String sn = wagaPblm.getSn();
  256. if (StringUtils.isNotBlank(sn)) {
  257. sn = sn.replace("至", "-");
  258. sn = sn.replace("到", "-");
  259. StringBuffer buffer = new StringBuffer();
  260. if (sn.contains(",")) {
  261. String[] arrays = sn.split(",");
  262. for (String array : arrays) {
  263. if (array.contains("-")) {
  264. String[] startAndEnd = array.split("-");
  265. if (startAndEnd.length == 2) {
  266. int start = Integer.parseInt(startAndEnd[0]);
  267. int end = Integer.parseInt(startAndEnd[1]);
  268. for (int i = start; i <= end; i++) {
  269. buffer.append(i + ",");
  270. }
  271. } else {
  272. buffer.append(startAndEnd[0] + ",");
  273. }
  274. } else {
  275. buffer.append(array + ",");
  276. }
  277. }
  278. } else if (sn.contains("-")) {
  279. String[] startAndEnd = sn.split("-");
  280. if (startAndEnd.length == 2) {
  281. int start = Integer.parseInt(startAndEnd[0]);
  282. int end = Integer.parseInt(startAndEnd[1]);
  283. for (int i = start; i <= end; i++) {
  284. buffer.append(i + ",");
  285. }
  286. } else {
  287. buffer.append(startAndEnd[0] + ",");
  288. }
  289. } else {
  290. buffer.append(sn);
  291. }
  292. String snStr = buffer.toString();
  293. if (snStr.endsWith(",")) {
  294. snStr = snStr.substring(0, snStr.length() - 1);
  295. }
  296. wagaPblm.setSn(snStr);
  297. List<ObjInspPblms> inspPblms = objInspPblmsDao.findWagaPblm(wagaPblm.getSn(), wagaPblm.getAttach(), getCurrentOrgId());
  298. Map<String, Object> retMap = new HashMap<>();
  299. List<String> pblmNames = new ArrayList<>();
  300. for (ObjInspPblms pblms : inspPblms) {
  301. if (!pblmNames.contains(pblms.getInspPblmsName())) {
  302. pblmNames.add(pblms.getInspPblmsName());
  303. }
  304. }
  305. retMap.put("pblms", pblmNames);
  306. retMap.put("datas", inspPblms);
  307. return buildSuccessResponse(retMap);
  308. }
  309. return buildSuccessResponse(null);
  310. }
  311. @ApiOperation(value = "根据规则id和类型获取对应的描述信息")
  312. @RequestMapping(value = "/getPblmsByQuesNum/{id}/{type}", method = {RequestMethod.GET})
  313. public BaseResponse<List<ObjTypeCheck>> getPblmsByQuesNum(@ApiParam(name = "id", value = "规则id", required = true) @PathVariable String id,
  314. @ApiParam(name = "type", value = "类型", required = true) @PathVariable String type) {
  315. // 1. 跟id取出对应的 规则(问题标准 0:全国标准,1:自定义标准)
  316. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(getCurrentOrgId());
  317. if (olBisInspOrg == null) {
  318. throw new CheckException("当前机构不存在!!");
  319. }
  320. List<ObjTypeCheck> bisInspItemQuesNumDtoList = objInspPblmsService.getPblmsByQuesNum(id, type, olBisInspOrg);
  321. return buildSuccessResponse(bisInspItemQuesNumDtoList);
  322. }
  323. @ApiOperation(value = "根据督查类型获取所有的问题标准的分类、检查项和描述信息")
  324. @RequestMapping(value = "/getAllPblmsByType/{type}", method = {RequestMethod.GET})
  325. public BaseResponse getAllPblmsByType(@ApiParam(name = "type", value = "类型", required = true)
  326. @PathVariable String type) {
  327. return buildSuccessResponse(objInspPblmsService.getAllPblmsByType(type, getCurrentOrgId()));
  328. }
  329. @ApiOperation(value = "获取小水库(水闸)标准数据tree类型:type=1水库,type=6水闸")
  330. @RequestMapping(value = "/getPblmsRverTree/{type}", method = {RequestMethod.GET})
  331. public BaseResponse<List<ObjInspPblmsDto>> getPblmsRverTree(@PathVariable(required = true) String type, HttpServletRequest request) {
  332. //第一节点
  333. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(getCurrentOrgId());
  334. String orgId = "";
  335. if ("1".equals(olBisInspOrg.getPblmLogo()) && "1".equals(type)) {
  336. orgId = olBisInspOrg.getQuoteOrgId();
  337. }
  338. String pblmsName = request.getParameter("pblmsName");
  339. String sort1 = request.getParameter("sort1");
  340. List<ObjInspPblmsDto> pblmsType = new ArrayList<>();
  341. List<ObjInspPblmsDto> pblmsList = new ArrayList<>();
  342. pblmsType = objInspPblmsService.findPblmsDtoName(type, pblmsName, orgId, sort1);
  343. pblmsList = objInspPblmsService.findPblmsDTO(type, pblmsName, orgId, sort1);
  344. Set<ObjInspPblmsDto> secondList = new HashSet<>();
  345. if (pblmsList == null) {
  346. throw new CheckException("未查到任何数据!!");
  347. }
  348. for (ObjInspPblmsDto pblm : pblmsList) {
  349. ObjInspPblmsDto secChild = new ObjInspPblmsDto();
  350. secChild.setCheckPoint(pblm.getCheckPoint());
  351. secChild.setInspPblmsName(pblm.getInspPblmsName());
  352. secondList.add(secChild);
  353. }
  354. for (ObjInspPblmsDto pblm : pblmsType) {
  355. List<ObjInspPblmsDto> chlist = new ArrayList<>();
  356. for (ObjInspPblmsDto sec : secondList) {
  357. if (pblm.getInspPblmsName().equals(sec.getInspPblmsName())) {
  358. chlist.add(sec);
  359. }
  360. }
  361. pblm.setChildren(chlist);
  362. }
  363. for (ObjInspPblmsDto sec : secondList) {
  364. List<ObjInspPblmsDto> chlist = new ArrayList<>();
  365. for (ObjInspPblmsDto pblm : pblmsList) {
  366. if (sec.getInspPblmsName().equals(pblm.getInspPblmsName()) && sec.getCheckPoint().equals(pblm.getCheckPoint())) {
  367. chlist.add(pblm);
  368. }
  369. }
  370. sec.setChildren(chlist);
  371. }
  372. return buildSuccessResponse(pblmsType);
  373. }
  374. @ApiOperation("获取导入模板")
  375. @GetMapping(value = "/getExl")
  376. public void getExl(HttpServletResponse response) {
  377. String path = templatePath + File.separator + "objInspPblms.xlsx";
  378. try {
  379. ExpAndImpUtil.downloadFile(response, path, "问题清单表");
  380. } catch (Exception e) {
  381. logger.error(e.getMessage(), e);
  382. }
  383. }
  384. private List<String> sort1List = new ArrayList<>();
  385. private int sort1Index = 1;
  386. private List<String> sort2List = new ArrayList<>();
  387. private int sort2Index = 1;
  388. @ApiOperation("上传 xls 导入数据")
  389. @RequestMapping(value = "/impExl/{type}", method = RequestMethod.POST)
  390. public BaseResponse<Map<String, Object>> impExl(@PathVariable String type, @RequestParam("file") MultipartFile multfile) throws IOException, InvalidFormatException {
  391. // 获取文件名
  392. String fileName = multfile.getOriginalFilename();
  393. // 获取文件后缀
  394. String prefix = fileName.substring(fileName.lastIndexOf("."));
  395. // 用uuid作为文件名,防止生成的临时文件重复
  396. String uuid = UuidUtil.uuid();
  397. File file = File.createTempFile(uuid, prefix);
  398. // MultipartFile to File
  399. multfile.transferTo(Paths.get(file.getPath()));
  400. Map<String, Object> map = new HashMap<>(2);
  401. int shu = 0;
  402. int success = 0;
  403. String[][] data = ReadExcelUtil.getData(file, 1);
  404. try {
  405. if (data != null && data.length > 0) {
  406. for (int i = 0; i < data.length; i++) {
  407. ObjInspPblms objInspPblms = new ObjInspPblms();
  408. objInspPblms.setType(type);
  409. objInspPblms.setGuid(UuidUtil.uuid());
  410. objInspPblms.setPguid("00000000000000000000000000000000");
  411. objInspPblms.setAttach("1");
  412. objInspPblms.setSnClass("1");
  413. objInspPblms.setSn(data[i][0]);
  414. objInspPblms.setInspPblmsName(data[i][1]);
  415. objInspPblms.setCheckPoint(data[i][2]);
  416. objInspPblms.setPblmDesc(data[i][3]);
  417. objInspPblms.setSort1(generateSort1(data[i][1])); // Sort1是一级排序
  418. objInspPblms.setSort2(generateSort2(data[i][2])); // Sort2是二级排序
  419. if (data[i][4] != null) {
  420. objInspPblms.setInspPblmCate(data[i][4]);
  421. } else {
  422. objInspPblms.setInspPblmCate("0");
  423. }
  424. insert(objInspPblms);
  425. success++;
  426. }
  427. }
  428. } catch (Exception e) {
  429. shu++;
  430. logger.error(e.getMessage(), e);
  431. }
  432. map.put("false", shu);
  433. map.put("success", success);
  434. return buildSuccessResponse(map);
  435. }
  436. /**
  437. * 根据一级分类名称和顺序生成一级排序值
  438. *
  439. * @param inspPblmsName 一级分类名称
  440. * @return 排序值,长度不超过2位
  441. */
  442. private String generateSort1(String inspPblmsName) {
  443. if (sort1List.contains(inspPblmsName)) {
  444. for (int i = 0; i < sort1List.size(); i++) {
  445. if (inspPblmsName.equals(sort1List.get(i))) {
  446. return String.valueOf(i + 1);
  447. }
  448. }
  449. } else {
  450. sort1List.add(inspPblmsName);
  451. return String.valueOf(sort1Index++);
  452. }
  453. return null;
  454. }
  455. /**
  456. * 根据二级分类名称和顺序生成二级排序值
  457. *
  458. * @param checkPoint 二级分类名称
  459. * @return 排序值,长度不超过2位
  460. */
  461. private String generateSort2(String checkPoint) {
  462. if (sort2List.contains(checkPoint)) {
  463. for (int i = 0; i < sort2List.size(); i++) {
  464. if (checkPoint.equals(sort2List.get(i))) {
  465. return String.valueOf(i + 1);
  466. }
  467. }
  468. } else {
  469. sort2List.add(checkPoint);
  470. return String.valueOf(sort2Index++);
  471. }
  472. return null;
  473. }
  474. }