Files
emsback/ems-system/src/main/resources/mapper/ems/EmsPointConfigMapper.xml

374 lines
18 KiB
XML
Raw Normal View History

2026-02-12 21:07:41 +08:00
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xzzn.ems.mapper.EmsPointConfigMapper">
<resultMap type="EmsPointConfig" id="EmsPointConfigResult">
<result property="id" column="id"/>
2026-02-13 21:41:23 +08:00
<result property="pointId" column="point_id"/>
2026-02-12 21:07:41 +08:00
<result property="siteId" column="site_id"/>
<result property="deviceCategory" column="device_category"/>
<result property="deviceId" column="device_id"/>
<result property="pointName" column="point_name"/>
<result property="dataKey" column="data_key"/>
<result property="pointDesc" column="point_desc"/>
<result property="registerAddress" column="register_address"/>
<result property="dataUnit" column="data_unit"/>
<result property="dataA" column="data_a"/>
<result property="dataK" column="data_k"/>
<result property="dataB" column="data_b"/>
<result property="dataBit" column="data_bit"/>
<result property="isAlarm" column="is_alarm"/>
<result property="pointType" column="point_type"/>
<result property="calcExpression" column="calc_expression"/>
2026-02-22 18:59:40 +08:00
<result property="collectEnabled" column="collect_enabled"/>
<result property="collectSource" column="collect_source"/>
<result property="modbusRegisterType" column="modbus_register_type"/>
<result property="modbusDataType" column="modbus_data_type"/>
<result property="modbusReadOrder" column="modbus_read_order"/>
<result property="modbusGroup" column="modbus_group"/>
2026-02-12 21:07:41 +08:00
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
</resultMap>
<sql id="selectEmsPointConfigVo">
2026-02-13 21:41:23 +08:00
select id, point_id, site_id, device_category, device_id, point_name, data_key, point_desc, register_address,
2026-02-12 21:07:41 +08:00
data_unit, data_a, data_k, data_b, data_bit, is_alarm, point_type, calc_expression,
2026-02-22 18:59:40 +08:00
collect_enabled, collect_source, modbus_register_type, modbus_data_type, modbus_read_order, modbus_group,
2026-02-12 21:07:41 +08:00
create_by, create_time, update_by, update_time, remark
from ems_point_config
</sql>
<select id="selectEmsPointConfigById" parameterType="Long" resultMap="EmsPointConfigResult">
<include refid="selectEmsPointConfigVo"/>
where id = #{id}
</select>
<select id="selectEmsPointConfigList" parameterType="EmsPointConfig" resultMap="EmsPointConfigResult">
<include refid="selectEmsPointConfigVo"/>
<where>
<if test="siteId != null and siteId != ''">and site_id = #{siteId}</if>
2026-03-18 10:06:42 +08:00
<if test="pointId != null and pointId != ''">and point_id like concat('%', #{pointId}, '%')</if>
2026-02-12 21:07:41 +08:00
<if test="deviceCategory != null and deviceCategory != ''">and device_category = #{deviceCategory}</if>
<if test="deviceId != null and deviceId != ''">and device_id = #{deviceId}</if>
<if test="dataKey != null and dataKey != ''">and data_key like concat('%', #{dataKey}, '%')</if>
<if test="pointDesc != null and pointDesc != ''">and point_desc like concat('%', #{pointDesc}, '%')</if>
<if test="pointType != null and pointType != ''">and point_type = #{pointType}</if>
2026-02-22 18:59:40 +08:00
<if test="collectEnabled != null">and collect_enabled = #{collectEnabled}</if>
<if test="collectSource != null and collectSource != ''">and collect_source = #{collectSource}</if>
<if test="modbusRegisterType != null and modbusRegisterType != ''">and modbus_register_type = #{modbusRegisterType}</if>
<if test="modbusDataType != null and modbusDataType != ''">and modbus_data_type = #{modbusDataType}</if>
2026-02-12 21:07:41 +08:00
<if test="registerAddress != null and registerAddress != ''">and register_address = #{registerAddress}</if>
</where>
order by update_time desc, id desc
</select>
<insert id="insertEmsPointConfig" parameterType="EmsPointConfig" useGeneratedKeys="true" keyProperty="id">
insert into ems_point_config
<trim prefix="(" suffix=")" suffixOverrides=",">
2026-02-13 21:41:23 +08:00
<if test="pointId != null">point_id,</if>
2026-02-12 21:07:41 +08:00
<if test="siteId != null">site_id,</if>
<if test="deviceCategory != null">device_category,</if>
<if test="deviceId != null">device_id,</if>
<if test="pointName != null">point_name,</if>
<if test="dataKey != null">data_key,</if>
<if test="pointDesc != null">point_desc,</if>
<if test="registerAddress != null">register_address,</if>
<if test="dataUnit != null">data_unit,</if>
<if test="dataA != null">data_a,</if>
<if test="dataK != null">data_k,</if>
<if test="dataB != null">data_b,</if>
<if test="dataBit != null">data_bit,</if>
<if test="isAlarm != null">is_alarm,</if>
<if test="pointType != null">point_type,</if>
<if test="calcExpression != null">calc_expression,</if>
2026-02-22 18:59:40 +08:00
<if test="collectEnabled != null">collect_enabled,</if>
<if test="collectSource != null">collect_source,</if>
<if test="modbusRegisterType != null">modbus_register_type,</if>
<if test="modbusDataType != null">modbus_data_type,</if>
<if test="modbusReadOrder != null">modbus_read_order,</if>
<if test="modbusGroup != null">modbus_group,</if>
2026-02-12 21:07:41 +08:00
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
2026-02-13 21:41:23 +08:00
<if test="pointId != null">#{pointId},</if>
2026-02-12 21:07:41 +08:00
<if test="siteId != null">#{siteId},</if>
<if test="deviceCategory != null">#{deviceCategory},</if>
<if test="deviceId != null">#{deviceId},</if>
<if test="pointName != null">#{pointName},</if>
<if test="dataKey != null">#{dataKey},</if>
<if test="pointDesc != null">#{pointDesc},</if>
<if test="registerAddress != null">#{registerAddress},</if>
<if test="dataUnit != null">#{dataUnit},</if>
<if test="dataA != null">#{dataA},</if>
<if test="dataK != null">#{dataK},</if>
<if test="dataB != null">#{dataB},</if>
<if test="dataBit != null">#{dataBit},</if>
<if test="isAlarm != null">#{isAlarm},</if>
<if test="pointType != null">#{pointType},</if>
<if test="calcExpression != null">#{calcExpression},</if>
2026-02-22 18:59:40 +08:00
<if test="collectEnabled != null">#{collectEnabled},</if>
<if test="collectSource != null">#{collectSource},</if>
<if test="modbusRegisterType != null">#{modbusRegisterType},</if>
<if test="modbusDataType != null">#{modbusDataType},</if>
<if test="modbusReadOrder != null">#{modbusReadOrder},</if>
<if test="modbusGroup != null">#{modbusGroup},</if>
2026-02-12 21:07:41 +08:00
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
2026-02-13 21:41:23 +08:00
<insert id="insertBatchEmsPointConfig">
insert into ems_point_config (
point_id, site_id, device_category, device_id, point_name, data_key, point_desc, register_address,
data_unit, data_a, data_k, data_b, data_bit, is_alarm, point_type, calc_expression,
2026-02-22 18:59:40 +08:00
collect_enabled, collect_source, modbus_register_type, modbus_data_type, modbus_read_order, modbus_group,
2026-02-13 21:41:23 +08:00
create_by, create_time, update_by, update_time, remark
)
values
<foreach collection="list" item="item" separator=",">
(
#{item.pointId},
#{item.siteId},
#{item.deviceCategory},
#{item.deviceId},
#{item.pointName},
#{item.dataKey},
#{item.pointDesc},
#{item.registerAddress},
#{item.dataUnit},
#{item.dataA},
#{item.dataK},
#{item.dataB},
#{item.dataBit},
#{item.isAlarm},
#{item.pointType},
#{item.calcExpression},
2026-02-22 18:59:40 +08:00
#{item.collectEnabled},
#{item.collectSource},
#{item.modbusRegisterType},
#{item.modbusDataType},
#{item.modbusReadOrder},
#{item.modbusGroup},
2026-02-13 21:41:23 +08:00
#{item.createBy},
now(),
#{item.updateBy},
now(),
#{item.remark}
)
</foreach>
</insert>
2026-02-12 21:07:41 +08:00
<update id="updateEmsPointConfig" parameterType="EmsPointConfig">
update ems_point_config
<trim prefix="SET" suffixOverrides=",">
2026-02-13 21:41:23 +08:00
<if test="pointId != null">point_id = #{pointId},</if>
2026-02-12 21:07:41 +08:00
<if test="siteId != null">site_id = #{siteId},</if>
<if test="deviceCategory != null">device_category = #{deviceCategory},</if>
<if test="deviceId != null">device_id = #{deviceId},</if>
<if test="pointName != null">point_name = #{pointName},</if>
<if test="dataKey != null">data_key = #{dataKey},</if>
<if test="pointDesc != null">point_desc = #{pointDesc},</if>
<if test="registerAddress != null">register_address = #{registerAddress},</if>
<if test="dataUnit != null">data_unit = #{dataUnit},</if>
<if test="dataA != null">data_a = #{dataA},</if>
<if test="dataK != null">data_k = #{dataK},</if>
<if test="dataB != null">data_b = #{dataB},</if>
<if test="dataBit != null">data_bit = #{dataBit},</if>
<if test="isAlarm != null">is_alarm = #{isAlarm},</if>
<if test="pointType != null">point_type = #{pointType},</if>
<if test="calcExpression != null">calc_expression = #{calcExpression},</if>
2026-02-22 18:59:40 +08:00
<if test="collectEnabled != null">collect_enabled = #{collectEnabled},</if>
<if test="collectSource != null">collect_source = #{collectSource},</if>
<if test="modbusRegisterType != null">modbus_register_type = #{modbusRegisterType},</if>
<if test="modbusDataType != null">modbus_data_type = #{modbusDataType},</if>
<if test="modbusReadOrder != null">modbus_read_order = #{modbusReadOrder},</if>
<if test="modbusGroup != null">modbus_group = #{modbusGroup},</if>
2026-02-12 21:07:41 +08:00
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where id = #{id}
</update>
2026-03-18 10:06:42 +08:00
<update id="updateEmsPointConfigForImport" parameterType="EmsPointConfig">
update ems_point_config
set point_id = #{pointId},
site_id = #{siteId},
device_category = #{deviceCategory},
device_id = #{deviceId},
point_name = #{pointName},
data_key = #{dataKey},
point_desc = #{pointDesc},
register_address = #{registerAddress},
data_unit = #{dataUnit},
data_a = #{dataA},
data_k = #{dataK},
data_b = #{dataB},
data_bit = #{dataBit},
is_alarm = #{isAlarm},
point_type = #{pointType},
calc_expression = #{calcExpression},
collect_enabled = #{collectEnabled},
collect_source = #{collectSource},
modbus_register_type = #{modbusRegisterType},
modbus_data_type = #{modbusDataType},
modbus_read_order = #{modbusReadOrder},
modbus_group = #{modbusGroup},
update_by = #{updateBy},
update_time = now(),
remark = #{remark}
where id = #{id}
</update>
2026-02-12 21:07:41 +08:00
<delete id="deleteEmsPointConfigById" parameterType="Long">
delete from ems_point_config where id = #{id}
</delete>
<delete id="deleteEmsPointConfigByIds" parameterType="String">
delete from ems_point_config where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="countBySiteId" resultType="int">
select count(1)
from ems_point_config
where site_id = #{siteId}
</select>
<delete id="deleteBySiteId">
delete from ems_point_config
where site_id = #{siteId}
</delete>
<insert id="copyTemplateToSite">
insert into ems_point_config (
2026-02-13 21:41:23 +08:00
point_id, site_id, device_category, device_id, point_name, data_key, point_desc, register_address,
2026-02-12 21:07:41 +08:00
data_unit, data_a, data_k, data_b, data_bit, is_alarm, point_type, calc_expression,
2026-02-22 18:59:40 +08:00
collect_enabled, collect_source, modbus_register_type, modbus_data_type, modbus_read_order, modbus_group,
2026-02-12 21:07:41 +08:00
create_by, create_time, update_by, update_time, remark
)
select
2026-02-13 21:41:23 +08:00
concat('PT_', replace(uuid(), '-', '')), #{targetSiteId}, device_category, device_id, point_name, data_key, point_desc, register_address,
2026-02-12 21:07:41 +08:00
data_unit, data_a, data_k, data_b, data_bit, is_alarm, point_type, calc_expression,
2026-02-22 18:59:40 +08:00
collect_enabled, collect_source, modbus_register_type, modbus_data_type, modbus_read_order, modbus_group,
2026-02-12 21:07:41 +08:00
#{operName}, now(), #{operName}, now(), remark
from ems_point_config
where site_id = #{templateSiteId}
</insert>
<select id="getRegisterAddress" resultType="java.lang.String">
select register_address
from ems_point_config
where site_id = #{siteId}
and device_category = #{deviceCategory}
and device_id = #{deviceId}
and data_key = #{dataKey}
limit 1
</select>
<select id="getPointNameList" resultType="com.xzzn.ems.domain.vo.GeneralQueryPointOptionVo">
2026-02-15 16:02:06 +08:00
select point_id as pointId,
point_name as pointName,
2026-02-12 21:07:41 +08:00
data_key as dataKey,
point_desc as pointDesc
from ems_point_config
where 1 = 1
<if test="siteIds != null and siteIds.size() > 0">
and site_id in
<foreach collection="siteIds" item="siteId" open="(" separator="," close=")">
#{siteId}
</foreach>
</if>
<if test="deviceCategory != null and deviceCategory != ''">
and device_category = #{deviceCategory}
</if>
<if test="deviceId != null and deviceId != ''">
and device_id = #{deviceId}
</if>
<if test="pointName != null and pointName != ''">
and (
point_name like concat('%', #{pointName}, '%')
or data_key like concat('%', #{pointName}, '%')
or point_desc like concat('%', #{pointName}, '%')
)
</if>
2026-02-15 16:02:06 +08:00
group by point_id, point_name, data_key, point_desc
order by point_id asc, point_name asc, data_key asc
2026-02-12 21:07:41 +08:00
</select>
<select id="getConfigListForGeneralQuery" resultMap="EmsPointConfigResult">
<include refid="selectEmsPointConfigVo"/>
where 1 = 1
<if test="siteIds != null and siteIds.size() > 0">
and site_id in
<foreach collection="siteIds" item="siteId" open="(" separator="," close=")">
#{siteId}
</foreach>
</if>
2026-02-15 16:02:06 +08:00
<choose>
<when test="pointIds != null and pointIds.size() > 0">
and point_id in
<foreach collection="pointIds" item="pointId" open="(" separator="," close=")">
#{pointId}
</foreach>
</when>
<otherwise>
<if test="deviceCategory != null and deviceCategory != ''">
and device_category = #{deviceCategory}
</if>
<if test="pointNames != null and pointNames.size() > 0">
and point_name in
<foreach collection="pointNames" item="pointName" open="(" separator="," close=")">
#{pointName}
</foreach>
</if>
<if test="deviceIds != null and deviceIds.size() > 0">
and device_id in
<foreach collection="deviceIds" item="deviceId" open="(" separator="," close=")">
#{deviceId}
</foreach>
</if>
</otherwise>
</choose>
2026-02-12 21:07:41 +08:00
</select>
2026-02-13 21:41:23 +08:00
<select id="selectBySiteIdAndPointIds" resultMap="EmsPointConfigResult">
<include refid="selectEmsPointConfigVo"/>
where site_id = #{siteId}
and point_id in
<foreach collection="pointIds" item="pointId" open="(" separator="," close=")">
#{pointId}
</foreach>
</select>
2026-02-22 18:59:40 +08:00
<select id="selectModbusCollectPointConfigs" resultMap="EmsPointConfigResult">
<include refid="selectEmsPointConfigVo"/>
where collect_enabled = 1
and collect_source = 'MODBUS'
2026-03-18 10:06:42 +08:00
and (point_type is null or point_type &lt;&gt; 'calc')
2026-02-22 18:59:40 +08:00
and (is_alarm is null or is_alarm = 0)
2026-03-18 10:06:42 +08:00
and register_address is not null and register_address &lt;&gt; ''
and modbus_register_type is not null and modbus_register_type &lt;&gt; ''
and modbus_data_type is not null and modbus_data_type &lt;&gt; ''
2026-02-22 18:59:40 +08:00
<if test="siteId != null and siteId != ''">
and site_id = #{siteId}
</if>
order by site_id asc, device_id asc, modbus_read_order asc, id asc
</select>
2026-02-12 21:07:41 +08:00
</mapper>