WeEmpleCodeMapper.xml 11.1 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="skipVerify" column="skip_verify"/>
        <result property="scenario" column="scenario"/>
        <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"/>
        <result property="scanTimes" column="scan_times" />
        <result property="state" column="state" />
        <result property="isJoinConfirmFriends" column="is_join_confirm_friends" />
        <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, skip_verify, scenario, welcome_msg, create_by, create_time, del_flag, config_id,qr_code, state, scan_times from we_emple_code
    </sql>

    <sql id="getQrcodeByUserIdVo">
        select
        wec.id,
        wec.code_type,
        wec.skip_verify,
        wec.scenario,
        wec.welcome_msg,
        wec.create_by,
        wec.create_time,
        wec.del_flag,
        wec.config_id,
        wec.state,
        wec.qr_code,
        wec.scan_times
        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.skip_verify,
            wecode.scenario,
            wecode.welcome_msg,
            wecode.create_by,
            wecode.create_time,
            wecode.del_flag,
            wecode.config_id,
            wecode.qr_code,
            wecode.state,
            wecode.scan_times,
            wecusn.business_id,
            wecusn.business_name,
            wecusn.mobile,
            wect.tag_id,
            wect.tag_name,
            wecode.is_join_confirm_friends
        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" resultType="com.linkwechat.wecom.domain.WeEmpleCode">
        <include refid="selectWeEmpleCodeLsit"/>
        <if test="codeType != null ">and wecode.code_type = #{codeType}</if>
        <if test="skipVerify != null ">and wecode.skip_verify = #{skipVerify}</if>
        <if test="scenario != null  and scenario != ''">
            and wecode.scenario like concat('%', #{scenario}, '%')
        </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>
        group by wecode.id
    </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="skipVerify != null">skip_verify,</if>
            <if test="scenario != null">scenario,</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>
            <if test="state != null">state,</if>
            <if test="scanTimes != null">scan_times,</if>
            <if test="isJoinConfirmFriends != null">is_join_confirm_friends,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="codeType != null">#{codeType},</if>
            <if test="skipVerify != null">#{skipVerify},</if>
            <if test="scenario != null">#{scenario},</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>
            <if test="state != null">#{state},</if>
            <if test="scanTimes != null">#{scanTimes},</if>
            <if test="isJoinConfirmFriends != null">#{isJoinConfirmFriends},</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="skipVerify != null">skip_verify = #{skipVerify},</if>
            <if test="scenario != null">scenario = #{scenario},</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>
            <if test="state != null">state = #{state},</if>
            <if test="scanTimes != null">scan_times = #{scanTimes},</if>
            <if test="isJoinConfirmFriends != null"> is_join_confirm_friends =#{isJoinConfirmFriends},</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="selectWelcomeMsgByScenario" 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="scenario != null and scenario != ''">
            and wecode.scenario = #{scenario}
        </if>
        <if test="userId != null and userId != ''">
            and wecus.business_id = #{userId}
        </if>
    </select>


    <select id="selectWelcomeMsgByState" 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="state != null and state != ''">
            and wecode.state = #{state}
        </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>

    <update id="updateScanTimesByState" parameterType="String">
        update we_emple_code
        set scan_times = scan_times + 1
        where state = #{state}
    </update>
</mapper>