wg-basic/module-instant-message/src/main/resources/mybatis/mapper/notice-mapper.xml

476 lines
16 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="ink.wgink.module.instantmessage.dao.INoticeDao">
<cache flushInterval="3600000"/>
<resultMap id="noticePO" type="ink.wgink.module.instantmessage.pojo.pos.NoticePO">
<id column="id" property="id"/>
<result column="notice_id" property="noticeId"/>
<result column="notice_title" property="noticeTitle"/>
<result column="notice_msg" property="noticeMsg"/>
<result column="notice_target" property="noticeTarget"/>
<result column="notice_system" property="noticeSystem"/>
<result column="notice_module" property="noticeModule"/>
<result column="notice_menu" property="noticeMenu"/>
<result column="notice_service_id" property="noticeServiceId"/>
<result column="user_id" property="userId"/>
<result column="user_name" property="userName"/>
<result column="user_username" property="userUsername"/>
<result column="is_send" property="isSend"/>
<result column="is_handle" property="isHandle"/>
<result column="gmt_create" property="gmtCreate"/>
<result column="creator" property="creator"/>
<result column="gmt_modified" property="gmtModified"/>
<result column="modifier" property="modifier"/>
<result column="is_delete" property="isDelete"/>
</resultMap>
<resultMap id="noticeDTO" type="ink.wgink.module.instantmessage.pojo.dtos.NoticeDTO">
<id column="id" property="id"/>
<result column="notice_id" property="noticeId"/>
<result column="notice_title" property="noticeTitle"/>
<result column="notice_msg" property="noticeMsg"/>
<result column="notice_target" property="noticeTarget"/>
<result column="notice_system" property="noticeSystem"/>
<result column="notice_module" property="noticeModule"/>
<result column="notice_menu" property="noticeMenu"/>
<result column="notice_service_id" property="noticeServiceId"/>
<result column="user_id" property="userId"/>
<result column="user_name" property="userName"/>
<result column="user_username" property="userUsername"/>
<result column="is_send" property="isSend"/>
<result column="is_handle" property="isHandle"/>
<result column="gmt_create" property="gmtCreate"/>
<result column="gmt_modified" property="gmtModified"/>
</resultMap>
<!-- 建表 -->
<update id="createTable">
CREATE TABLE IF NOT EXISTS `im_notice` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`notice_id` char(36) DEFAULT NULL COMMENT '主键',
`notice_title` varchar(255) DEFAULT NULL COMMENT '通知标题',
`notice_msg` varchar(500) DEFAULT NULL COMMENT '通知内容',
`notice_target` varchar(255) DEFAULT NULL COMMENT '通知触发目标',
`notice_system` varchar(255) DEFAULT NULL COMMENT '通知业务系统',
`notice_module` varchar(255) DEFAULT NULL COMMENT '通知业务模块',
`notice_menu` varchar(255) DEFAULT NULL COMMENT '通知业务菜单',
`notice_service_id` varchar(255) DEFAULT NULL COMMENT '通知业务ID',
`user_id` char(36) DEFAULT NULL COMMENT '通知人',
`user_username` varchar(255) DEFAULT NULL COMMENT '用户名',
`user_name` varchar(255) DEFAULT NULL COMMENT '用户昵称',
`is_send` int(1) DEFAULT '0' COMMENT '是否发送',
`is_handle` int(1) DEFAULT '0' COMMENT '是否处理',
`gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
`creator` char(36) DEFAULT NULL COMMENT '创建人',
`gmt_modified` datetime DEFAULT NULL COMMENT '修改时间',
`modifier` char(36) DEFAULT NULL COMMENT '修改人',
`is_delete` int(1) DEFAULT '0' COMMENT '是否删除',
PRIMARY KEY (`id`),
UNIQUE KEY `notice_id` (`notice_id`) USING BTREE,
KEY `notice_title` (`notice_title`) USING BTREE,
KEY `notice_msg` (`notice_msg`) USING BTREE,
KEY `notice_target` (`notice_target`) USING BTREE,
KEY `notice_module` (`notice_module`) USING BTREE,
KEY `notice_service_id` (`notice_service_id`) USING BTREE,
KEY `user_id` (`user_id`) USING BTREE,
KEY `is_handle` (`is_handle`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='小程序用户';
</update>
<!-- 保存 -->
<insert id="save" parameterType="map" flushCache="true">
INSERT INTO im_notice (
notice_id,
notice_title,
notice_msg,
notice_target,
notice_system,
notice_module,
notice_menu,
notice_service_id,
user_id,
user_name,
user_username,
is_send,
is_handle,
gmt_create,
creator,
gmt_modified,
modifier,
is_delete
) VALUES(
#{noticeId},
#{noticeTitle},
#{noticeMsg},
#{noticeTarget},
#{noticeSystem},
#{noticeModule},
#{noticeMenu},
#{noticeServiceId},
#{userId},
#{userName},
#{userUsername},
#{isSend},
#{isHandle},
#{gmtCreate},
#{creator},
#{gmtModified},
#{modifier},
#{isDelete}
)
</insert>
<!-- 更新已办状态 -->
<update id="updateHandle" parameterType="map" flushCache="true">
UPDATE
im_notice
SET
is_handle = #{isHandle},
gmt_modified = #{gmtModified},
modifier = #{modifier}
WHERE
notice_system = #{noticeSystem}
AND
notice_service_id = #{noticeServiceId}
</update>
<!-- 修改发送状态 -->
<update id="updateSend" parameterType="map" flushCache="true">
UPDATE
im_notice
SET
is_send = #{isSend},
gmt_modified = #{gmtModified},
modifier = #{modifier}
WHERE
notice_id = #{noticeId}
</update>
<!-- 删除 -->
<delete id="delete" parameterType="map" flushCache="true">
DELETE FROM
im_notice
WHERE
<if test="serviceIds != null and serviceIds.size > 0">
notice_service_id IN
<foreach collection="serviceIds" index="index" open="(" separator="," close=")">
#{serviceIds[${index}]}
</foreach>
</if>
</delete>
<!-- 删除 -->
<update id="remove" parameterType="map" flushCache="true">
UPDATE
im_notice
SET
is_delete = 1,
gmt_modified = #{gmtModified},
modifier = #{modifier}
WHERE
notice_id IN
<foreach collection="noticeIds" index="index" open="(" separator="," close=")">
#{noticeIds[${index}]}
</foreach>
</update>
<!-- 详情 -->
<select id="getPO" parameterType="map" resultMap="noticePO" useCache="false">
SELECT
notice_id,
notice_title,
notice_msg,
notice_target,
notice_system,
notice_module,
notice_menu,
notice_service_id,
user_id,
user_name,
user_username,
is_send,
is_handle,
gmt_create,
creator,
gmt_modified,
modifier,
is_delete
FROM
im_notice
WHERE
is_delete = 0
<if test="noticeId != null and noticeId != ''">
AND
notice_id = #{noticeId}
</if>
<if test="noticeSystem != null and noticeSystem != ''">
AND
notice_system = #{noticeSystem}
</if>
<if test="noticeModule != null and noticeModule != ''">
AND
notice_module = #{noticeModule}
</if>
<if test="noticeMenu != null and noticeMenu">
AND
notice_menu = #{noticeMenu}
</if>
<if test="noticeServiceId != null and noticeServiceId != ''">
AND
notice_service_id = #{noticeServiceId}
</if>
<if test="userId != null and userId != ''">
AND
user_id = #{userId}
</if>
</select>
<!-- 列表 -->
<select id="listPO" parameterType="map" resultMap="noticePO" useCache="true">
SELECT
notice_id,
notice_title,
notice_msg,
notice_target,
notice_system,
notice_module,
notice_menu,
notice_service_id,
user_id,
user_name,
user_username,
is_send,
is_handle,
gmt_create,
creator,
gmt_modified,
modifier,
is_delete
FROM
im_notice
WHERE
is_delete = 0
<if test="noticeSystem != null and noticeSystem != ''">
AND
notice_system = #{noticeSystem}
</if>
<if test="noticeModule != null and noticeModule != ''">
AND
notice_module = #{noticeModule}
</if>
<if test="noticeMenu != null and noticeMenu">
AND
notice_menu = #{noticeMenu}
</if>
<if test="noticeServiceId != null and noticeServiceId != ''">
AND
notice_service_id = #{noticeServiceId}
</if>
<if test="userId != null and userId != ''">
AND
user_id = #{userId}
</if>
<if test="isSend != null">
AND
is_send = #{isSend}
</if>
<if test="isHandle != null">
AND
is_handle = #{isHandle}
</if>
<if test="serviceId != null and serviceId != ''">
AND
notice_service_id = #{serviceId}
</if>
<if test="date != null and date != ''">
AND
LEFT(gmt_create, 10) = #{date}
</if>
<if test="serviceIds != null and serviceIds.size > 0">
AND
notice_service_id IN
<foreach collection="serviceIds" index="index" open="(" separator="," close=")">
#{serviceIds[${index}]}
</foreach>
</if>
<if test="startTime != null and startTime != ''">
AND
LEFT(gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
</if>
</select>
<!-- 列表 -->
<select id="list" parameterType="map" resultMap="noticeDTO" useCache="true">
SELECT
notice_id,
notice_title,
notice_msg,
notice_target,
notice_system,
notice_module,
notice_menu,
notice_service_id,
user_id,
user_name,
user_username,
is_send,
is_handle,
LEFT(gmt_create, 19) gmt_create,
LEFT(gmt_modified, 19) gmt_modified
FROM
im_notice
WHERE
is_delete = 0
<if test="keywords != null and keywords != ''">
AND (
user_name LIKE CONCAT('%', #{keywords}, '%')
OR
user_username LIKE CONCAT('%', #{keywords}, '%')
OR
notice_title LIKE CONCAT('%', #{keywords}, '%')
OR
notice_msg LIKE CONCAT('%', #{keywords}, '%')
)
</if>
<if test="noticeSystem != null and noticeSystem != ''">
AND
notice_system = #{noticeSystem}
</if>
<if test="noticeModule != null and noticeModule != ''">
AND
notice_module = #{noticeModule}
</if>
<if test="noticeMenu != null and noticeMenu">
AND
notice_menu = #{noticeMenu}
</if>
<if test="noticeServiceId != null and noticeServiceId != ''">
AND
notice_service_id = #{noticeServiceId}
</if>
<if test="userId != null and userId != ''">
AND
user_id = #{userId}
</if>
<if test="isHandle != null">
AND
is_handle = #{isHandle}
</if>
<if test="serviceId != null and serviceId != ''">
AND
notice_service_id = #{serviceId}
</if>
<if test="serviceIds != null and serviceIds.size > 0">
AND
notice_service_id IN
<foreach collection="serviceIds" index="index" open="(" separator="," close=")">
#{serviceIds[${index}]}
</foreach>
</if>
<if test="startTime != null and startTime != ''">
AND
LEFT(gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
</if>
</select>
<!-- 系统列表 -->
<select id="listSystems" parameterType="map" resultType="java.lang.String" useCache="true">
SELECT
notice_system
FROM
im_notice
WHERE
is_delete = 0
<if test="userId != null and userId != ''">
AND
user_id = #{userId}
</if>
GROUP BY
notice_system
</select>
<!-- 模块列表 -->
<select id="listModules" parameterType="map" resultType="java.lang.String" useCache="true">
SELECT
notice_module
FROM
im_notice
WHERE
is_delete = 0
<if test="userId != null and userId != ''">
AND
user_id = #{userId}``
</if>
<if test="noticeSystem != null and noticeSystem != ''">
AND
notice_system = #{noticeSystem}
</if>
GROUP BY
notice_module
</select>
<!-- 菜单列表 -->
<select id="listMenus" parameterType="map" resultType="java.lang.String" useCache="true">
SELECT
notice_menu
FROM
im_notice
WHERE
is_delete = 0
<if test="userId != null and userId != ''">
AND
user_id = #{userId}
</if>
<if test="noticeSystem != null and noticeSystem != ''">
AND
notice_system = #{noticeSystem}
</if>
<if test="noticeModule != null and noticeModule != ''">
AND
notice_module = #{noticeModule}
</if>
GROUP BY
notice_menu
</select>
<!-- 统计 -->
<select id="count" parameterType="map" resultType="java.lang.Integer" useCache="false">
SELECT
COUNT(*)
FROM
im_notice
WHERE
is_delete = 0
<if test="userId != null and userId != ''">
AND
user_id = #{userId}
</if>
<if test="noticeSystem != null and noticeSystem != ''">
AND
notice_system = #{noticeSystem}
</if>
<if test="noticeModule != null and noticeModule != ''">
AND
notice_module = #{noticeModule}
</if>
<if test="noticeMenu != null and noticeMenu != ''">
AND
notice_menu = #{noticeMenu}
</if>
<if test="isHandle != null">
AND
is_handle = #{isHandle}
</if>
</select>
</mapper>