diff --git a/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsPointMatchController.java b/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsPointMatchController.java new file mode 100644 index 0000000..ad98c35 --- /dev/null +++ b/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsPointMatchController.java @@ -0,0 +1,65 @@ +package com.xzzn.web.controller.ems; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.xzzn.common.annotation.Log; +import com.xzzn.common.core.controller.BaseController; +import com.xzzn.common.core.domain.AjaxResult; +import com.xzzn.common.enums.BusinessType; +import com.xzzn.ems.domain.EmsPointMatch; +import com.xzzn.ems.service.IEmsPointMatchService; +import com.xzzn.common.utils.poi.ExcelUtil; +import org.springframework.web.multipart.MultipartFile; + +/** + * 点位匹配Controller + * + * @author xzzn + * @date 2025-11-04 + */ +@RestController +@RequestMapping("/ems/pointMatch") +public class EmsPointMatchController extends BaseController +{ + @Autowired + private IEmsPointMatchService emsPointMatchService; + + /** + * 导出点位匹配列表 + */ + @PreAuthorize("@ss.hasPermi('system:match:export')") + @Log(title = "点位匹配", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, EmsPointMatch emsPointMatch) + { + List list = emsPointMatchService.selectEmsPointMatchList(emsPointMatch); + ExcelUtil util = new ExcelUtil(EmsPointMatch.class); + util.exportExcel(response, list, "点位匹配数据"); + } + + /** + * 上传点位清单 + * @param file + * @param updateSupport + * @return + * @throws Exception + */ + @PreAuthorize("@ss.hasPermi('system:user:import')") + @Log(title = "点位匹配", businessType = BusinessType.IMPORT) + @PostMapping("/importData") + public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception + { + ExcelUtil util = new ExcelUtil(EmsPointMatch.class); + List pointMatcheList = util.importExcel(file.getInputStream()); + String operName = getUsername(); + String message = emsPointMatchService.importPoint(pointMatcheList, updateSupport, operName); + return success(message); + } + +} diff --git a/ems-system/src/main/java/com/xzzn/ems/domain/EmsPointMatch.java b/ems-system/src/main/java/com/xzzn/ems/domain/EmsPointMatch.java index c15a3d0..9bc8f12 100644 --- a/ems-system/src/main/java/com/xzzn/ems/domain/EmsPointMatch.java +++ b/ems-system/src/main/java/com/xzzn/ems/domain/EmsPointMatch.java @@ -9,7 +9,7 @@ import com.xzzn.common.annotation.Excel; * 点位匹配对象 ems_point_match * * @author xzzn - * @date 2025-10-14 + * @date 2025-11-04 */ public class EmsPointMatch extends BaseEntity { @@ -54,8 +54,16 @@ public class EmsPointMatch extends BaseEntity @Excel(name = "数据单位") private String dataUnit; - /** 数据类型:1-瞬时值 2-增量 */ - @Excel(name = "数据类型:1-瞬时值 2-增量") + /** 地址 */ + @Excel(name = "地址") + private String ipAddress; + + /** 端口 */ + @Excel(name = "端口") + private Integer ipPort; + + /** 数据类型:1-瞬时值 2-累计值 */ + @Excel(name = "数据类型:1-瞬时值 2-累计值") private Long dataType; /** 点位是否需要区分多设备:0-不需要 1-需要 */ @@ -162,6 +170,24 @@ public class EmsPointMatch extends BaseEntity return dataUnit; } + public void setIpAddress(String ipAddress) + { + this.ipAddress = ipAddress; + } + + public String getIpAddress() + { + return ipAddress; + } + + public Integer getIpPort() { + return ipPort; + } + + public void setIpPort(Integer ipPort) { + this.ipPort = ipPort; + } + public void setDataType(Long dataType) { this.dataType = dataType; @@ -195,6 +221,8 @@ public class EmsPointMatch extends BaseEntity .append("dataPointName", getDataPointName()) .append("dataDevice", getDataDevice()) .append("dataUnit", getDataUnit()) + .append("ipAddress", getIpAddress()) + .append("ipPort", getIpPort()) .append("dataType", getDataType()) .append("needDiffDeviceId", getNeedDiffDeviceId()) .append("createBy", getCreateBy()) diff --git a/ems-system/src/main/java/com/xzzn/ems/domain/vo/PointDataRequest.java b/ems-system/src/main/java/com/xzzn/ems/domain/vo/PointDataRequest.java index cddf9f5..994b54a 100644 --- a/ems-system/src/main/java/com/xzzn/ems/domain/vo/PointDataRequest.java +++ b/ems-system/src/main/java/com/xzzn/ems/domain/vo/PointDataRequest.java @@ -31,6 +31,26 @@ public class PointDataRequest { private String sortData; /** 父类deviceId */ private String parentId; + /** modbus地址 */ + private String ipAddress; + /** modbus端口 */ + private Integer ipPort; + + public String getIpAddress() { + return ipAddress; + } + + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + } + + public Integer getIpPort() { + return ipPort; + } + + public void setIpPort(Integer ipPort) { + this.ipPort = ipPort; + } public String getParentId() { return parentId; diff --git a/ems-system/src/main/java/com/xzzn/ems/domain/vo/PointQueryResponse.java b/ems-system/src/main/java/com/xzzn/ems/domain/vo/PointQueryResponse.java index a9c24b1..18e72e2 100644 --- a/ems-system/src/main/java/com/xzzn/ems/domain/vo/PointQueryResponse.java +++ b/ems-system/src/main/java/com/xzzn/ems/domain/vo/PointQueryResponse.java @@ -42,9 +42,13 @@ public class PointQueryResponse @Excel(name = "数据单位") private String dataUnit; - public String getDataUnit() { - return dataUnit; - } + /** 地址 */ + @Excel(name = "地址") + private String ipAddress; + + /** 端口 */ + @Excel(name = "端口") + private String ipPort; public void setDataUnit(String dataUnit) { this.dataUnit = dataUnit; @@ -105,4 +109,24 @@ public class PointQueryResponse public void setPointName(String pointName) { this.pointName = pointName; } + + public String getDataUnit() { + return dataUnit; + } + + public String getIpAddress() { + return ipAddress; + } + + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + } + + public String getIpPort() { + return ipPort; + } + + public void setIpPort(String ipPort) { + this.ipPort = ipPort; + } } diff --git a/ems-system/src/main/java/com/xzzn/ems/mapper/EmsPointMatchMapper.java b/ems-system/src/main/java/com/xzzn/ems/mapper/EmsPointMatchMapper.java index b3d4f72..27f9497 100644 --- a/ems-system/src/main/java/com/xzzn/ems/mapper/EmsPointMatchMapper.java +++ b/ems-system/src/main/java/com/xzzn/ems/mapper/EmsPointMatchMapper.java @@ -125,12 +125,19 @@ public interface EmsPointMatchMapper public List getSingleSiteDevicePoints(@Param("siteId")String siteId, @Param("deviceCategory")String deviceCategory, @Param("pointName")String pointName, - @Param("dataPoint")String dataPoint); + @Param("dataPoint")String dataPoint, + @Param("ipAddress")String ipAddress, + @Param("ipPort")Integer ipPort); // 单个站点单个设备点位查询-电池簇使用 public List getClusterDevicePoints(@Param("siteId")String siteId, - @Param("deviceId")String deviceId, - @Param("parentDeviceId")String parentDeviceId, - @Param("deviceCategory")String deviceCategory, - @Param("pointName")String pointName, - @Param("dataPoint")String dataPoint); + @Param("deviceId")String deviceId, + @Param("parentDeviceId")String parentDeviceId, + @Param("deviceCategory")String deviceCategory, + @Param("pointName")String pointName, + @Param("dataPoint")String dataPoint, + @Param("ipAddress")String ipAddress, + @Param("ipPort")Integer ipPort); + + // 根据站点,设备类别,点位,获取唯一数据 + public EmsPointMatch getUniquePoint(String siteId, String deviceCategory, String dataPoint); } diff --git a/ems-system/src/main/java/com/xzzn/ems/service/IEmsPointMatchService.java b/ems-system/src/main/java/com/xzzn/ems/service/IEmsPointMatchService.java new file mode 100644 index 0000000..2242e4e --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/service/IEmsPointMatchService.java @@ -0,0 +1,32 @@ +package com.xzzn.ems.service; + +import java.util.List; + +import com.xzzn.ems.domain.EmsPointMatch; + +/** + * 点位匹配Service接口 + * + * @author xzzn + * @date 2025-11-04 + */ +public interface IEmsPointMatchService +{ + /** + * 查询点位匹配列表 + * + * @param emsPointMatch 点位匹配 + * @return 点位匹配集合 + */ + public List selectEmsPointMatchList(EmsPointMatch emsPointMatch); + + + /** + * 上传点位清单 + * @param userList + * @param updateSupport + * @param operName + * @return + */ + public String importPoint(List userList, boolean updateSupport, String operName); +} diff --git a/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsDeviceSettingServiceImpl.java b/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsDeviceSettingServiceImpl.java index 5d3d2a9..f5e1d53 100644 --- a/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsDeviceSettingServiceImpl.java +++ b/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsDeviceSettingServiceImpl.java @@ -140,15 +140,17 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService String dataPointName = request.getDataPointName(); String dataPoint = request.getDataPoint(); String parentDeviceId = request.getParentId(); + String ipAddress = request.getIpAddress(); + Integer ipPort = request.getIpPort(); // 电动所的电池簇特殊处理-来源pcs+bmsd if (siteId.equals(DDS_SITE_ID) && DeviceCategory.CLUSTER.getCode().equals(deviceCategory)) { - response = specialDealWithDDSCluster(siteId,deviceId,deviceCategory,dataPointName,dataPoint); + response = specialDealWithDDSCluster(siteId,deviceId,deviceCategory,dataPointName,dataPoint,ipAddress,ipPort); } else if (DeviceCategory.BATTERY.getCode().equals(deviceCategory)) { response = specialDealWithBattery(siteId,deviceId,deviceCategory, - dataPointName,dataPoint,parentDeviceId); + dataPointName,dataPoint,parentDeviceId,ipAddress,ipPort); } else { response = emsPointMatchMapper.getSingleSiteDevicePoints( - siteId,deviceCategory,dataPointName,dataPoint); + siteId,deviceCategory,dataPointName,dataPoint,ipAddress,ipPort); // 从redis取最新数据 JSONObject mqttJson = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + deviceId); if(mqttJson == null){ @@ -233,9 +235,9 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService } private List specialDealWithBattery(String siteId, String deviceId, String deviceCategory, - String dataPointName, String dataPoint, String parentDeviceId) { + String dataPointName, String dataPoint, String parentDeviceId, String ipAddress, Integer ipPort) { List response = emsPointMatchMapper.getSingleSiteDevicePoints(siteId,deviceCategory, - dataPointName,dataPoint); + dataPointName,dataPoint,ipAddress,ipPort); // 获取redis同步最新数据 JSONObject jsonObject = new JSONObject(); @@ -314,12 +316,12 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService // 对于dds的电池簇点位最新数据获取特殊处理 private List specialDealWithDDSCluster(String siteId, String deviceId, String deviceCategory, - String dataPointName, String dataPoint) { + String dataPointName, String dataPoint, String ipAddress, Integer ipPort) { // 替换为对应的父类id String bmsdDeviceId = deviceId.replace("BMSC","BMSD"); List response = emsPointMatchMapper - .getClusterDevicePoints(siteId,deviceId,bmsdDeviceId,deviceCategory,dataPointName,dataPoint); + .getClusterDevicePoints(siteId,deviceId,bmsdDeviceId,deviceCategory,dataPointName,dataPoint,ipAddress,ipPort); JSONObject mergedData = new JSONObject(); diff --git a/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsPointMatchServiceImpl.java b/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsPointMatchServiceImpl.java new file mode 100644 index 0000000..5cfc126 --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsPointMatchServiceImpl.java @@ -0,0 +1,99 @@ +package com.xzzn.ems.service.impl; + +import java.util.List; + +import com.xzzn.common.exception.ServiceException; +import com.xzzn.common.utils.StringUtils; +import com.xzzn.common.utils.bean.BeanValidators; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.xzzn.ems.mapper.EmsPointMatchMapper; +import com.xzzn.ems.domain.EmsPointMatch; +import com.xzzn.ems.service.IEmsPointMatchService; + +import javax.validation.Validator; + +/** + * 点位匹配Service业务层处理 + * + * @author xzzn + * @date 2025-11-04 + */ +@Service +public class EmsPointMatchServiceImpl implements IEmsPointMatchService +{ + @Autowired + private EmsPointMatchMapper emsPointMatchMapper; + @Autowired + protected Validator validator; + + /** + * 查询点位匹配列表 + * + * @param emsPointMatch 点位匹配 + * @return 点位匹配 + */ + @Override + public List selectEmsPointMatchList(EmsPointMatch emsPointMatch) + { + return emsPointMatchMapper.selectEmsPointMatchList(emsPointMatch); + } + + /** + * 上传点位清单 + * @param pointMatchList + * @param isUpdateSupport + * @param operName + * @return + */ + @Override + public String importPoint(List pointMatchList, boolean isUpdateSupport, String operName) { + if (StringUtils.isNull(pointMatchList) || pointMatchList.size() == 0) + { + throw new ServiceException("导入用户数据不能为空!"); + } + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + for (EmsPointMatch pointMatch : pointMatchList) + { + try + { + // 验证点位是否存在 + EmsPointMatch point = emsPointMatchMapper.getUniquePoint(pointMatch.getSiteId(), + pointMatch.getDeviceCategory(),pointMatch.getDataPoint()); + if (StringUtils.isNull(point)) { + BeanValidators.validateWithException(validator, pointMatch); + pointMatch.setCreateBy(operName); + emsPointMatchMapper.insertEmsPointMatch(pointMatch); + successNum++; + successMsg.append("
" + successNum + "、站点 " + pointMatch.getSiteId() + "、点位 " + pointMatch.getDataPoint()+ " 导入成功"); + } else if (isUpdateSupport) { + BeanValidators.validateWithException(validator, pointMatch); + pointMatch.setUpdateBy(operName); + emsPointMatchMapper.updateEmsPointMatch(pointMatch); + successNum++; + successMsg.append("
" + successNum + "、站点 " + pointMatch.getSiteId() + "、点位 " + pointMatch.getDataPoint()+ " 更新成功"); + } else { + failureNum++; + failureMsg.append("
" + failureNum + "、站点" + pointMatch.getSiteId() + "、点位 " + pointMatch.getDataPoint() + " 已存在"); + } + } + catch (Exception e) { + failureNum++; + String msg = "
" + failureNum + "、站点" + pointMatch.getSiteId() + "、点位 " + pointMatch.getDataPoint() + " 导入失败:"; + failureMsg.append(msg + e.getMessage()); + } + } + if (failureNum > 0) { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new ServiceException(failureMsg.toString()); + } else { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + } + return successMsg.toString(); + } + + +} diff --git a/ems-system/src/main/resources/mapper/ems/EmsPointMatchMapper.xml b/ems-system/src/main/resources/mapper/ems/EmsPointMatchMapper.xml index 4a0f96e..4e1f76f 100644 --- a/ems-system/src/main/resources/mapper/ems/EmsPointMatchMapper.xml +++ b/ems-system/src/main/resources/mapper/ems/EmsPointMatchMapper.xml @@ -15,6 +15,8 @@ + + @@ -25,7 +27,7 @@ - select id, point_name, match_table, match_field, site_id, device_category, data_point, data_point_name, data_device, data_unit, data_type, need_diff_device_id, create_by, create_time, update_by, update_time, remark from ems_point_match + select id, point_name, match_table, match_field, site_id, device_category, data_point, data_point_name, data_device, data_unit, ip_address, ip_port, data_type, need_diff_device_id, create_by, create_time, update_by, update_time, remark from ems_point_match \ No newline at end of file