|
|
|
@ -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<IotThingR |
|
|
|
, IotThingRelationDetailDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void exportExcel(Map<String, Object> 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<ObjectNode> list = findList(orderField, order, rootIds, name, entityName, groupName); |
|
|
|
if(CollectionUtils.isEmpty(list)){ |
|
|
|
throw new SysException("当前关系无详情,无需导出物物关系列表"); |
|
|
|
} |
|
|
|
List<IotThingRelationDetailExcel> 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<IotThingRelationDetailExcel> 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<String> entityCodes = sheetDataList.stream().flatMap(s -> Stream.of(s.getFromCode(), s.getToCode(),s.getRootThingCode())).distinct().toList(); |
|
|
|
List<IotThingEntity> 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<ObjectNode> 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() |
|
|
|
|