|
@@ -5,15 +5,18 @@ import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
-import org.apache.poi.ss.usermodel.CellType;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.poi.excel.ExcelUtil;
|
|
|
+import cn.hutool.poi.excel.RowUtil;
|
|
|
+import cn.hutool.poi.excel.WorkbookUtil;
|
|
|
+import cn.hutool.poi.excel.cell.CellUtil;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
@@ -86,11 +89,10 @@ public class RelationReportController {
|
|
|
private final RelationObjectContext relationObjectContext;
|
|
|
|
|
|
private final IRelationReportService relationReportService;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 查询总数量
|
|
|
*
|
|
|
- * @param queryCriteria
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
|
@@ -132,7 +134,6 @@ public class RelationReportController {
|
|
|
* 项目关系类型查询
|
|
|
* {"filters":"relationType in [\"bd2sp\",\"fl2sp\"];computationalState>1"}
|
|
|
*
|
|
|
- * @param queryCriteria
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
|
@@ -271,7 +272,6 @@ public class RelationReportController {
|
|
|
* 下载报告-统计项目下已有的设备,以及静态和iot 信息点使用情况
|
|
|
* 设备.xlsx 是个空模板,所以这里未使用
|
|
|
*
|
|
|
- * @param projectId
|
|
|
* @param request
|
|
|
* @param response
|
|
|
* @return
|
|
@@ -480,7 +480,6 @@ public class RelationReportController {
|
|
|
* 文件导入,这里由于需要回写文件,且存储到本地,采用原始POI文件解析、上传、回写、存储
|
|
|
*
|
|
|
* @param relType
|
|
|
- * @param code
|
|
|
* @param zoneType
|
|
|
* @param request
|
|
|
* @param response
|
|
@@ -624,7 +623,7 @@ public class RelationReportController {
|
|
|
int failCount = 0;
|
|
|
int successCount = 0;
|
|
|
String failure = null;
|
|
|
- XSSFWorkbook workbook = null;
|
|
|
+ Workbook workbook = null;
|
|
|
String groupCode = AppContext.getContext().getGroupCode();
|
|
|
String projectId = AppContext.getContext().getProjectId();
|
|
|
ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
|
|
@@ -632,37 +631,33 @@ public class RelationReportController {
|
|
|
if (file == null) {
|
|
|
return AdmResponse.failure("未选择文件");
|
|
|
}
|
|
|
-
|
|
|
- workbook = new XSSFWorkbook(file.getInputStream());
|
|
|
- XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
- XSSFRow row = sheet.getRow(0);
|
|
|
+ workbook = ExcelUtil.getReader(file.getInputStream()).getWorkbook();
|
|
|
+ Sheet sheet = WorkbookUtil.getOrCreateSheet(workbook,0);
|
|
|
+ Row row = RowUtil.getOrCreateRow(sheet,0);
|
|
|
if (row == null) {
|
|
|
return AdmResponse.failure("文件标题行不存在");
|
|
|
}
|
|
|
-
|
|
|
- int identificationCode = -1, infosCode = -1, tableCode = -1, functionCode = -1, infosFeedback = -1,
|
|
|
+ int identificationCode = -1, infosCode = -1, tableCode = -1, functionCode = -1, infosFeedback = -1,
|
|
|
classCodeIndexes = -1, bimIdIndexes = -1;
|
|
|
-
|
|
|
short lastCellNum = row.getLastCellNum();
|
|
|
for (int i = 0; i <= lastCellNum; i++) {
|
|
|
- XSSFCell cell = row.getCell(i);
|
|
|
- if (cell != null && cell.getStringCellValue() != null && "本地编码".equals(cell.getStringCellValue().trim())) {
|
|
|
+ String cellValue = StrUtil.str(CellUtil.getCellValue(CellUtil.getOrCreateCell(row,i),true), StandardCharsets.UTF_8);
|
|
|
+ if (StrUtil.isNotBlank(cellValue) && "本地编码".equals(cellValue)) {
|
|
|
identificationCode = i;
|
|
|
- } else if (cell != null && cell.getStringCellValue() != null && "信息点编码".equals(cell.getStringCellValue().trim())) {
|
|
|
+ } else if (StrUtil.isNotBlank(cellValue) && "信息点编码".equals(cellValue)) {
|
|
|
infosCode = i;
|
|
|
- } else if (cell != null && cell.getStringCellValue() != null && "表号".equals(cell.getStringCellValue().trim())) {
|
|
|
+ } else if (StrUtil.isNotBlank(cellValue) && "表号".equals(cellValue)) {
|
|
|
tableCode = i;
|
|
|
- } else if (cell != null && cell.getStringCellValue() != null && "功能号".equals(cell.getStringCellValue().trim())) {
|
|
|
+ } else if (StrUtil.isNotBlank(cellValue) && "功能号".equals(cellValue)) {
|
|
|
functionCode = i;
|
|
|
- } else if (cell != null && cell.getStringCellValue() != null && "反馈信息".equals(cell.getStringCellValue().trim())) {
|
|
|
+ } else if (StrUtil.isNotBlank(cellValue) && "反馈信息".equals(cellValue)) {
|
|
|
infosFeedback = i;
|
|
|
- } else if (cell != null && cell.getStringCellValue() != null && "设备类型".equals(cell.getStringCellValue().trim())) {
|
|
|
+ } else if (StrUtil.isNotBlank(cellValue) && "设备类型".equals(cellValue)) {
|
|
|
classCodeIndexes = i;
|
|
|
- } else if (cell != null && cell.getStringCellValue() != null && "BIMID".equals(cell.getStringCellValue().trim())) {
|
|
|
+ } else if (StrUtil.isNotBlank(cellValue) && "BIMID".equals(cellValue)) {
|
|
|
bimIdIndexes = i;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
if (identificationCode == -1) {
|
|
|
failure = "缺少识别码:本地编码";
|
|
|
} else if (infosCode == -1) {
|
|
@@ -681,44 +676,67 @@ public class RelationReportController {
|
|
|
if (StrUtil.isNotBlank(failure)) {
|
|
|
return AdmExcelUtil.getImportFailResult(failure, "3", 0, 0);
|
|
|
}
|
|
|
-
|
|
|
+ // 表中的设备编码code集合
|
|
|
+ Set<String> classCodes = CollUtil.newHashSet();
|
|
|
+ // 表中的设备本地编码集合
|
|
|
+ Set<String> equipLocalIds = CollUtil.newHashSet();
|
|
|
// 业务数据获取
|
|
|
- int lastRowNum = sheet.getLastRowNum();
|
|
|
+ int lastRowNum = sheet.getLastRowNum();
|
|
|
+ for (int i = 1; i < lastRowNum; i++) {
|
|
|
+ String classCode = StrUtil.str(CellUtil
|
|
|
+ .getCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(sheet,i),classCodeIndexes),true), StandardCharsets.UTF_8);
|
|
|
+ String localId = StrUtil.str(CellUtil
|
|
|
+ .getCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(sheet,i),identificationCode),true), StandardCharsets.UTF_8);
|
|
|
+ if (StrUtil.isNotBlank(classCode)){
|
|
|
+ classCodes.add(classCode);
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(localId)){
|
|
|
+ equipLocalIds.add(localId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 1.根据设备类型code集合查询定义
|
|
|
+ Map<String,ObjectTypeDefine> defineMap = relationReportService.queryDefineTypeMapByClassCodes(classCodes);
|
|
|
+ // 2.根据设备类型code集合查询设备类的信息点
|
|
|
+ Map<String,List<ObjectInfoDefine>> defineInfoMap = relationReportService.queryDefineInfoMapByClassCodes(classCodes);
|
|
|
+ // 3.根据是否根据设备类型code上传来区分处理
|
|
|
+ Map<String,List<ObjectNode>> objectDigitalMap = relationReportService.queryEquipsByConditions("localId",equipLocalIds,classCodes);
|
|
|
+ List<ObjectNode> updateObjs = new ArrayList<>();
|
|
|
+ Set<String> addEquipIds = new HashSet<>();
|
|
|
for (int i = 1; i <= lastRowNum; i++) {
|
|
|
- XSSFRow xssfRow = sheet.getRow(i);
|
|
|
+ Row xssfRow = sheet.getRow(i);
|
|
|
if (xssfRow == null) {
|
|
|
sheet.getRow(0).createCell(16).setCellValue("第" + i + " 行数据为空");
|
|
|
continue;
|
|
|
}
|
|
|
- XSSFCell identificationCodeCell = xssfRow.getCell(identificationCode);
|
|
|
+ Cell identificationCodeCell = xssfRow.getCell(identificationCode);
|
|
|
if (identificationCodeCell == null || StrUtil.isBlank(identificationCodeCell.getStringCellValue())) {
|
|
|
failCount++;
|
|
|
xssfRow.createCell(infosFeedback).setCellValue("本地编码不可以为空");
|
|
|
continue;
|
|
|
}
|
|
|
identificationCodeCell.setCellType(CellType.STRING);
|
|
|
- XSSFCell infosCodeCell = xssfRow.getCell(infosCode);
|
|
|
+ Cell infosCodeCell = xssfRow.getCell(infosCode);
|
|
|
if (infosCodeCell == null || StrUtil.isBlank(infosCodeCell.getStringCellValue())) {
|
|
|
failCount++;
|
|
|
xssfRow.createCell(infosFeedback).setCellValue("信息点编码不可以为空");
|
|
|
continue;
|
|
|
}
|
|
|
infosCodeCell.setCellType(CellType.STRING);
|
|
|
- XSSFCell tableCodeCell = xssfRow.getCell(tableCode);
|
|
|
- if (tableCodeCell == null || StrUtil.isBlank(tableCodeCell.getRawValue())) {
|
|
|
+ Cell tableCodeCell = xssfRow.getCell(tableCode);
|
|
|
+ if (tableCodeCell == null || StrUtil.isBlank(StrUtil.str(CellUtil.getCellValue(tableCodeCell,true), StandardCharsets.UTF_8))) {
|
|
|
failCount++;
|
|
|
xssfRow.createCell(infosFeedback).setCellValue("表号不可以为空");
|
|
|
continue;
|
|
|
}
|
|
|
tableCodeCell.setCellType(CellType.STRING);
|
|
|
- XSSFCell functionCodeCell = xssfRow.getCell(functionCode);
|
|
|
- if (functionCodeCell == null || StrUtil.isBlank(functionCodeCell.getRawValue())) {
|
|
|
+ Cell functionCodeCell = xssfRow.getCell(functionCode);
|
|
|
+ if (functionCodeCell == null || StrUtil.isBlank(StrUtil.str(CellUtil.getCellValue(functionCodeCell,true), StandardCharsets.UTF_8))) {
|
|
|
failCount++;
|
|
|
xssfRow.createCell(infosFeedback).setCellValue("功能号不可以为空");
|
|
|
continue;
|
|
|
}
|
|
|
functionCodeCell.setCellType(CellType.STRING);
|
|
|
- XSSFCell classCodeIndexesCell = xssfRow.getCell(classCodeIndexes);
|
|
|
+ Cell classCodeIndexesCell = xssfRow.getCell(classCodeIndexes);
|
|
|
if (classCodeIndexesCell == null || StrUtil.isBlank(classCodeIndexesCell.getStringCellValue())) {
|
|
|
failCount++;
|
|
|
xssfRow.createCell(infosFeedback).setCellValue("设备类型不可以为空");
|
|
@@ -727,24 +745,24 @@ public class RelationReportController {
|
|
|
classCodeIndexesCell.setCellType(CellType.STRING);
|
|
|
String classCode = classCodeIndexesCell.getStringCellValue().trim();
|
|
|
// 验证此classCode是否存在
|
|
|
- ObjectTypeDefine typeDefine = this.queryClassList(groupCode, projectId, classCode, AdmObjectType.SYSTEM.getIndex());
|
|
|
+ ObjectTypeDefine typeDefine = defineMap.get(classCode);
|
|
|
if (typeDefine == null) {
|
|
|
failCount++;
|
|
|
xssfRow.createCell(infosFeedback).setCellValue("设备类型未在数据字典定义范围");
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 获取实际cell值
|
|
|
String val0 = identificationCodeCell.getStringCellValue().trim();
|
|
|
String val1 = infosCodeCell.getStringCellValue().trim();
|
|
|
String val2 = tableCodeCell.getStringCellValue().trim();
|
|
|
String val3 = functionCodeCell.getStringCellValue().trim();
|
|
|
-
|
|
|
+
|
|
|
// 获取设备信息
|
|
|
ObjectNode criteria = objectMapper.createObjectNode();
|
|
|
criteria.put("localId", val0);
|
|
|
criteria.put("classCode", classCode);
|
|
|
- List<ObjectNode> equipments = this.relationReportService.getObjectNode(criteria, groupCode, projectId, null);
|
|
|
+ List<ObjectNode> equipments = objectDigitalMap.getOrDefault(val0+StrUtil.UNDERLINE+classCode,new ArrayList<>());
|
|
|
if (CollectionUtil.isEmpty(equipments)) {
|
|
|
failCount++;
|
|
|
xssfRow.createCell(infosFeedback).setCellValue("设备类型下本地编码不存在");
|
|
@@ -764,35 +782,39 @@ public class RelationReportController {
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 获取信息点定义
|
|
|
- List<ObjectInfoDefine> funidList = this.relationReportService.queryFunidList(groupCode, projectId, Sets.newHashSet(classCode), val1, null);
|
|
|
+ List<ObjectInfoDefine> funidList = defineInfoMap.getOrDefault(classCode,new ArrayList<>())
|
|
|
+ .stream()
|
|
|
+ .filter(obj->val1.equals(obj.getAliasCode()))
|
|
|
+ .collect(Collectors.toList());;
|
|
|
if (CollectionUtil.isEmpty(funidList)) {
|
|
|
failCount++;
|
|
|
xssfRow.createCell(infosFeedback).setCellValue("信息点不存在");
|
|
|
continue;
|
|
|
}
|
|
|
- ObjectInfoDefine infoDefine = funidList.get(0);
|
|
|
-
|
|
|
+ ObjectInfoDefine infoDefine = funidList.get(0);
|
|
|
+ if ("STATIC".equals(infoDefine.getCategory())) {
|
|
|
+ failCount++;
|
|
|
+ xssfRow.createCell(infosFeedback).setCellValue("该信息点为静态信息点");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
// 数据更新,更新对应code值为,表号和功能号
|
|
|
- ObjectNode objectNode = objectMapper.createObjectNode();
|
|
|
- objectNode.put("id", equipments.get(0).get("id").asText());
|
|
|
+ ObjectNode objectNode = equipments.get(0);
|
|
|
objectNode.put(infoDefine.getCode(), val2 + "-" +val3);
|
|
|
-
|
|
|
- ObjectDigital updateOne = DigitalObjectFacade.updateOne(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, objectNode);
|
|
|
- if (updateOne == null) {
|
|
|
- failCount++;
|
|
|
- xssfRow.createCell(infosFeedback).setCellValue("失败");
|
|
|
- String bimId = this.getObjectBimId(equipments.get(0));
|
|
|
- if (StrUtil.isNotBlank(bimId)) {
|
|
|
- xssfRow.createCell(bimIdIndexes).setCellValue(bimId);
|
|
|
- }
|
|
|
- } else {
|
|
|
- xssfRow.createCell(infosFeedback).setCellValue("成功");
|
|
|
- successCount++;
|
|
|
+ successCount++;
|
|
|
+ if (!addEquipIds.contains(objectNode.get("id").asText())){
|
|
|
+ addEquipIds.add(objectNode.get("id").asText());
|
|
|
+ updateObjs.add(objectNode);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ if (CollUtil.isNotEmpty(updateObjs)){
|
|
|
+ DigitalObjectFacade.update(AppContext.getContext().getGroupCode(),
|
|
|
+ AppContext.getContext().getProjectId(),
|
|
|
+ AppContext.getContext().getAppId(),
|
|
|
+ AppContext.getContext().getAccountId(),
|
|
|
+ updateObjs);
|
|
|
+ }
|
|
|
// 文件存储及返回
|
|
|
String fileName = AdmExcelUtil.writeFile2Local(workbook, projectId, AdmCommonConstant.SERVER_ROOT_PATH + AdmExcelUtil.TEMP_UPLOAD_PAHT, file.getOriginalFilename());
|
|
|
return AdmExcelUtil.getImportSuccessResult(fileName, successCount, failCount);
|