123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- <?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.zhyc.xps.common.mapper.MsgMapper">
- <resultMap id="MsgDtoResultMap" type="com.zhyc.xps.common.dto.MsgDto" >
- <result column="oc_id" property="ocId" jdbcType="BIGINT" />
- <result column="msg_id" property="msgId" jdbcType="BIGINT" />
- <result column="msg_fr_id" property="msgFrId" jdbcType="BIGINT" />
- <result column="msg_to_group" property="msgToGroup" jdbcType="VARCHAR" />
- <result column="msg_cc" property="msgCc" jdbcType="VARCHAR" />
- <result column="msg_to" property="msgTo" jdbcType="VARCHAR" />
- <result column="msg_cat_id" property="msgCatId" jdbcType="BIGINT" />
- <result column="msg_content" property="msgContent" jdbcType="VARCHAR" />
- <result column="msg_time" property="msgTime" jdbcType="TIMESTAMP"/>
- <result column="status" property="status" jdbcType="BIGINT" />
- <result column="msg_fr_name" property="msgFrName" jdbcType="VARCHAR" />
- <result column="msg_fr_real_name" property="msgFrRealName" jdbcType="VARCHAR" />
- <result column="msg_fr_avatar" property="msgFrAvatar" jdbcType="VARCHAR" />
- <result column="msg_cat_title" property="msgCatTitle" jdbcType="VARCHAR" />
- <result column="is_link" property="isLink" jdbcType="BIGINT" />
- <result column="msg_cat_link" property="msgCatLink" jdbcType="VARCHAR" />
- <result column="msg_cat_link_params" property="msgCatLinkParams" jdbcType="VARCHAR" />
- <result column="msg_params" property="msgParams" jdbcType="VARCHAR" />
- <result column="is_detailed" property="isDetailed" jdbcType="BIGINT" />
- <result column="is_read" property="isRead" jdbcType="BIGINT" />
- </resultMap>
- <resultMap id="MsgDetailDtoResultMap" type="com.zhyc.xps.common.dto.MsgDetailDto" >
- <result column="oc_id" property="ocId" jdbcType="BIGINT" />
- <result column="msg_id" property="msgId" jdbcType="BIGINT" />
- <result column="msg_fr_id" property="msgFrId" jdbcType="BIGINT" />
- <result column="msg_fr_name" property="msgFrName" jdbcType="VARCHAR" />
- <result column="msg_fr_real_name" property="msgFrRealName" jdbcType="VARCHAR" />
- <result column="msg_fr_avatar" property="msgFrAvatar" jdbcType="VARCHAR" />
- <result column="msg_cat_id" property="msgCatId" jdbcType="BIGINT" />
- <result column="msg_cat_title" property="msgCatTitle" jdbcType="VARCHAR" />
- <result column="is_link" property="isLink" jdbcType="BIGINT" />
- <result column="msg_cat_link" property="msgCatLink" jdbcType="VARCHAR" />
- <result column="msg_cat_link_params" property="msgCatLinkParams" jdbcType="VARCHAR" />
- <result column="msg_params" property="msgParams" jdbcType="VARCHAR" />
- <result column="is_detailed" property="isDetailed" jdbcType="BIGINT" />
- <result column="msg_to_group" property="msgToGroup" jdbcType="VARCHAR" />
- <result column="msg_cc" property="msgCc" jdbcType="VARCHAR" />
- <result column="msg_to" property="msgTo" jdbcType="VARCHAR" />
- <result column="msg_time" property="msgTime" jdbcType="TIMESTAMP"/>
- <result column="status" property="status" jdbcType="BIGINT" />
- <result column="msg_content" property="msgContent" jdbcType="VARCHAR" />
- <result column="msg_detail" property="msgDetail" jdbcType="VARCHAR" />
- </resultMap>
- <sql id="MsgDto_Cols">
- M.oc_id,
- M.msg_id,
- M.msg_fr_id,
- A.account_name AS msg_fr_name,
- A.account_real_name AS msg_fr_real_name,
- A.account_avatar AS msg_fr_avatar,
- M.msg_to_group,
- M.msg_cc,
- M.msg_to,
- M.msg_content,
- M.msg_cat_id,
- MC.msg_cat_title,
- MC.is_link,
- MC.msg_cat_link,
- MC.msg_cat_link_params,
- M.msg_params,
- MC.is_detailed,
- M.status,
- IFNULL(CASE WHEN B.status > 0 THEN B.status ELSE C.status END, 0) AS is_read,
- M.msg_time
- </sql>
- <sql id="MsgDetailDto_Cols">
- M.oc_id,
- M.msg_id,
- M.msg_fr_id,
- A.account_name AS msg_fr_name,
- A.account_real_name AS msg_fr_real_name,
- A.account_avatar AS msg_fr_avatar,
- M.msg_to_group,
- M.msg_cc,
- M.msg_to,
- M.msg_content,
- M.msg_detail,
- M.msg_cat_id,
- MC.msg_cat_title,
- MC.is_link,
- MC.msg_cat_link,
- MC.msg_cat_link_params,
- M.msg_params,
- MC.is_detailed,
- M.status,
- M.msg_time
- </sql>
- <!--列表查询-->
- <select id="getByList" parameterType="java.util.Map" resultMap="MsgDtoResultMap">
- SELECT
- <include refid="MsgDto_Cols"/>
- FROM msg AS M
- LEFT JOIN account AS A ON (M.oc_id = A.oc_id AND M.msg_fr_id = A.account_id)
- LEFT JOIN msg_to AS B ON (M.oc_id = B.oc_id AND M.msg_id = B.msg_id AND B.msg_to_id=#{msgToCc, jdbcType=BIGINT})
- LEFT JOIN msg_cc AS C ON (M.oc_id = C.oc_id AND M.msg_id = C.msg_id AND C.msg_cc_id=#{msgToCc, jdbcType=BIGINT})
- LEFT JOIN msg_cat AS MC ON (MC.msg_cat_id = M.msg_cat_id)
- WHERE M.deleted_flag = 0
- <if test="ocId != null">
- AND M.oc_id = #{ocId,jdbcType=BIGINT}
- </if>
- <if test="msgFrId != null">
- AND M.msg_fr_id = #{msgFrId, jdbcType=BIGINT}
- </if>
- <if test="msgToCc != null">
- AND (
- EXISTS (
- SELECT 1 FROM msg_to TT
- WHERE M.oc_id = TT.oc_id AND M.msg_id = TT.msg_id AND TT.msg_to_id = #{msgToCc, jdbcType=BIGINT}
- ) OR
- EXISTS (
- SELECT 1 FROM msg_cc CC
- WHERE M.oc_id = CC.oc_id AND M.msg_id = CC.msg_id AND CC.msg_cc_id = #{msgToCc, jdbcType=BIGINT}
- )
- )
- </if>
- ORDER BY M.created_at DESC
- </select>
- <!--分页查询-->
- <select id="getByPage" parameterType="java.util.Map" resultMap="MsgDtoResultMap">
- SELECT
- <include refid="MsgDto_Cols"/>
- FROM msg AS M
- LEFT JOIN account AS A ON ( M.oc_id = A.oc_id AND M.msg_fr_id = A.account_id)
- LEFT JOIN msg_to AS B ON ( M.oc_id = B.oc_id AND M.msg_id = B.msg_id AND B.msg_to_id=#{msgToCc, jdbcType=BIGINT})
- LEFT JOIN msg_cc AS C ON ( M.oc_id = C.oc_id AND M.msg_id = C.msg_id AND C.msg_cc_id=#{msgToCc, jdbcType=BIGINT})
- LEFT JOIN msg_cat AS MC ON ( MC.msg_cat_id = M.msg_cat_id)
- WHERE M.deleted_flag = 0
- <if test="ocId != null">
- AND M.oc_id = #{ocId,jdbcType=BIGINT}
- </if>
- <if test="msgFrId != null">
- AND M.msg_fr_id = #{msgFrId,jdbcType=BIGINT}
- </if>
- <if test="msgToCc != null">
- AND (
- EXISTS (
- SELECT 1 FROM msg_to TT
- WHERE M.oc_id = TT.oc_id AND M.msg_id = TT.msg_id AND TT.msg_to_id = #{msgToCc, jdbcType=BIGINT}
- ) OR
- EXISTS (
- SELECT 1 FROM msg_cc CC
- WHERE M.oc_id = CC.oc_id AND M.msg_id = CC.msg_id AND CC.msg_cc_id = #{msgToCc, jdbcType=BIGINT}
- )
- )
- </if>
- ORDER BY M.created_at DESC
- </select>
- <!--基于ID查询-->
- <select id="getById" resultMap="MsgDetailDtoResultMap">
- SELECT
- <include refid="MsgDetailDto_Cols"/>
- FROM msg AS M
- LEFT JOIN account AS A ON (M.oc_id = A.oc_id AND M.msg_fr_id = A.account_id)
- LEFT JOIN msg_cat AS MC ON (MC.msg_cat_id = M.msg_cat_id)
- WHERE M.deleted_flag = 0
- <if test="ocId != null">
- AND M.oc_id = #{ocId, jdbcType=BIGINT}
- </if>
- <if test="msgId != null">
- AND M.msg_id = #{msgId, jdbcType=BIGINT}
- </if>
- </select>
- <!--新增Create-->
- <insert id="create" parameterType="com.zhyc.xps.common.entity.Msg">
- INSERT INTO msg
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="ocId != null">
- oc_id,
- </if>
- <if test="msgId != null">
- msg_id,
- </if>
- <if test="msgFrId != null">
- msg_fr_id,
- </if>
- <if test="msgToGroup != null and msgToGroup != ''">
- msg_to_group,
- </if>
- <if test="msgTo != null and msgTo != ''">
- msg_to,
- </if>
- <if test="msgCc != null and msgCc != ''">
- msg_cc,
- </if>
- <if test="msgCatId != null">
- msg_cat_id,
- </if>
- <if test="msgContent != null and msgContent != ''">
- msg_content,
- </if>
- <if test="msgDetail != null and msgDetail !=''">
- msg_detail,
- </if>
- <if test="msgTime != null">
- msg_time,
- </if>
- <if test="msgParams != null and msgParams !=''">
- msg_params,
- </if>
- <if test="createdBy != null">
- created_by,
- </if>
- <if test="createdAt != null">
- created_at,
- </if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="ocId != null">
- #{ocId,jdbcType=BIGINT},
- </if>
- <if test="msgId != null">
- #{msgId,jdbcType=BIGINT},
- </if>
- <if test="msgFrId != null">
- #{msgFrId,jdbcType=BIGINT},
- </if>
- <if test="msgToGroup != null and msgToGroup !=''">
- #{msgToGroup,jdbcType=VARCHAR},
- </if>
- <if test="msgTo != null and msgTo != ''">
- #{msgTo,jdbcType=VARCHAR},
- </if>
- <if test="msgCc != null and msgCc != ''">
- #{msgCc,jdbcType=VARCHAR},
- </if>
- <if test="msgCatId != null">
- #{msgCatId,jdbcType=BIGINT},
- </if>
- <if test="msgContent != null and msgContent != ''">
- #{msgContent,jdbcType=VARCHAR},
- </if>
- <if test="msgDetail != null and msgDetail != ''">
- #{msgDetail,jdbcType=VARCHAR},
- </if>
- <if test="msgTime != null">
- #{msgTime,jdbcType=TIMESTAMP},
- </if>
- <if test="msgParams != null and msgParams !=''">
- #{msgParams, jdbcType=VARCHAR},
- </if>
- <if test="createdBy != null">
- #{createdBy,jdbcType=BIGINT},
- </if>
- <if test="createdAt != null">
- #{createdAt,jdbcType=TIMESTAMP},
- </if>
- </trim>
- </insert>
- <!--更新-->
- <update id="update" parameterType="com.zhyc.xps.common.entity.Msg">
- UPDATE msg
- <trim suffixOverrides=",">
- <set>
- <if test="msgFrId != null">
- msg_fr_id = #{msgFrId ,jdbcType=BIGINT},
- </if>
- <if test="msgToGroup != null and msgToGroup !=''">
- msg_to_group = #{msgToGroup ,jdbcType=VARCHAR},
- </if>
- <if test="msgTo != null and msgTo !=''">
- msg_to = #{msgTo ,jdbcType=VARCHAR},
- </if>
- <if test="msgCc != null and msgCc != ''">
- msg_cc = #{msgCc ,jdbcType=VARCHAR},
- </if>
- <if test="msgCatId != null">
- msg_cat_id = #{msgCatId ,jdbcType=BIGINT},
- </if>
- <if test="msgContent != null and msgContent != ''">
- msg_content =#{msgContent ,jdbcType=VARCHAR},
- </if>
- <if test="msgDetail != null and msgDetail != ''">
- msg_detail = #{msgDetail ,jdbcType=VARCHAR},
- </if>
- <if test="msgParams != null and msgParams !=''">
- msg_params = #{msgParams, jdbcType=VARCHAR},
- </if>
- <if test="updatedBy != null">
- updated_by = #{updatedBy ,jdbcType=BIGINT},
- </if>
- <if test="updatedAt != null">
- updated_at = #{updatedAt ,jdbcType=TIMESTAMP},
- </if>
- </set>
- </trim>
- WHERE msg_id = #{msgId ,jdbcType=BIGINT}
- <if test="ocId != null">
- AND oc_id = #{ocId ,jdbcType=BIGINT}
- </if>
- </update>
- <!--删除-->
- <update id="delete" parameterType="java.util.Map">
- UPDATE msg
- <trim suffixOverrides=",">
- <set>
- <if test="deletedBy != null">
- deleted_by = #{deletedBy ,jdbcType=BIGINT},
- </if>
- <if test="deletedAt != null">
- deleted_at = #{deletedAt ,jdbcType=DATE},
- </if>
- <if test="deletedFlag != null">
- deleted_flag = #{deletedFlag ,jdbcType=BIGINT},
- </if>
- </set>
- </trim>
- WHERE 1 = 1 AND deleted_flag = 0
- <if test="ocId != null">
- AND oc_id = #{ocId,jdbcType=BIGINT}
- </if>
- <if test="msgId != null ">
- AND msg_id = #{msgId ,jdbcType=BIGINT}
- </if>
- </update>
- <select id="getUnReadCount" resultType="int">
- SELECT count(*)
- FROM msg AS M
- WHERE M.oc_id = #{ocId,jdbcType=BIGINT}
- AND (
- EXISTS (
- SELECT 1 FROM msg_to TT
- WHERE M.oc_id = TT.oc_id AND M.msg_id = TT.msg_id AND TT.msg_to_id = #{msgToCc, jdbcType=BIGINT} AND TT.status=0
- ) OR
- EXISTS (
- SELECT 1 FROM msg_cc CC
- WHERE M.oc_id = CC.oc_id AND M.msg_id = CC.msg_id AND CC.msg_cc_id = #{msgToCc, jdbcType=BIGINT} AND CC.status=0
- )
- )
- </select>
- </mapper>
|