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..dad35a6 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,14 @@ 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.apache.commons.lang3.ArrayUtils; 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 +192,28 @@ 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(@RequestBody Long[] ids, @RequestParam Map params, HttpServletResponse response) throws Exception { + if(ArrayUtils.isNotEmpty(ids)){ + params.put("ids",ids); + } + service.exportExcel(params,response); + } + + @PostMapping("template") + @Operation(summary="物关系模板下载") + public void exportTemplate(HttpServletResponse response) { + 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..3c6dc26 --- /dev/null +++ b/modules/thing/src/main/java/com/thing/thing/relation/detail/excel/IotThingRelationDetailExcel.java @@ -0,0 +1,62 @@ +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 { + + @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..b3fd3f4 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,16 @@ 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.excel.IotThingViewExcel; 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 +45,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 +982,99 @@ 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 = JacksonUtil.convertValue(node, IotThingRelationDetailExcel.class); + long rootThingId = node.get("rootThingId").asLong(); + IotThingEntityInfoDTO entity = thingEntitiesService.findEntityById(rootThingId); + excel.setRootThingCode(entity.getCode()); + return excel; + }).toList(); + + ExcelUtils.exportExcel(resList, "物关系详情信息", "物关系详情", IotThingViewExcel.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 -> { + //关系名称 + if(!Objects.isNull(rootDTO)){ + IotThingRelationDetailEntity entity = new IotThingRelationDetailEntity(); + IotThingEntity fromEntity = entities.stream().filter(e -> e.getCode().equals(excel.getFromCode())).findFirst().get(); + 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.setFromCode(excel.getFromCode()); + entity.setFromCode(excel.getName()); + entity.setFromId(fromEntity.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), "物关系详情信息", "物关系详情", IotThingViewExcel.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..3d838d5 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 @@ -236,6 +236,12 @@ 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);