点位清单-导入导出
This commit is contained in:
@ -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())
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,12 +125,19 @@ public interface EmsPointMatchMapper
|
||||
public List<PointQueryResponse> 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<PointQueryResponse> 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);
|
||||
}
|
||||
|
||||
@ -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<EmsPointMatch> selectEmsPointMatchList(EmsPointMatch emsPointMatch);
|
||||
|
||||
|
||||
/**
|
||||
* 上传点位清单
|
||||
* @param userList
|
||||
* @param updateSupport
|
||||
* @param operName
|
||||
* @return
|
||||
*/
|
||||
public String importPoint(List<EmsPointMatch> userList, boolean updateSupport, String operName);
|
||||
}
|
||||
@ -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<PointQueryResponse> specialDealWithBattery(String siteId, String deviceId, String deviceCategory,
|
||||
String dataPointName, String dataPoint, String parentDeviceId) {
|
||||
String dataPointName, String dataPoint, String parentDeviceId, String ipAddress, Integer ipPort) {
|
||||
List<PointQueryResponse> 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<PointQueryResponse> 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<PointQueryResponse> response = emsPointMatchMapper
|
||||
.getClusterDevicePoints(siteId,deviceId,bmsdDeviceId,deviceCategory,dataPointName,dataPoint);
|
||||
.getClusterDevicePoints(siteId,deviceId,bmsdDeviceId,deviceCategory,dataPointName,dataPoint,ipAddress,ipPort);
|
||||
|
||||
|
||||
JSONObject mergedData = new JSONObject();
|
||||
|
||||
@ -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<EmsPointMatch> selectEmsPointMatchList(EmsPointMatch emsPointMatch)
|
||||
{
|
||||
return emsPointMatchMapper.selectEmsPointMatchList(emsPointMatch);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传点位清单
|
||||
* @param pointMatchList
|
||||
* @param isUpdateSupport
|
||||
* @param operName
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String importPoint(List<EmsPointMatch> 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("<br/>" + successNum + "、站点 " + pointMatch.getSiteId() + "、点位 " + pointMatch.getDataPoint()+ " 导入成功");
|
||||
} else if (isUpdateSupport) {
|
||||
BeanValidators.validateWithException(validator, pointMatch);
|
||||
pointMatch.setUpdateBy(operName);
|
||||
emsPointMatchMapper.updateEmsPointMatch(pointMatch);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、站点 " + pointMatch.getSiteId() + "、点位 " + pointMatch.getDataPoint()+ " 更新成功");
|
||||
} else {
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>" + failureNum + "、站点" + pointMatch.getSiteId() + "、点位 " + pointMatch.getDataPoint() + " 已存在");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
failureNum++;
|
||||
String msg = "<br/>" + 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user