WeEmpleCodeMapper.xml 9.52 KB
<?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.linkwechat.wecom.mapper.WeEmpleCodeMapper">

    <resultMap type="WeEmpleCode" id="WeEmpleCodeResult">
        <result property="id" column="id"/>
        <result property="codeType" column="code_type"/>
        <result property="isJoinConfirmFriends" column="is_join_confirm_friends"/>
        <result property="activityScene" column="activity_scene"/>
        <result property="welcomeMsg" column="welcome_msg"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="delFlag" column="del_flag"/>
        <result property="configId" column="config_id"/>
        <result property="qrCode" column="qr_code"/>
        <result property="mediaId" column="media_id"/>
        <collection property="weEmpleCodeUseScops" ofType="com.linkwechat.wecom.domain.WeEmpleCodeUseScop">
            <result property="businessId" column="business_id"/>
            <result property="businessName" column="business_name"/>
            <result property="mobile" column="mobile"/>
        </collection>
        <collection property="weEmpleCodeTags" ofType="com.linkwechat.wecom.domain.WeEmpleCodeTag">
            <result property="tagId" column="tag_id"/>
            <result property="tagName" column="tag_name"/>
        </collection>
    </resultMap>

    <sql id="selectWeEmpleCodeVo">
        select id, code_type, is_join_confirm_friends, activity_scene, welcome_msg, create_by, create_time, del_flag, config_id,qr_code from we_emple_code
    </sql>

    <sql id="getQrcodeByUserIdVo">
        select
        wec.id,
        wec.code_type,
        wec.is_join_confirm_friends,
        wec.activity_scene,
        wec.welcome_msg,
        wec.create_by,
        wec.create_time,
        wec.del_flag,
        wec.config_id,
        wec.qr_code
        from we_emple_code wec
        left join we_emple_code_use_scop wecus on wec.id = wecus.emple_code_id
        and wecus.business_id_type = 2
        and wecus.del_flag = 0
    </sql>

    <sql id="selectWeEmpleCodeLsit">
                select
            wecode.id,
            wecode.code_type,
            wecode.media_id,
            wecode.is_join_confirm_friends,
            wecode.activity_scene,
            wecode.welcome_msg,
            wecode.create_by,
            wecode.create_time,
            wecode.del_flag,
            wecode.config_id,
            wecode.qr_code,
            wecusn.business_id,
            wecusn.business_name,
            wecusn.mobile,
            wect.tag_id,
            wect.tag_name
        from
            we_emple_code wecode
        left join (
            SELECT
                wecus.emple_code_id, wecus.business_id, wecus.business_name,wu.mobile
            FROM
                we_emple_code_use_scop wecus
            LEFT JOIN we_user wu ON
                wu.user_id = wecus.business_id
            WHERE
                wecus.del_flag = 0
                ) as wecusn on
            wecode.id = wecusn.emple_code_id
        left join we_emple_code_tag wect on
            wecode.id = wect.emple_code_id
        where 1=1 and wecode.del_flag = 0
	</sql>

    <select id="selectWeEmpleCodeList" parameterType="WeEmpleCode" resultMap="WeEmpleCodeResult">
        <include refid="selectWeEmpleCodeLsit"/>
        <if test="codeType != null ">and wecode.code_type = #{codeType}</if>
        <if test="isJoinConfirmFriends != null ">and wecode.is_join_confirm_friends = #{isJoinConfirmFriends}</if>
        <if test="activityScene != null  and activityScene != ''">
            and wecode.activity_scene like concat('%', #{activityScene}, '%')
        </if>
        <if test="welcomeMsg != null ">and wecode.welcome_msg = #{welcomeMsg}</if>
        <if test="createBy != null and createBy !=''">
            AND wecode.create_by like concat('%', #{createBy}, '%')
        </if>
        <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
            AND date_format(wecode.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
        </if>
        <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
            AND date_format(wecode.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
        </if>
        <if test="mobile != null and mobile !=''">
            AND wecusn.mobile like concat('%', #{mobile}, '%')
        </if>
        <if test="useUserName != null and useUserName !=''">
            AND wecusn.business_name like concat('%', #{useUserName}, '%')
        </if>
    </select>

    <select id="selectWeEmpleCodeById" parameterType="Long" resultMap="WeEmpleCodeResult">
        <include refid="selectWeEmpleCodeLsit"/>
        <if test="id != null and id !=''">
            and wecode.id = #{id}
        </if>
    </select>

    <select id="selectWeEmpleCodeByIds" parameterType="java.util.ArrayList" resultMap="WeEmpleCodeResult">
        <include refid="selectWeEmpleCodeLsit"/>
        <if test="ids != null and ids.size > 0">
            and wecode.id in
            <foreach collection="ids" item="id" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
    </select>

    <insert id="insertWeEmpleCode" parameterType="WeEmpleCode">
        insert into we_emple_code
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="codeType != null">code_type,</if>
            <if test="isJoinConfirmFriends != null">is_join_confirm_friends,</if>
            <if test="activityScene != null">activity_scene,</if>
            <if test="welcomeMsg != null">welcome_msg,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="configId != null">config_id,</if>
            <if test="qrCode != null">qr_code,</if>
            <if test="mediaId != null">media_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="codeType != null">#{codeType},</if>
            <if test="isJoinConfirmFriends != null">#{isJoinConfirmFriends},</if>
            <if test="activityScene != null">#{activityScene},</if>
            <if test="welcomeMsg != null">#{welcomeMsg},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="configId != null">#{configId},</if>
            <if test="qrCode != null">#{qrCode},</if>
            <if test="mediaId != null">#{mediaId},</if>
        </trim>
    </insert>

    <update id="updateWeEmpleCode" parameterType="WeEmpleCode">
        update we_emple_code
        <trim prefix="SET" suffixOverrides=",">
            <if test="codeType != null">code_type = #{codeType},</if>
            <if test="isJoinConfirmFriends != null">is_join_confirm_friends = #{isJoinConfirmFriends},</if>
            <if test="activityScene != null">activity_scene = #{activityScene},</if>
            <if test="welcomeMsg != null">welcome_msg = #{welcomeMsg},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="configId != null">config_id = #{configId},</if>
            <if test="qrCode != null">qr_code = #{qrCode},</if>
            <if test="mediaId != null">media_id = #{mediaId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWeEmpleCodeById" parameterType="Long">
        delete from we_emple_code where id = #{id}
    </delete>

    <delete id="deleteWeEmpleCodeByIds" parameterType="String">
        delete from we_emple_code where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <update id="batchRemoveWeEmpleCodeIds">
        update we_emple_code set
        del_flag = 1
        where id in
        <foreach collection="ids" item="id" index="index"
                 separator="," open="(" close=")">
            #{id}
        </foreach>
    </update>


    <select id="selectWelcomeMsgByActivityScene" parameterType="String"
            resultType="com.linkwechat.wecom.domain.dto.WeEmpleCodeDto">
        select
        wecode.id as emple_code_id,
        wecode.welcome_msg ,
        wm.category_id,
        wm.material_url,
        wm.content,
        wm.material_name,
        wm.digest,
        wm.cover_url
        from
        we_emple_code wecode
        left join we_emple_code_use_scop wecus on
        wecode.id = wecus.emple_code_id
        left join we_material wm on
        wm .id = wecode.media_id
        where
        wecode.del_flag = 0
        <if test="activityScene != null and activityScene != ''">
            and wecode.activity_scene = #{activityScene}
        </if>
        <if test="userId != null and userId != ''">
            and wecus.business_id = #{userId}
        </if>
    </select>



    <select id="getQrcodeByUserId" parameterType="java.lang.String" resultType="com.linkwechat.wecom.domain.WeEmpleCode">
        <include refid="getQrcodeByUserIdVo"/>
        <where>
            <if test="userId != null and userId != ''">
                and wecus.business_id = #{userId}
            </if>
        </where>
    </select>
</mapper>