点位清单-导入导出

This commit is contained in:
2025-11-05 14:58:05 +08:00
parent 3598cb2d66
commit c2682f38a8
9 changed files with 329 additions and 24 deletions

View File

@ -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<EmsPointMatch> list = emsPointMatchService.selectEmsPointMatchList(emsPointMatch);
ExcelUtil<EmsPointMatch> util = new ExcelUtil<EmsPointMatch>(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<EmsPointMatch> util = new ExcelUtil<EmsPointMatch>(EmsPointMatch.class);
List<EmsPointMatch> pointMatcheList = util.importExcel(file.getInputStream());
String operName = getUsername();
String message = emsPointMatchService.importPoint(pointMatcheList, updateSupport, operName);
return success(message);
}
}

View File

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

View File

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

View File

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

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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();

View File

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

View File

@ -15,6 +15,8 @@
<result property="dataPointName" column="data_point_name" />
<result property="dataDevice" column="data_device" />
<result property="dataUnit" column="data_unit" />
<result property="ipAddress" column="ip_address" />
<result property="ipPort" column="ip_port" />
<result property="dataType" column="data_type" />
<result property="needDiffDeviceId" column="need_diff_device_id" />
<result property="createBy" column="create_by" />
@ -25,7 +27,7 @@
</resultMap>
<sql id="selectEmsPointMatchVo">
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
</sql>
<select id="selectEmsPointMatchList" parameterType="EmsPointMatch" resultMap="EmsPointMatchResult">
@ -40,6 +42,8 @@
<if test="dataPointName != null and dataPointName != ''"> and data_point_name like concat('%', #{dataPointName}, '%')</if>
<if test="dataDevice != null and dataDevice != ''"> and data_device = #{dataDevice}</if>
<if test="dataUnit != null and dataUnit != ''"> and data_unit = #{dataUnit}</if>
<if test="ipAddress != null and ipAddress != ''"> and ip_address = #{ipAddress}</if>
<if test="ipPort != null "> and ip_port = #{ipPort}</if>
<if test="dataType != null "> and data_type = #{dataType}</if>
<if test="needDiffDeviceId != null "> and need_diff_device_id = #{needDiffDeviceId}</if>
</where>
@ -62,6 +66,8 @@
<if test="dataPointName != null">data_point_name,</if>
<if test="dataDevice != null">data_device,</if>
<if test="dataUnit != null">data_unit,</if>
<if test="ipAddress != null">ip_address,</if>
<if test="ipPort != null">ip_port,</if>
<if test="dataType != null">data_type,</if>
<if test="needDiffDeviceId != null">need_diff_device_id,</if>
<if test="createBy != null">create_by,</if>
@ -80,6 +86,8 @@
<if test="dataPointName != null">#{dataPointName},</if>
<if test="dataDevice != null">#{dataDevice},</if>
<if test="dataUnit != null">#{dataUnit},</if>
<if test="ipAddress != null">#{ipAddress},</if>
<if test="ipPort != null">#{ipPort},</if>
<if test="dataType != null">#{dataType},</if>
<if test="needDiffDeviceId != null">#{needDiffDeviceId},</if>
<if test="createBy != null">#{createBy},</if>
@ -102,6 +110,8 @@
<if test="dataPointName != null">data_point_name = #{dataPointName},</if>
<if test="dataDevice != null">data_device = #{dataDevice},</if>
<if test="dataUnit != null">data_unit = #{dataUnit},</if>
<if test="ipAddress != null">ip_address = #{ipAddress},</if>
<if test="ipPort != null">ip_port = #{ipPort},</if>
<if test="dataType != null">data_type = #{dataType},</if>
<if test="needDiffDeviceId != null">need_diff_device_id = #{needDiffDeviceId},</if>
<if test="createBy != null">create_by = #{createBy},</if>
@ -343,7 +353,9 @@
t.data_point_name as dataPointName,
t.data_device as dataDevice,
t.need_diff_device_id as isNeedDeviceId,
t.data_unit as dataUnit
t.data_unit as dataUnit,
t.ip_address as ipAddress,
t.ip_port as ipPort
from ems_point_match t
where 1=1
<if test="siteId != null and siteId != ''">
@ -358,6 +370,12 @@
<if test="dataPoint != null and dataPoint != ''">
and t.data_point like CONCAT('%', #{dataPoint}, '%')
</if>
<if test="ipAddress != null and ipAddress != ''">
and t.ip_address = #{ipAddress}
</if>
<if test="ipPort != null">
and t.ip_port = #{ipPort}
</if>
</select>
<select id="getClusterDevicePoints" resultType="com.xzzn.ems.domain.vo.PointQueryResponse">
@ -365,7 +383,9 @@
tmp.dataPoint,
tmp.dataDevice,
tmp.dataPointName,
tmp.dataUnit
tmp.dataUnit,
tmp.ipAddress,
tmp.ipPort
FROM ( select t.point_name as pointName,
case
when t.need_diff_device_id = 1 and t.data_device = 'PCS' then concat(#{deviceId}, t.data_point)
@ -373,7 +393,9 @@
else t.data_point end as dataPoint,
t.data_point_name as dataPointName,
t.data_device as dataDevice,
t.data_unit as dataUnit
t.data_unit as dataUnit,
t.ip_address as ipAddress,
t.ip_port as ipPort
from ems_point_match t
where 1=1
<if test="siteId != null and siteId != ''">
@ -385,10 +407,16 @@
) as tmp
where 1=1
<if test="pointName != null and pointName != ''">
and tmp.point_name like CONCAT('%', #{pointName}, '%')
and tmp.dataPointName like CONCAT('%', #{pointName}, '%')
</if>
<if test="dataPoint != null and dataPoint != ''">
and tmp.dataPoint like CONCAT('%', #{dataPoint}, '%')
</if>
<if test="ipAddress != null and ipAddress != ''">
and tmp.ipAddress = #{ipAddress}
</if>
<if test="ipPort != null">
and tmp.ipPort = #{ipPort}
</if>
</select>
</mapper>