AdmEquipmentController.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. package com.persagy.proxy.object.controller;
  2. import java.awt.Color;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.Set;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13. import org.apache.poi.ss.usermodel.CellType;
  14. import org.apache.poi.ss.usermodel.FillPatternType;
  15. import org.apache.poi.xssf.usermodel.XSSFCell;
  16. import org.apache.poi.xssf.usermodel.XSSFCellStyle;
  17. import org.apache.poi.xssf.usermodel.XSSFColor;
  18. import org.apache.poi.xssf.usermodel.XSSFRow;
  19. import org.apache.poi.xssf.usermodel.XSSFSheet;
  20. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.web.bind.annotation.GetMapping;
  23. import org.springframework.web.bind.annotation.PostMapping;
  24. import org.springframework.web.bind.annotation.RequestBody;
  25. import org.springframework.web.bind.annotation.RequestMapping;
  26. import org.springframework.web.bind.annotation.RequestParam;
  27. import org.springframework.web.bind.annotation.RestController;
  28. import org.springframework.web.multipart.MultipartFile;
  29. import com.alibaba.fastjson.JSONObject;
  30. import com.fasterxml.jackson.databind.ObjectMapper;
  31. import com.fasterxml.jackson.databind.node.ObjectNode;
  32. import com.google.common.collect.Sets;
  33. import com.persagy.dmp.basic.model.QueryCriteria;
  34. import com.persagy.dmp.basic.utils.JsonNodeUtils;
  35. import com.persagy.dmp.common.context.AppContext;
  36. import com.persagy.dmp.common.helper.SpringHelper;
  37. import com.persagy.dmp.define.client.DigitalDefineFacade;
  38. import com.persagy.dmp.define.entity.ObjectInfoDefine;
  39. import com.persagy.dmp.define.entity.ObjectTypeDefine;
  40. import com.persagy.dmp.digital.client.DigitalObjectFacade;
  41. import com.persagy.proxy.adm.constant.AdmCommonConstant;
  42. import com.persagy.proxy.adm.request.AdmCreateRequest;
  43. import com.persagy.proxy.adm.request.AdmQueryCriteria;
  44. import com.persagy.proxy.adm.request.AdmResponse;
  45. import com.persagy.proxy.adm.service.IAdmRelationService;
  46. import com.persagy.proxy.adm.utils.AdmContextUtil;
  47. import com.persagy.proxy.adm.utils.AdmExcelUtil;
  48. import com.persagy.proxy.adm.utils.ObjectNameUtil;
  49. import com.persagy.proxy.common.entity.RelationDTO;
  50. import com.persagy.proxy.object.model.AdmEquipment;
  51. import com.persagy.proxy.object.service.IAdmEquipmentService;
  52. import com.persagy.proxy.report.service.IRelationReportService;
  53. import cn.hutool.core.collection.CollUtil;
  54. import cn.hutool.core.collection.CollectionUtil;
  55. import cn.hutool.core.date.DateUtil;
  56. import cn.hutool.core.util.StrUtil;
  57. import lombok.extern.slf4j.Slf4j;
  58. /**
  59. * Adm 楼层 API
  60. * @author lvxy
  61. * @date 2021/8/16
  62. */
  63. @Slf4j
  64. @RestController
  65. @RequestMapping("/object/equip")
  66. public class AdmEquipmentController {
  67. @Autowired
  68. private IAdmEquipmentService service;
  69. @Autowired
  70. private IAdmRelationService relationService;
  71. @Autowired
  72. private IRelationReportService relationReportService;
  73. /**
  74. * 统计
  75. *
  76. * @param request
  77. * @return
  78. * @throws Exception
  79. */
  80. @PostMapping("/count")
  81. public AdmResponse count(@RequestBody AdmQueryCriteria request) throws Exception {
  82. request.setName(AdmEquipment.OBJ_TYPE);
  83. request.setOnlyCount(true);
  84. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
  85. }
  86. /**
  87. * 创建
  88. * @param createRequest
  89. * @return
  90. * @throws Exception
  91. */
  92. @PostMapping("/create")
  93. public AdmResponse create(@RequestBody AdmCreateRequest<AdmEquipment> createRequest) throws Exception {
  94. List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
  95. if(CollUtil.isEmpty(vos)){
  96. return AdmResponse.success();
  97. }
  98. //创建设备
  99. vos.stream().forEach(equipment -> {
  100. if (StrUtil.isEmpty(equipment.getName())){
  101. equipment.setName(ObjectNameUtil.objectName("设备-"));
  102. }
  103. });
  104. vos = service.doInsertEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
  105. return AdmResponse.success(vos);
  106. }
  107. /**
  108. * 根据ID删除
  109. * @param vos
  110. * @return
  111. * @throws Exception
  112. */
  113. @PostMapping("/delete")
  114. public AdmResponse delete( @RequestBody List<AdmEquipment> vos) throws Exception {
  115. // 组装上下文条件
  116. service.doDelete(AdmContextUtil.toDmpContext(), vos);
  117. return AdmResponse.success();
  118. }
  119. /**
  120. * 更新
  121. * @param createRequest
  122. * @return
  123. * @throws Exception
  124. */
  125. @PostMapping("/update")
  126. public AdmResponse update(@RequestBody AdmCreateRequest<AdmEquipment> createRequest) throws Exception {
  127. List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
  128. //vos = service.doUpdateEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
  129. //针对设备更新时,所有更新的字段都放到信息点中的情况特殊处理
  130. if(CollUtil.isNotEmpty(vos)){
  131. List<AdmEquipment> equipmentList = new ArrayList<>(vos.size());
  132. vos.stream().forEach(equipment -> {
  133. if(CollUtil.isNotEmpty(equipment.getInfos())){
  134. AdmEquipment admEquipment = new AdmEquipment();
  135. admEquipment.setId(equipment.getId());
  136. admEquipment.setInfos(equipment.getInfos());
  137. ObjectNode objectNode = JsonNodeUtils.toObjectNode(admEquipment, "infos", null);
  138. AdmEquipment admEquipmentNew = JsonNodeUtils.toEntity(objectNode, AdmEquipment.class, "infos");
  139. equipmentList.add(admEquipmentNew);
  140. }
  141. });
  142. vos = equipmentList;
  143. }
  144. vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
  145. return AdmResponse.success(vos);
  146. }
  147. /**
  148. * 查询
  149. *
  150. * @param request
  151. * @return
  152. * @throws Exception
  153. */
  154. @PostMapping("/query")
  155. public AdmResponse query(@RequestBody AdmQueryCriteria request) throws Exception {
  156. // 组装上下文条件
  157. request.setName(AdmEquipment.OBJ_TYPE);
  158. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
  159. }
  160. /**
  161. * 设备绑定的动态信息点或静态信息点
  162. * @param admEquipment
  163. * @return
  164. * @throws Exception
  165. */
  166. @GetMapping("/export")
  167. public AdmResponse exportInfos(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
  168. List<AdmEquipment> vos = CollUtil.newArrayList(admEquipment.getContent());
  169. vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
  170. return AdmResponse.success(vos);
  171. }
  172. /**
  173. * 根据项目id查询所有的设备和部件
  174. *
  175. * @param request
  176. * @return
  177. * @throws Exception
  178. */
  179. @GetMapping("/query-equip")
  180. public AdmResponse queryEquip(@RequestBody AdmQueryCriteria request) throws Exception {
  181. //request.setName("equipment");
  182. if(StrUtil.isNotEmpty(request.getFilters())){
  183. request.setFilters(String.join(";",request.getFilters(),"objType in ['equipment','component']"));
  184. }else{
  185. request.setFilters("objType in ['equipment','component']");
  186. }
  187. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
  188. }
  189. /**
  190. * 批量创建设备同时创建资产、创建设备和系统的关系
  191. * @param admEquipment
  192. * @return
  193. * @throws Exception
  194. */
  195. @PostMapping("/creat-equip-pro")
  196. public AdmResponse createExt(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
  197. List<AdmEquipment> vos = admEquipment.getContent();
  198. if(CollUtil.isEmpty(vos)){
  199. return AdmResponse.success();
  200. }
  201. //创建设备
  202. vos.stream().forEach(equipment -> {
  203. if (StrUtil.isEmpty(equipment.getName())){
  204. equipment.setName(ObjectNameUtil.objectName("设备-"));
  205. }
  206. });
  207. List<AdmEquipment> reVos = new ArrayList<>(vos.size());
  208. List<RelationDTO> relationDTOS = new ArrayList<>(16);
  209. vos.stream().forEach(admEq -> {
  210. //创建设备
  211. List<AdmEquipment> vosR = service.doInsert(AdmContextUtil.toDmpContext(), AdmEquipment.class, CollUtil.newArrayList(admEq));
  212. //TODO 创建资产
  213. //添加设备和系统、建筑、楼层的关系
  214. if(CollUtil.isNotEmpty(vosR)){
  215. String equipId = vosR.get(0).getId();
  216. if(StrUtil.isNotEmpty(equipId)){
  217. if(CollUtil.isNotEmpty(admEq.getLinkSystem())){
  218. admEq.getLinkSystem().stream().forEach(admSystem -> {
  219. relationDTOS.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null , admSystem.getId(), equipId));
  220. });
  221. }
  222. if(StrUtil.isNotEmpty(admEq.getBuildingId())){
  223. relationDTOS.add(new RelationDTO(null, "MechInArch", "Eq2Bd", null , equipId, admEq.getBuildingId()));
  224. }
  225. if(StrUtil.isNotEmpty(admEq.getFloorId())){
  226. relationDTOS.add(new RelationDTO(null, "MechInArch", "Eq2Fl", null , equipId, admEq.getBuildingId()));
  227. }
  228. }
  229. }
  230. reVos.addAll(vosR);
  231. });
  232. relationService.doSave(AdmContextUtil.toDmpContext(),relationDTOS);
  233. return AdmResponse.success(reVos);
  234. }
  235. /**
  236. * 设备上传excel识别静态信息点
  237. *
  238. * @param relType
  239. * @param code
  240. * @param zoneType
  241. * @param request
  242. * @param response
  243. */
  244. @RequestMapping("/import")
  245. public AdmResponse importFile(@RequestParam("file") MultipartFile file, @RequestParam String relType, @RequestParam(required = false) String zoneType,
  246. HttpServletRequest request, HttpServletResponse response) {
  247. if (file == null) {
  248. return AdmResponse.failure("未选择文件");
  249. }
  250. String path = AdmCommonConstant.SERVER_ROOT_PATH + AdmExcelUtil.TEMP_UPLOAD_PAHT;
  251. int failurNum = 0;
  252. int successCount = 0;
  253. String failure = null;
  254. String primaryKey = null;
  255. String classCodeCloumn = null;
  256. XSSFWorkbook workbook = null;
  257. FileOutputStream fileOutputStream = null;
  258. String groupCode = AppContext.getContext().getGroupCode();
  259. String projectId = AppContext.getContext().getProjectId();
  260. try {
  261. workbook = new XSSFWorkbook(file.getInputStream());
  262. XSSFSheet sheet = workbook.getSheetAt(0); // 第一个sheet
  263. XSSFRow row1 = sheet.getRow(1);
  264. if (row1 == null) {
  265. AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
  266. return AdmExcelUtil.getImportFailResult("数据不存在", "2", 0, ++failurNum);
  267. }
  268. /** 获取识别码 */
  269. XSSFCell markCell = row1.getCell(0);
  270. if (markCell == null) {
  271. AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
  272. return AdmExcelUtil.getImportFailResult("未填写识别码", "2", 0, ++failurNum);
  273. }
  274. primaryKey = markCell.getStringCellValue().trim(); // 识别码
  275. boolean containsKey = AdmCommonConstant.codeColMap.containsKey(primaryKey);
  276. if (!containsKey) {
  277. AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
  278. return AdmExcelUtil.getImportFailResult("未找到识别码", "2", 0, ++failurNum);
  279. }
  280. /** 获取类型 */
  281. XSSFCell cell = row1.getCell(1);
  282. if (cell == null) {
  283. AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
  284. return AdmExcelUtil.getImportFailResult("未填写设备类型", "2", 0, ++failurNum);
  285. }
  286. classCodeCloumn = cell.getStringCellValue().trim();
  287. if (!"ClassCode".equals(classCodeCloumn)) {
  288. AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
  289. return AdmExcelUtil.getImportFailResult("缺少设备类型(ClassCode)", "2", 0, ++failurNum);
  290. }
  291. // 存取所有的信息点
  292. Map<Integer, String> infoMap = new HashMap<Integer, String>();
  293. short lastCellNum = row1.getLastCellNum();
  294. for (int i = 1; i <= lastCellNum; i++) {
  295. XSSFCell xssfCell = row1.getCell(i);
  296. if (xssfCell != null && xssfCell.getStringCellValue() != null) {
  297. infoMap.put(i, xssfCell.getStringCellValue().trim());
  298. }
  299. }
  300. // 录入数据获取
  301. int lastRowNum = sheet.getLastRowNum();
  302. boolean isClassCode = "classCode".equals(primaryKey);
  303. for (int i = 2; i <= lastRowNum; i++) {
  304. String value = null;
  305. String code = null;
  306. String classCode = null;
  307. ObjectNode equipment = null;
  308. List<ObjectNode> equipmentList = null;
  309. Map<String, Object> tempMap = new HashMap<String, Object>();
  310. XSSFRow xssfRow = sheet.getRow(i);
  311. if (xssfRow == null) {
  312. continue;
  313. }
  314. lastCellNum = row1.getLastCellNum();
  315. for (int j = 1; j <= lastCellNum; i++) {
  316. cell = row1.getCell(j);
  317. if (cell == null) {
  318. continue;
  319. }
  320. if (j == 0) {
  321. value = cell.getStringCellValue();
  322. if (StrUtil.isBlank(value)) {
  323. continue;
  324. }
  325. code = isClassCode ? xssfRow.getCell(0).toString() : xssfRow.getCell(1).toString();
  326. // 获取类型定义
  327. ObjectTypeDefine define = this.getObjectTypeDefine(groupCode, projectId, code);
  328. if (define == null) {
  329. this.setColor(workbook, 56, 94, 15, cell);
  330. continue;
  331. }
  332. classCode = define.getCode();
  333. equipmentList = isClassCode ? this.getEquipmentList(groupCode, projectId, null, null, classCode)
  334. : this.getEquipmentList(groupCode, projectId, primaryKey, code, classCode);
  335. if (CollectionUtil.isEmpty(equipmentList)) {
  336. failurNum++;
  337. this.setColor(workbook, 153, 225, 77, cell);
  338. continue;
  339. }
  340. if (isClassCode) {
  341. equipment = equipmentList.get(0);
  342. } else {
  343. if (equipmentList.size() > 1) {
  344. failurNum++;
  345. this.setColor(workbook, 249, 203, 77, cell);
  346. } else {
  347. equipment = equipmentList.get(0);
  348. }
  349. }
  350. continue;
  351. }
  352. // 剩余列数据处理
  353. if (j != 1 && StrUtil.isNotBlank(code) && equipment != null && infoMap.containsKey(j)) {
  354. // 获取设备类的信息点
  355. List<ObjectInfoDefine> funidList = this.relationReportService.queryFunidList(groupCode, projectId, Sets.newHashSet(classCode), infoMap.get(j), "STATIC");
  356. if (CollectionUtil.isEmpty(funidList)) {
  357. failurNum++;
  358. this.setColor(workbook, 249, 203, 77, cell);
  359. continue;
  360. }
  361. ObjectInfoDefine define = funidList.get(0);
  362. if ("STRING".equalsIgnoreCase(define.getDataType())) {
  363. tempMap.put(define.getCode(), cell.getStringCellValue().trim());
  364. } else if ("INTEGER".equalsIgnoreCase(define.getDataType())) {
  365. try {
  366. if (!CellType.NUMERIC.equals(cell.getCellTypeEnum())) {
  367. failurNum++;
  368. this.setColor(workbook, 155, 227, 255, cell);
  369. continue;
  370. }
  371. tempMap.put(define.getCode(), cell.getRawValue().toString().trim());
  372. } catch (Exception e) {
  373. failurNum++;
  374. this.setColor(workbook, 155, 227, 255, cell);
  375. continue;
  376. }
  377. } else if ("ENUM".equalsIgnoreCase(define.getDataType())) {
  378. if (CellType.NUMERIC.equals(cell.getCellTypeEnum())) {
  379. tempMap.put(define.getCode(), cell.getRawValue().toString().trim());
  380. } else if (CellType.STRING.equals(cell.getCellTypeEnum())) {
  381. tempMap.put(define.getCode(), cell.getStringCellValue().trim());
  382. } else {
  383. failurNum++;
  384. this.setColor(workbook, 155, 227, 255, cell);
  385. continue;
  386. }
  387. } else if ("DATETIME".equalsIgnoreCase(define.getDataType())) {
  388. try {
  389. String trim = cell.getRawValue().trim();
  390. tempMap.put(define.getCode(), DateUtil.parseByPatterns(trim, "yyyyMMdd"));
  391. } catch (Exception e) {
  392. failurNum++;
  393. this.setColor(workbook, 155, 227, 255, cell);
  394. continue;
  395. }
  396. } else if ("DOUBLE".equalsIgnoreCase(define.getDataType())) {
  397. try {
  398. String trim = cell.getRawValue().trim();
  399. tempMap.put(define.getCode(), Double.parseDouble(trim));
  400. } catch (Exception e) {
  401. failurNum++;
  402. this.setColor(workbook, 155, 227, 255, cell);
  403. continue;
  404. }
  405. } else if ("BOOLEAN".equalsIgnoreCase(define.getDataType())) {
  406. String trim = cell.getRawValue() == null ? null : cell.getRawValue().toString().trim();
  407. if ("1".equals(trim) || "0".equals(trim)) {
  408. tempMap.put(define.getCode(), Double.parseDouble(trim));
  409. } else {
  410. failurNum++;
  411. this.setColor(workbook, 155, 227, 255, cell);
  412. continue;
  413. }
  414. } else {
  415. failurNum++;
  416. this.setColor(workbook, 155, 227, 255, cell);
  417. continue;
  418. }
  419. }
  420. }
  421. if (isClassCode) {
  422. if (CollectionUtil.isNotEmpty(equipmentList) && tempMap.size() > 0) {
  423. for (ObjectNode equipNode : equipmentList) {
  424. int success = this.updateEquipInfo(tempMap, groupCode, projectId, equipNode.get("id").asText());
  425. successCount += success;
  426. }
  427. }
  428. } else {
  429. if (StrUtil.isNotBlank(code) && equipment != null && tempMap.size() > 0) {
  430. int success = this.updateEquipInfo(tempMap, groupCode, projectId, equipment.get("id").asText());
  431. successCount += success;
  432. }
  433. }
  434. }
  435. // 写入错误报告对比值颜色
  436. this.wirteReport(workbook, sheet);
  437. // 返回正确结果
  438. String fileName = AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
  439. return AdmExcelUtil.getImportSuccessResult(fileName, successCount, failurNum);
  440. } catch (Exception e) {
  441. log.error("台账信息导入失败", e);
  442. failure = e.getMessage();
  443. } finally {
  444. if (fileOutputStream != null) {
  445. try {
  446. fileOutputStream.flush();
  447. fileOutputStream.close();
  448. } catch (IOException e) {}
  449. }
  450. if (workbook != null) {
  451. try {
  452. workbook.close();
  453. } catch (IOException e) {}
  454. }
  455. }
  456. return AdmResponse.failure(failure);
  457. }
  458. /**
  459. * 更新设备信息
  460. *
  461. * @param tempMap
  462. * @param groupCode
  463. * @param projectId
  464. * @param equipId
  465. * @return
  466. */
  467. private int updateEquipInfo(Map<String, Object> tempMap, String groupCode, String projectId, String equipId) {
  468. int successCount = 0;
  469. ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
  470. Set<String> keySet = tempMap.keySet();
  471. List<ObjectNode> objectNodes = new ArrayList<ObjectNode>();
  472. for (String key : keySet) {
  473. Object obj = tempMap.get(key);
  474. ObjectNode updateEquip = objectMapper.createObjectNode();
  475. updateEquip.put("id", equipId);
  476. if (obj instanceof Date) {
  477. updateEquip.putPOJO(key, obj);
  478. } else {
  479. updateEquip.put(key, obj.toString());
  480. }
  481. successCount++;
  482. objectNodes.add(updateEquip);
  483. }
  484. if (CollectionUtil.isNotEmpty(objectNodes)) {
  485. DigitalObjectFacade.update(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, objectNodes);
  486. }
  487. return successCount;
  488. }
  489. /**
  490. * 获取类型定义
  491. *
  492. * @param code
  493. * @return
  494. */
  495. private ObjectTypeDefine getObjectTypeDefine(String groupCode, String projectId, String code) {
  496. QueryCriteria queryCriteria = new QueryCriteria();
  497. ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
  498. ObjectNode condition = objectMapper.createObjectNode();
  499. JSONObject arrays = new JSONObject();
  500. arrays.put("$ne", "system");
  501. condition.putPOJO("parentCode", arrays);
  502. condition.put("code", code);
  503. queryCriteria.setCriteria(condition);
  504. List<ObjectTypeDefine> objectType = DigitalDefineFacade.queryObjectType(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
  505. return CollectionUtil.isEmpty(objectType) ? null : objectType.get(0);
  506. }
  507. /**
  508. * 获取设备
  509. *
  510. * @param groupCode
  511. * @param projectId
  512. * @param primaryKey
  513. * @param code
  514. * @param classCode
  515. * @return
  516. */
  517. private List<ObjectNode> getEquipmentList(String groupCode, String projectId, String primaryKey, String code, String classCode) {
  518. QueryCriteria queryCriteria = new QueryCriteria();
  519. ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
  520. ObjectNode condition = objectMapper.createObjectNode();
  521. if (StrUtil.isAllNotBlank(primaryKey, code)) {
  522. condition.put(primaryKey, code);
  523. }
  524. condition.put("classCode", classCode);
  525. queryCriteria.setCriteria(condition);
  526. List<ObjectNode> objectNodes = DigitalObjectFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
  527. return objectNodes;
  528. }
  529. /**
  530. * 设置填充色
  531. *
  532. * @param workbook
  533. * @param r
  534. * @param g
  535. * @param b
  536. * @param cell
  537. */
  538. private void setColor(XSSFWorkbook workbook, int r, int g, int b, XSSFCell cell) {
  539. /** 创建样式 */
  540. XSSFCellStyle createCellStyle = workbook.createCellStyle();
  541. /** 实心填充 */
  542. createCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  543. createCellStyle.setFillForegroundColor(new XSSFColor(new Color(r, g, b)));
  544. cell.setCellStyle(createCellStyle);
  545. }
  546. /**
  547. * 写入错误报告对比值颜色
  548. *
  549. * @param workbook
  550. * @param sheet
  551. */
  552. private void wirteReport(XSSFWorkbook workbook, XSSFSheet sheet) {
  553. XSSFRow row = sheet.getRow(1);
  554. short column = (short) (row.getLastCellNum() + 2);
  555. XSSFRow row4 = sheet.getRow(4);
  556. if (row4 == null) {
  557. row4 = sheet.createRow(4);
  558. }
  559. XSSFCell createCell = row4.createCell(column);
  560. createCell.setCellValue("导入失败,识别码超出范围( 本地编码,本地名称,数字化交付码 )");
  561. createCell = row4.createCell(column + 1);
  562. this.setColor(workbook,233,99,99,createCell);
  563. XSSFRow row5 = sheet.getRow(5);
  564. if (row5 == null) {
  565. row5 = sheet.createRow(5);
  566. }
  567. createCell = row5.createCell(column);
  568. createCell.setCellValue("导入失败,识别码为空");
  569. createCell = row5.createCell(column + 1);
  570. this.setColor(workbook,252,147,77,createCell);
  571. XSSFRow row6 = sheet.getRow(6);
  572. if (row6 == null) {
  573. row6 = sheet.createRow(6);
  574. }
  575. createCell = row6.createCell(column);
  576. createCell.setCellValue("导入失败,多个实例");
  577. createCell = row6.createCell(column + 1);
  578. this.setColor(workbook,249,203,77,createCell);
  579. XSSFRow row7 = sheet.getRow(7);
  580. if (row7 == null) {
  581. row7 = sheet.createRow(7);
  582. }
  583. createCell = row7.createCell(column);
  584. createCell.setCellValue("导入失败,设备不存在");
  585. createCell = row7.createCell(column + 1);
  586. this.setColor(workbook,153,225,77,createCell);
  587. XSSFRow row8 = sheet.getRow(8);
  588. if (row8 == null) {
  589. row8 = sheet.createRow(8);
  590. }
  591. createCell = row8.createCell(column);
  592. createCell.setCellValue("导入失败,识别码值为空");
  593. createCell = row8.createCell(column + 1);
  594. this.setColor(workbook,252,255,77,createCell);
  595. XSSFRow row9 = sheet.getRow(9);
  596. if (row9 == null) {
  597. row9 = sheet.createRow(9);
  598. }
  599. createCell = row9.createCell(column);
  600. createCell.setCellValue("导入失败,输入类型与字典定义不一致");
  601. createCell = row9.createCell(column + 1);
  602. this.setColor(workbook,155,227,255,createCell);
  603. XSSFRow row10 = sheet.getRow(10);
  604. if (row10 == null) {
  605. row10 = sheet.createRow(10);
  606. }
  607. createCell = row10.createCell(column);
  608. createCell.setCellValue("导入失败,未支持的输入类型");
  609. createCell = row10.createCell(column + 1);
  610. this.setColor(workbook,204,99,233,createCell);
  611. XSSFRow row11 = sheet.getRow(11);
  612. if (row11 == null) {
  613. row11 = sheet.createRow(11);
  614. }
  615. createCell = row11.createCell(column);
  616. createCell.setCellValue("导入失败,信息点不存在");
  617. createCell = row11.createCell(column + 1);
  618. this.setColor(workbook,77,178,255,createCell);
  619. XSSFRow row12 = sheet.getRow(12);
  620. if (row12 == null) {
  621. row12 = sheet.createRow(12);
  622. }
  623. createCell = row12.createCell(column);
  624. createCell.setCellValue("导入失败,设备类型不在字典定义中");
  625. createCell = row12.createCell(column + 1);
  626. this.setColor(workbook,56,94,15,createCell);
  627. }
  628. }