|
@@ -42,6 +42,7 @@ import com.persagy.dmp.define.client.DigitalDefineFacade;
|
|
|
import com.persagy.dmp.define.entity.ObjectInfoDefine;
|
|
|
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.request.AdmCreateRequest;
|
|
|
import com.persagy.proxy.adm.request.AdmQueryCriteria;
|
|
@@ -296,6 +297,7 @@ public class AdmEquipmentController {
|
|
|
AdmExcelUtil.writeFile2Local(workbook, projectId, path, file.getOriginalFilename());
|
|
|
return AdmExcelUtil.getImportFailResult("未找到识别码", "2", 0, ++failurNum);
|
|
|
}
|
|
|
+ primaryKey = AdmCommonConstant.codeColMap.get(primaryKey);
|
|
|
|
|
|
/** 获取类型 */
|
|
|
XSSFCell cell = row1.getCell(1);
|
|
@@ -320,42 +322,43 @@ public class AdmEquipmentController {
|
|
|
}
|
|
|
|
|
|
// 录入数据获取
|
|
|
-
|
|
|
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 code = null;
|
|
|
String classCode = null;
|
|
|
ObjectNode equipment = null;
|
|
|
List<ObjectNode> equipmentList = null;
|
|
|
Map<String, Object> tempMap = new HashMap<String, Object>();
|
|
|
|
|
|
- XSSFRow xssfRow = sheet.getRow(i);
|
|
|
- if (xssfRow == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- lastCellNum = row1.getLastCellNum();
|
|
|
- for (int j = 1; j <= lastCellNum; i++) {
|
|
|
- cell = row1.getCell(j);
|
|
|
- if (cell == null) {
|
|
|
+ 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));
|
|
|
+ }
|
|
|
continue;
|
|
|
}
|
|
|
if (j == 0) {
|
|
|
- value = cell.getStringCellValue();
|
|
|
- if (StrUtil.isBlank(value)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- code = isClassCode ? xssfRow.getCell(0).toString() : xssfRow.getCell(1).toString();
|
|
|
+ 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, code);
|
|
|
+ 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, code, classCode);
|
|
|
+ : this.getEquipmentList(groupCode, projectId, primaryKey, value, classCode);
|
|
|
|
|
|
if (CollectionUtil.isEmpty(equipmentList)) {
|
|
|
failurNum++;
|
|
@@ -377,12 +380,12 @@ public class AdmEquipmentController {
|
|
|
continue;
|
|
|
}
|
|
|
// 剩余列数据处理
|
|
|
- if (j != 1 && StrUtil.isNotBlank(code) && equipment != null && infoMap.containsKey(j)) {
|
|
|
+ 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, 249, 203, 77, cell);
|
|
|
+ this.setColor(workbook, 77, 178, 255, cell);
|
|
|
continue;
|
|
|
}
|
|
|
ObjectInfoDefine define = funidList.get(0);
|
|
@@ -392,14 +395,14 @@ public class AdmEquipmentController {
|
|
|
try {
|
|
|
if (!CellType.NUMERIC.equals(cell.getCellTypeEnum()) || StrUtil.isBlank(cell.getRawValue())) {
|
|
|
failurNum++;
|
|
|
- this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
continue;
|
|
|
}
|
|
|
cell.setCellType(CellType.STRING);
|
|
|
tempMap.put(define.getCode(), cell.getStringCellValue().trim());
|
|
|
} catch (Exception e) {
|
|
|
failurNum++;
|
|
|
- this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
continue;
|
|
|
}
|
|
|
} else if ("ENUM".equalsIgnoreCase(define.getDataType())) {
|
|
@@ -410,7 +413,7 @@ public class AdmEquipmentController {
|
|
|
tempMap.put(define.getCode(), cell.getStringCellValue().trim());
|
|
|
} else {
|
|
|
failurNum++;
|
|
|
- this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
continue;
|
|
|
}
|
|
|
} else if ("DATETIME".equalsIgnoreCase(define.getDataType())) {
|
|
@@ -420,7 +423,7 @@ public class AdmEquipmentController {
|
|
|
tempMap.put(define.getCode(), DateUtil.parseByPatterns(trim, "yyyyMMdd"));
|
|
|
} catch (Exception e) {
|
|
|
failurNum++;
|
|
|
- this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
continue;
|
|
|
}
|
|
|
} else if ("DOUBLE".equalsIgnoreCase(define.getDataType())) {
|
|
@@ -430,7 +433,7 @@ public class AdmEquipmentController {
|
|
|
tempMap.put(define.getCode(), Double.parseDouble(trim));
|
|
|
} catch (Exception e) {
|
|
|
failurNum++;
|
|
|
- this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
continue;
|
|
|
}
|
|
|
} else if ("BOOLEAN".equalsIgnoreCase(define.getDataType())) {
|
|
@@ -445,7 +448,7 @@ public class AdmEquipmentController {
|
|
|
}
|
|
|
} else {
|
|
|
failurNum++;
|
|
|
- this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ this.setColor(workbook, 204, 99, 233, cell);
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
@@ -455,13 +458,21 @@ public class AdmEquipmentController {
|
|
|
if (CollectionUtil.isNotEmpty(equipmentList) && tempMap.size() > 0) {
|
|
|
for (ObjectNode equipNode : equipmentList) {
|
|
|
int success = this.updateEquipInfo(tempMap, groupCode, projectId, equipNode.get("id").asText());
|
|
|
- successCount += success;
|
|
|
+ if (success == 0) {
|
|
|
+ failurNum++;
|
|
|
+ } else {
|
|
|
+ successCount++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- if (StrUtil.isNotBlank(code) && equipment != null && tempMap.size() > 0) {
|
|
|
+ if (StrUtil.isNotBlank(value) && equipment != null && tempMap.size() > 0) {
|
|
|
int success = this.updateEquipInfo(tempMap, groupCode, projectId, equipment.get("id").asText());
|
|
|
- successCount += success;
|
|
|
+ if (success == 0) {
|
|
|
+ failurNum++;
|
|
|
+ } else {
|
|
|
+ successCount++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -501,14 +512,13 @@ public class AdmEquipmentController {
|
|
|
* @return
|
|
|
*/
|
|
|
private int updateEquipInfo(Map<String, Object> tempMap, String groupCode, String projectId, String equipId) {
|
|
|
- int successCount = 0;
|
|
|
ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
|
|
|
|
|
|
Set<String> keySet = tempMap.keySet();
|
|
|
- List<ObjectNode> objectNodes = new ArrayList<ObjectNode>();
|
|
|
+ ObjectNode updateEquip = objectMapper.createObjectNode();
|
|
|
for (String key : keySet) {
|
|
|
Object obj = tempMap.get(key);
|
|
|
- ObjectNode updateEquip = objectMapper.createObjectNode();
|
|
|
+
|
|
|
updateEquip.put("id", equipId);
|
|
|
if (obj instanceof Date) {
|
|
|
updateEquip.putPOJO(key, obj);
|
|
@@ -516,15 +526,10 @@ public class AdmEquipmentController {
|
|
|
updateEquip.put(key, obj.toString());
|
|
|
}
|
|
|
|
|
|
- successCount++;
|
|
|
- objectNodes.add(updateEquip);
|
|
|
- }
|
|
|
-
|
|
|
- if (CollectionUtil.isNotEmpty(objectNodes)) {
|
|
|
- DigitalObjectFacade.update(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, objectNodes);
|
|
|
}
|
|
|
|
|
|
- return successCount;
|
|
|
+ ObjectDigital updateOne = DigitalObjectFacade.updateOne(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, updateEquip);
|
|
|
+ return updateOne == null ? 0 : 1;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -581,9 +586,7 @@ public class AdmEquipmentController {
|
|
|
* @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);
|