diff --git a/mh-admin/src/main/java/com/mh/web/controller/comprehensive/CompreReportController.java b/mh-admin/src/main/java/com/mh/web/controller/comprehensive/CompreReportController.java new file mode 100644 index 0000000..c3bbd6b --- /dev/null +++ b/mh-admin/src/main/java/com/mh/web/controller/comprehensive/CompreReportController.java @@ -0,0 +1,34 @@ +package com.mh.web.controller.comprehensive; + +import com.mh.common.core.controller.BaseController; +import com.mh.common.core.domain.vo.EnergyQueryVO; +import com.mh.common.core.page.TableDataInfo; +import com.mh.system.service.report.IComprehensiveReportService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Classname CompreReportController + * Todo: 综合报表 + * @Date 2025-10-05 13:59 + * @Created by LJF + */ +@RestController +@RequestMapping("/compre") +public class CompreReportController extends BaseController { + + private final IComprehensiveReportService proOverviewService; + + public CompreReportController(IComprehensiveReportService proOverviewService) { + this.proOverviewService = proOverviewService; + } + + @GetMapping("/report") + public TableDataInfo report(@RequestBody EnergyQueryVO vo) { + startPage(); + return getDataTable(proOverviewService.report(vo)); + } + +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/CollectionParamsManage.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/CollectionParamsManage.java index 2b626c3..ee2fc8b 100644 --- a/mh-common/src/main/java/com/mh/common/core/domain/entity/CollectionParamsManage.java +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/CollectionParamsManage.java @@ -144,6 +144,11 @@ public class CollectionParamsManage extends BaseEntity { */ private String communicationType; + /** + * 通信质量 + */ + private String quality; + /** * 读取响应的寄存器大小(创建指令的时候需要) */ diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/CpmSpaceRelation.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/CpmSpaceRelation.java index 2fa1f4a..51c75a6 100644 --- a/mh-common/src/main/java/com/mh/common/core/domain/entity/CpmSpaceRelation.java +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/CpmSpaceRelation.java @@ -30,6 +30,11 @@ public class CpmSpaceRelation extends BaseEntity { @TableId(value = "id", type = IdType.ASSIGN_UUID) private String id; + /** + * 台账id + */ + private String ledgerId; + /** * 采集参数id */ @@ -76,6 +81,7 @@ public class CpmSpaceRelation extends BaseEntity { public String toString() { return new ToStringBuilder(this) .append("id", id) + .append("ledgerId", ledgerId) .append("cpmId", cpmId) .append("areaId", areaId) .append("buildingId", buildingId) diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/HouseInfo.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/HouseInfo.java index 724baa6..f921a59 100644 --- a/mh-common/src/main/java/com/mh/common/core/domain/entity/HouseInfo.java +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/HouseInfo.java @@ -92,6 +92,20 @@ public class HouseInfo extends BaseEntity { private int orderNum; + /** + * 台账id + */ + @JsonIgnore + @TableField(exist = false) + private String ledgerId; + + /** + * 采集节点id + */ + @JsonIgnore + @TableField(exist = false) + private String cpmId; + @Override public String toString() { return new ToStringBuilder(this) diff --git a/mh-common/src/main/java/com/mh/common/enums/ComputeEnum.java b/mh-common/src/main/java/com/mh/common/enums/ComputeEnum.java index 2e22262..5fc23e8 100644 --- a/mh-common/src/main/java/com/mh/common/enums/ComputeEnum.java +++ b/mh-common/src/main/java/com/mh/common/enums/ComputeEnum.java @@ -103,6 +103,16 @@ public enum ComputeEnum implements ComputeService { Map.Entry>> entry) { return null; } + }, + /** + * 蒸汽流量计数据处理 + */ + STEAM_FLOW("蒸汽流量计数据处理", 12) { + @Override + public ArrayList> getDataList( + Map.Entry>> entry) { + return null; + } }; private String des; diff --git a/mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java b/mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java index 53a7cbe..6f48215 100644 --- a/mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java +++ b/mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java @@ -201,7 +201,8 @@ public class DataProcessServiceImpl implements DataProcessService { for (AdvantechDatas advantechDatas : list) { String tag = advantechDatas.getTag(); String value = String.valueOf(advantechDatas.getValue()); - log.info("时间: {},tag标签: {},value值: {}", formattedTime, tag, value); + String quality = String.valueOf(advantechDatas.getQuality()); + log.info("时间: {},tag标签: {},value值: {}, 质量:{}", formattedTime, tag, value, quality); try { if (StringUtils.isBlank(tag)) { continue; @@ -212,6 +213,7 @@ public class DataProcessServiceImpl implements DataProcessService { collectionParamsManage = entity; try { collectionParamsManage.setCurValue(new BigDecimal(value)); + collectionParamsManage.setQuality(quality); } catch (NumberFormatException e) { log.error("数值格式解析异常", e); continue; diff --git a/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java b/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java index df1c515..1ad23b6 100644 --- a/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java +++ b/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java @@ -334,8 +334,14 @@ public interface CollectionParamsManageMapper extends BaseMapper selectBySystemTypeAndHouseId(@Param("systemType") String systemType, @Param("houseId") String houseId); - @Update("update collection_params_manage set cur_value = #{curValue}, cur_time = #{curTime} where id = #{id} ") - int updateCurValueById(@Param("id") String id, @Param("curValue") BigDecimal curValue, @Param("curTime") Date curTime); + @Update("update collection_params_manage " + + " set cur_value = #{curValue}, " + + " cur_time = #{curTime}, " + + " quality = #{quality} where id = #{id} ") + int updateCurValueById(@Param("id") String id, + @Param("curValue") BigDecimal curValue, + @Param("curTime") Date curTime, + @Param("quality") String quality); @Select("select" + " device_ledger_id " + diff --git a/mh-system/src/main/java/com/mh/system/mapper/device/DeviceLedgerMapper.java b/mh-system/src/main/java/com/mh/system/mapper/device/DeviceLedgerMapper.java index cf4284b..86befaa 100644 --- a/mh-system/src/main/java/com/mh/system/mapper/device/DeviceLedgerMapper.java +++ b/mh-system/src/main/java/com/mh/system/mapper/device/DeviceLedgerMapper.java @@ -18,8 +18,8 @@ import java.util.List; @Mapper public interface DeviceLedgerMapper extends BaseMapper { - @Update("update device_ledger set status = 0, update_time = current_timestamp where id = #{id}") - void updateOnlineStatus(@Param("id") String deviceLedgerId); + @Update("update device_ledger set status = #{status} , update_time = current_timestamp where id = #{id}") + void updateOnlineStatus(@Param("id") String deviceLedgerId, @Param("status") int status); @Update("update device_ledger set status = #{status}, update_time = current_timestamp where id = #{id}") void updateOnlineOrOfflineStatus(@Param("id") String deviceLedgerId, @Param("status") int integer); diff --git a/mh-system/src/main/java/com/mh/system/mapper/report/ComprehensiveReportMapper.java b/mh-system/src/main/java/com/mh/system/mapper/report/ComprehensiveReportMapper.java new file mode 100644 index 0000000..c2cb764 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/report/ComprehensiveReportMapper.java @@ -0,0 +1,209 @@ +package com.mh.system.mapper.report; + +import com.mh.common.core.domain.ColumnFilter; +import com.mh.common.core.domain.entity.CollectionParamsManage; +import com.mh.common.core.domain.entity.WaterLevel; +import org.apache.ibatis.annotations.*; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水温度记录 + * @date 2025-06-19 16:24:31 + */ +@Mapper +public interface ComprehensiveReportMapper { + + + @Select("") + BigDecimal queryByDeviceNum(@Param("deviceNums") List deviceNums); + + @Select("") + List energyAnalysisManyTable(@Param("deviceNums") List deviceNums, + @Param("lastTableName") String lastTableName, + @Param("curTableName") String curTableName, + @Param("startTime") Date startTime, + @Param("endTime") Date endTime, + @Param("timeType") String timeType); + + @Select("") + BigDecimal selectEER(@Param("deviceNums") List deviceNums); + + @Select("") + List energyAnalysisOneTable(@Param("deviceNums") List deviceNums, + @Param("lastTableName") String lastTableName, + @Param("curTableName") String curTableName, + @Param("startTime") Date startTime, + @Param("endTime") Date endTime, + @Param("timeType") String timeType); + +} diff --git a/mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java index 3c766fd..ac4732c 100644 --- a/mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java +++ b/mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java @@ -387,17 +387,35 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag chillersEntities.forEach(chillerEntity -> { log.info("chillerEntity: {}", chillerEntity.toString()); if (chillerEntity.getId() != null && !StringUtils.isEmpty(chillerEntity.getId())) { - collectionParamsManageMapper.updateCurValueById(chillerEntity.getId(), chillerEntity.getCurValue(), chillerEntity.getCurTime()); + collectionParamsManageMapper.updateCurValueById(chillerEntity.getId(), + chillerEntity.getCurValue(), + chillerEntity.getCurTime(), + chillerEntity.getQuality()); } }); // 根据台账id更新台账在线情况 - // 根据chillerEntity使用stream流获取台账id分组数据 - chillersEntities.stream().map(CollectionParamsManage::getDeviceLedgerId).distinct().forEach(deviceLedgerId -> { - // 根据台账id 更新 device_ledger 在线情况,0:在线,1:离线 - if (!StringUtils.isEmpty(deviceLedgerId)) { - deviceLedgerMapper.updateOnlineStatus(deviceLedgerId); - } - }); + // 根据chillerEntity使用stream流获取台账id分组数据,并且判断属于当前台账的所有设备的在线情况,如果质量全部是0, + // 则更新台账在线状态为0,否则更新为1 +// chillersEntities.stream().map(CollectionParamsManage::getDeviceLedgerId).distinct().forEach(deviceLedgerId -> { +// // 根据台账id 更新 device_ledger 在线情况,0:在线,1:离线 +// if (!StringUtils.isEmpty(deviceLedgerId)) { +// deviceLedgerMapper.updateOnlineStatus(deviceLedgerId); +// } +// }); + // 根据台账id更新台账在线情况 + // 根据chillerEntity使用stream流获取台账id分组数据,并且判断属于当前台账的所有设备的在线情况,如果质量全部是0, + // 则更新台账在线状态为0,否则更新为1 + chillersEntities.stream() + .filter(entity -> entity.getDeviceLedgerId() != null && !entity.getDeviceLedgerId().isEmpty()) + .collect(Collectors.groupingBy(CollectionParamsManage::getDeviceLedgerId)) + .forEach((deviceLedgerId, entities) -> { + // 检查该台账下所有设备的质量是否都为0(在线) + boolean allOnline = entities.stream() + .allMatch(entity -> entity.getQuality() != null && entity.getQuality().equals("0")); + + // 更新设备台账在线状态:0-在线,1-离线 + deviceLedgerMapper.updateOnlineStatus(deviceLedgerId, allOnline ? 0 : 1); + }); // 根据网关id更新网关在线情况 chillersEntities.stream().map(CollectionParamsManage::getGatewayId).distinct().forEach(gatewayId -> { // 根据网关id 更新 gateway_manage 在线情况,0:在线,1:离线 diff --git a/mh-system/src/main/java/com/mh/system/service/policy/impl/PolicyManageServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/policy/impl/PolicyManageServiceImpl.java index 1f44d7f..3a8831a 100644 --- a/mh-system/src/main/java/com/mh/system/service/policy/impl/PolicyManageServiceImpl.java +++ b/mh-system/src/main/java/com/mh/system/service/policy/impl/PolicyManageServiceImpl.java @@ -66,7 +66,7 @@ public class PolicyManageServiceImpl implements IPolicyManageService { if (StringUtils.isEmpty(cpmId)) { throw new RuntimeException("未找到该时间策略值"); } - return collectionParamsManageMapper.updateCurValueById(cpmId, new BigDecimal(timeValue), new Date()); + return collectionParamsManageMapper.updateCurValueById(cpmId, new BigDecimal(timeValue), new Date(), "0"); } @Override diff --git a/mh-system/src/main/java/com/mh/system/service/report/IComprehensiveReportService.java b/mh-system/src/main/java/com/mh/system/service/report/IComprehensiveReportService.java new file mode 100644 index 0000000..8029940 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/report/IComprehensiveReportService.java @@ -0,0 +1,14 @@ +package com.mh.system.service.report; + +import com.mh.common.core.domain.vo.EnergyQueryVO; + +import java.util.List; + +/** + * @Description: 综合能耗报表 + * @Author: LJF + * @Date: 2020/4/1 10:03 + **/ +public interface IComprehensiveReportService { + List report(EnergyQueryVO vo); +} diff --git a/mh-system/src/main/java/com/mh/system/service/report/impl/ComprehensiveReportServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/report/impl/ComprehensiveReportServiceImpl.java new file mode 100644 index 0000000..42aa9e3 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/report/impl/ComprehensiveReportServiceImpl.java @@ -0,0 +1,206 @@ +package com.mh.system.service.report.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.mh.common.core.domain.ColumnFilter; +import com.mh.common.core.domain.dto.OverviewEnergyDTO; +import com.mh.common.core.domain.entity.CollectionParamsManage; +import com.mh.common.core.domain.entity.SysDictData; +import com.mh.common.core.domain.vo.EnergyQueryVO; +import com.mh.common.utils.DateUtils; +import com.mh.system.mapper.SysDictDataMapper; +import com.mh.system.mapper.device.CollectionParamsManageMapper; +import com.mh.system.mapper.report.ComprehensiveReportMapper; +import com.mh.system.service.report.IComprehensiveReportService; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.*; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; + +/** + * @Classname ComprehensiveReportServiceImpl + * Todo: 综合能耗数据报表 + * @Date 2025-10-05 14:05 + * @Created by LJF + */ +@Service +public class ComprehensiveReportServiceImpl implements IComprehensiveReportService { + + @Resource + private SysDictDataMapper sysDictDataMapper; + + @Resource + private CollectionParamsManageMapper collectionParamsManageMapper; + + @Resource + private ComprehensiveReportMapper comprehensiveReportMapper; + + @Override + public List report(EnergyQueryVO vo) { + DateUtils.sysEnergyDateChange(vo); + // 获取参数 + AtomicReference lastTableName = new AtomicReference<>("data_" + vo.getTimeType()); + AtomicReference curTableName = new AtomicReference<>("data_" + vo.getTimeType()); + String timeType = vo.getTimeType(); + + // 判断是否是单表 + boolean isSingleTable = "month".equalsIgnoreCase(timeType) || "year".equalsIgnoreCase(timeType); + if (!isSingleTable) { + lastTableName.set(lastTableName + vo.getStartTime().substring(0, 4)); + curTableName.set(curTableName + vo.getEndTime().substring(0, 4)); + } + + // 查询系统类型数据 + List sysTypeData = sysDictDataMapper.selectDictDataByType("sys_type"); + // 定义参数类型 + String[] paramTypes = {"16", "17", "18", "19"}; + // 初始化结果列表 + List result = new ArrayList<>(); + // 使用Map存储不同类型的能源DTO + Map energyMap = new HashMap<>(); + energyMap.put("16", new OverviewEnergyDTO()); + energyMap.put("17", new OverviewEnergyDTO()); + energyMap.put("18", new OverviewEnergyDTO()); + energyMap.put("19", new OverviewEnergyDTO()); + + for (String paramType : paramTypes) { + List dataList = new ArrayList<>(); + for (SysDictData sysDictData : sysTypeData) { + String sysType = sysDictData.getDictValue(); + // 查询采集参数 + List collectionParamsManages = queryCollectionParams(paramType, sysType, 40, null, false); + // 合并数据 + if (collectionParamsManages != null && !collectionParamsManages.isEmpty()) { + // 判断两个表是否一样 + boolean isSameTable = lastTableName.get().equals(curTableName.get()); + if (isSameTable) { + List columnFilters = comprehensiveReportMapper.energyAnalysisOneTable(collectionParamsManages, + lastTableName.get(), + curTableName.get(), + DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getStartTime()), + DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getEndTime()), + timeType); + dataList.addAll(columnFilters); + } else { + // 两个表不一样 + List columnFilters = comprehensiveReportMapper.energyAnalysisManyTable(collectionParamsManages, + lastTableName.get(), + curTableName.get(), + DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getStartTime()), + DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getEndTime()), + timeType); + dataList.addAll(columnFilters); + } + } + } + // 初始化能源数据 + initialEnergyData(dataList, energyMap.get(paramType), getEnergyLabel(paramType), getEnergyUnit(paramType), result); + + } + return result.isEmpty() ? List.of() : result; + } + + private List queryCollectionParams(String paramType, String sysType, int grade, String terminalDeviceType, boolean isNow) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + LocalDate today = LocalDate.now(); + String todayStr = today.toString(); // 格式为 'YYYY-MM-DD' + queryWrapper.eq("param_type", paramType) + .eq("system_type", sysType) + .eq("grade", grade); + if (isNow) { + queryWrapper.apply("DATE(cur_time) = DATE({0})", todayStr); + } + + + if (terminalDeviceType != null && !terminalDeviceType.isEmpty()) { + queryWrapper.eq("terminal_device_type", terminalDeviceType); + } + + // 先查询总表 + queryWrapper.eq("mt_is_sum", 0); + Long count = collectionParamsManageMapper.selectCount(queryWrapper); + if (count > 0) { + return collectionParamsManageMapper.selectList(queryWrapper); + } + + // 查询分表 + queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("param_type", paramType) + .eq("system_type", sysType) + .eq("grade", grade); + if (isNow) { + queryWrapper.apply("DATE(cur_time) = DATE({0})", todayStr); + } + +// if (terminalDeviceType != null && !terminalDeviceType.isEmpty()) { +// queryWrapper.eq("terminal_device_type", terminalDeviceType); +// } + return collectionParamsManageMapper.selectList(queryWrapper); + } + + private String getEnergyLabel(String paramType) { + switch (paramType) { + case "16": + return "总用电量"; + case "17": + return "总产冷量"; + case "18": + return "总用水量"; + case "19": + return "总用气量"; + default: + throw new IllegalArgumentException("Invalid param type: " + paramType); + } + } + + private String getEnergyUnit(String paramType) { + switch (paramType) { + case "16": + return "kw/h"; + case "17": + return "kw"; + case "18": + return "t"; + case "19": + return "t"; + default: + throw new IllegalArgumentException("Invalid param type: " + paramType); + } + } + + + private static void initialEnergyData(List dataList, + OverviewEnergyDTO ele, + String paramTypeName, + String unitName, + List result) { + if (!dataList.isEmpty()) { + // 根据时间分组,求和取总和,再根据时间升序排序 + // 使用LinkedHashMap保持时间顺序 + LinkedHashMap eleMap = dataList.stream() + .sorted(Comparator.comparing(ColumnFilter::getName)) // 按时间字段排序 + .collect(Collectors.groupingBy( + ColumnFilter::getName, + LinkedHashMap::new, + Collectors.summingDouble(value -> + new BigDecimal(value.getValue()).doubleValue()) + )); + + // 提取时间序列和数值序列 + String[] timeArray = eleMap.keySet().toArray(new String[0]); + String[] valueArray = eleMap.values().stream() + .map(d -> String.format("%.2f", d)) // 保留两位小数 + .toArray(String[]::new); + + // 设置到对象中 + ele.setName(paramTypeName); + ele.setUnit(unitName); + ele.setTimeStr(timeArray); + ele.setData(valueArray); + result.add(ele); + } + } +} diff --git a/mh-system/src/main/java/com/mh/system/service/space/impl/HouseInfoServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/space/impl/HouseInfoServiceImpl.java index 718bf20..cee98a6 100644 --- a/mh-system/src/main/java/com/mh/system/service/space/impl/HouseInfoServiceImpl.java +++ b/mh-system/src/main/java/com/mh/system/service/space/impl/HouseInfoServiceImpl.java @@ -6,10 +6,7 @@ import com.mh.common.core.domain.TreeSelect; import com.mh.common.core.domain.entity.*; import com.mh.common.utils.StringUtils; import com.mh.system.mapper.SysParamsMapper; -import com.mh.system.mapper.space.AreaInfoMapper; -import com.mh.system.mapper.space.BuildingInfoMapper; -import com.mh.system.mapper.space.FloorInfoMapper; -import com.mh.system.mapper.space.HouseInfoMapper; +import com.mh.system.mapper.space.*; import com.mh.system.service.space.IHouseInfoService; import jakarta.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired; @@ -43,6 +40,9 @@ public class HouseInfoServiceImpl implements IHouseInfoService { @Resource private SysParamsMapper sysParamsMapper; + @Resource + private CpmSpaceRelationMapper cpmSpaceRelationMapper; + @Override public List selectHouseInfoList(HouseInfo houseInfo) { if (houseInfo == null) { @@ -81,7 +81,19 @@ public class HouseInfoServiceImpl implements IHouseInfoService { @Override public int insertHouseInfo(HouseInfo houseInfo) { getAreaIdAndBuildingId(houseInfo); - return houseInfoMapper.insert(houseInfo); + int insert = houseInfoMapper.insert(houseInfo); + // 插入关联的区域关联表 + CpmSpaceRelation cpmSpaceRelation = new CpmSpaceRelation(); + cpmSpaceRelation.setAreaId(houseInfo.getAreaId()); + cpmSpaceRelation.setBuildingId(houseInfo.getBuildingId()); + cpmSpaceRelation.setHouseId(houseInfo.getId()); + cpmSpaceRelation.setFloorId(houseInfo.getFloorId()); + cpmSpaceRelation.setLedgerId(houseInfo.getLedgerId()); + cpmSpaceRelation.setCpmId(houseInfo.getCpmId()); + cpmSpaceRelation.setCreateBy(houseInfo.getCreateBy()); + cpmSpaceRelation.setCreateTime(houseInfo.getCreateTime()); + cpmSpaceRelationMapper.insert(cpmSpaceRelation); + return insert; } // 递归查找楼栋节点方法 @@ -103,7 +115,25 @@ public class HouseInfoServiceImpl implements IHouseInfoService { @Override public int updateHouseInfo(HouseInfo houseInfo) { getAreaIdAndBuildingId(houseInfo); - return houseInfoMapper.updateById(houseInfo); + int updateById = houseInfoMapper.updateById(houseInfo); + if (updateById > 0) { + // 判断关联表是否已经存在对应的cpmId + CpmSpaceRelation cpmSpaceRelation = cpmSpaceRelationMapper.selectOne(new QueryWrapper() + .eq("house_id", houseInfo.getId()).eq("cpm_id", houseInfo.getCpmId())); + if (cpmSpaceRelation == null) { + cpmSpaceRelation = new CpmSpaceRelation(); + cpmSpaceRelation.setAreaId(houseInfo.getAreaId()); + cpmSpaceRelation.setBuildingId(houseInfo.getBuildingId()); + cpmSpaceRelation.setFloorId(houseInfo.getFloorId()); + cpmSpaceRelation.setHouseId(houseInfo.getId()); + cpmSpaceRelation.setLedgerId(houseInfo.getLedgerId()); + cpmSpaceRelation.setCpmId(houseInfo.getCpmId()); + cpmSpaceRelation.setCreateTime(new Date()); + cpmSpaceRelation.setCreateBy(houseInfo.getUpdateBy()); + cpmSpaceRelationMapper.insert(cpmSpaceRelation); + } + } + return updateById; } private void getAreaIdAndBuildingId(HouseInfo houseInfo) { diff --git a/sql/2025新增.sql b/sql/2025新增.sql index abf2699..59fba9e 100644 --- a/sql/2025新增.sql +++ b/sql/2025新增.sql @@ -121,4 +121,17 @@ INSERT INTO public.cpm_space_relation (id, cpm_id, area_id, building_id, floor_i INSERT INTO public.cpm_space_relation (id, cpm_id, area_id, building_id, floor_id, house_id, create_by, update_by, create_time, update_time) VALUES('ddc1443b3a898d85f3a1205a2d8ddc99008', 'ddc0193bhat98d85g3a1205a2e82071e102', 'd39d42e89387bc01e0c5b4df4180f209', '4029cfbb357e4dd82cc3eeef59cff8ff', 'd301d47283e31f8f2666e4cf1c980b2e', 'e90e6240b5f4f72d44ba089bb92d15c8', '开发', '', '2025-09-17 16:23:00.000', '2025-09-17 23:21:42.046'); INSERT INTO public.cpm_space_relation (id, cpm_id, area_id, building_id, floor_id, house_id, create_by, update_by, create_time, update_time) VALUES('ddc1443b3a898d85f3a1205a2d8ddc99009', 'ddc0193bhat98d85g3a1205a2e82071e116', 'd39d42e89387bc01e0c5b4df4180f209', '4029cfbb357e4dd82cc3eeef59cff8ff', 'd301d47283e31f8f2666e4cf1c980b2e', '3f28f6510a6244d09ee2f0d34ae0164c', '开发', '', '2025-09-17 16:23:00.000', '2025-09-17 23:21:42.046'); INSERT INTO public.cpm_space_relation (id, cpm_id, area_id, building_id, floor_id, house_id, create_by, update_by, create_time, update_time) VALUES('ddc1443b3a898d85f3a1205a2d8ddc99010', 'ddc0193bhat98d85g3a1205a2e82071e105', 'd39d42e89387bc01e0c5b4df4180f209', '4029cfbb357e4dd82cc3eeef59cff8ff', 'd301d47283e31f8f2666e4cf1c980b2e', '3e59af0f558d4c495b0bfa61b3604611', '开发', '', '2025-09-17 16:23:00.000', '2025-09-17 23:21:42.046'); -INSERT INTO public.cpm_space_relation (id, cpm_id, area_id, building_id, floor_id, house_id, create_by, update_by, create_time, update_time) VALUES('ddc1443b3a898d85f3a1205a2d8ddc99011', 'ddc0193bhat98d85g3a1205a2e82071e107', 'd39d42e89387bc01e0c5b4df4180f209', '4029cfbb357e4dd82cc3eeef59cff8ff', 'd301d47283e31f8f2666e4cf1c980b2e', '3e59af0f558d4c495b0bfa61b3604612', '开发', '', '2025-09-17 16:23:00.000', '2025-09-17 23:21:42.046'); \ No newline at end of file +INSERT INTO public.cpm_space_relation (id, cpm_id, area_id, building_id, floor_id, house_id, create_by, update_by, create_time, update_time) VALUES('ddc1443b3a898d85f3a1205a2d8ddc99011', 'ddc0193bhat98d85g3a1205a2e82071e107', 'd39d42e89387bc01e0c5b4df4180f209', '4029cfbb357e4dd82cc3eeef59cff8ff', 'd301d47283e31f8f2666e4cf1c980b2e', '3e59af0f558d4c495b0bfa61b3604612', '开发', '', '2025-09-17 16:23:00.000', '2025-09-17 23:21:42.046'); + +-- 2025-10-06 +-- cpm_space_relation表新增字段,添加台账id ledgerId +ALTER TABLE cpm_space_relation ADD COLUMN ledger_id varchar(36) NULL; +-- ledgerId备注 +COMMENT ON COLUMN cpm_space_relation.ledger_id IS '台账id'; + +-- collection_params_manage添加质量字段,quality +ALTER TABLE collection_params_manage ADD COLUMN quality varchar(10) NULL; +-- 设置默认值为0 +UPDATE collection_params_manage SET quality = 0; +-- quality备注 +COMMENT ON COLUMN collection_params_manage.quality IS '质量:网关上传的值质量'; \ No newline at end of file