Browse Source

Merge pull request 'master' (#75) from master into V3

Reviewed-on: http://git.lrdaiot.cn:9000/thing/thing_api/pulls/75
qingyuan_dev_new
李帅 1 year ago
parent
commit
6dbcdc08c7
  1. 10
      common/core/src/main/java/com/thing/common/core/enumeration/AttributeTypeEnum.java
  2. 10
      modules/report-analysis/src/main/java/com/thing/carbon/energyrepory/service/impl/EnergyUsageServiceImpl.java
  3. 4
      modules/thing/src/main/java/com/thing/device/deviceManagement/dto/IotDeviceManagementDTO.java
  4. 11
      modules/thing/src/main/java/com/thing/device/deviceManagement/entity/IotDeviceManagementEntity.java
  5. 24
      modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java
  6. 66
      modules/thing/src/main/java/com/thing/thing/relation/detail/excel/IotThingRelationDetailExcel.java
  7. 9
      modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java
  8. 111
      modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java
  9. 2
      modules/thing/src/main/java/com/thing/thing/relation/root/service/IotThingRelationRootService.java
  10. 27
      modules/thing/src/main/java/com/thing/thing/relation/root/service/impl/IotThingRelationRootServiceImpl.java

10
common/core/src/main/java/com/thing/common/core/enumeration/AttributeTypeEnum.java

@ -230,4 +230,14 @@ public enum AttributeTypeEnum {
}
return attrCode;
}
public List<LocalDateTime> 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());
}
}

10
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<TsKvDTO> 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()));
}

4
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;

11
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;
}

24
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<Void> importTenant(MultipartFile file, HttpServletRequest request) {
service.importExcel(file, request);
return new Result<>();
}
@PostMapping("export")
@Operation(summary="物关系导出")
@LogOperation("物关系导出")
public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
service.exportExcel(params,response);
}
@PostMapping("template")
@Operation(summary="物关系模板下载")
public void template(HttpServletResponse response) throws Exception {
service.template(response);
}
}

66
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;
}

9
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<IotThingRela
void saveRelationNodes(ThingRelationDTO relationDTO);
List<IotThingRelationDetailDTO> findRootDetailChildNodeByRootIdAndToIdAndRootThingId(Long relationTypeId, Long id, Long relationTopId);
void exportExcel(Map<String, Object> params, HttpServletResponse response);
void importExcel(MultipartFile file, HttpServletRequest request);
void template(HttpServletResponse response);
}

111
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<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()

2
modules/thing/src/main/java/com/thing/thing/relation/root/service/IotThingRelationRootService.java

@ -24,6 +24,8 @@ public interface IotThingRelationRootService extends IBaseService<IotThingRelati
IotThingRelationRootDTO findById(Long id);
IotThingRelationRootDTO findByName(String name);
List<IotThingRelationRootDTO> findByIds(List<Long> id,boolean isAsc);
Long findMaxSort();

27
modules/thing/src/main/java/com/thing/thing/relation/root/service/impl/IotThingRelationRootServiceImpl.java

@ -200,11 +200,29 @@ public class IotThingRelationRootServiceImpl extends BaseServiceImpl<IotThingRel
iotThingRelationRootInsert.getGroupName()+CacheInit.KEY+ iotThingRelationRootInsert.getName()+CacheInit.KEY+ iotThingRelationRootInsert.getId(),nodes);
}
private void updateRootAndCacheAny(IotThingRelationRootEntity iotThingRelationRootInsert) {
IotThingRelationRootDTO relationRootDTO = ConvertUtils.sourceToTarget(iotThingRelationRootInsert, IotThingRelationRootDTO.class);
ObjectNode nodes = JsonConverter.convertToJsonObjectObjectNode(relationRootDTO);
nodes.put("fromId", "0");
nodes.put("rootId", nodes.get("id").asText());
nodes.put("toId", nodes.get("id").asText());
nodes.put("toName", nodes.get("name").asText());
nodes.put("rootThingId", "0");
cache.updateAccurateKeyMap(CacheNameEnum.THING_ROOT_RELATION,
iotThingRelationRootInsert.getGroupName()+CacheInit.KEY+ iotThingRelationRootInsert.getName()+CacheInit.KEY+ iotThingRelationRootInsert.getId(),nodes);
}
@Transactional(rollbackFor = Exception.class)
@Override
public void update(IotThingRelationRootDTO dto) {
Long id = dto.getId();
IotThingRelationRootEntity iotThingRelationRootEntity = mapper.selectOneById(id);
String oldKey = iotThingRelationRootEntity.getGroupName() + CacheInit.KEY + iotThingRelationRootEntity.getName() + CacheInit.KEY + iotThingRelationRootEntity.getId();
iotThingRelationRootEntity.setName(dto.getName());
String url = BizUtils.trimAll(dto.getUrl());
if(StringUtils.isNotBlank(url)){
@ -214,8 +232,9 @@ public class IotThingRelationRootServiceImpl extends BaseServiceImpl<IotThingRel
iotThingRelationRootEntity.setUrl(url);
iotThingRelationRootEntity.setRemark(dto.getRemark());
iotThingRelationRootEntity.setGroupName(dto.getGroupName());
mapper.insertOrUpdateSelective(iotThingRelationRootEntity);
mapper.update(iotThingRelationRootEntity);
//更新缓存
cache.deleteKeyMap(CacheNameEnum.THING_ROOT_RELATION,oldKey);
updateRootAndCache(iotThingRelationRootEntity);
}
@ -236,6 +255,12 @@ public class IotThingRelationRootServiceImpl extends BaseServiceImpl<IotThingRel
return mapper.selectOneByQueryAs(QueryWrapper.create().eq(IotThingRelationRootEntity::getId,id),IotThingRelationRootDTO.class);
}
@Override
public IotThingRelationRootDTO findByName(String name) {
return mapper.selectOneByQueryAs(QueryWrapper.create().eq(IotThingRelationRootEntity::getName,name)
.eq(IotThingRelationRootEntity::getTenantCode,UserContext.getRealTenantCode()),IotThingRelationRootDTO.class);
}
@Override
public List<IotThingRelationRootDTO> findByIds(List<Long> ids,boolean isAsc) {
return mapper.selectListByQueryAs(QueryWrapper.create().in(IotThingRelationRootEntity::getId,ids).orderBy(IotThingRelationRootEntity::getSort,isAsc),IotThingRelationRootDTO.class);

Loading…
Cancel
Save