|
@@ -3,6 +3,8 @@ package com.persagy.proxy.object.controller;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
@@ -12,6 +14,7 @@ import com.google.common.collect.Sets;
|
|
|
import com.persagy.dmp.basic.model.QueryCriteria;
|
|
|
import com.persagy.dmp.basic.utils.JsonNodeUtils;
|
|
|
import com.persagy.dmp.common.context.AppContext;
|
|
|
+import com.persagy.dmp.common.exception.BusinessException;
|
|
|
import com.persagy.dmp.common.helper.SpringHelper;
|
|
|
import com.persagy.dmp.common.model.entity.BaseEntity;
|
|
|
import com.persagy.dmp.define.client.DigitalDefineFacade;
|
|
@@ -20,6 +23,7 @@ import com.persagy.dmp.define.entity.ObjectTypeDefine;
|
|
|
import com.persagy.dmp.digital.client.DigitalObjectFacade;
|
|
|
import com.persagy.dmp.digital.entity.ObjectDigital;
|
|
|
import com.persagy.proxy.adm.constant.AdmCommonConstant;
|
|
|
+import com.persagy.proxy.adm.constant.AdmDictCategoryEnum;
|
|
|
import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
|
|
|
import com.persagy.proxy.adm.request.AdmCreateRequest;
|
|
|
import com.persagy.proxy.adm.request.AdmQueryCriteria;
|
|
@@ -29,6 +33,9 @@ import com.persagy.proxy.adm.utils.AdmContextUtil;
|
|
|
import com.persagy.proxy.adm.utils.AdmExcelUtil;
|
|
|
import com.persagy.proxy.adm.utils.ObjectNameUtil;
|
|
|
import com.persagy.proxy.common.entity.RelationDTO;
|
|
|
+import com.persagy.proxy.dictionary.model.AdmDict;
|
|
|
+import com.persagy.proxy.dictionary.model.AdmObjectType;
|
|
|
+import com.persagy.proxy.dictionary.service.IAdmDictService;
|
|
|
import com.persagy.proxy.object.model.AdmEquipment;
|
|
|
import com.persagy.proxy.object.service.IAdmEquipmentService;
|
|
|
import com.persagy.proxy.report.service.IRelationReportService;
|
|
@@ -57,61 +64,93 @@ import java.util.*;
|
|
|
@RestController
|
|
|
@RequestMapping("/object/equip")
|
|
|
public class AdmEquipmentController {
|
|
|
- @Autowired
|
|
|
- private IAdmEquipmentService service;
|
|
|
- @Autowired
|
|
|
- private IAdmRelationService relationService;
|
|
|
- @Autowired
|
|
|
- private IRelationReportService relationReportService;
|
|
|
+ @Autowired
|
|
|
+ private IAdmEquipmentService service;
|
|
|
+ @Autowired
|
|
|
+ private IAdmRelationService relationService;
|
|
|
+ @Autowired
|
|
|
+ private IRelationReportService relationReportService;
|
|
|
+ @Autowired
|
|
|
+ private IAdmDictService dictService;
|
|
|
|
|
|
- /**
|
|
|
- * 统计
|
|
|
- *
|
|
|
- * @param request
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @PostMapping("/count")
|
|
|
- public AdmResponse count(@RequestBody AdmQueryCriteria request) throws Exception {
|
|
|
- request.setName(AdmEquipment.OBJ_TYPE);
|
|
|
- request.setOnlyCount(true);
|
|
|
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 统计
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("/count")
|
|
|
+ public AdmResponse count(@RequestBody AdmQueryCriteria request) throws Exception {
|
|
|
+ request.setName(AdmEquipment.OBJ_TYPE);
|
|
|
+ request.setOnlyCount(true);
|
|
|
+ return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 创建
|
|
|
- * @param createRequest
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @PostMapping("/create")
|
|
|
- public AdmResponse create(@RequestBody AdmCreateRequest<AdmEquipment> createRequest) throws Exception {
|
|
|
- List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
|
|
|
- if(CollUtil.isEmpty(vos)){
|
|
|
- return AdmResponse.success();
|
|
|
- }
|
|
|
- //创建设备
|
|
|
- vos.stream().forEach(equipment -> {
|
|
|
- if (StrUtil.isEmpty(equipment.getName())){
|
|
|
- equipment.setName(ObjectNameUtil.objectName("设备-"));
|
|
|
- }
|
|
|
- });
|
|
|
- vos = service.doInsertEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
|
|
|
- return AdmResponse.success(vos);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 创建
|
|
|
+ * @param createRequest
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("/create")
|
|
|
+ public AdmResponse create(@RequestBody AdmCreateRequest<AdmEquipment> createRequest) throws Exception {
|
|
|
+ List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
|
|
|
+ if(CollUtil.isEmpty(vos)){
|
|
|
+ return AdmResponse.success();
|
|
|
+ }
|
|
|
+ // 查询所有设备类型
|
|
|
+ AdmDict dictCond = AdmDict.builder().type(AdmDictCategoryEnum.EQUIPMENT.getValue()).build();
|
|
|
+ AdmResponse dictResponse = dictService.queryCategory(AdmContextUtil.toDmpContext(), dictCond, AdmObjectType.class);
|
|
|
+ List<AdmObjectType> dicts = (List<AdmObjectType>) dictResponse.getContent();
|
|
|
+ // 转换为Map,key为编码后4位。用于适配旧类型编码
|
|
|
+ Map<String, AdmObjectType> shortDictMap = new HashMap<>();
|
|
|
+ Map<String, AdmObjectType> fullDictMap = new HashMap<>();
|
|
|
+ for(int i = 0,j = CollUtil.size(dicts);i < j;i++) {
|
|
|
+ AdmObjectType dict = dicts.get(i);
|
|
|
+ shortDictMap.put(StrUtil.subSufByLength(dict.getCode(), 4), dict);
|
|
|
+ fullDictMap.put(dict.getCode(), dict);
|
|
|
+ }
|
|
|
+ // 设备属性调整
|
|
|
+ vos.stream().forEach(equipment -> {
|
|
|
+ // 如果不是Eq开头,则重新生成ID
|
|
|
+ if(StrUtil.startWith(equipment.getId(), "Eq")) {
|
|
|
+ equipment.setId("Eq"+ IdUtil.simpleUUID());
|
|
|
+ }
|
|
|
+ // 类型编码适配
|
|
|
+ String classCode = equipment.getClassCode();
|
|
|
+ // 如果编码为空,或在4位、6位里都不存在,则报错
|
|
|
+ if(StrUtil.isBlank(classCode) ||
|
|
|
+ (shortDictMap.get(classCode) == null && fullDictMap.get(classCode) == null)) {
|
|
|
+ throw new BusinessException(StrUtil.format("没有找到对象类型【{}】!", equipment.getClassCode()));
|
|
|
+ }
|
|
|
+ // 如果少于6位,则需要适配新编码
|
|
|
+ if(classCode.length() < 6) {
|
|
|
+ AdmObjectType dict = MapUtil.get(shortDictMap, classCode, AdmObjectType.class);
|
|
|
+ equipment.setClassCode(dict.getCode());
|
|
|
+ }
|
|
|
+ // 如果名称为空,则提供默认名称
|
|
|
+ if (StrUtil.isEmpty(equipment.getName())){
|
|
|
+ AdmObjectType dict = MapUtil.get(shortDictMap, equipment.getClassCode(), AdmObjectType.class);
|
|
|
+ equipment.setName(ObjectNameUtil.objectName(dict.getName() + "-"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ vos = service.doInsertEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
|
|
|
+ return AdmResponse.success(vos);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 根据ID删除
|
|
|
- * @param vos
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @PostMapping("/delete")
|
|
|
- public AdmResponse delete( @RequestBody List<AdmEquipment> vos) throws Exception {
|
|
|
- // 组装上下文条件
|
|
|
- service.doDelete(AdmContextUtil.toDmpContext(), vos);
|
|
|
- return AdmResponse.success();
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 根据ID删除
|
|
|
+ * @param vos
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("/delete")
|
|
|
+ public AdmResponse delete( @RequestBody List<AdmEquipment> vos) throws Exception {
|
|
|
+ // 组装上下文条件
|
|
|
+ service.doDelete(AdmContextUtil.toDmpContext(), vos);
|
|
|
+ return AdmResponse.success();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -177,102 +216,103 @@ public class AdmEquipmentController {
|
|
|
return AdmResponse.success(vos);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 查询
|
|
|
- *
|
|
|
- * @param request
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @PostMapping("/query")
|
|
|
- public AdmResponse query(@RequestBody AdmQueryCriteria request) throws Exception {
|
|
|
- // 组装上下文条件
|
|
|
- request.setName(AdmEquipment.OBJ_TYPE);
|
|
|
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 查询
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("/query")
|
|
|
+ public AdmResponse query(@RequestBody AdmQueryCriteria request) throws Exception {
|
|
|
+ // 组装上下文条件
|
|
|
+ request.setName(AdmEquipment.OBJ_TYPE);
|
|
|
+ return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 设备绑定的动态信息点或静态信息点
|
|
|
- * @param admEquipment
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @GetMapping("/export")
|
|
|
- public AdmResponse exportInfos(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
|
|
|
- List<AdmEquipment> vos = CollUtil.newArrayList(admEquipment.getContent());
|
|
|
- vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
|
|
|
- return AdmResponse.success(vos);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 设备绑定的动态信息点或静态信息点
|
|
|
+ * @param admEquipment
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @GetMapping("/export")
|
|
|
+ public AdmResponse exportInfos(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
|
|
|
+ List<AdmEquipment> vos = CollUtil.newArrayList(admEquipment.getContent());
|
|
|
+ vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
|
|
|
+ return AdmResponse.success(vos);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 根据项目id查询所有的设备和部件
|
|
|
- *
|
|
|
- * @param request
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @GetMapping("/query-equip")
|
|
|
- public AdmResponse queryEquip(@RequestBody AdmQueryCriteria request) throws Exception {
|
|
|
- //request.setName("equipment");
|
|
|
- if(StrUtil.isNotEmpty(request.getFilters())){
|
|
|
- request.setFilters(String.join(";",request.getFilters(),"objType in ['equipment','component']"));
|
|
|
- }else{
|
|
|
- request.setFilters("objType in ['equipment','component']");
|
|
|
- }
|
|
|
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 根据项目id查询所有的设备和部件
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @GetMapping("/query-equip")
|
|
|
+ public AdmResponse queryEquip(@RequestBody AdmQueryCriteria request) throws Exception {
|
|
|
+ //request.setName("equipment");
|
|
|
+ if(StrUtil.isNotEmpty(request.getFilters())){
|
|
|
+ request.setFilters(String.join(";",request.getFilters(),"objType in ['equipment','component']"));
|
|
|
+ }else{
|
|
|
+ request.setFilters("objType in ['equipment','component']");
|
|
|
+ }
|
|
|
+ return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 批量创建设备同时创建资产、创建设备和系统的关系
|
|
|
- * @param admEquipment
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @PostMapping("/creat-equip-pro")
|
|
|
- public AdmResponse createExt(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
|
|
|
- List<AdmEquipment> vos = admEquipment.getContent();
|
|
|
- if(CollUtil.isEmpty(vos)){
|
|
|
- return AdmResponse.success();
|
|
|
- }
|
|
|
- //创建设备
|
|
|
- vos.stream().forEach(equipment -> {
|
|
|
- if (StrUtil.isEmpty(equipment.getName())){
|
|
|
- equipment.setName(ObjectNameUtil.objectName("设备-"));
|
|
|
- }
|
|
|
- });
|
|
|
- List<AdmEquipment> reVos = new ArrayList<>(vos.size());
|
|
|
- List<RelationDTO> relationDTOS = new ArrayList<>(16);
|
|
|
- vos.stream().forEach(admEq -> {
|
|
|
- //创建设备
|
|
|
- List<AdmEquipment> vosR = service.doInsert(AdmContextUtil.toDmpContext(), AdmEquipment.class, CollUtil.newArrayList(admEq));
|
|
|
- //TODO 创建资产
|
|
|
- //添加设备和系统、建筑、楼层的关系
|
|
|
- if(CollUtil.isNotEmpty(vosR)){
|
|
|
- String equipId = vosR.get(0).getId();
|
|
|
- if(StrUtil.isNotEmpty(equipId)){
|
|
|
- if(CollUtil.isNotEmpty(admEq.getLinkSystem())){
|
|
|
- admEq.getLinkSystem().stream().forEach(admSystem -> {
|
|
|
- relationDTOS.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null , admSystem.getId(), equipId));
|
|
|
- });
|
|
|
- }
|
|
|
- if(StrUtil.isNotEmpty(admEq.getBuildingId())){
|
|
|
- relationDTOS.add(new RelationDTO(null, "MechInArch", "Eq2Bd", null , equipId, admEq.getBuildingId()));
|
|
|
- }
|
|
|
- if(StrUtil.isNotEmpty(admEq.getFloorId())){
|
|
|
- relationDTOS.add(new RelationDTO(null, "MechInArch", "Eq2Fl", null , equipId, admEq.getFloorId()));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- reVos.addAll(vosR);
|
|
|
- });
|
|
|
- relationService.doSave(AdmContextUtil.toDmpContext(),relationDTOS);
|
|
|
- return AdmResponse.success(reVos);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 批量创建设备同时创建资产、创建设备和系统的关系
|
|
|
+ * @param admEquipment
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("/creat-equip-pro")
|
|
|
+ public AdmResponse createExt(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
|
|
|
+ List<AdmEquipment> vos = admEquipment.getContent();
|
|
|
+ if(CollUtil.isEmpty(vos)){
|
|
|
+ return AdmResponse.success();
|
|
|
+ }
|
|
|
+ //创建设备
|
|
|
+ vos.stream().forEach(equipment -> {
|
|
|
+ if (StrUtil.isEmpty(equipment.getName())){
|
|
|
+ equipment.setName(ObjectNameUtil.objectName("设备-"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<AdmEquipment> reVos = new ArrayList<>(vos.size());
|
|
|
+ List<RelationDTO> relationDTOS = new ArrayList<>(16);
|
|
|
+ vos.stream().forEach(admEq -> {
|
|
|
+ //创建设备
|
|
|
+ List<AdmEquipment> vosR = service.doInsert(AdmContextUtil.toDmpContext(), AdmEquipment.class, CollUtil.newArrayList(admEq));
|
|
|
+ //TODO 创建资产
|
|
|
+ //添加设备和系统、建筑、楼层的关系
|
|
|
+ if(CollUtil.isNotEmpty(vosR)){
|
|
|
+ String equipId = vosR.get(0).getId();
|
|
|
+ if(StrUtil.isNotEmpty(equipId)){
|
|
|
+ if(CollUtil.isNotEmpty(admEq.getLinkSystem())){
|
|
|
+ admEq.getLinkSystem().stream().forEach(admSystem -> {
|
|
|
+ relationDTOS.add(new RelationDTO(null, "MechSubset", "Sy2Eq", null , admSystem.getId(), equipId));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(admEq.getBuildingId())){
|
|
|
+ relationDTOS.add(new RelationDTO(null, "MechInArch", "Eq2Bd", null , equipId, admEq.getBuildingId()));
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(admEq.getFloorId())){
|
|
|
+ relationDTOS.add(new RelationDTO(null, "MechInArch", "Eq2Fl", null , equipId, admEq.getFloorId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reVos.addAll(vosR);
|
|
|
+ });
|
|
|
+ relationService.doSave(AdmContextUtil.toDmpContext(),relationDTOS);
|
|
|
+ return AdmResponse.success(reVos);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 设备上传excel识别静态信息点
|
|
|
*
|
|
|
+ * @param file
|
|
|
* @param request
|
|
|
* @param response
|
|
|
*/
|
|
@@ -282,7 +322,7 @@ public class AdmEquipmentController {
|
|
|
return AdmResponse.failure("未选择文件");
|
|
|
}
|
|
|
String path = AdmCommonConstant.SERVER_ROOT_PATH + AdmExcelUtil.TEMP_UPLOAD_PAHT;
|
|
|
-
|
|
|
+
|
|
|
int failurNum = 0;
|
|
|
int successCount = 0;
|
|
|
String failure = null;
|
|
@@ -293,187 +333,187 @@ public class AdmEquipmentController {
|
|
|
String groupCode = AppContext.getContext().getGroupCode();
|
|
|
String projectId = AppContext.getContext().getProjectId();
|
|
|
try {
|
|
|
-
|
|
|
+
|
|
|
workbook = new XSSFWorkbook(file.getInputStream());
|
|
|
- XSSFSheet sheet = workbook.getSheetAt(0); // 第一个sheet
|
|
|
- XSSFRow row1 = sheet.getRow(1);
|
|
|
- if (row1 == null) {
|
|
|
- AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
|
|
|
- return AdmExcelUtil.getImportFailResult("数据不存在", "2", 0, ++failurNum);
|
|
|
+ XSSFSheet sheet = workbook.getSheetAt(0); // 第一个sheet
|
|
|
+ XSSFRow row1 = sheet.getRow(1);
|
|
|
+ if (row1 == null) {
|
|
|
+ AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
|
|
|
+ return AdmExcelUtil.getImportFailResult("数据不存在", "2", 0, ++failurNum);
|
|
|
}
|
|
|
-
|
|
|
- /** 获取识别码 */
|
|
|
- XSSFCell markCell = row1.getCell(0);
|
|
|
- if (markCell == null) {
|
|
|
- AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
|
|
|
- return AdmExcelUtil.getImportFailResult("未填写识别码", "2", 0, ++failurNum);
|
|
|
+
|
|
|
+ /** 获取识别码 */
|
|
|
+ XSSFCell markCell = row1.getCell(0);
|
|
|
+ if (markCell == null) {
|
|
|
+ AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
|
|
|
+ return AdmExcelUtil.getImportFailResult("未填写识别码", "2", 0, ++failurNum);
|
|
|
}
|
|
|
- primaryKey = markCell.getStringCellValue().trim(); // 识别码
|
|
|
+ primaryKey = markCell.getStringCellValue().trim(); // 识别码
|
|
|
boolean containsKey = AdmCommonConstant.codeColMap.containsKey(primaryKey);
|
|
|
if (!containsKey) {
|
|
|
AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
|
|
|
- return AdmExcelUtil.getImportFailResult("未找到识别码", "2", 0, ++failurNum);
|
|
|
+ return AdmExcelUtil.getImportFailResult("未找到识别码", "2", 0, ++failurNum);
|
|
|
}
|
|
|
primaryKey = AdmCommonConstant.codeColMap.get(primaryKey);
|
|
|
-
|
|
|
- /** 获取类型 */
|
|
|
- XSSFCell cell = row1.getCell(1);
|
|
|
- if (cell == null) {
|
|
|
- AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
|
|
|
- return AdmExcelUtil.getImportFailResult("未填写设备类型", "2", 0, ++failurNum);
|
|
|
+
|
|
|
+ /** 获取类型 */
|
|
|
+ XSSFCell cell = row1.getCell(1);
|
|
|
+ if (cell == null) {
|
|
|
+ AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
|
|
|
+ return AdmExcelUtil.getImportFailResult("未填写设备类型", "2", 0, ++failurNum);
|
|
|
}
|
|
|
- classCodeCloumn = cell.getStringCellValue().trim();
|
|
|
- if (!"ClassCode".equals(classCodeCloumn)) {
|
|
|
- AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
|
|
|
- return AdmExcelUtil.getImportFailResult("缺少设备类型(ClassCode)", "2", 0, ++failurNum);
|
|
|
+ classCodeCloumn = cell.getStringCellValue().trim();
|
|
|
+ if (!"ClassCode".equals(classCodeCloumn)) {
|
|
|
+ AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
|
|
|
+ return AdmExcelUtil.getImportFailResult("缺少设备类型(ClassCode)", "2", 0, ++failurNum);
|
|
|
}
|
|
|
-
|
|
|
- // 存取所有的信息点
|
|
|
- Map<Integer, String> infoMap = new HashMap<Integer, String>();
|
|
|
- short lastCellNum = row1.getLastCellNum();
|
|
|
- for (int i = 1; i <= lastCellNum; i++) {
|
|
|
- XSSFCell xssfCell = row1.getCell(i);
|
|
|
- if (xssfCell != null && xssfCell.getStringCellValue() != null) {
|
|
|
- infoMap.put(i, xssfCell.getStringCellValue().trim());
|
|
|
+
|
|
|
+ // 存取所有的信息点
|
|
|
+ Map<Integer, String> infoMap = new HashMap<Integer, String>();
|
|
|
+ short lastCellNum = row1.getLastCellNum();
|
|
|
+ for (int i = 1; i <= lastCellNum; i++) {
|
|
|
+ XSSFCell xssfCell = row1.getCell(i);
|
|
|
+ if (xssfCell != null && xssfCell.getStringCellValue() != null) {
|
|
|
+ infoMap.put(i, xssfCell.getStringCellValue().trim());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 录入数据获取
|
|
|
- int lastRowNum = sheet.getLastRowNum();
|
|
|
- boolean isClassCode = "classCode".equals(primaryKey);
|
|
|
- for (int i = 2; i <= lastRowNum; i++) {
|
|
|
- XSSFRow xssfRow = sheet.getRow(i);
|
|
|
- if (xssfRow == null) {
|
|
|
+
|
|
|
+ // 录入数据获取
|
|
|
+ int lastRowNum = sheet.getLastRowNum();
|
|
|
+ boolean isClassCode = "classCode".equals(primaryKey);
|
|
|
+ for (int i = 2; i <= lastRowNum; i++) {
|
|
|
+ XSSFRow xssfRow = sheet.getRow(i);
|
|
|
+ if (xssfRow == null) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- String value = null;
|
|
|
- String classCode = null;
|
|
|
- ObjectNode equipment = null;
|
|
|
- List<ObjectNode> equipmentList = null;
|
|
|
- Map<String, Object> tempMap = new HashMap<String, Object>();
|
|
|
-
|
|
|
- lastCellNum = xssfRow.getLastCellNum();
|
|
|
- for (int j = 0; j <= lastCellNum; j++) {
|
|
|
- cell = xssfRow.getCell(j);
|
|
|
- if (cell == null || StrUtil.isBlank(cell.getRawValue())) {
|
|
|
- xssfRow.createCell(j);
|
|
|
- if (j == 0) {
|
|
|
- this.setColor(workbook, 252, 255, 77, xssfRow.getCell(j));
|
|
|
+
|
|
|
+ String value = null;
|
|
|
+ String classCode = null;
|
|
|
+ ObjectNode equipment = null;
|
|
|
+ List<ObjectNode> equipmentList = null;
|
|
|
+ Map<String, Object> tempMap = new HashMap<String, Object>();
|
|
|
+
|
|
|
+ lastCellNum = xssfRow.getLastCellNum();
|
|
|
+ for (int j = 0; j <= lastCellNum; j++) {
|
|
|
+ cell = xssfRow.getCell(j);
|
|
|
+ if (cell == null || StrUtil.isBlank(cell.getRawValue())) {
|
|
|
+ xssfRow.createCell(j);
|
|
|
+ if (j == 0) {
|
|
|
+ this.setColor(workbook, 252, 255, 77, xssfRow.getCell(j));
|
|
|
} else {
|
|
|
this.setColor(workbook, 77, 178, 255, xssfRow.getCell(j));
|
|
|
}
|
|
|
- continue;
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (j == 0) {
|
|
|
- cell.setCellType(CellType.STRING);
|
|
|
- value = cell.getStringCellValue().trim();
|
|
|
- String codeType = isClassCode ? xssfRow.getCell(0).toString().trim() : xssfRow.getCell(1).toString().trim();
|
|
|
- // 获取类型定义
|
|
|
- ObjectTypeDefine define = this.getObjectTypeDefine(groupCode, projectId, codeType);
|
|
|
- if (define == null) {
|
|
|
+ if (j == 0) {
|
|
|
+ cell.setCellType(CellType.STRING);
|
|
|
+ value = cell.getStringCellValue().trim();
|
|
|
+ String codeType = isClassCode ? xssfRow.getCell(0).toString().trim() : xssfRow.getCell(1).toString().trim();
|
|
|
+ // 获取类型定义
|
|
|
+ ObjectTypeDefine define = this.getObjectTypeDefine(groupCode, projectId, codeType);
|
|
|
+ if (define == null) {
|
|
|
this.setColor(workbook, 56, 94, 15, cell);
|
|
|
continue;
|
|
|
}
|
|
|
- classCode = define.getCode();
|
|
|
- equipmentList = isClassCode ? this.getEquipmentList(groupCode, projectId, null, null, classCode)
|
|
|
- : this.getEquipmentList(groupCode, projectId, primaryKey, value, classCode);
|
|
|
-
|
|
|
- if (CollectionUtil.isEmpty(equipmentList)) {
|
|
|
- failurNum++;
|
|
|
- this.setColor(workbook, 153, 225, 77, cell);
|
|
|
- continue;
|
|
|
+ classCode = define.getCode();
|
|
|
+ equipmentList = isClassCode ? this.getEquipmentList(groupCode, projectId, null, null, classCode)
|
|
|
+ : this.getEquipmentList(groupCode, projectId, primaryKey, value, classCode);
|
|
|
+
|
|
|
+ if (CollectionUtil.isEmpty(equipmentList)) {
|
|
|
+ failurNum++;
|
|
|
+ this.setColor(workbook, 153, 225, 77, cell);
|
|
|
+ continue;
|
|
|
}
|
|
|
-
|
|
|
- if (isClassCode) {
|
|
|
- equipment = equipmentList.get(0);
|
|
|
+
|
|
|
+ if (isClassCode) {
|
|
|
+ equipment = equipmentList.get(0);
|
|
|
} else {
|
|
|
if (equipmentList.size() > 1) {
|
|
|
failurNum++;
|
|
|
- this.setColor(workbook, 249, 203, 77, cell);
|
|
|
- } else {
|
|
|
- equipment = equipmentList.get(0);
|
|
|
+ this.setColor(workbook, 249, 203, 77, cell);
|
|
|
+ } else {
|
|
|
+ equipment = equipmentList.get(0);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 剩余列数据处理
|
|
|
- if (j != 1 && equipment != null && infoMap.containsKey(j)) {
|
|
|
- // 获取设备类的信息点
|
|
|
- List<ObjectInfoDefine> funidList = this.relationReportService.queryFunidList(groupCode, projectId, Sets.newHashSet(classCode), infoMap.get(j), "STATIC");
|
|
|
- if (CollectionUtil.isEmpty(funidList)) {
|
|
|
- failurNum++;
|
|
|
- this.setColor(workbook, 77, 178, 255, cell);
|
|
|
- continue;
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 剩余列数据处理
|
|
|
+ if (j != 1 && equipment != null && infoMap.containsKey(j)) {
|
|
|
+ // 获取设备类的信息点
|
|
|
+ List<ObjectInfoDefine> funidList = this.relationReportService.queryFunidList(groupCode, projectId, Sets.newHashSet(classCode), infoMap.get(j), "STATIC");
|
|
|
+ if (CollectionUtil.isEmpty(funidList)) {
|
|
|
+ failurNum++;
|
|
|
+ this.setColor(workbook, 77, 178, 255, cell);
|
|
|
+ continue;
|
|
|
}
|
|
|
- ObjectInfoDefine define = funidList.get(0);
|
|
|
- if ("STRING".equalsIgnoreCase(define.getDataType())) {
|
|
|
- tempMap.put(define.getCode(), cell.getStringCellValue().trim());
|
|
|
+ ObjectInfoDefine define = funidList.get(0);
|
|
|
+ if ("STRING".equalsIgnoreCase(define.getDataType())) {
|
|
|
+ tempMap.put(define.getCode(), cell.getStringCellValue().trim());
|
|
|
} else if ("INTEGER".equalsIgnoreCase(define.getDataType())) {
|
|
|
try {
|
|
|
if (!CellType.NUMERIC.equals(cell.getCellTypeEnum()) || StrUtil.isBlank(cell.getRawValue())) {
|
|
|
failurNum++;
|
|
|
this.setColor(workbook, 155, 227, 255, cell);
|
|
|
- continue;
|
|
|
+ continue;
|
|
|
}
|
|
|
cell.setCellType(CellType.STRING);
|
|
|
tempMap.put(define.getCode(), cell.getStringCellValue().trim());
|
|
|
} catch (Exception e) {
|
|
|
failurNum++;
|
|
|
this.setColor(workbook, 155, 227, 255, cell);
|
|
|
- continue;
|
|
|
+ continue;
|
|
|
}
|
|
|
} else if ("ENUM".equalsIgnoreCase(define.getDataType())) {
|
|
|
if (CellType.NUMERIC.equals(cell.getCellTypeEnum()) && StrUtil.isNotBlank(cell.getRawValue())) {
|
|
|
cell.setCellType(CellType.STRING);
|
|
|
tempMap.put(define.getCode(), cell.getStringCellValue().trim());
|
|
|
- } else if (CellType.STRING.equals(cell.getCellTypeEnum()) && StrUtil.isNotBlank(cell.getRawValue())) {
|
|
|
- tempMap.put(define.getCode(), cell.getStringCellValue().trim());
|
|
|
- } else {
|
|
|
- failurNum++;
|
|
|
- this.setColor(workbook, 155, 227, 255, cell);
|
|
|
- continue;
|
|
|
- }
|
|
|
+ } else if (CellType.STRING.equals(cell.getCellTypeEnum()) && StrUtil.isNotBlank(cell.getRawValue())) {
|
|
|
+ tempMap.put(define.getCode(), cell.getStringCellValue().trim());
|
|
|
+ } else {
|
|
|
+ failurNum++;
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
} else if ("DATETIME".equalsIgnoreCase(define.getDataType())) {
|
|
|
- try {
|
|
|
- cell.setCellType(CellType.STRING);
|
|
|
- String trim = cell.getStringCellValue().trim();
|
|
|
- tempMap.put(define.getCode(), DateUtil.parseByPatterns(trim, "yyyyMMdd"));
|
|
|
- } catch (Exception e) {
|
|
|
- failurNum++;
|
|
|
- this.setColor(workbook, 155, 227, 255, cell);
|
|
|
- continue;
|
|
|
- }
|
|
|
+ try {
|
|
|
+ cell.setCellType(CellType.STRING);
|
|
|
+ String trim = cell.getStringCellValue().trim();
|
|
|
+ tempMap.put(define.getCode(), DateUtil.parseByPatterns(trim, "yyyyMMdd"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ failurNum++;
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
} else if ("DOUBLE".equalsIgnoreCase(define.getDataType())) {
|
|
|
try {
|
|
|
cell.setCellType(CellType.STRING);
|
|
|
- String trim = cell.getStringCellValue().trim();
|
|
|
+ String trim = cell.getStringCellValue().trim();
|
|
|
tempMap.put(define.getCode(), Double.parseDouble(trim));
|
|
|
} catch (Exception e) {
|
|
|
- failurNum++;
|
|
|
- this.setColor(workbook, 155, 227, 255, cell);
|
|
|
- continue;
|
|
|
- }
|
|
|
+ failurNum++;
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
} else if ("BOOLEAN".equalsIgnoreCase(define.getDataType())) {
|
|
|
cell.setCellType(CellType.STRING);
|
|
|
- String trim = cell.getStringCellValue() == null ? null : cell.getStringCellValue().trim();
|
|
|
+ String trim = cell.getStringCellValue() == null ? null : cell.getStringCellValue().trim();
|
|
|
if ("1".equals(trim) || "0".equals(trim)) {
|
|
|
tempMap.put(define.getCode(), Double.parseDouble(trim));
|
|
|
} else {
|
|
|
failurNum++;
|
|
|
- this.setColor(workbook, 155, 227, 255, cell);
|
|
|
- continue;
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ continue;
|
|
|
}
|
|
|
} else {
|
|
|
failurNum++;
|
|
|
this.setColor(workbook, 204, 99, 233, cell);
|
|
|
- continue;
|
|
|
+ continue;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (isClassCode) {
|
|
|
+
|
|
|
+ if (isClassCode) {
|
|
|
if (CollectionUtil.isNotEmpty(equipmentList) && tempMap.size() > 0) {
|
|
|
for (ObjectNode equipNode : equipmentList) {
|
|
|
int success = this.updateEquipInfo(tempMap, groupCode, projectId, equipNode.get("id").asText());
|
|
@@ -494,14 +534,14 @@ public class AdmEquipmentController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // 写入错误报告对比值颜色
|
|
|
- this.wirteReport(workbook, sheet);
|
|
|
-
|
|
|
- // 返回正确结果
|
|
|
- String fileName = AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
|
|
|
- return AdmExcelUtil.getImportSuccessResult(fileName, successCount, failurNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写入错误报告对比值颜色
|
|
|
+ this.wirteReport(workbook, sheet);
|
|
|
+
|
|
|
+ // 返回正确结果
|
|
|
+ String fileName = AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
|
|
|
+ return AdmExcelUtil.getImportSuccessResult(fileName, successCount, failurNum);
|
|
|
} catch (Exception e) {
|
|
|
log.error("台账信息导入失败", e);
|
|
|
failure = e.getMessage();
|
|
@@ -520,10 +560,10 @@ public class AdmEquipmentController {
|
|
|
}
|
|
|
return AdmResponse.failure(failure);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 更新设备信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param tempMap
|
|
|
* @param groupCode
|
|
|
* @param projectId
|
|
@@ -532,28 +572,28 @@ public class AdmEquipmentController {
|
|
|
*/
|
|
|
private int updateEquipInfo(Map<String, Object> tempMap, String groupCode, String projectId, String equipId) {
|
|
|
ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
|
|
|
-
|
|
|
+
|
|
|
Set<String> keySet = tempMap.keySet();
|
|
|
ObjectNode updateEquip = objectMapper.createObjectNode();
|
|
|
for (String key : keySet) {
|
|
|
Object obj = tempMap.get(key);
|
|
|
-
|
|
|
+
|
|
|
updateEquip.put("id", equipId);
|
|
|
if (obj instanceof Date) {
|
|
|
updateEquip.putPOJO(key, obj);
|
|
|
} else {
|
|
|
updateEquip.put(key, obj.toString());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
ObjectDigital updateOne = DigitalObjectFacade.updateOne(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, updateEquip);
|
|
|
return updateOne == null ? 0 : 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 获取类型定义
|
|
|
- *
|
|
|
+ *
|
|
|
* @param code
|
|
|
* @return
|
|
|
*/
|
|
@@ -566,14 +606,14 @@ public class AdmEquipmentController {
|
|
|
condition.putPOJO("parentCode", arrays);
|
|
|
condition.put("code", code);
|
|
|
queryCriteria.setCriteria(condition);
|
|
|
-
|
|
|
+
|
|
|
List<ObjectTypeDefine> objectType = DigitalDefineFacade.queryObjectType(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
|
|
|
return CollectionUtil.isEmpty(objectType) ? null : objectType.get(0);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 获取设备
|
|
|
- *
|
|
|
+ *
|
|
|
* @param groupCode
|
|
|
* @param projectId
|
|
|
* @param primaryKey
|
|
@@ -590,30 +630,30 @@ public class AdmEquipmentController {
|
|
|
}
|
|
|
condition.put("classCode", classCode);
|
|
|
queryCriteria.setCriteria(condition);
|
|
|
-
|
|
|
+
|
|
|
List<ObjectNode> objectNodes = DigitalObjectFacade.query(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, queryCriteria);
|
|
|
return objectNodes;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置填充色
|
|
|
- *
|
|
|
- * @param workbook
|
|
|
- * @param r
|
|
|
- * @param g
|
|
|
- * @param b
|
|
|
- * @param cell
|
|
|
- */
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置填充色
|
|
|
+ *
|
|
|
+ * @param workbook
|
|
|
+ * @param r
|
|
|
+ * @param g
|
|
|
+ * @param b
|
|
|
+ * @param cell
|
|
|
+ */
|
|
|
private void setColor(XSSFWorkbook workbook, int r, int g, int b, XSSFCell cell) {
|
|
|
- XSSFCellStyle createCellStyle = workbook.createCellStyle();
|
|
|
- createCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
- createCellStyle.setFillForegroundColor(new XSSFColor(new Color(r, g, b)));
|
|
|
- cell.setCellStyle(createCellStyle);
|
|
|
- }
|
|
|
-
|
|
|
+ XSSFCellStyle createCellStyle = workbook.createCellStyle();
|
|
|
+ createCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ createCellStyle.setFillForegroundColor(new XSSFColor(new Color(r, g, b)));
|
|
|
+ cell.setCellStyle(createCellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 写入错误报告对比值颜色
|
|
|
- *
|
|
|
+ *
|
|
|
* @param workbook
|
|
|
* @param sheet
|
|
|
*/
|
|
@@ -628,7 +668,7 @@ public class AdmEquipmentController {
|
|
|
createCell.setCellValue("导入失败,识别码超出范围( 本地编码,本地名称,数字化交付码 )");
|
|
|
createCell = row4.createCell(column + 1);
|
|
|
this.setColor(workbook,233,99,99,createCell);
|
|
|
-
|
|
|
+
|
|
|
XSSFRow row5 = sheet.getRow(5);
|
|
|
if (row5 == null) {
|
|
|
row5 = sheet.createRow(5);
|
|
@@ -637,7 +677,7 @@ public class AdmEquipmentController {
|
|
|
createCell.setCellValue("导入失败,识别码为空");
|
|
|
createCell = row5.createCell(column + 1);
|
|
|
this.setColor(workbook,252,147,77,createCell);
|
|
|
-
|
|
|
+
|
|
|
XSSFRow row6 = sheet.getRow(6);
|
|
|
if (row6 == null) {
|
|
|
row6 = sheet.createRow(6);
|
|
@@ -646,7 +686,7 @@ public class AdmEquipmentController {
|
|
|
createCell.setCellValue("导入失败,多个实例");
|
|
|
createCell = row6.createCell(column + 1);
|
|
|
this.setColor(workbook,249,203,77,createCell);
|
|
|
-
|
|
|
+
|
|
|
XSSFRow row7 = sheet.getRow(7);
|
|
|
if (row7 == null) {
|
|
|
row7 = sheet.createRow(7);
|
|
@@ -655,7 +695,7 @@ public class AdmEquipmentController {
|
|
|
createCell.setCellValue("导入失败,设备不存在");
|
|
|
createCell = row7.createCell(column + 1);
|
|
|
this.setColor(workbook,153,225,77,createCell);
|
|
|
-
|
|
|
+
|
|
|
XSSFRow row8 = sheet.getRow(8);
|
|
|
if (row8 == null) {
|
|
|
row8 = sheet.createRow(8);
|
|
@@ -664,7 +704,7 @@ public class AdmEquipmentController {
|
|
|
createCell.setCellValue("导入失败,识别码值为空");
|
|
|
createCell = row8.createCell(column + 1);
|
|
|
this.setColor(workbook,252,255,77,createCell);
|
|
|
-
|
|
|
+
|
|
|
XSSFRow row9 = sheet.getRow(9);
|
|
|
if (row9 == null) {
|
|
|
row9 = sheet.createRow(9);
|
|
@@ -673,7 +713,7 @@ public class AdmEquipmentController {
|
|
|
createCell.setCellValue("导入失败,输入类型与字典定义不一致");
|
|
|
createCell = row9.createCell(column + 1);
|
|
|
this.setColor(workbook,155,227,255,createCell);
|
|
|
-
|
|
|
+
|
|
|
XSSFRow row10 = sheet.getRow(10);
|
|
|
if (row10 == null) {
|
|
|
row10 = sheet.createRow(10);
|
|
@@ -682,7 +722,7 @@ public class AdmEquipmentController {
|
|
|
createCell.setCellValue("导入失败,未支持的输入类型");
|
|
|
createCell = row10.createCell(column + 1);
|
|
|
this.setColor(workbook,204,99,233,createCell);
|
|
|
-
|
|
|
+
|
|
|
XSSFRow row11 = sheet.getRow(11);
|
|
|
if (row11 == null) {
|
|
|
row11 = sheet.createRow(11);
|
|
@@ -701,5 +741,5 @@ public class AdmEquipmentController {
|
|
|
createCell = row12.createCell(column + 1);
|
|
|
this.setColor(workbook,56,94,15,createCell);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|