diff --git a/common/core/src/main/java/com/thing/common/core/enumeration/AttributeTypeEnum.java b/common/core/src/main/java/com/thing/common/core/enumeration/AttributeTypeEnum.java index 5730468..a23ec18 100644 --- a/common/core/src/main/java/com/thing/common/core/enumeration/AttributeTypeEnum.java +++ b/common/core/src/main/java/com/thing/common/core/enumeration/AttributeTypeEnum.java @@ -230,4 +230,14 @@ public enum AttributeTypeEnum { } return attrCode; } + + + public List getTimeRangeAny(LocalDateTime localDateTime, LocalDateTime localDateTime1) { + + LocalDateTime beginTimeOfMin = LocalDateTime.of(localDateTime.toLocalDate(), LocalTime.MIN); + LocalDateTime endTimeOfMin = LocalDateTime.of(localDateTime1.toLocalDate(), LocalTime.MAX); + return Stream.iterate(beginTimeOfMin, d -> d.plusMinutes(15)) + .limit((ChronoUnit.MINUTES.between(beginTimeOfMin, endTimeOfMin) + 1) / 15) + .collect(Collectors.toList()); + } } diff --git a/modules/report-analysis/src/main/java/com/thing/carbon/energyrepory/service/impl/EnergyUsageServiceImpl.java b/modules/report-analysis/src/main/java/com/thing/carbon/energyrepory/service/impl/EnergyUsageServiceImpl.java index b5d3699..594b843 100644 --- a/modules/report-analysis/src/main/java/com/thing/carbon/energyrepory/service/impl/EnergyUsageServiceImpl.java +++ b/modules/report-analysis/src/main/java/com/thing/carbon/energyrepory/service/impl/EnergyUsageServiceImpl.java @@ -313,10 +313,10 @@ public class EnergyUsageServiceImpl implements EnergyUsageService { // 超过十天的任意时间的数据特殊处理: // 1. 小于10天数据量极小,全量查询无压力; // 2. 以三四天的数据量分多次查询反而会有更多IO消耗,直观感觉至少要五天才不亏,这里选择10天 - if (request.isAnyTime() && moreThanTenDays(timeRange)) { - return handleAnyTimeReport( - thing, sourceList, codeInfoMap, energyDictMap, varietyMap, timeRange); - } +// if (request.isAnyTime() && moreThanTenDays(timeRange)) { +// return handleAnyTimeReport( +// thing, sourceList, codeInfoMap, energyDictMap, varietyMap, timeRange); +// } // 查询tskv List tsKvMapList = findTsKv(sourceList, timeRange, null); @@ -371,6 +371,8 @@ public class EnergyUsageServiceImpl implements EnergyUsageService { begin = begin.plusDays(1); } return dateTimeList; + } else if(request.isAnyTime()){ + return attrTypeEnum.getTimeRangeAny(DateTimeUtils.parseDateTime(request.getBeginTime()),DateTimeUtils.parseDateTime(request.getEndTime())); } else { return attrTypeEnum.getTimeRange(DateTimeUtils.parseDateTime(request.getBeginTime())); } diff --git a/modules/thing/src/main/java/com/thing/device/deviceManagement/dto/IotDeviceManagementDTO.java b/modules/thing/src/main/java/com/thing/device/deviceManagement/dto/IotDeviceManagementDTO.java index 77bf8e0..15a3a93 100644 --- a/modules/thing/src/main/java/com/thing/device/deviceManagement/dto/IotDeviceManagementDTO.java +++ b/modules/thing/src/main/java/com/thing/device/deviceManagement/dto/IotDeviceManagementDTO.java @@ -50,6 +50,10 @@ public class IotDeviceManagementDTO implements Serializable { private String thingAttrBoundary; @Schema(description = "英文逗号分割,如2,3,4 表示2天3小时4分钟") private String timeInfo; + @Schema(description = "是否为数据处理: 0 否 1 是") + private String dataTreatingMark; + @Schema(description = "映射子集(子数据列表)") + private String childConfig; @Schema(description = "控制详情,只有 configType是3得 控制得,这里才会有数据") private IotDeviceControlEntity ctlInfo; diff --git a/modules/thing/src/main/java/com/thing/device/deviceManagement/entity/IotDeviceManagementEntity.java b/modules/thing/src/main/java/com/thing/device/deviceManagement/entity/IotDeviceManagementEntity.java index 0dbe922..add9be4 100644 --- a/modules/thing/src/main/java/com/thing/device/deviceManagement/entity/IotDeviceManagementEntity.java +++ b/modules/thing/src/main/java/com/thing/device/deviceManagement/entity/IotDeviceManagementEntity.java @@ -84,4 +84,15 @@ public class IotDeviceManagementEntity implements Serializable { */ private String timeInfo; + /** + * 是否为数据处理: 0 否 1 是 + */ + private String dataTreatingMark; + + + /** + * 映射子集(子数据列表) + */ + private String childConfig; + } \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java b/modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java index 2f78c74..bb7e7d5 100644 --- a/modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java +++ b/modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java @@ -20,9 +20,13 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; +import java.util.Map; @RestController @RequestMapping("v2/relation/detail") @@ -187,5 +191,25 @@ public class IotThingRelationDetailController { *} */ + @PostMapping("import") + @Operation(summary="物关系导入") + @LogOperation("物关系导入") + public Result importTenant(MultipartFile file, HttpServletRequest request) { + service.importExcel(file, request); + return new Result<>(); + } + + @PostMapping("export") + @Operation(summary="物关系导出") + @LogOperation("物关系导出") + public void export(@RequestParam Map params, HttpServletResponse response) throws Exception { + service.exportExcel(params,response); + } + + @PostMapping("template") + @Operation(summary="物关系模板下载") + public void template(HttpServletResponse response) throws Exception { + service.template(response); + } } \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/thing/relation/detail/excel/IotThingRelationDetailExcel.java b/modules/thing/src/main/java/com/thing/thing/relation/detail/excel/IotThingRelationDetailExcel.java new file mode 100644 index 0000000..398077f --- /dev/null +++ b/modules/thing/src/main/java/com/thing/thing/relation/detail/excel/IotThingRelationDetailExcel.java @@ -0,0 +1,66 @@ +package com.thing.thing.relation.detail.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; + +import java.io.Serial; +import java.io.Serializable; + +/** + * 物关系详情表 + * + * @author xc/ls + * @since 3.0 2023-06-05 + */ + +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper=false) +@NoArgsConstructor +@AllArgsConstructor +public class IotThingRelationDetailExcel implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + @Excel(name = "关系名称",width = 25) + private String name; + + @Excel(name = "上级物编码",orderNum = "1",width = 25) + private String fromCode; + + @Excel(name = "上级物名称",orderNum = "2",width = 25 ) + private String fromName; + + @Excel(name = "下级物编码",orderNum = "3",width = 25 ) + private String toCode; + + @Excel(name = "下级物名称",orderNum = "4",width = 25 ) + private String toName; + + @Excel(name = "位置",orderNum = "5",width = 25 ) + private String config; + + @Excel(name = "备注",orderNum = "6",width = 25 ) + private String remark; + + @Excel(name = "排序",orderNum = "7",width = 25 ) + private Long sort; + + @Excel(name = "根物实体编码",orderNum = "8",width = 25 ) + private String rootThingCode; + + @Excel(name = "图片信息地址",orderNum = "9",width = 25 ) + private String url; + + @Excel(name = "标签",orderNum = "10",width = 25 ) + private String tag; + + +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java b/modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java index ab1a7ae..6b95cb5 100644 --- a/modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java +++ b/modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java @@ -12,7 +12,10 @@ import com.thing.thing.relation.detail.dto.ThingTreeDTO; import com.thing.thing.relation.detail.entity.IotThingRelationDetailEntity; import com.thing.thing.relation.detail.param.IotThingRelationDetailParamDTO; import com.thing.thing.relation.root.dto.ThingSortTreeDTO; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.multipart.MultipartFile; import java.util.Collection; import java.util.List; @@ -83,4 +86,10 @@ public interface IotThingRelationDetailService extends IBaseService findRootDetailChildNodeByRootIdAndToIdAndRootThingId(Long relationTypeId, Long id, Long relationTopId); + + void exportExcel(Map params, HttpServletResponse response); + + void importExcel(MultipartFile file, HttpServletRequest request); + + void template(HttpServletResponse response); } diff --git a/modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java b/modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java index 072700f..fd5d6f0 100644 --- a/modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java +++ b/modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java @@ -17,6 +17,7 @@ import com.thing.common.core.enumeration.DatasetThingRelationStatus; import com.thing.common.core.enumeration.TreeNodeStatus; import com.thing.common.core.exception.SysException; import com.thing.common.core.utils.*; +import com.thing.common.core.utils.excel.ExcelUtils; import com.thing.common.core.web.response.PageData; import com.thing.common.orm.service.impl.BaseServiceImpl; import com.thing.event.ThingRelationDetailSaveEvent; @@ -25,12 +26,15 @@ import com.thing.thing.api.dto.ApiEntityRelationDTO; import com.thing.thing.cache.service.CacheInit; import com.thing.thing.cache.service.ThingCache; import com.thing.thing.entity.dto.IotThingEntityDTO; +import com.thing.thing.entity.dto.IotThingEntityInfoDTO; +import com.thing.thing.entity.entity.IotThingEntity; import com.thing.thing.entity.service.IotThingEntityService; import com.thing.thing.model.service.IotThingModelService; import com.thing.thing.relation.detail.dto.IotThingRelationDetailDTO; import com.thing.thing.relation.detail.dto.RelationDetailBatchSaveDTO; import com.thing.thing.relation.detail.dto.ThingRelationDTO; import com.thing.thing.relation.detail.entity.IotThingRelationDetailEntity; +import com.thing.thing.relation.detail.excel.IotThingRelationDetailExcel; import com.thing.thing.relation.detail.mapper.IotThingRelationDetailMapper; import com.thing.thing.relation.detail.param.IotThingRelationDetailParamDTO; import com.thing.thing.relation.detail.service.IotThingRelationDetailService; @@ -40,13 +44,17 @@ import com.thing.thing.relation.root.entity.IotThingRelationRootEntity; import com.thing.thing.relation.root.service.IotThingRelationRootService; import com.thing.transport.api.adaptor.JsonConverter; import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; import java.util.*; import java.util.concurrent.atomic.AtomicLong; @@ -973,6 +981,109 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl params, HttpServletResponse response) { + String orderField = MapUtils.getString(params, "orderField"); + String order = MapUtils.getString(params, "order"); + String rootIds = MapUtils.getString(params, "rootIds"); + String name = MapUtils.getString(params, "name"); + String entityName = MapUtils.getString(params, "entityName"); + String groupName = MapUtils.getString(params, "groupName"); + List list = findList(orderField, order, rootIds, name, entityName, groupName); + if(CollectionUtils.isEmpty(list)){ + throw new SysException("当前关系无详情,无需导出物物关系列表"); + } + List resList = list.stream().map(node -> { + IotThingRelationDetailExcel excel = new IotThingRelationDetailExcel(); + excel.setFromName(node.get("fromName").asText()); + excel.setFromCode(node.get("fromCode").isNull() ? "" : node.get("fromCode").asText()); + excel.setToName(node.get("toName").asText()); + excel.setToCode(node.get("toCode").asText()); + excel.setConfig(node.get("config").isNull() ? "" : node.get("config").asText()); + excel.setRemark(node.get("remark").isNull() ? "" : node.get("remark").asText()); + excel.setSort(node.get("sort").asLong()); + excel.setUrl(node.get("url").isNull() ? "" : node.get("url").asText()); + excel.setTag(node.get("tag").isNull() ? "" : node.get("tag").asText()); + long rootThingId = node.get("rootThingId").asLong(); + IotThingEntityInfoDTO entity = thingEntitiesService.findEntityById(rootThingId); + excel.setRootThingCode(entity.getCode()); + long rootId = node.get("rootId").asLong(); + IotThingRelationRootDTO rootDTO = relationRootsService.findById(rootId); + excel.setName(rootDTO.getName()); + return excel; + }).toList(); + ExcelUtils.exportExcel(new ArrayList<>(resList), "物关系详情信息", "物关系详情", IotThingRelationDetailExcel.class, "物关系详情模板.xls", response); + } + + @Override + public void importExcel(MultipartFile file, HttpServletRequest request) { + List sheetDataList = new ArrayList<>(ExcelUtils.importExcel(file, 1, 1, IotThingRelationDetailExcel.class, 0)); + if (CollectionUtil.isEmpty(sheetDataList)) { + throw new SysException("导入数据是空的"); + } + String rootName = sheetDataList.get(0).getName(); + IotThingRelationRootDTO rootDTO = relationRootsService.findByName(rootName); + if(Objects.isNull(rootDTO)){ + throw new SysException("导入的物关系名称不存在"); + } + List entityCodes = sheetDataList.stream().flatMap(s -> Stream.of(s.getFromCode(), s.getToCode(),s.getRootThingCode())).distinct().toList(); + List entities = thingEntitiesService.findAllByCodeInAndTenantCode(entityCodes, UserContext.getRealTenantCode()); + if(CollectionUtils.isEmpty(entities)){ + throw new SysException("导入的物关系实体不存在"); + } + + sheetDataList.forEach(excel -> { + IotThingRelationDetailEntity entity = new IotThingRelationDetailEntity(); + //说明是第一节点 + if(StringUtils.equals(excel.getRootThingCode(),excel.getToCode()) && StringUtils.isBlank(excel.getFromCode())){ + entity.setFromId(rootDTO.getId()); + entity.setFromName(rootDTO.getName()); + }else{ + IotThingEntity fromEntity = entities.stream().filter(e -> e.getCode().equals(excel.getFromCode())).findFirst().get(); + entity.setFromId(fromEntity.getId()); + entity.setFromName(excel.getFromName()); + entity.setFromCode(excel.getFromCode()); + } + IotThingEntity toEntity = entities.stream().filter(e -> e.getCode().equals(excel.getToCode())).findFirst().get(); + IotThingEntity rootEntity = entities.stream().filter(e -> e.getCode().equals(excel.getRootThingCode())).findFirst().get(); + entity.setRootId(rootDTO.getId()); + entity.setToCode(excel.getToCode()); + entity.setToName(excel.getToName()); + entity.setToId(toEntity.getId()); + entity.setConfig(excel.getConfig()); + entity.setConfig(excel.getRemark()); + entity.setSort(excel.getSort()); + entity.setRootThingId(rootEntity.getId()); + entity.setUrl(excel.getUrl()); + entity.setTag(excel.getTag()); + mapper.insert(entity); + ObjectNode node = JsonConverter.convertToJsonObjectObjectNode(ConvertUtils.sourceToTarget(entity, IotThingRelationDetailDTO.class)); + List mapAccurateKey = cache.findMapAccurateKey(CacheNameEnum.THING_MODEL, entity.getToCode()); + if (CollectionUtils.isNotEmpty(mapAccurateKey)) { + String status = mapAccurateKey.get(0).get(CacheNameEnum.ModelField.THING_MODEL_STATUS.getField()).asText(); + node.put("thingStatus", status); + } + cache.updateAccurateKeyMap(CacheNameEnum.THING_DETAIL_RELATION, + entity.getRootId() + CacheInit.KEY + entity.getId() + CacheInit.KEY + entity.getRootThingId(), node); + }); + } + + @Override + public void template(HttpServletResponse response) { + IotThingRelationDetailExcel excel = new IotThingRelationDetailExcel(); + excel.setFromCode("X_xxxxx_xx上级节点编码"); + excel.setFromName("X_xxxxx_xx上级节点名称"); + excel.setToCode("X_xxxxx_xx下级节点编码"); + excel.setToName("X_xxxxx_xx下级节点名称"); + excel.setName("关系名称"); + excel.setRootThingCode("根关系物编码"); + excel.setConfig("关系位置:默认{\"width\":120,\"height\":40,\"shape\":\"rect\"}"); + excel.setTag("下级节点名称-标签"); + excel.setRemark("备注"); + excel.setUrl("图片地址"); + ExcelUtils.exportExcel(Lists.newArrayList(excel), "物关系详情信息", "物关系详情", IotThingRelationDetailExcel.class, "物关系详情模板.xls", response); + } + @Override public IotThingRelationDetailDTO findRootDetailParentNodeByRootIdAndToIdAndRootThingId(Long rootId, Long toId, Long rootThingId) { return mapper.selectOneByQueryAs(QueryWrapper.create() diff --git a/modules/thing/src/main/java/com/thing/thing/relation/root/service/IotThingRelationRootService.java b/modules/thing/src/main/java/com/thing/thing/relation/root/service/IotThingRelationRootService.java index cd6fc34..c22df42 100644 --- a/modules/thing/src/main/java/com/thing/thing/relation/root/service/IotThingRelationRootService.java +++ b/modules/thing/src/main/java/com/thing/thing/relation/root/service/IotThingRelationRootService.java @@ -24,6 +24,8 @@ public interface IotThingRelationRootService extends IBaseService findByIds(List id,boolean isAsc); Long findMaxSort(); diff --git a/modules/thing/src/main/java/com/thing/thing/relation/root/service/impl/IotThingRelationRootServiceImpl.java b/modules/thing/src/main/java/com/thing/thing/relation/root/service/impl/IotThingRelationRootServiceImpl.java index 64cb123..6921cff 100644 --- a/modules/thing/src/main/java/com/thing/thing/relation/root/service/impl/IotThingRelationRootServiceImpl.java +++ b/modules/thing/src/main/java/com/thing/thing/relation/root/service/impl/IotThingRelationRootServiceImpl.java @@ -200,11 +200,29 @@ public class IotThingRelationRootServiceImpl extends BaseServiceImpl findByIds(List ids,boolean isAsc) { return mapper.selectListByQueryAs(QueryWrapper.create().in(IotThingRelationRootEntity::getId,ids).orderBy(IotThingRelationRootEntity::getSort,isAsc),IotThingRelationRootDTO.class);