|
@@ -1,34 +1,12 @@
|
|
|
package com.persagy.proxy.report.controller;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.net.URLEncoder;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
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;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.util.ResourceUtils;
|
|
|
-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.excel.EasyExcel;
|
|
|
import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -36,7 +14,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
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.common.context.AppContext;
|
|
|
import com.persagy.dmp.common.helper.SpringHelper;
|
|
@@ -44,26 +21,44 @@ 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.constant.AdmObjectType;
|
|
|
import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
|
|
|
import com.persagy.proxy.adm.handler.RelationReportHandler;
|
|
|
import com.persagy.proxy.adm.request.AdmQueryCriteria;
|
|
|
import com.persagy.proxy.adm.request.AdmResponse;
|
|
|
import com.persagy.proxy.adm.strategy.RelationObjectContext;
|
|
|
+import com.persagy.proxy.adm.utils.AdmContextUtil;
|
|
|
import com.persagy.proxy.adm.utils.AdmExcelUtil;
|
|
|
import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
|
|
|
+import com.persagy.proxy.common.entity.InstanceUrlParam;
|
|
|
import com.persagy.proxy.report.model.AdmRelationObject;
|
|
|
import com.persagy.proxy.report.model.EquipmentBindPointExcel;
|
|
|
import com.persagy.proxy.report.model.EquipmentCountExcel;
|
|
|
import com.persagy.proxy.report.model.EquipmentExcel;
|
|
|
import com.persagy.proxy.report.service.IRelationReportService;
|
|
|
-
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+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;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.springframework.util.ResourceUtils;
|
|
|
+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 javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 报表/模板下载
|
|
@@ -81,9 +76,6 @@ public class RelationReportController {
|
|
|
|
|
|
public static final String EXPORT_SHEET_NAME = "关系维护";
|
|
|
|
|
|
- @Value("${middleware.group.code}")
|
|
|
- private String defaultCode;
|
|
|
-
|
|
|
private final RelationReportHandler relationReportHandler;
|
|
|
|
|
|
private final RelationObjectContext relationObjectContext;
|
|
@@ -98,10 +90,8 @@ public class RelationReportController {
|
|
|
*/
|
|
|
@RequestMapping("/graphic/query-count")
|
|
|
public AdmResponse queryCount(HttpServletRequest request) {
|
|
|
- String groupCode = request.getHeader(AdmCommonConstant.GROUP_CODE_HEADER);
|
|
|
- String projectId = request.getHeader(AdmCommonConstant.PROJECT_ID_HEADER);
|
|
|
-
|
|
|
- List<JSONObject> relationProjectCal = this.relationReportService.getAllRelationProjectCalTree(groupCode, projectId);
|
|
|
+ InstanceUrlParam context = AdmContextUtil.toDmpContext();
|
|
|
+ List<JSONObject> relationProjectCal = this.relationReportService.getAllRelationProjectCalTree(context.getGroupCode(), context.getProjectId());
|
|
|
return AdmResponse.success(relationProjectCal);
|
|
|
}
|
|
|
|
|
@@ -112,9 +102,8 @@ public class RelationReportController {
|
|
|
*/
|
|
|
@RequestMapping("/graphic/type/query-count")
|
|
|
public AdmResponse countRelationObjects(@RequestParam String type, HttpServletRequest request) {
|
|
|
- String groupCode = request.getHeader(AdmCommonConstant.GROUP_CODE_HEADER);
|
|
|
- String projectId = request.getHeader(AdmCommonConstant.PROJECT_ID_HEADER);
|
|
|
- JSONObject objectNode = this.relationReportService.getRelationProjectCal(groupCode, projectId, type);
|
|
|
+ InstanceUrlParam context = AdmContextUtil.toDmpContext();
|
|
|
+ JSONObject objectNode = this.relationReportService.getRelationProjectCal(context.getGroupCode(), context.getProjectId(), type);
|
|
|
return AdmResponse.success(Lists.newArrayList(objectNode));
|
|
|
}
|
|
|
|
|
@@ -139,8 +128,7 @@ public class RelationReportController {
|
|
|
*/
|
|
|
@RequestMapping("/graphic/relation_type_project")
|
|
|
public AdmResponse queryRelationObjects(@RequestBody AdmQueryCriteria requestCriteria, HttpServletRequest request) {
|
|
|
- String groupCode = request.getHeader(AdmCommonConstant.GROUP_CODE_HEADER);
|
|
|
- String projectId = request.getHeader(AdmCommonConstant.PROJECT_ID_HEADER);
|
|
|
+ InstanceUrlParam context = AdmContextUtil.toDmpContext();
|
|
|
String filters = requestCriteria.getFilters();
|
|
|
|
|
|
|
|
@@ -187,9 +175,9 @@ public class RelationReportController {
|
|
|
relObject.put("$in", relCodes);
|
|
|
criteria.putPOJO("relCode", relObject);
|
|
|
}
|
|
|
- criteria.put("projectId", projectId);
|
|
|
+ criteria.put("projectId", context.getProjectId());
|
|
|
queryCriteria.setCriteria(criteria);
|
|
|
- List<JSONObject> relationProjectCal = this.relationReportService.getAllRelationProjectCal(queryCriteria, groupCode, projectId);
|
|
|
+ List<JSONObject> relationProjectCal = this.relationReportService.getAllRelationProjectCal(queryCriteria, context.getGroupCode(), context.getProjectId());
|
|
|
return AdmResponse.success(relationProjectCal);
|
|
|
}
|
|
|
|
|
@@ -219,9 +207,9 @@ public class RelationReportController {
|
|
|
*/
|
|
|
@RequestMapping("/graphic/downloads/eq/not/sp")
|
|
|
public void downloadsEqNotSp(@RequestParam(required = false) String projectId, HttpServletRequest request, HttpServletResponse response) {
|
|
|
- String groupCode = request.getHeader(AdmCommonConstant.GROUP_CODE_HEADER);
|
|
|
+ InstanceUrlParam context = AdmContextUtil.toDmpContext();
|
|
|
if (StrUtil.isBlank(projectId)) {
|
|
|
- projectId = request.getHeader(AdmCommonConstant.PROJECT_ID_HEADER);
|
|
|
+ projectId = context.getProjectId();
|
|
|
}
|
|
|
try {
|
|
|
response.setContentType("application/vnd.ms-excel");
|
|
@@ -231,7 +219,7 @@ public class RelationReportController {
|
|
|
String fileName = URLEncoder.encode("equipment", encode);
|
|
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
|
|
|
- List<EquipmentExcel> equipByNotSpace = this.relationReportHandler.findEquipByNotSpace(groupCode, projectId);
|
|
|
+ List<EquipmentExcel> equipByNotSpace = this.relationReportHandler.findEquipByNotSpace(context.getGroupCode(), projectId);
|
|
|
EasyExcel.write(response.getOutputStream(), EquipmentExcel.class).sheet("设备").doWrite(equipByNotSpace);
|
|
|
} catch(Exception e) {
|
|
|
log.error("设备数据导出异常", e);
|
|
@@ -249,9 +237,9 @@ public class RelationReportController {
|
|
|
*/
|
|
|
@RequestMapping("/graphic/downloads/project/binding/point")
|
|
|
public void downloadsProjectBindingPoint(@RequestParam(required = false) String projectId, HttpServletRequest request, HttpServletResponse response) {
|
|
|
- String groupCode = request.getHeader(AdmCommonConstant.GROUP_CODE_HEADER);
|
|
|
+ InstanceUrlParam context = AdmContextUtil.toDmpContext();
|
|
|
if (StrUtil.isBlank(projectId)) {
|
|
|
- projectId = request.getHeader(AdmCommonConstant.PROJECT_ID_HEADER);
|
|
|
+ projectId = context.getProjectId();
|
|
|
}
|
|
|
try {
|
|
|
response.setContentType("application/vnd.ms-excel");
|
|
@@ -261,7 +249,7 @@ public class RelationReportController {
|
|
|
String fileName = URLEncoder.encode("设备实例交付", encode);
|
|
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
|
|
|
- List<EquipmentBindPointExcel> equipmentBindPointExcel = this.relationReportHandler.queryProjectBindPoint(groupCode, projectId);
|
|
|
+ List<EquipmentBindPointExcel> equipmentBindPointExcel = this.relationReportHandler.queryProjectBindPoint(context.getGroupCode(), projectId);
|
|
|
EasyExcel.write(response.getOutputStream(), EquipmentBindPointExcel.class).sheet(0).doWrite(equipmentBindPointExcel);
|
|
|
} catch(Exception e) {
|
|
|
log.error("设备数据导出异常", e);
|
|
@@ -444,8 +432,10 @@ public class RelationReportController {
|
|
|
@RequestParam(required = false) String zoneType, HttpServletRequest request, HttpServletResponse response) {
|
|
|
ExcelWriter excelWriter = null;
|
|
|
try {
|
|
|
- String groupCode = request.getHeader(AdmCommonConstant.GROUP_CODE_HEADER);
|
|
|
- groupCode = StrUtil.isBlank(groupCode) ? defaultCode : groupCode;
|
|
|
+ InstanceUrlParam context = AdmContextUtil.toDmpContext();
|
|
|
+ if(StrUtil.isBlank(projectId)) {
|
|
|
+ projectId = context.getProjectId();
|
|
|
+ }
|
|
|
code = StrUtil.isBlank(code) ? "对象ID" : code;
|
|
|
|
|
|
response.setContentType("application/vnd.ms-excel");
|
|
@@ -453,13 +443,13 @@ public class RelationReportController {
|
|
|
response.setCharacterEncoding(encode);
|
|
|
response.setHeader("Content-disposition", "attachment;filename=relation-template.xlsx");
|
|
|
|
|
|
- log.info("下载报表: groupCode[{}], projectId[{}], relType[{}], code[{}]", groupCode, projectId, relType, code);
|
|
|
+ log.info("下载报表: groupCode[{}], projectId[{}], relType[{}], code[{}]", context.getGroupCode(), projectId, relType, code);
|
|
|
AdmRelationTypeEnum typeEnum = AdmCommonConstant.RELATION_TYPE_MAP.get(relType);
|
|
|
|
|
|
List<AdmRelationObject> relationObjects = null;
|
|
|
if (typeEnum != null) {
|
|
|
String graphAndRelKey = typeEnum.getGraphCode() + AdmCommonConstant.UNDERLINE + typeEnum.getRelCode();
|
|
|
- relationObjects = this.relationObjectContext.exportRelationObject(groupCode, projectId, graphAndRelKey);
|
|
|
+ relationObjects = this.relationObjectContext.exportRelationObject(context.getGroupCode(), projectId, graphAndRelKey);
|
|
|
}
|
|
|
|
|
|
File templateFile = AdmExcelUtil.getTemplateFile("relation-template.xlsx");
|
|
@@ -507,11 +497,7 @@ public class RelationReportController {
|
|
|
Set<Integer> rowNums = new HashSet<Integer>();
|
|
|
// 批量更新数据
|
|
|
List<ObjectNode> relationObjects = new ArrayList<ObjectNode>();
|
|
|
-
|
|
|
- String groupCode = request.getHeader(AdmCommonConstant.GROUP_CODE_HEADER);
|
|
|
- groupCode = StrUtil.isBlank(groupCode) ? defaultCode : groupCode;
|
|
|
- String projectId = request.getHeader(AdmCommonConstant.PROJECT_ID_HEADER);
|
|
|
-
|
|
|
+ InstanceUrlParam context = AdmContextUtil.toDmpContext();
|
|
|
workbook = new XSSFWorkbook(file.getInputStream());
|
|
|
XSSFSheet sheet = workbook.getSheet("关系维护");
|
|
|
// 获取识别码的属性
|
|
@@ -535,7 +521,8 @@ public class RelationReportController {
|
|
|
relationObject.setSlaveId(slaveIdCell == null ? null : slaveIdCell.getStringCellValue());
|
|
|
|
|
|
// 校验数据
|
|
|
- Object result = this.relationObjectContext.checkRelationObject(relationObject, groupCode, projectId, graphAndRelKey, code, typeEnum);
|
|
|
+ Object result = this.relationObjectContext.checkRelationObject(relationObject, context.getGroupCode(),
|
|
|
+ context.getProjectId(), graphAndRelKey, code, typeEnum);
|
|
|
if (result instanceof String) {
|
|
|
failurNum++;
|
|
|
xssfRow.createCell(16).setCellValue((String)result);
|
|
@@ -548,7 +535,8 @@ public class RelationReportController {
|
|
|
rowNums.add(i);
|
|
|
relationObjects.add(relation);
|
|
|
if (relationObjects.size() >= 1000) {
|
|
|
- boolean objects = this.relationObjectContext.saveRelationObjects(relationObjects, groupCode, projectId, graphAndRelKey);
|
|
|
+ boolean objects = this.relationObjectContext.saveRelationObjects(relationObjects, context.getGroupCode(),
|
|
|
+ context.getProjectId(), graphAndRelKey);
|
|
|
if (objects) {
|
|
|
successNum += relationObjects.size();
|
|
|
for (int rowNum : rowNums) {
|
|
@@ -566,7 +554,7 @@ public class RelationReportController {
|
|
|
}
|
|
|
// 最后一次遗留数据录入
|
|
|
if (CollectionUtil.isNotEmpty(relationObjects)) {
|
|
|
- boolean objects = this.relationObjectContext.saveRelationObjects(relationObjects, groupCode, projectId, graphAndRelKey);
|
|
|
+ boolean objects = this.relationObjectContext.saveRelationObjects(relationObjects, context.getGroupCode(), context.getProjectId(), graphAndRelKey);
|
|
|
if (objects) {
|
|
|
successNum += relationObjects.size();
|
|
|
for (int rowNum : rowNums) {
|
|
@@ -582,7 +570,7 @@ public class RelationReportController {
|
|
|
|
|
|
try {
|
|
|
// 调用中台存储完成之后,此文件存储至本地
|
|
|
- String fileName = projectId + AdmCommonConstant.LINE_THROUGH + relType + AdmCommonConstant.EXCEL_SUFFIX_XLSX;
|
|
|
+ String fileName = context.getProjectId() + AdmCommonConstant.LINE_THROUGH + relType + AdmCommonConstant.EXCEL_SUFFIX_XLSX;
|
|
|
File templateFile = AdmExcelUtil.createTemplateFile(AdmCommonConstant.SERVER_ROOT_PATH + AdmExcelUtil.TEMP_PAHT, fileName);
|
|
|
fileOutputStream = new FileOutputStream(templateFile);
|
|
|
workbook.write(fileOutputStream);
|
|
@@ -844,8 +832,6 @@ public class RelationReportController {
|
|
|
* @return
|
|
|
*/
|
|
|
private ObjectTypeDefine queryClassList(String groupCode, String projectId, String classCode, String objType) {
|
|
|
- groupCode = StrUtil.isBlank(groupCode) ? defaultCode : groupCode;
|
|
|
-
|
|
|
ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
|
|
|
QueryCriteria classCriteria = new QueryCriteria();
|
|
|
ObjectNode condition = objectMapper.createObjectNode();
|