|
@@ -1,30 +1,75 @@
|
|
|
package com.persagy.proxy.adm.controller;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
+import java.awt.Color;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.apache.poi.ss.usermodel.CellType;
|
|
|
+import org.apache.poi.ss.usermodel.FillPatternType;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFColor;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+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.helper.SpringHelper;
|
|
|
+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.proxy.adm.constant.AdmCommonConstant;
|
|
|
import com.persagy.proxy.adm.model.AdmEquipment;
|
|
|
import com.persagy.proxy.adm.request.AdmCreateRequest;
|
|
|
import com.persagy.proxy.adm.request.AdmQueryCriteria;
|
|
|
import com.persagy.proxy.adm.request.AdmResponse;
|
|
|
import com.persagy.proxy.adm.service.IAdmEquipmentService;
|
|
|
import com.persagy.proxy.adm.service.IAdmRelationService;
|
|
|
+import com.persagy.proxy.adm.service.IRelationReportService;
|
|
|
import com.persagy.proxy.adm.utils.AdmContextUtil;
|
|
|
import com.persagy.proxy.adm.utils.ObjectNameUtil;
|
|
|
import com.persagy.proxy.common.entity.RelationDTO;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
/**
|
|
|
* Adm 楼层 API
|
|
|
* @author lvxy
|
|
|
* @date 2021/8/16
|
|
|
*/
|
|
|
-
|
|
|
+@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping("/object/equip")
|
|
|
public class AdmEquipmentController {
|
|
@@ -32,6 +77,8 @@ public class AdmEquipmentController {
|
|
|
private IAdmEquipmentService service;
|
|
|
@Autowired
|
|
|
private IAdmRelationService relationService;
|
|
|
+ @Autowired
|
|
|
+ private IRelationReportService relationReportService;
|
|
|
|
|
|
/**
|
|
|
* 统计
|
|
@@ -141,19 +188,6 @@ public class AdmEquipmentController {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 设备上传excel识别静态信息点
|
|
|
- * @param admEquipment
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @PostMapping("/import")
|
|
|
- public AdmResponse importInfos(@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
|
|
@@ -218,5 +252,518 @@ public class AdmEquipmentController {
|
|
|
return AdmResponse.success(reVos);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设备上传excel识别静态信息点
|
|
|
+ *
|
|
|
+ * @param relType
|
|
|
+ * @param code
|
|
|
+ * @param zoneType
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @RequestMapping("/import")
|
|
|
+ public AdmResponse importFile(@RequestParam("file") MultipartFile file, @RequestParam String relType, @RequestParam(required = false) String zoneType,
|
|
|
+ HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ if (file == null) {
|
|
|
+ return AdmResponse.failure("未选择文件");
|
|
|
+ }
|
|
|
+
|
|
|
+ int failurNum = 0;
|
|
|
+ int successCount = 0;
|
|
|
+ String failure = null;
|
|
|
+ String primaryKey = null;
|
|
|
+ String classCodeCloumn = null;
|
|
|
+ FileOutputStream fileOutputStream = null;
|
|
|
+ String groupCode = AppContext.getContext().getGroupCode();
|
|
|
+ String projectId = AppContext.getContext().getProjectId();
|
|
|
+ try {
|
|
|
+
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(file.getInputStream());
|
|
|
+ XSSFSheet sheet = workbook.getSheetAt(0); // 第一个sheet
|
|
|
+ XSSFRow row1 = sheet.getRow(1);
|
|
|
+ if (row1 == null) {
|
|
|
+ this.writeFile2Local(workbook, projectId, file.getOriginalFilename());
|
|
|
+ return this.getImportFailResult("数据不存在", "2", 0, ++failurNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 获取识别码 */
|
|
|
+ XSSFCell markCell = row1.getCell(0);
|
|
|
+ if (markCell == null) {
|
|
|
+ this.writeFile2Local(workbook, projectId, file.getOriginalFilename());
|
|
|
+ return this.getImportFailResult("未填写识别码", "2", 0, ++failurNum);
|
|
|
+ }
|
|
|
+ primaryKey = markCell.getStringCellValue().trim(); // 识别码
|
|
|
+ boolean containsKey = AdmCommonConstant.codeColMap.containsKey(primaryKey);
|
|
|
+ if (!containsKey) {
|
|
|
+ this.writeFile2Local(workbook, projectId, file.getOriginalFilename());
|
|
|
+ return this.getImportFailResult("未找到识别码", "2", 0, ++failurNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 获取类型 */
|
|
|
+ XSSFCell cell = row1.getCell(1);
|
|
|
+ if (cell == null) {
|
|
|
+ this.writeFile2Local(workbook, projectId, file.getOriginalFilename());
|
|
|
+ return this.getImportFailResult("未填写设备类型", "2", 0, ++failurNum);
|
|
|
+ }
|
|
|
+ classCodeCloumn = cell.getStringCellValue().trim();
|
|
|
+ if (!"ClassCode".equals(classCodeCloumn)) {
|
|
|
+ this.writeFile2Local(workbook, projectId, file.getOriginalFilename());
|
|
|
+ return this.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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 录入数据获取
|
|
|
+
|
|
|
+ int lastRowNum = sheet.getLastRowNum();
|
|
|
+ boolean isClassCode = "classCode".equals(primaryKey);
|
|
|
+ for (int i = 2; i <= lastRowNum; i++) {
|
|
|
+ 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) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (j == 0) {
|
|
|
+ value = cell.getStringCellValue();
|
|
|
+ if (StrUtil.isBlank(value)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ code = isClassCode ? xssfRow.getCell(0).toString() : xssfRow.getCell(1).toString();
|
|
|
+ // 获取类型定义
|
|
|
+ ObjectTypeDefine define = this.getObjectTypeDefine(groupCode, projectId, code);
|
|
|
+ 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);
|
|
|
+
|
|
|
+ if (CollectionUtil.isEmpty(equipmentList)) {
|
|
|
+ failurNum++;
|
|
|
+ this.setColor(workbook, 153, 225, 77, cell);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isClassCode) {
|
|
|
+ equipment = equipmentList.get(0);
|
|
|
+ } else {
|
|
|
+ if (equipmentList.size() > 1) {
|
|
|
+ failurNum++;
|
|
|
+ this.setColor(workbook, 249, 203, 77, cell);
|
|
|
+ } else {
|
|
|
+ equipment = equipmentList.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 剩余列数据处理
|
|
|
+ if (j != 1 && StrUtil.isNotBlank(code) && 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);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ 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())) {
|
|
|
+ failurNum++;
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ tempMap.put(define.getCode(), cell.getRawValue().toString().trim());
|
|
|
+ } catch (Exception e) {
|
|
|
+ failurNum++;
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } else if ("ENUM".equalsIgnoreCase(define.getDataType())) {
|
|
|
+ if (CellType.NUMERIC.equals(cell.getCellTypeEnum())) {
|
|
|
+ tempMap.put(define.getCode(), cell.getRawValue().toString().trim());
|
|
|
+ } else if (CellType.STRING.equals(cell.getCellTypeEnum())) {
|
|
|
+ tempMap.put(define.getCode(), cell.getStringCellValue().trim());
|
|
|
+ } else {
|
|
|
+ failurNum++;
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } else if ("DATETIME".equalsIgnoreCase(define.getDataType())) {
|
|
|
+ try {
|
|
|
+ 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 {
|
|
|
+ String trim = cell.getStringCellValue().trim();
|
|
|
+ tempMap.put(define.getCode(), Double.parseDouble(trim));
|
|
|
+ } catch (Exception e) {
|
|
|
+ failurNum++;
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } else if ("BOOLEAN".equalsIgnoreCase(define.getDataType())) {
|
|
|
+ String trim = cell.getRawValue() == null ? null : cell.getRawValue().toString().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;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ failurNum++;
|
|
|
+ this.setColor(workbook, 155, 227, 255, cell);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isClassCode) {
|
|
|
+ if (CollectionUtil.isNotEmpty(equipmentList) && tempMap.size() > 0) {
|
|
|
+ for (ObjectNode equipNode : equipmentList) {
|
|
|
+ int success = this.updateEquipInfo(tempMap, groupCode, projectId, equipNode.get("id").asText());
|
|
|
+ successCount += success;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (StrUtil.isNotBlank(code) && equipment != null && tempMap.size() > 0) {
|
|
|
+ int success = this.updateEquipInfo(tempMap, groupCode, projectId, equipment.get("id").asText());
|
|
|
+ successCount += success;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写入错误报告对比值颜色
|
|
|
+ this.wirteReport(workbook, sheet);
|
|
|
+
|
|
|
+ // 返回正确结果
|
|
|
+ String fileName = this.writeFile2Local(workbook, projectId, file.getOriginalFilename());
|
|
|
+ return this.getImportSuccessResult(fileName, successCount, failurNum);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("文件导入失败", e);
|
|
|
+ failure = e.getMessage();
|
|
|
+ } finally {
|
|
|
+ if (fileOutputStream != null) {
|
|
|
+ try {
|
|
|
+ fileOutputStream.flush();
|
|
|
+ fileOutputStream.close();
|
|
|
+ } catch (IOException e) {}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return AdmResponse.failure(failure);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新设备信息
|
|
|
+ *
|
|
|
+ * @param tempMap
|
|
|
+ * @param groupCode
|
|
|
+ * @param projectId
|
|
|
+ * @param equipId
|
|
|
+ * @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>();
|
|
|
+ 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);
|
|
|
+ } else {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 文件写入至本地
|
|
|
+ *
|
|
|
+ * @param workbook
|
|
|
+ * @param projectId
|
|
|
+ * @param orgFileName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String writeFile2Local(XSSFWorkbook workbook, String projectId, String orgFileName) {
|
|
|
+ FileOutputStream fileOutputStream = null;
|
|
|
+ String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
|
|
+ // 重组文件名
|
|
|
+ String fileName = projectId + date + "." + orgFileName.substring(orgFileName.lastIndexOf(".") + 1);
|
|
|
+ try {
|
|
|
+ // 调用中台存储完成之后,此文件存储至本地
|
|
|
+ File templateFile = this.createTemplateFile(fileName);
|
|
|
+ fileOutputStream = new FileOutputStream(templateFile);
|
|
|
+ workbook.write(fileOutputStream);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("文件存储失败", e);
|
|
|
+ } finally {
|
|
|
+ if (fileOutputStream != null) {
|
|
|
+ try {
|
|
|
+ fileOutputStream.close();
|
|
|
+ } catch (IOException e) {}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fileName;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建本地文件,这里不再在classpath下创建
|
|
|
+ *
|
|
|
+ * @param fileName 文件名称,带后缀
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ private File createTemplateFile(String fileName) throws IOException {
|
|
|
+ String path = AdmCommonConstant.SERVER_ROOT_PATH + "/template/upload/";
|
|
|
+ File file = new File(path);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdirs();
|
|
|
+ }
|
|
|
+ file = new File(path + fileName);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.createNewFile();
|
|
|
+ }
|
|
|
+ return file;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取类型定义
|
|
|
+ *
|
|
|
+ * @param code
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ObjectTypeDefine getObjectTypeDefine(String groupCode, String projectId, String code) {
|
|
|
+ QueryCriteria queryCriteria = new QueryCriteria();
|
|
|
+ ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
|
|
|
+ ObjectNode condition = objectMapper.createObjectNode();
|
|
|
+ JSONObject arrays = new JSONObject();
|
|
|
+ arrays.put("$ne", "system");
|
|
|
+ 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
|
|
|
+ * @param code
|
|
|
+ * @param classCode
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ObjectNode> getEquipmentList(String groupCode, String projectId, String primaryKey, String code, String classCode) {
|
|
|
+ QueryCriteria queryCriteria = new QueryCriteria();
|
|
|
+ ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
|
|
|
+ ObjectNode condition = objectMapper.createObjectNode();
|
|
|
+ if (StrUtil.isAllNotBlank(primaryKey, code)) {
|
|
|
+ condition.put(primaryKey, code);
|
|
|
+ }
|
|
|
+ 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
|
|
|
+ */
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 写入错误报告对比值颜色
|
|
|
+ *
|
|
|
+ * @param workbook
|
|
|
+ * @param sheet
|
|
|
+ */
|
|
|
+ private void wirteReport(XSSFWorkbook workbook, XSSFSheet sheet) {
|
|
|
+ XSSFRow row = sheet.getRow(1);
|
|
|
+ short column = (short) (row.getLastCellNum() + 2);
|
|
|
+ XSSFRow row4 = sheet.getRow(4);
|
|
|
+ if (row4 == null) {
|
|
|
+ row4 = sheet.createRow(4);
|
|
|
+ }
|
|
|
+ XSSFCell createCell = row4.createCell(column);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ createCell = row5.createCell(column);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ createCell = row6.createCell(column);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ createCell = row7.createCell(column);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ createCell = row8.createCell(column);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ createCell = row9.createCell(column);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ createCell = row10.createCell(column);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ createCell = row11.createCell(column);
|
|
|
+ createCell.setCellValue("导入失败,信息点不存在");
|
|
|
+ createCell = row11.createCell(column + 1);
|
|
|
+ this.setColor(workbook,77,178,255,createCell);
|
|
|
|
|
|
+ XSSFRow row12 = sheet.getRow(12);
|
|
|
+ if (row12 == null) {
|
|
|
+ row12 = sheet.createRow(12);
|
|
|
+ }
|
|
|
+ createCell = row12.createCell(column);
|
|
|
+ createCell.setCellValue("导入失败,设备类型不在字典定义中");
|
|
|
+ createCell = row12.createCell(column + 1);
|
|
|
+ this.setColor(workbook,56,94,15,createCell);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取导入结果
|
|
|
+ *
|
|
|
+ * @param message
|
|
|
+ * @param successCount
|
|
|
+ * @param failCount
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private AdmResponse getImportFailResult(String message, String state, int successCount, int failCount) {
|
|
|
+ JSONObject content = new JSONObject();
|
|
|
+ content.put("state", state);
|
|
|
+ content.put("successCount", successCount);
|
|
|
+ content.put("failCount", failCount);
|
|
|
+
|
|
|
+ AdmResponse failure = AdmResponse.failure(message);
|
|
|
+ failure.setContent(Lists.newArrayList(content));
|
|
|
+ return failure;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取导入结果
|
|
|
+ *
|
|
|
+ * @param successCount
|
|
|
+ * @param failCount
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private AdmResponse getImportSuccessResult(String message, int successCount, int failCount) {
|
|
|
+ JSONObject content = new JSONObject();
|
|
|
+ String state = null;
|
|
|
+ if (successCount > 0 && failCount > 0) {
|
|
|
+ state = "1";
|
|
|
+ } else if (successCount > 0 && failCount == 0) {
|
|
|
+ state = "0";
|
|
|
+ } else {
|
|
|
+ state = "2";
|
|
|
+ }
|
|
|
+ content.put("state", state);
|
|
|
+ content.put("successCount", successCount);
|
|
|
+ content.put("failCount", failCount);
|
|
|
+ AdmResponse success = AdmResponse.success(Lists.newArrayList(content));
|
|
|
+ success.setMessage(message);
|
|
|
+ return success;
|
|
|
+ }
|
|
|
+
|
|
|
}
|