|
@@ -14,17 +14,21 @@ import cn.hutool.poi.excel.RowUtil;
|
|
|
import cn.hutool.poi.excel.WorkbookUtil;
|
|
|
import cn.hutool.poi.excel.cell.CellUtil;
|
|
|
import cn.hutool.poi.excel.editors.TrimEditor;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.persagy.dmp.basic.dto.RequestData;
|
|
|
import com.persagy.dmp.basic.model.QueryCriteria;
|
|
|
+import com.persagy.dmp.common.constant.ResponseCode;
|
|
|
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.common.model.response.CommonResult;
|
|
|
import com.persagy.dmp.define.client.DigitalDefineFacade;
|
|
|
+import com.persagy.dmp.define.client.DigitalObjectInfoFacade;
|
|
|
import com.persagy.dmp.define.entity.ObjectInfoDefine;
|
|
|
import com.persagy.dmp.define.entity.ObjectTypeDefine;
|
|
|
import com.persagy.dmp.digital.client.DigitalObjectFacade;
|
|
@@ -33,20 +37,22 @@ import com.persagy.dmp.simple.client.DigitalObjectSimpleFacade;
|
|
|
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.AdmCreateResponse;
|
|
|
-import com.persagy.proxy.adm.request.AdmQueryCriteria;
|
|
|
-import com.persagy.proxy.adm.request.AdmResponse;
|
|
|
+import com.persagy.proxy.adm.request.*;
|
|
|
import com.persagy.proxy.adm.service.IAdmRelationService;
|
|
|
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.adm.utils.ObjectNameUtil;
|
|
|
+import com.persagy.proxy.common.entity.InstanceUrlParam;
|
|
|
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.model.AdmProject;
|
|
|
import com.persagy.proxy.object.service.IAdmEquipmentService;
|
|
|
+import com.persagy.proxy.object.service.IAdmProjectService;
|
|
|
+import com.persagy.proxy.report.model.EquipmentPointExcel;
|
|
|
import com.persagy.proxy.report.service.IRelationReportService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
@@ -61,6 +67,8 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.awt.Color;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.List;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -82,6 +90,8 @@ public class AdmEquipmentController {
|
|
|
private IRelationReportService relationReportService;
|
|
|
@Autowired
|
|
|
private IAdmDictService dictService;
|
|
|
+ @Autowired
|
|
|
+ private IAdmProjectService projectService;
|
|
|
|
|
|
/**
|
|
|
* 统计
|
|
@@ -325,16 +335,74 @@ public class AdmEquipmentController {
|
|
|
|
|
|
/**
|
|
|
* 设备绑定的动态信息点或静态信息点
|
|
|
- * @param type static:已交付的静态信息点;iot:已交付的iot信息点
|
|
|
+ * @param type 数据类型 static (静态)、iot (动态)
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@GetMapping("/export")
|
|
|
- public AdmResponse exportInfos(@RequestParam("type") String type,@RequestParam("projectId") String projectId) throws Exception {
|
|
|
- return null;
|
|
|
+ public void exportInfos(@RequestParam("type") String type, @RequestParam("projectId") String projectId, HttpServletResponse response) throws Exception {
|
|
|
+ try {
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ String encode = StandardCharsets.UTF_8.name();
|
|
|
+ response.setCharacterEncoding(encode);
|
|
|
+ AdmQueryCriteria projectRequest = new AdmQueryCriteria();
|
|
|
+ projectRequest.setName(AdmProject.OBJ_TYPE);
|
|
|
+ projectRequest.setFilters("id = '" + projectId + "';");
|
|
|
+ AdmResponse responsePro = projectService.doQuery(AdmContextUtil.toDmpContext(), projectRequest, AdmProject.class);
|
|
|
+
|
|
|
+ if (CollUtil.isEmpty(responsePro.getContent())) {
|
|
|
+ throw new BusinessException(ResponseCode.A0402.getCode(), ResponseCode.A0402.getDesc());
|
|
|
+ } else {
|
|
|
+ AdmProject admProject = (AdmProject) responsePro.getContent().get(0);
|
|
|
+ // 防止中文乱码
|
|
|
+ String fileName = admProject.getLocalName() + "设备已交付信息点";
|
|
|
+ fileName = URLEncoder.encode(fileName, encode);
|
|
|
+
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
+ List<EquipmentPointExcel> equipmentPointExcels = dealEquipmentPoint(admProject.getGroupCode(),admProject.getId(),type, false, null);
|
|
|
+ int count = equipmentPointExcels.size();
|
|
|
+ if(count > 100000){
|
|
|
+ EasyExcel.write(response.getOutputStream(), EquipmentPointExcel.class).sheet("sheet1").doWrite(equipmentPointExcels.subList(0,100000));
|
|
|
+ EasyExcel.write(response.getOutputStream(), EquipmentPointExcel.class).sheet("sheet2").doWrite(equipmentPointExcels.subList(100000,count+1));
|
|
|
+ }else{
|
|
|
+ EasyExcel.write(response.getOutputStream(), EquipmentPointExcel.class).sheet("sheet1").doWrite(equipmentPointExcels);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("设备数据导出异常,获取项目失败",e);
|
|
|
+ }
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 根据建筑 查询设备绑定的动态信息点或静态信息点
|
|
|
+ * @param type 数据类型 static (静态)、iot (动态)
|
|
|
+ */
|
|
|
+ @GetMapping("/export/bulidng")
|
|
|
+ public void equipInfosTwo(@RequestParam("type") String type, @RequestParam("projectId") String projectId, HttpServletResponse response,@RequestParam("buildingId") String buildingId) {
|
|
|
+ try {
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ String encode = StandardCharsets.UTF_8.name();
|
|
|
+ response.setCharacterEncoding(encode);
|
|
|
+ AdmQueryCriteria projectRequest = new AdmQueryCriteria();
|
|
|
+ projectRequest.setName(AdmProject.OBJ_TYPE);
|
|
|
+ projectRequest.setFilters("id = '" + projectId + "';");
|
|
|
+ AdmResponse responsePro = projectService.doQuery(AdmContextUtil.toDmpContext(), projectRequest, AdmProject.class);
|
|
|
|
|
|
+ if (CollUtil.isEmpty(responsePro.getContent())) {
|
|
|
+ throw new BusinessException(ResponseCode.A0402.getCode(), ResponseCode.A0402.getDesc());
|
|
|
+ } else {
|
|
|
+ AdmProject admProject = (AdmProject) responsePro.getContent().get(0);
|
|
|
+ // 防止中文乱码
|
|
|
+ String fileName = admProject.getLocalName() + "设备已交付信息点";
|
|
|
+ fileName = URLEncoder.encode(fileName, encode);
|
|
|
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
+ List<EquipmentPointExcel> equipmentPointExcels = dealEquipmentPoint(admProject.getGroupCode(),admProject.getId(),type, true, buildingId);
|
|
|
+ EasyExcel.write(response.getOutputStream(), EquipmentPointExcel.class).sheet("sheet1").doWrite(equipmentPointExcels);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("设备数据导出异常,获取项目失败",e);
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 根据项目id查询所有的设备和部件
|
|
|
*
|
|
@@ -1147,4 +1215,127 @@ public class AdmEquipmentController {
|
|
|
queryCriteria.setCriteria(rBd);
|
|
|
relationService.doDelete(AdmContextUtil.toDmpContext(), queryCriteria);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组装需要导出的设备信息点
|
|
|
+ * @param groupCode
|
|
|
+ * @param projectId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<EquipmentPointExcel> dealEquipmentPoint(String groupCode,String projectId, String type, Boolean withBuilding, String buildingId){
|
|
|
+ InstanceUrlParam context = AdmContextUtil.toDmpContext();
|
|
|
+ if(StrUtil.isAllNotEmpty(groupCode,projectId)){
|
|
|
+ // 结果封装
|
|
|
+ List<EquipmentPointExcel> excelList = new ArrayList<EquipmentPointExcel>();
|
|
|
+ /** 统计项目设备类型 */
|
|
|
+ RequestData requestData = new RequestData();
|
|
|
+ requestData.setProjectId(projectId);
|
|
|
+ requestData.setGroupCode(groupCode);
|
|
|
+ requestData.setObjType(AdmEquipment.OBJ_TYPE);
|
|
|
+ requestData.setObjTypes(CollUtil.newHashSet(AdmEquipment.OBJ_TYPE));
|
|
|
+ List<Map<String, Object>> equipTypeList = DigitalObjectSimpleFacade.queryDefineInfoByObjType(groupCode,projectId,null,null,requestData);
|
|
|
+ /** 统计信息不为空继续 */
|
|
|
+ if (equipTypeList.size() > 0 ) {
|
|
|
+ for(int i = 0; i < equipTypeList.size(); i++){
|
|
|
+ AdmDictQueryCriteria admQueryCriteriaInfo = new AdmDictQueryCriteria();
|
|
|
+ /** 是否查询静态信息点 */
|
|
|
+ if (type == "static"){
|
|
|
+ admQueryCriteriaInfo.addFilters("category = 'STATIC'");
|
|
|
+ } else {
|
|
|
+ admQueryCriteriaInfo.addFilters("category != 'STATIC'");
|
|
|
+ }
|
|
|
+ admQueryCriteriaInfo.addFilters("valid = 1 ");
|
|
|
+ admQueryCriteriaInfo.addFilters("classCode = '" + equipTypeList.get(i).get("code").toString() + "'");
|
|
|
+
|
|
|
+ AdmQueryCriteria admQueryCriteriaEquip = new AdmQueryCriteria();
|
|
|
+ admQueryCriteriaEquip.addFilters("classCode = '" + equipTypeList.get(i).get("code").toString() + "'");
|
|
|
+ admQueryCriteriaEquip.addFilters("not infos isnull");
|
|
|
+ admQueryCriteriaEquip.setName(AdmEquipment.OBJ_TYPE);
|
|
|
+ if(withBuilding){
|
|
|
+ if(StrUtil.isNotEmpty(buildingId)){
|
|
|
+ admQueryCriteriaEquip.addFilters("buildingId = '"+buildingId+"'");
|
|
|
+ }else{
|
|
|
+ admQueryCriteriaEquip.addFilters("buildingId isnull");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ AdmResponse eqResponse = service.query(admQueryCriteriaEquip);
|
|
|
+ List<AdmEquipment> equipmentList = (List<AdmEquipment>) eqResponse.getContent();
|
|
|
+ if (equipmentList.size() > 0) {
|
|
|
+ /** 字典信息点 */
|
|
|
+ //AdmResponse responseDic = dictService.query(context, admQueryCriteriaInfo, AdmDictConstant.CLASS_CODE, AdmObjectInfo.class);
|
|
|
+ //List<AdmObjectInfo> defFuncIdList = (List<AdmObjectInfo>) responseDic.getContent();
|
|
|
+ QueryCriteria queryCriteria = AdmQueryCriteriaHelper.toDmpCriteria(admQueryCriteriaInfo);
|
|
|
+ queryCriteria.setOnlyCount(false);
|
|
|
+ List<ObjectInfoDefine> defFuncIdList = DigitalObjectInfoFacade.query(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null,queryCriteria);
|
|
|
+
|
|
|
+ if (defFuncIdList.size() > 0) {
|
|
|
+ Map mapInfo = new HashMap<String,String>();
|
|
|
+ Map mapInputType = new HashMap<String,String>();
|
|
|
+ Map mapInputFirstName = new HashMap<String,String>();
|
|
|
+ for (ObjectInfoDefine defFuncId : defFuncIdList) {
|
|
|
+ if(StrUtil.isEmpty(defFuncId.getCode())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ mapInfo.put(defFuncId.getCode(),defFuncId.getName());
|
|
|
+ if(StrUtil.isNotEmpty(defFuncId.getDataType())){
|
|
|
+ mapInputType.put(defFuncId.getCode(), defFuncId.getDataType());
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(defFuncId.getFirstTag())){
|
|
|
+ mapInputFirstName.put(defFuncId.getCode(),defFuncId.getFirstTag());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (AdmEquipment equipment : equipmentList) {
|
|
|
+ if(CollUtil.isEmpty(equipment.getInfos())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<String, Object> info = equipment.getInfos();
|
|
|
+ for(String key : info.keySet()){
|
|
|
+ if(info.get(key) != null && StrUtil.isNotEmpty(info.get(key).toString())){
|
|
|
+ boolean containsKey = mapInfo.containsKey(key);
|
|
|
+ if(!containsKey){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ /** 处理数据写入文件 */
|
|
|
+ EquipmentPointExcel excel = new EquipmentPointExcel();
|
|
|
+ /** id */
|
|
|
+ excel.setId(equipment.getId());
|
|
|
+ /** 本地编码 */
|
|
|
+ excel.setLocalId(equipment.getLocalId());
|
|
|
+ /** 本地名称 */
|
|
|
+ excel.setLocalName(equipment.getLocalName());
|
|
|
+ /** 类型 */
|
|
|
+ excel.setClassCode(equipment.getClassCode());
|
|
|
+ /** 类型 */
|
|
|
+ excel.setClassCodeName(equipTypeList.get(i).get("name").toString());
|
|
|
+ /** 一级标签 */
|
|
|
+ boolean containsFirstName = mapInputFirstName.containsKey(key);
|
|
|
+ if (containsFirstName) {
|
|
|
+ /** 一级标签 */
|
|
|
+ excel.setMapInputFirstName(mapInputFirstName.get(key).toString());
|
|
|
+ }
|
|
|
+ /** 信息点名 */
|
|
|
+ excel.setInfoName(mapInfo.get(key).toString());
|
|
|
+ /** 信息点 */
|
|
|
+ excel.setInfoCode(key);
|
|
|
+ boolean containsInputType = mapInputType.containsKey(key);
|
|
|
+ if (containsInputType) {
|
|
|
+ /** 输入类型 */
|
|
|
+ excel.setInputType(mapInputType.get(key).toString());
|
|
|
+ }
|
|
|
+ /** 值 */
|
|
|
+ excel.setInputValue(info.get(key).toString());
|
|
|
+ excelList.add(excel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return excelList;
|
|
|
+ }else{
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|