155 lines
7.0 KiB
XML
155 lines
7.0 KiB
XML
<?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.agri.system.mapper.SysMessageMapper">
|
|
|
|
<resultMap type="SysMessage" id="SysMessageResult">
|
|
<result property="id" column="id" />
|
|
<result property="receiver" column="receiver" />
|
|
<result property="title" column="title" />
|
|
<result property="msgType" column="msg_type" />
|
|
<result property="readStatus" column="read_status" />
|
|
<result property="content" column="content" />
|
|
<result property="richContent" column="rich_content" />
|
|
<result property="imgUrl" column="img_url" />
|
|
<result property="linkUrl" column="link_url" />
|
|
<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="selectSysMessageVo">
|
|
select id, imei, receiver, title, msg_type, read_status, content, rich_content, img_url, link_url, create_by, create_time, update_by, update_time, remark from sys_message
|
|
</sql>
|
|
|
|
<select id="selectSysMessageList" parameterType="SysMessage" resultMap="SysMessageResult">
|
|
<include refid="selectSysMessageVo"/>
|
|
<where>
|
|
<if test="monitorDate != null"> and DATE_FORMAT(create_time, '%Y-%m-%d') = #{monitorDate}</if>
|
|
<if test="receiver != null and receiver != ''"> and receiver = #{receiver}</if>
|
|
<if test="title != null and title != ''"> and title = #{title}</if>
|
|
<if test="msgType != null and msgType != ''"> and msg_type = #{msgType}</if>
|
|
<if test="msgType != null and msgType == 'status'">
|
|
and DATE_FORMAT(create_time, '%Y-%m-%d') <= CURDATE()
|
|
and DATE_FORMAT(create_time, '%Y-%m-%d') >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
|
|
</if>
|
|
<if test="sortOldId != null and sortOldId != ''">
|
|
and id < #{sortOldId}
|
|
</if>
|
|
<if test="sortNewId != null and sortNewId != ''">
|
|
and id > #{sortNewId}
|
|
</if>
|
|
<if test="readStatus != null "> and read_status = #{readStatus}</if>
|
|
<if test="content != null and content != ''"> and content like concat('%', #{content}, '%')</if>
|
|
<if test="imeiList != null and imeiList.size() > 0">
|
|
imei IN
|
|
<foreach collection="imeiList" item="imei" open="(" separator="," close=")">
|
|
#{imei}
|
|
</foreach>
|
|
</if>
|
|
</where>
|
|
order by create_time desc
|
|
</select>
|
|
|
|
<select id="selectSysMessageById" parameterType="Long" resultMap="SysMessageResult">
|
|
<include refid="selectSysMessageVo"/>
|
|
where id = #{id}
|
|
</select>
|
|
|
|
<insert id="insertSysMessage" parameterType="SysMessage" useGeneratedKeys="true" keyProperty="id">
|
|
insert into sys_message
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
<if test="receiver != null and receiver != ''">receiver,</if>
|
|
<if test="title != null and title != ''">title,</if>
|
|
<if test="msgType != null and msgType != ''">msg_type,</if>
|
|
<if test="readStatus != null">read_status,</if>
|
|
<if test="content != null">content,</if>
|
|
<if test="richContent != null">rich_content,</if>
|
|
<if test="imgUrl != null">img_url,</if>
|
|
<if test="linkUrl != null">link_url,</if>
|
|
create_by,
|
|
create_time,
|
|
update_by,
|
|
update_time,
|
|
<if test="remark != null">remark,</if>
|
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
<if test="receiver != null and receiver != ''">#{receiver},</if>
|
|
<if test="title != null and title != ''">#{title},</if>
|
|
<if test="msgType != null and msgType != ''">#{msgType},</if>
|
|
<if test="readStatus != null">#{readStatus},</if>
|
|
<if test="content != null">#{content},</if>
|
|
<if test="richContent != null">#{richContent},</if>
|
|
<if test="imgUrl != null">#{imgUrl},</if>
|
|
<if test="linkUrl != null">#{linkUrl},</if>
|
|
#{createBy},
|
|
#{createTime},
|
|
#{updateBy},
|
|
#{updateTime},
|
|
<if test="remark != null">#{remark},</if>
|
|
</trim>
|
|
</insert>
|
|
|
|
<update id="updateSysMessage" parameterType="SysMessage">
|
|
update sys_message
|
|
<trim prefix="SET" suffixOverrides=",">
|
|
<if test="receiver != null and receiver != ''">receiver = #{receiver},</if>
|
|
<if test="title != null and title != ''">title = #{title},</if>
|
|
<if test="msgType != null and msgType != ''">msg_type = #{msgType},</if>
|
|
<if test="readStatus != null">read_status = #{readStatus},</if>
|
|
<if test="content != null">content = #{content},</if>
|
|
<if test="richContent != null">rich_content = #{richContent},</if>
|
|
<if test="imgUrl != null">img_url = #{imgUrl},</if>
|
|
<if test="linkUrl != null">link_url = #{linkUrl},</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>
|
|
<if test="remark != null">remark = #{remark},</if>
|
|
</trim>
|
|
where id = #{id}
|
|
</update>
|
|
|
|
<delete id="deleteSysMessageById" parameterType="Long">
|
|
delete from sys_message where id = #{id}
|
|
</delete>
|
|
|
|
<delete id="deleteSysMessageByIds" parameterType="String">
|
|
delete from sys_message where id in
|
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
|
#{id}
|
|
</foreach>
|
|
</delete>
|
|
|
|
<select id="getMsgOverview" parameterType="SysMessage" resultMap="SysMessageResult">
|
|
SELECT
|
|
*
|
|
FROM
|
|
(
|
|
SELECT
|
|
`imei`,
|
|
`receiver`,
|
|
`title`,
|
|
`msg_type`,
|
|
`read_status`,
|
|
`content`,
|
|
`rich_content`,
|
|
`img_url`,
|
|
`link_url`,
|
|
`create_time`, -- 必须加
|
|
`id`, -- 必须加
|
|
ROW_NUMBER() OVER (PARTITION BY msg_type ORDER BY create_time DESC, id DESC) AS rn
|
|
FROM
|
|
sys_message d
|
|
WHERE
|
|
-- 正确写法:包含今天所有时间
|
|
d.create_time >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
|
|
AND d.create_time < DATE_ADD(CURDATE(), INTERVAL 1 DAY)
|
|
) t
|
|
WHERE
|
|
t.rn = 1;
|
|
</select>
|
|
</mapper> |