YZProjectCloud/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/device/PitmonitSouthsmosDataMapper...

230 lines
12 KiB
XML
Raw Normal View History

2025-07-05 10:14:14 +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.yanzhu.device.mapper.PitmonitSouthsmosDataMapper">
<resultMap type="PitmonitSouthsmosData" id="PitmonitSouthsmosDataResult">
<result property="id" column="id" />
<result property="cfgId" column="cfgId" />
<result property="dataType" column="dataType" />
<result property="dataId" column="dataId" />
<result property="spId" column="spId" />
<result property="spName" column="spName" />
<result property="collectTime" column="collectTime" />
<result property="changeRate" column="changeRate" />
<result property="changeRate2" column="changeRate2" />
<result property="displace" column="displace" />
<result property="displace2" column="displace2" />
<result property="totalize" column="totalize" />
<result property="totalize2" column="totalize2" />
<result property="variation" column="variation" />
<result property="variation2" column="variation2" />
<result property="state" column="state" />
<result property="remark" column="remark" />
<result property="isDel" column="is_del" />
<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="deptName" column="deptName"/>
<result property="projectId" column="projectId"/>
<result property="prjName" column="prjName"/>
</resultMap>
<sql id="selectDevPitmonitSouthsmosDataVo">
select id, cfgId, dataType, dataId, spId, spName, collectTime, changeRate, changeRate2, displace, displace2, totalize, totalize2, variation, variation2, state, remark, is_del, create_by, create_time, update_by, update_time from dev_pitmonit_southsmos_data
</sql>
<select id="selectDevPitmonitSouthsmosDataList" parameterType="PitmonitSouthsmosData" resultMap="PitmonitSouthsmosDataResult">
2025-07-07 14:22:24 +08:00
SELECT a.*, b.project_id AS projectId, pi.project_name as prjName
2025-07-05 10:14:14 +08:00
FROM dev_pitmonit_southsmos_data a
JOIN sur_project_pit_monit_cfg b ON a.cfgId = b.id
2025-07-07 14:22:24 +08:00
JOIN pro_project_info pi on pi.id=b.project_id
<where>
2025-07-05 10:14:14 +08:00
<if test="cfgId != null "> and a.cfgId = #{cfgId}</if>
<if test="dataType != null and dataType != ''"> and a.dataType = #{dataType}</if>
<if test="dataId != null "> and a.dataId = #{dataId}</if>
<if test="spId != null "> and a.spId = #{spId}</if>
<if test="spName != null and spName != ''"> and a.spName like concat('%', #{spName}, '%')</if>
<if test="collectTime != null "> and a.collectTime = #{collectTime}</if>
<if test="changeRate != null "> and a.changeRate = #{changeRate}</if>
<if test="changeRate2 != null "> and a.changeRate2 = #{changeRate2}</if>
<if test="displace != null "> and a.displace = #{displace}</if>
<if test="displace2 != null "> and a.displace2 = #{displace2}</if>
<if test="totalize != null "> and a.totalize = #{totalize}</if>
<if test="totalize2 != null "> and a.totalize2 = #{totalize2}</if>
<if test="variation != null "> and a.variation = #{variation}</if>
<if test="variation2 != null "> and a.variation2 = #{variation2}</if>
<if test="state != null "> and a.state = #{state}</if>
<if test="createTime!=null">and date(a.collectTime) &gt;= date(#{createTime})</if>
<if test="updateTime!=null">and date(a.collectTime) &lt;= date(#{updateTime})</if>
<if test="projectId != null and projectId>0 "> and b.project_id= #{projectId}</if>
2025-07-07 14:22:24 +08:00
and a.is_del = 0
</where>
2025-07-05 10:14:14 +08:00
order by a.collectTime desc
</select>
<select id="selectDevPitmonitSouthsmosDataById" parameterType="Long" resultMap="PitmonitSouthsmosDataResult">
<include refid="selectDevPitmonitSouthsmosDataVo"/>
where id = #{id}
</select>
2025-07-05 16:49:31 +08:00
<select id="selectDevPitmonitSouthsmosAlarmByDataId" parameterType="Long" resultMap="PitmonitSouthsmosDataResult">
<include refid="selectDevPitmonitSouthsmosDataVo"/>
where dataId = #{dataId}
</select>
2025-07-05 10:14:14 +08:00
<insert id="insertDevPitmonitSouthsmosData" parameterType="PitmonitSouthsmosData" useGeneratedKeys="true" keyProperty="id">
insert into dev_pitmonit_southsmos_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="cfgId != null">cfgId,</if>
<if test="dataType != null">dataType,</if>
<if test="dataId != null">dataId,</if>
<if test="spId != null">spId,</if>
<if test="spName != null">spName,</if>
<if test="collectTime != null">collectTime,</if>
<if test="changeRate != null">changeRate,</if>
<if test="changeRate2 != null">changeRate2,</if>
<if test="displace != null">displace,</if>
<if test="displace2 != null">displace2,</if>
<if test="totalize != null">totalize,</if>
<if test="totalize2 != null">totalize2,</if>
<if test="variation != null">variation,</if>
<if test="variation2 != null">variation2,</if>
<if test="state != null">state,</if>
<if test="remark != null">remark,</if>
<if test="isDel != null">is_del,</if>
<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>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="cfgId != null">#{cfgId},</if>
<if test="dataType != null">#{dataType},</if>
<if test="dataId != null">#{dataId},</if>
<if test="spId != null">#{spId},</if>
<if test="spName != null">#{spName},</if>
<if test="collectTime != null">#{collectTime},</if>
<if test="changeRate != null">#{changeRate},</if>
<if test="changeRate2 != null">#{changeRate2},</if>
<if test="displace != null">#{displace},</if>
<if test="displace2 != null">#{displace2},</if>
<if test="totalize != null">#{totalize},</if>
<if test="totalize2 != null">#{totalize2},</if>
<if test="variation != null">#{variation},</if>
<if test="variation2 != null">#{variation2},</if>
<if test="state != null">#{state},</if>
<if test="remark != null">#{remark},</if>
<if test="isDel != null">#{isDel},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateDevPitmonitSouthsmosData" parameterType="PitmonitSouthsmosData">
update dev_pitmonit_southsmos_data
<trim prefix="SET" suffixOverrides=",">
<if test="cfgId != null">cfgId = #{cfgId},</if>
<if test="dataType != null">dataType = #{dataType},</if>
<if test="dataId != null">dataId = #{dataId},</if>
<if test="spId != null">spId = #{spId},</if>
<if test="spName != null">spName = #{spName},</if>
<if test="collectTime != null">collectTime = #{collectTime},</if>
<if test="changeRate != null">changeRate = #{changeRate},</if>
<if test="changeRate2 != null">changeRate2 = #{changeRate2},</if>
<if test="displace != null">displace = #{displace},</if>
<if test="displace2 != null">displace2 = #{displace2},</if>
<if test="totalize != null">totalize = #{totalize},</if>
<if test="totalize2 != null">totalize2 = #{totalize2},</if>
<if test="variation != null">variation = #{variation},</if>
<if test="variation2 != null">variation2 = #{variation2},</if>
<if test="state != null">state = #{state},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="isDel != null">is_del = #{isDel},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteDevPitmonitSouthsmosDataById" parameterType="Long">
delete from dev_pitmonit_southsmos_data where id = #{id}
</delete>
<delete id="deleteDevPitmonitSouthsmosDataByIds" parameterType="String">
delete from dev_pitmonit_southsmos_data where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="getCountByPrjId" resultType="Integer" parameterType="Long">
SELECT COUNT(1)
FROM dev_pitmonit_southsmos_data d
JOIN sur_project_pit_monit_cfg s ON d.cfgid = s.id
WHERE s.project_id = #{prjId}
AND d.is_del = 0
</select>
<select id="getLastDataForElement" parameterType="Long" resultMap="PitmonitSouthsmosDataResult">
WITH LatestData AS (
SELECT a.spid, MAX(a.id) AS max_id
FROM dev_pitmonit_southsmos_data a
JOIN sur_project_pit_monit_cfg b ON a.cfgId = b.id
WHERE b.project_id = #{id}
AND a.is_del = 0
GROUP BY a.spid
),
FilteredData AS (
SELECT a.*, c.unitName AS deptName, b.project_id AS projectId
FROM dev_pitmonit_southsmos_data a
JOIN sur_project_pit_monit_cfg b ON a.cfgId = b.id
JOIN sur_project_unit_info c ON b.sub_dept_id = c.unitId AND b.project_id = c.projectId
JOIN LatestData ld ON a.id = ld.max_id
WHERE b.project_id = #{id}
AND a.is_del = 0
),
SurveyPoints AS (
SELECT a.cfgid, a.spId, a.NAME, a.meNameEn,c.unitName AS deptName,c.projectId,a.position as remark
FROM dev_pitmonit_southsmos_surveypoint a
JOIN sur_project_pit_monit_cfg b ON a.cfgId = b.id
JOIN sur_project_unit_info c ON b.sub_dept_id=c.unitId AND b.project_id=c.projectId
WHERE b.project_id = #{id}
)
SELECT sp.cfgid, sp.spId, sp.NAME AS spName, sp.meNameEn AS datatype,
fd.id, fd.dataid, fd.collecttime, fd.changeRate, fd.changeRate2,
fd.displace, fd.displace2, fd.totalize, fd.totalize2, fd.variation,
fd.variation2, fd.state, sp.remark, fd.is_del, fd.create_by,
fd.create_time, fd.update_by, fd.update_time, sp.deptName, sp.projectId
FROM SurveyPoints sp
LEFT JOIN FilteredData fd ON sp.spId = fd.spid;
</select>
<select id="selectByDate" parameterType="PitmonitSouthsmosData" resultMap="PitmonitSouthsmosDataResult">
select
a.id, a.cfgId, a.dataType, a.dataId, a.spId, a.spName, a.collectTime, a.changeRate, a.changeRate2, a.displace, a.displace2, a.totalize,
a.totalize2, a.variation, a.variation2, a.state, a.remark, a.is_del, a.create_by, a.create_time, a.update_by, a.update_time
from dev_pitmonit_southsmos_data a
JOIN sur_project_pit_monit_cfg b on a.cfgId=b.id
WHERE b.project_id = #{projectId}
AND a.is_del = 0
<if test="dataType != null and dataType != ''"> and a.dataType = #{dataType}</if>
<if test="createTime != null">and a.collectTime &gt;= #{createTime}</if>
<if test="updateTime != null">and a.collectTime &lt;= #{updateTime}</if>
order by a.collectTime desc
</select>
<select id="monitDays" parameterType="Long" resultType="Date">
select min(collectTime) collectTime
from dev_pitmonit_southsmos_data a
JOIN sur_project_pit_monit_cfg b ON a.cfgId=b.id
WHERE b.project_id= #{id}
</select>
</mapper>