WeEmpleCodeMapper.xml 8.56 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"    />
        <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="selectWeEmpleCodeLsit">
                select
            wecode.id,
            wecode.code_type,
            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
	</sql>

    <select id="selectWeEmpleCodeList" parameterType="WeEmpleCode" resultMap="WeEmpleCodeResult">
        <include refid="selectWeEmpleCodeLsit"/>
        <where>
            <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>
        </where>
    </select>
    
    <select id="selectWeEmpleCodeById" parameterType="Long" resultMap="WeEmpleCodeResult">
        <include refid="selectWeEmpleCodeLsit"/>
        <where>
            wecode.id = #{id}
        </where>
    </select>

    <select id="selectWeEmpleCodeByIds" parameterType="java.util.ArrayList" resultMap="WeEmpleCodeResult">
        <include refid="selectWeEmpleCodeLsit"/>
        <where>
            <if test="ids != null">
                wecode.id in
                <foreach collection="ids" item="id" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
        </where>
    </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>
         </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>
         </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>
        </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
        wmt.welcome_msg ,
        wmt.welcome_msg_tpl_type,
        wm.category_id,
        wm.material_url,
        wm.content,
        wm.material_name,
        wm.digest,
        wm.cover_url
        from
        we_emple_code wecode
        left join
        we_msg_tlp_scope wmts on wecode.welcome_msg = wmts .msg_tlp_id
        left join we_msg_tlp wmt on wmt.id = wmts .msg_tlp_id
        left join we_material wm on wm .id = wmt.media_id
        where wmt.del_flag =0
        <if test="activityScene != null and activityScene != ''">
            and wecode.activity_scene = #{activityScene}
        </if>
    </select>
    
</mapper>