diff --git a/das/src/main/java/com/das/modules/data/controller/DataController.java b/das/src/main/java/com/das/modules/data/controller/DataController.java new file mode 100644 index 00000000..f312ec6f --- /dev/null +++ b/das/src/main/java/com/das/modules/data/controller/DataController.java @@ -0,0 +1,57 @@ +package com.das.modules.data.controller; + +import com.das.common.result.R; +import com.das.common.utils.JsonUtils; +import com.das.modules.data.domain.SnapshotValueQueryParam; +import com.das.modules.data.domain.TSValueQueryParam; +import com.das.modules.data.service.DataService; +import jakarta.validation.Valid; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Map; + +/** + * 数据查询controller + */ +@Slf4j +@RequestMapping("/api/data") +@RestController +public class DataController { + + @Autowired + DataService dataService; + + /** + * 实时数据查询 + * @param param 查询数据请求体 + * @return redis数据 + */ + @PostMapping("/snapshot") + public R>> querySnapshotValues(@RequestBody @Valid List param) { + if (log.isDebugEnabled()){ + log.debug("/api/rtdbsvr/snapshot is calling"); + log.debug(JsonUtils.toJsonString(param)); + } + return R.success(dataService.querySnapshotValues(param)); + } + + /** + * 历史区间数据查询 + * @param param + * @return + */ + @PostMapping("/history") + public R>>> queryTimeSeriesValues(@RequestBody @Valid TSValueQueryParam param) { + if (log.isDebugEnabled()){ + log.debug("/api/rtdbsvr/timeseries is calling"); + log.debug(JsonUtils.toJsonString(param)); + } + return R.success(dataService.queryTimeSeriesValues(param)); + } +} diff --git a/das/src/main/java/com/das/modules/data/domain/SnapshotValueQueryParam.java b/das/src/main/java/com/das/modules/data/domain/SnapshotValueQueryParam.java new file mode 100644 index 00000000..c431d698 --- /dev/null +++ b/das/src/main/java/com/das/modules/data/domain/SnapshotValueQueryParam.java @@ -0,0 +1,20 @@ +package com.das.modules.data.domain; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@Data +public class SnapshotValueQueryParam +{ + /** + * 测点irn列表 + */ + @NotNull + private String deviceId; + + private List attributes; +} diff --git a/das/src/main/java/com/das/modules/data/domain/TSValueQueryParam.java b/das/src/main/java/com/das/modules/data/domain/TSValueQueryParam.java new file mode 100644 index 00000000..1905bab7 --- /dev/null +++ b/das/src/main/java/com/das/modules/data/domain/TSValueQueryParam.java @@ -0,0 +1,39 @@ +package com.das.modules.data.domain; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +import java.util.Date; +import java.util.List; + +/** + * 时序数据查询实体 + */ +@Data +public class TSValueQueryParam +{ + /** + * 开始时间 + */ + private String startTime; + + /** + * 结束时间 + */ + private String endTime; + + /** + * 间隔 + */ + private String interval; + + /** + * 填充模式 + */ + private String fill; + + /** + * 设备属性列表 + */ + private List devices; +} diff --git a/das/src/main/java/com/das/modules/data/service/DataService.java b/das/src/main/java/com/das/modules/data/service/DataService.java new file mode 100644 index 00000000..7d1e75e6 --- /dev/null +++ b/das/src/main/java/com/das/modules/data/service/DataService.java @@ -0,0 +1,134 @@ +package com.das.modules.data.service; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.collection.ListUtil; +import com.das.common.exceptions.ServiceException; +import com.das.common.utils.AdminRedisTemplate; +import com.das.modules.data.domain.SnapshotValueQueryParam; +import com.das.modules.data.domain.TSValueQueryParam; +import com.das.modules.equipment.entity.SysIotModelField; +import com.das.modules.equipment.mapper.SysIotModelFieldMapper; +import com.das.modules.node.service.TDEngineService; +import com.das.modules.node.service.impl.DataServiceImpl; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.*; + +@Slf4j +@Service +public class DataService { + + public static final int COMMIT_COUNT = 1000; + + @Autowired + AdminRedisTemplate adminRedisTemplate; + + @Autowired + private SysIotModelFieldMapper sysIotModelFieldMapper; + + @Autowired + private TDEngineService tdEngineService; + + @Autowired + private DataServiceImpl dataService; + + // 读取实时数据快照 + public Map> querySnapshotValues(List paramList) { + long start = System.currentTimeMillis(); + Map> result = new HashMap<>(paramList.size()); + Map> finalResult = result; + ListUtil.page(paramList, COMMIT_COUNT, list -> { + List keyList = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + SnapshotValueQueryParam snapshotValueQueryParam = list.get(i); + List attributes = snapshotValueQueryParam.getAttributes(); + if (CollectionUtils.isEmpty(attributes)) { + //为空查全部 + List sysIotModelFields = sysIotModelFieldMapper.queryAllFiledNames(Long.valueOf(snapshotValueQueryParam.getDeviceId())); + for (String item : sysIotModelFields) { + String key = String.format("RT:[%s]:[%s]", snapshotValueQueryParam.getDeviceId(), item); + keyList.add(key); + } + } else { + for (String item : attributes) { + String key = String.format("RT:[%s]:[%s]", snapshotValueQueryParam.getDeviceId(), item); + keyList.add(key); + } + } + } + List dataList = adminRedisTemplate.mGet(keyList); + for (int i = 0; i < keyList.size(); i++) { + String key = keyList.get(i); + int firstColonIndex = key.indexOf('['); + int firstIndex = key.indexOf(']'); + int secondIndex = key.indexOf(']', firstIndex + 1); + int secondColonIndex = key.indexOf('[', firstColonIndex + 1); + String deviceId = key.substring(firstColonIndex + 1, firstIndex); + String fieldName = key.substring(secondColonIndex + 1, secondIndex); + if (finalResult.get(deviceId) == null) { + Map valueMap = new HashMap<>(); + valueMap.put(fieldName, dataList.get(i)); + finalResult.put(deviceId, valueMap); + } else { + finalResult.get(deviceId).put(fieldName, dataList.get(i)); + } + } + }); + long end = System.currentTimeMillis(); + log.debug("读取快照{}个,耗时: {}秒", paramList.size(), (end - start) / 1000.0); + return finalResult; + } + + + public Map>> queryTimeSeriesValues(TSValueQueryParam param) { + if (CollectionUtil.isEmpty(param.getDevices()) || (param.getStartTime() == null && param.getEndTime() == null)) { + throw new ServiceException("必要参数缺失"); + } + Date startTime = new Date(Long.parseLong(param.getStartTime())); + Date endTime = new Date(Long.parseLong(param.getEndTime())); + Map>> result = new HashMap<>(param.getDevices().size()); + List deviceFieldList = param.getDevices(); + for (SnapshotValueQueryParam item : deviceFieldList) { + //field分为高频和低频查询 + Map>> values = queryHistoryCurveValues(Long.valueOf(item.getDeviceId()), startTime, endTime, param.getInterval(), param.getFill(), item.getAttributes()); + result.putAll(values); + } + return result; + } + + private Map>> queryHistoryCurveValues(Long irn, Date startTime, Date endTime, String interval, String fill, List attributes) { + + String iotModelCode = sysIotModelFieldMapper.queryModelCodeByDeviceId(irn); + Map highSpeedFieldMap = dataService.highIotFieldMap.get(iotModelCode); + Map lowSpeedFieldMap = dataService.lowIotFieldMap.get(iotModelCode); + List highSpeedField = new ArrayList<>(); + List lowSpeedField = new ArrayList<>(); + for (String field : attributes) { + if (highSpeedFieldMap.containsKey(field)) { + highSpeedField.add(field); + } + if (lowSpeedFieldMap.containsKey(field)) { + lowSpeedField.add(field); + } + } + Map>> result = new HashMap<>(); + if (!CollectionUtils.isEmpty(highSpeedField)) { + Map>> highHistoryCurve = tdEngineService.fetchHighHistoryCurve(irn, startTime, endTime, interval, highSpeedField); + result.putAll(highHistoryCurve); + } + if (!CollectionUtils.isEmpty(lowSpeedField)) { + Map>> lowHistoryCurve = tdEngineService.fetchLowHistoryCurve(irn, startTime, endTime, interval, lowSpeedField); + if (result.get(irn.toString()) == null) { + result.putAll(lowHistoryCurve); + } else { + result.get(irn.toString()).putAll(lowHistoryCurve.get(irn.toString())); + } + } + return result; + } + + +} diff --git a/das/src/main/java/com/das/modules/equipment/domain/dto/SysIotModelFieldDto.java b/das/src/main/java/com/das/modules/equipment/domain/dto/SysIotModelFieldDto.java index fa118d39..9d081a3d 100644 --- a/das/src/main/java/com/das/modules/equipment/domain/dto/SysIotModelFieldDto.java +++ b/das/src/main/java/com/das/modules/equipment/domain/dto/SysIotModelFieldDto.java @@ -65,4 +65,9 @@ public class SysIotModelFieldDto implements Serializable { private Integer visible; + private String orderColumn; + + private String orderType; + + } diff --git a/das/src/main/java/com/das/modules/equipment/domain/dto/SysIotModelServiceDto.java b/das/src/main/java/com/das/modules/equipment/domain/dto/SysIotModelServiceDto.java index bf100e17..8ef7ded2 100644 --- a/das/src/main/java/com/das/modules/equipment/domain/dto/SysIotModelServiceDto.java +++ b/das/src/main/java/com/das/modules/equipment/domain/dto/SysIotModelServiceDto.java @@ -46,4 +46,9 @@ public class SysIotModelServiceDto implements Serializable { * 当前页数 */ private Integer pageNum; + + + private String orderColumn; + + private String orderType; } diff --git a/das/src/main/java/com/das/modules/equipment/mapper/SysEquipmentMapper.java b/das/src/main/java/com/das/modules/equipment/mapper/SysEquipmentMapper.java index 989ffc85..ae6dafd3 100644 --- a/das/src/main/java/com/das/modules/equipment/mapper/SysEquipmentMapper.java +++ b/das/src/main/java/com/das/modules/equipment/mapper/SysEquipmentMapper.java @@ -29,6 +29,10 @@ public interface SysEquipmentMapper extends BaseMapperPlus getEquipmentAttributeInfo(Long equipmentId); + List getAttributeImpInfo(String code, Long equipmentId, Long linkId); + + List getServiceImpInfo(String code, Long equipmentId, Long linkId); + // 获取设备的动作信息 List getEquipmentServiceInfo(Long equipmentId); diff --git a/das/src/main/java/com/das/modules/equipment/mapper/SysIotModelFieldMapper.java b/das/src/main/java/com/das/modules/equipment/mapper/SysIotModelFieldMapper.java index a0117ee4..9f2da697 100644 --- a/das/src/main/java/com/das/modules/equipment/mapper/SysIotModelFieldMapper.java +++ b/das/src/main/java/com/das/modules/equipment/mapper/SysIotModelFieldMapper.java @@ -9,6 +9,8 @@ import com.das.modules.equipment.entity.SysIotModelField; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.List; + @Mapper public interface SysIotModelFieldMapper extends BaseMapperPlus { @@ -17,4 +19,8 @@ public interface SysIotModelFieldMapper extends BaseMapperPlus queryAllFiledNames(@Param("deviceId") Long deviceId); + + String queryModelCodeByDeviceId(@Param("deviceId") Long deviceId); } diff --git a/das/src/main/java/com/das/modules/node/controller/SysNodeController.java b/das/src/main/java/com/das/modules/node/controller/SysNodeController.java index edcf98fa..7bbc6987 100644 --- a/das/src/main/java/com/das/modules/node/controller/SysNodeController.java +++ b/das/src/main/java/com/das/modules/node/controller/SysNodeController.java @@ -165,13 +165,13 @@ public class SysNodeController { public R getMappingList(@RequestBody SysImptabmappingDto sysImptabmappingDto) { //判断是否有权限 - boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_DEVICE_MGR.toString()); - if(!hasPermission){ - return R.fail("没有节点管理权限"); - } - if (sysImptabmappingDto.getLinkId() == null) { - throw new ServiceException("参数缺失"); - } +// boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_DEVICE_MGR.toString()); +// if(!hasPermission){ +// return R.fail("没有节点管理权限"); +// } +// if (sysImptabmappingDto.getLinkId() == null) { +// throw new ServiceException("参数缺失"); +// } List list = sysNodeService.getMappingList(sysImptabmappingDto); return R.success(list); } diff --git a/das/src/main/java/com/das/modules/node/service/TDEngineService.java b/das/src/main/java/com/das/modules/node/service/TDEngineService.java index 0438de97..6acb3dcf 100644 --- a/das/src/main/java/com/das/modules/node/service/TDEngineService.java +++ b/das/src/main/java/com/das/modules/node/service/TDEngineService.java @@ -1,6 +1,7 @@ package com.das.modules.node.service; import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.util.StrUtil; import com.das.modules.equipment.domain.vo.IotModelFieldVo; import com.das.modules.equipment.mapper.SysIotModelMapper; import com.das.modules.node.domain.bo.RTData; @@ -13,13 +14,12 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.sql.*; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.Date; import java.util.concurrent.ConcurrentHashMap; @Slf4j @@ -131,7 +131,8 @@ public class TDEngineService { sb.setLength(0); sb.append("ALTER STABLE "); sb.append(stableName); - sb.append(" DROP COLUMN");; + sb.append(" DROP COLUMN"); + ; sb.append(fieldCode); sb.append(";"); try { @@ -140,7 +141,7 @@ public class TDEngineService { log.error("删除超级表列失败:{},失败原因{}", sb.toString(), e); } - }catch (Exception ignored){ + } catch (Exception ignored) { } } @@ -148,7 +149,7 @@ public class TDEngineService { /** * 删除超级表 */ - public void deleteStable(String stableName){ + public void deleteStable(String stableName) { try (Connection conn = hikariDataSource.getConnection(); Statement pstmt = conn.createStatement()) { StringBuilder sb = new StringBuilder(1024 * 1024); @@ -162,7 +163,7 @@ public class TDEngineService { log.error("删除超级表失败:{},失败原因{}", sb.toString(), e); } - }catch (Exception ignored){ + } catch (Exception ignored) { } } @@ -191,7 +192,7 @@ public class TDEngineService { for (String key : map.keySet()) { sb.append(", "); sb.append(key); - sb.append(" "+map.get(key)); + sb.append(" " + map.get(key)); } sb.append(") TAGS (`deviceid` BIGINT);"); try { @@ -215,7 +216,7 @@ public class TDEngineService { for (String key : map.keySet()) { sb.append(", "); sb.append(key); - sb.append(" "+map.get(key)); + sb.append(" " + map.get(key)); } sb.append(") TAGS (`deviceid` BIGINT);"); try { @@ -342,6 +343,153 @@ public class TDEngineService { } } + public Map>> fetchHighHistoryCurve(Long irn, Date startTime, Date endTime, String interval, List fieldList) { + SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + String tbName = String.format("h%d", irn); + Date now = new Date(); + if (endTime.after(now)) { + endTime = now; + } + Map>> result = new HashMap<>(); + Map> valueMap = new HashMap<>(); + StringBuffer sb = new StringBuffer(2048); + if (StrUtil.isNotBlank(interval)) { + String startTimeStr = SIMPLE_DATE_FORMAT.format(startTime); + String endTimeStr = SIMPLE_DATE_FORMAT.format(endTime); + String timeStr = String.format("'%s','%s'", startTimeStr, endTimeStr); + String intervalStr = convertInterval(interval); + + sb.append("select _irowts updatetime"); + fieldList.forEach(field -> + sb.append(" ,").append("interp(").append(field).append(") ").append(field) + ); + sb.append(" from "); + sb.append(tbName); + sb.append(String.format(" range(%s)", timeStr)); + sb.append(String.format(" every(%s)", intervalStr)); + sb.append(String.format(" FILL(%s)", "PREV")); + sb.append(" order by updatetime"); + } else { + sb.append("select updatetime, datavalue from "); + fieldList.forEach(field -> + sb.append(", ").append(field) + ); + sb.append(" from "); + sb.append(tbName); + sb.append(" where "); + sb.append(String.format(" updatetime >= %d and updatetime < %d ", startTime.getTime(), endTime.getTime())); + sb.append(" order by updatetime"); + } + log.debug(sb.toString()); + try (Connection conn = hikariDataSource.getConnection(); + Statement smt = conn.createStatement(); + ResultSet rs = smt.executeQuery(sb.toString())) { + while (rs.next()) { + for (int i = 0; i < fieldList.size(); i++){ + if (valueMap.get(fieldList.get(i)) == null){ + Map map = new HashMap<>(); + List timeList = new ArrayList<>(); + timeList.add(rs.getTimestamp(1).getTime()); + List valueList = new ArrayList<>(); + valueList.add(rs.getObject(fieldList.get(i))); + map.put("times",timeList); + map.put("values",valueList); + valueMap.put(fieldList.get(i),map); + }else { + Map map = valueMap.get(fieldList.get(i)); + List times = (List) map.get("times"); + List values = (List) map.get("values"); + times.add(rs.getTimestamp(1).getTime()); + values.add(rs.getObject(fieldList.get(i))); + } + } + } + result.put(irn.toString(),valueMap); + } catch (Exception e) { + log.error("获取数据异常", e); + return result; + } + return result; + } + + public Map>> fetchLowHistoryCurve(Long irn, Date startTime, Date endTime, String interval, List fieldList) { + SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + String tbName = String.format("l%d", irn); + Date now = new Date(); + if (endTime.after(now)) { + endTime = now; + } + Map>> result = new HashMap<>(); + Map> valueMap = new HashMap<>(); + StringBuffer sb = new StringBuffer(2048); + if (StrUtil.isNotBlank(interval)) { + String startTimeStr = SIMPLE_DATE_FORMAT.format(startTime); + String endTimeStr = SIMPLE_DATE_FORMAT.format(endTime); + String timeStr = String.format("'%s','%s'", startTimeStr, endTimeStr); + String intervalStr = convertInterval(interval); + + sb.append("select _irowts updatetime"); + fieldList.forEach(field -> + sb.append(" ,").append("interp(").append(field).append(") ").append(field) + ); + sb.append(" from "); + sb.append(tbName); + sb.append(String.format(" range(%s)", timeStr)); + sb.append(String.format(" every(%s)", intervalStr)); + sb.append(String.format(" FILL(%s)", "PREV")); + sb.append(" order by updatetime"); + } else { + sb.append("select updatetime, datavalue from "); + fieldList.forEach(field -> + sb.append(", ").append(field) + ); + sb.append(" from "); + sb.append(tbName); + sb.append(" where "); + sb.append(String.format(" updatetime >= %d and updatetime < %d ", startTime.getTime(), endTime.getTime())); + sb.append(" order by updatetime"); + } + log.debug(sb.toString()); + try (Connection conn = hikariDataSource.getConnection(); + Statement smt = conn.createStatement(); + ResultSet rs = smt.executeQuery(sb.toString())) { + while (rs.next()) { + for (int i = 0; i < fieldList.size(); i++){ + if (valueMap.get(fieldList.get(i)) == null){ + Map map = new HashMap<>(); + List timeList = new ArrayList<>(); + timeList.add(rs.getTimestamp(1).getTime()); + List valueList = new ArrayList<>(); + valueList.add(rs.getObject(fieldList.get(i))); + map.put("times",timeList); + map.put("values",valueList); + valueMap.put(fieldList.get(i),map); + }else { + Map map = valueMap.get(fieldList.get(i)); + List times = (List) map.get("times"); + List values = (List) map.get("values"); + times.add(rs.getTimestamp(1).getTime()); + values.add(rs.getObject(fieldList.get(i))); + } + } + } + result.put(irn.toString(),valueMap); + } catch (Exception e) { + log.error("获取数据异常", e); + return result; + } + return result; + } + + private String convertInterval(String interval) { + if (!StringUtils.hasText(interval)) { + interval = "1m"; + } + return interval; + } + @PreDestroy public void free() { diff --git a/das/src/main/java/com/das/modules/node/service/impl/SysNodeServiceImpl.java b/das/src/main/java/com/das/modules/node/service/impl/SysNodeServiceImpl.java index 1b243984..37f9724b 100644 --- a/das/src/main/java/com/das/modules/node/service/impl/SysNodeServiceImpl.java +++ b/das/src/main/java/com/das/modules/node/service/impl/SysNodeServiceImpl.java @@ -210,6 +210,9 @@ public class SysNodeServiceImpl implements SysNodeService { public void bindDeviceMeas(List equipmentId, Long linkId) { List addList = new ArrayList<>(); List addList2 = new ArrayList<>(); + if (CollectionUtils.isEmpty(equipmentId)) { + sysImptabmappingMapper.deleteBindDevice(linkId); + } // 先更新设备地址 for (BindEquipmentInfoDto info : equipmentId) { // 更新设备表里面的设备地址 @@ -217,16 +220,15 @@ public class SysNodeServiceImpl implements SysNodeService { } // 获取已经绑定的设备 List bindDeviceList = sysImptabmappingMapper.getBindDevice(linkId); - // 过滤已经绑定的设备 - for (SysImptabmappingVo bindDevice : bindDeviceList) { - addList2.add(bindDevice.getEquipmentId()); - } + + //过滤 - equipmentId.removeIf(item -> addList2.contains(item.getEquipmentId())); +// equipmentId.removeIf(item -> addList2.contains(item.getEquipmentId())); SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY); addSysImptabmapping(equipmentId, linkId, sysUserVo, addList); if (!CollectionUtils.isEmpty(addList)) { - sysImptabmappingMapper.insertBatch(addList); + sysImptabmappingMapper.deleteBindDevice(linkId); + sysImptabmappingMapper.insertOrUpdateBatch(addList); } } @@ -364,21 +366,46 @@ public class SysNodeServiceImpl implements SysNodeService { // 获取设备的测点信息 for (BindEquipmentInfoDto info : equipmentId) { List fieldList = sysEquipmentMapper.getEquipmentAttributeInfo(info.getEquipmentId()); + // 获取映射表相关信息 List serviceList = sysEquipmentMapper.getEquipmentServiceInfo(info.getEquipmentId()); + if (!CollectionUtils.isEmpty(fieldList)) { for (BaseImptabmappingVo field : fieldList) { - SysImptabmapping sysImptabmapping = getSysImptabmapping(linkId, sysUserVo, info); - sysImptabmapping.setEquipmentAttribute(field.getCode()); - sysImptabmapping.setParams(field.getParams()); - addList.add(sysImptabmapping); + List fieldImpList = sysEquipmentMapper.getAttributeImpInfo(field.getCode(), info.getEquipmentId(), linkId); + if (!CollectionUtils.isEmpty(fieldImpList)) { + for (BaseImptabmappingVo fieldImp : fieldImpList) { + if(field.getCode().equals(fieldImp.getCode())) { + SysImptabmapping sysImptabmapping = getSysImptabmapping(linkId, sysUserVo, info); + sysImptabmapping.setEquipmentAttribute(field.getCode()); + sysImptabmapping.setParams(fieldImp.getParams()); + addList.add(sysImptabmapping); + } + } + } else { + SysImptabmapping sysImptabmapping = getSysImptabmapping(linkId, sysUserVo, info); + sysImptabmapping.setEquipmentAttribute(field.getCode()); + addList.add(sysImptabmapping); + } } } if (!CollectionUtils.isEmpty(serviceList)) { for (BaseImptabmappingVo service : serviceList) { - SysImptabmapping sysImptabmapping = getSysImptabmapping(linkId, sysUserVo, info); - sysImptabmapping.setEquipmentService(service.getCode()); - sysImptabmapping.setParams(service.getParams()); - addList.add(sysImptabmapping); + List serviceImpList = sysEquipmentMapper.getServiceImpInfo(service.getCode(), info.getEquipmentId(), linkId); + + if (!CollectionUtils.isEmpty(serviceImpList)) { + for (BaseImptabmappingVo serviceImp : serviceImpList) { + if(service.getCode().equals(serviceImp.getCode())) { + SysImptabmapping sysImptabmapping = getSysImptabmapping(linkId, sysUserVo, info); + sysImptabmapping.setEquipmentService(service.getCode()); + sysImptabmapping.setParams(serviceImp.getParams()); + addList.add(sysImptabmapping); + } + } + }else { + SysImptabmapping sysImptabmapping = getSysImptabmapping(linkId, sysUserVo, info); + sysImptabmapping.setEquipmentService(service.getCode()); + addList.add(sysImptabmapping); + } } } diff --git a/das/src/main/resources/mapper/SysEquipmentMapper.xml b/das/src/main/resources/mapper/SysEquipmentMapper.xml index c9d4211b..9b26a30c 100644 --- a/das/src/main/resources/mapper/SysEquipmentMapper.xml +++ b/das/src/main/resources/mapper/SysEquipmentMapper.xml @@ -129,16 +129,29 @@ - + select simf.attribute_code as code, si.params,si.id,si.revision from sys_imptabmapping si + left join sys_iot_model_field simf on si.equipment_attribute = simf.attribute_code + left join sys_equipment se on simf.iot_model_id = se.iot_model_id + where si.equipment_id = #{equipmentId} and si.link_id = #{linkId} and si.equipment_attribute = #{code} + + + + + diff --git a/das/src/main/resources/mapper/SysImptabmappingMapper.xml b/das/src/main/resources/mapper/SysImptabmappingMapper.xml index b9d0337d..595e8290 100644 --- a/das/src/main/resources/mapper/SysImptabmappingMapper.xml +++ b/das/src/main/resources/mapper/SysImptabmappingMapper.xml @@ -28,7 +28,7 @@ left join sys_equipment se on si.equipment_id = se.id left join sys_iot_model_field simf on si.equipment_attribute = simf.attribute_code and se.iot_model_id = simf.iot_model_id where si.link_id = #{linkId} and simf.attribute_type = #{type} - order by si.porder + order by simf.porder @@ -34,6 +40,16 @@ + + diff --git a/das/src/main/resources/mapper/SysIotModelServiceMapper.xml b/das/src/main/resources/mapper/SysIotModelServiceMapper.xml index f273bf67..612b5251 100644 --- a/das/src/main/resources/mapper/SysIotModelServiceMapper.xml +++ b/das/src/main/resources/mapper/SysIotModelServiceMapper.xml @@ -24,6 +24,12 @@ and t.service_code like concat('%',#{info.serviceCode},'%') + + order by ${info.orderColumn} ${info.orderType} + + + order by t.porder asc +