PadMessageBoxMapper.xml 15.7 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="cn.com.glsx.dj.mindworkplate.mapper.PadMessageBoxMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.PadMessageBox">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="module_type" property="moduleType" jdbcType="INTEGER"/>
        <result column="business_type" property="businessType" jdbcType="INTEGER"/>
        <result column="uuid" property="uuid" jdbcType="VARCHAR"/>
        <result column="phone" property="phone" jdbcType="VARCHAR"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="status" property="status" jdbcType="INTEGER"/>
        <result column="created_by" property="createdBy" jdbcType="VARCHAR"/>
        <result column="created_time" property="createdTime" jdbcType="TIMESTAMP"/>
        <result column="updated_by" property="updatedBy" jdbcType="VARCHAR"/>
        <result column="updated_time" property="updatedTime" jdbcType="TIMESTAMP"/>
        <result column="del_flag" property="delFlag" jdbcType="CHAR"/>
        <result column="popup_count" property="popupCount" jdbcType="INTEGER"/>
        <result column="read_type" property="readType" jdbcType="INTEGER"/>
        <result column="read_count" property="readCount" jdbcType="INTEGER"/>
        <result column="latest_read_time" property="latestReadTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <resultMap id="ScriptRecordPadPushDTOMap" extends="BaseResultMap"
               type="cn.com.glsx.dj.mindworkplate.dto.script.ScriptRecordPadPushDTO" >
        <id column="title" property="title"/>
        <id column="task_name" property="taskName"/>
        <id column="finish_time" property="finishTime"/>
        <id column="task_type" property="taskType"/>
        <id column="complete_status" property="completeStatus"/>
        <id column="punish_type" property="punishType"/>
        <id column="task_progress" property="taskProgress"/>
        <id column="course_total_count" property="courseTotalCount"/>
        <id column="total_duration" property="totalDuration"/>
        <id column="detail_id" property="detailId"/>
    </resultMap>

    <resultMap id="BoxRecordDetailMap" type="cn.com.glsx.dj.mindworkplate.dto.script.PadMessageBoxRecordDetail">
        <id column="id" property="id"/>
        <id column="scriptId" property="scriptId"/>
        <id column="class_name" property="className"/>
        <id column="class_code" property="classCode"/>
        <id column="status" property="status"/>
        <id column="polish_content" property="polishContent"/>
        <id column="push_time" property="pushTime"/>
        <id column="label_name" property="excellentLabelName"/>
        <id column="scene_label_name" property="sceneLabelName"/>
        <result column="created_time" property="createdTime"/>
    </resultMap>

    <resultMap id="SopTaskMessageMap" type="cn.com.glsx.dj.mindworkplate.dto.script.SopTaskMessageInfoDTO">
        <id column="boxId" property="boxId"/>
        <id column="push_time" property="pushTime"/>
        <id column="status" property="status"/>
        <association property="sopTaskDetailInfoDTO" javaType="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskDetailInfoDTO">
            <id column="id" property="id"/>
            <id column="check_date" property="checkDate"/>
            <id column="staff_uuid" property="staffUuid"/>
            <id column="staff_phone" property="staffPhone"/>
            <id column="merchant_id" property="merchantId"/>
            <id column="task_status" property="taskStatus"/>
        </association>
    </resultMap>



    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
        -->
        id, module_type, business_type, uuid, phone, name, status, created_by, created_time,
        updated_by, updated_time, del_flag
    </sql>

    <select id="listMessageBoxRecordDetail" parameterType="cn.com.glsx.dj.mindworkplate.dto.script.ScriptSearchDTO"
            resultMap="BoxRecordDetailMap">
        select pmb.id,
        secc.class_name,
        secc.class_code,
        ser.polish_content,
        ser.push_time,
        ser.id as scriptId,
        pmb.status, sl.scene_label_name,el.label_name,
        pmb.created_time
        from pad_message_box pmb
        left join script_record_pad_push srpp on pmb.id = srpp.msg_bos_id and srpp.del_flag = 'N'
        left join script_extract_record ser on srpp.script_id = ser.id
        left join script_extract_config_class secc on ser.class_code = secc.class_code and secc.del_flag = 'N'
        left join script_extract_config_scene_label sl on ser.scene_label_code = sl.scene_label_code and sl.del_flag =
        'N'
        left join script_extract_config_excellent_label el on ser.label_code = el.label_code and el.del_flag = 'N'
        <where>
            pmb.del_flag = 'N' and ser.del_flag = 'N'
            and pmb.module_type = 1
            <if test="businessType != null">
                and pmb.business_type = #{businessType}
            </if>
            <if test="businessTypeList != null and businessTypeList.size>0">
                and pmb.business_type IN
                <foreach item="item" collection="businessTypeList" open="(" separator="," close=")">
                    #{item}
                 </foreach>
            </if>
            and pmb.phone = #{phone}
            <if test="classCode != null and classCode != ''">
                and ser.class_code = #{classCode}
            </if>
            <if test="status != null">
                and pmb.status = #{status}
            </if>
        </where>
        order by pmb.status asc, ser.push_time desc
    </select>

    <select id="listSopMessageBoxRecordDetail" parameterType="cn.com.glsx.dj.mindworkplate.dto.script.ScriptSearchDTO" resultMap="SopTaskMessageMap">
        select pmb.id as boxId, pmb.created_time as push_time,  pmb.status,
        stdi.id,
        stdi.check_date,
        stdi.task_status,
        sti.merchant_id,
        sti.staff_phone,
        sti.staff_uuid
        from pad_message_box pmb
        inner join sop_task_pad_push stpp on pmb.id = stpp.msg_bos_id and stpp.del_flag = 'N'
        inner join sop_task_detail_info stdi on stpp.task_id = stdi.id and stdi.deleted_flag = 'N'
        inner join sop_task_info sti on stdi.sop_task_id = sti.id and sti.deleted_flag = 'N'
        <where>
            pmb.del_flag = 'N'
            and pmb.module_type = 3
            and pmb.business_type = #{businessType}
            and pmb.phone = #{phone}
            <if test="status != null">
                and pmb.status = #{status}
            </if>
            <if test="checkDate != null and checkDate != ''">
                and stdi.check_date = #{checkDate}
            </if>
        </where>
        order by pmb.created_time desc
    </select>

    <select id="listAllConfigClass" resultType="cn.com.glsx.dj.mindworkplate.dto.script.ScriptExtractConfigClassCount">
        select secc.class_code as classCode,
        secc.class_name as className
        from script_extract_config_class secc
        where secc.del_flag = 'N'
    </select>

    <select id="pageStaffInfo" resultMap="BaseResultMap">
        select staff_uuid as uuid,
        staff_name as name,
        phone_number as phone
        from dj_car_life_staff_info
        where deleted_flag = 'N' and phone_number is not null and length(phone_number) > 0
        group by phone_number
    </select>
    <select id="messageBoxCountByStatus" resultType="java.lang.Integer">
        SELECT ifnull(count(0),0) FROM `pad_message_box`
        WHERE `phone` = #{phone}
        AND del_flag='N'
        <if test="status != null">
            AND status = #{status}
        </if>
        <if test="businessType != null">
            AND (business_type = #{businessType} OR business_type IS NULL)
        </if>
        <if test="moduleType != null">
            and module_type = #{moduleType}
        </if>
    </select>
    <select id="listShortCourseBoxMessage" resultMap="ScriptRecordPadPushDTOMap">
        select
        pmb.id,
        stdi.id detail_id,
        case when t.min_box_id = pmb.id then '新的短课程学习任务' else '短课程学习提醒' end title,
        case when t.min_box_id = pmb.id then 1 else 2 end task_type,
        concat_ws('·','短课程',date_format(stdi.created_date,'%m月%d日')) task_name,
        DATE_ADD(stdi.created_date, INTERVAL stc.study_day DAY) finish_time,
        pmb.created_time,
        case when stdi.task_status = 2 then 1 else 0 end complete_status,
        stc.punish_type punish_type,
        pmb.status
        from pad_message_box pmb
        left join sop_task_pad_push stpp on pmb.id = stpp.msg_bos_id
        left join (
        select stpp2.task_id,min(pmb2.id) min_box_id
        from pad_message_box pmb2
        left join sop_task_pad_push stpp2 on pmb2.id = stpp2.msg_bos_id
        where pmb2.del_flag = 'N' and stpp2.del_flag = 'N' and pmb2.module_type = 3
        group by stpp2.task_id
        )t on stpp.task_id = t.task_id
        left join sop_task_detail_info stdi on stpp.task_id = stdi.id
        left join sop_task_info sti on stdi.sop_task_id = sti.id
        left join sop_task_config stc on sti.config_id = stc.id
        where pmb.del_flag = 'N' and stpp.del_flag = 'N' and stdi.deleted_flag = 'N' and sti.deleted_flag = 'N'
        and stc.deleted_flag = 'N' and pmb.module_type = 3 and stdi.business_id is not null
        <if test="phone != null and phone != ''">
            and sti.staff_phone = #{phone}
        </if>
        group by pmb.id
        order by pmb.status asc, pmb.created_time desc
    </select>
    <select id="listLongCourseBoxMessage" resultMap="ScriptRecordPadPushDTOMap">
        select
        pmb.id,
        dclcmts.id detail_id,
        case when t.min_box_id = pmb.id then '新的长课程学习任务' else '长课程学习提醒' end title,
        case when t.min_box_id = pmb.id then 1 else 2 end task_type,
        dclcmt.title task_name,
        dclcmtec.deadline finish_time,
        pmb.created_time,
        case when ss.punish_status = 3 then 1 else 0 end complete_status,
        dclcmtec.punish_type punish_type,
        ROUND(100 * count(case when ssc.status = 5 then ssc.id end) / NULLIF(count(ssc.id), 0), 2) task_progress,
        count(ssc.id) course_total_count,
        sum(sbc.total_duration) total_duration,
        pmb.status
        from pad_message_box pmb
        left join dj_car_life_content_manager_task_staff_pad_push dclcmtspp on pmb.id = dclcmtspp.msg_bos_id
        left join (
        select dclcmtspp2.task_staff_id, min(pmb2.id) min_box_id
        from pad_message_box pmb2
        left join dj_car_life_content_manager_task_staff_pad_push dclcmtspp2 on pmb2.id = dclcmtspp2.msg_bos_id
        where pmb2.del_flag = 'N' and dclcmtspp2.deleted_flag = 'N' and pmb2.module_type = 4
        group by dclcmtspp2.task_staff_id
        )t on t.task_staff_id = dclcmtspp.task_staff_id
        left join dj_car_life_content_manager_task_staff dclcmts on dclcmtspp.task_staff_id = dclcmts.id
        left join dj_car_life_content_manager_task dclcmt on dclcmts.cmt_id = dclcmt.id
        left join dj_car_life_content_manager_task_extend_config dclcmtec on dclcmt.id = dclcmtec.cmt_id
        left join staff_study ss on dclcmts.id = ss.content_task_staff_id
        left join staff_study_course ssc on ss.id = ssc.staff_study_id
        left join staff_beisen_course sbc on sbc.course_id = ssc.course_id and sbc.deleted_flag = 'N'
        where pmb.del_flag = 'N' and dclcmtspp.deleted_flag = 'N' and dclcmts.deleted_flag = 'N' and dclcmt.deleted_flag = 'N'
        and ss.deleted_flag = 'N' and ssc.deleted_flag = 'N' and dclcmtec.deleted_flag = 'N' and pmb.module_type = 4
        <if test="phone != null and phone != ''">
            and dclcmts.phone_number = #{phone}
        </if>
        group by pmb.id
        order by pmb.status asc, pmb.created_time desc
    </select>

    <update id="markDeadline">
        update pad_message_box set updated_by = #{updatedBy}, updated_time = now(), status = 1
        where del_flag = 'N' and status = 0 and id in
        <foreach item="item" collection="ids" separator="," open="(" close=")" index="index">
            #{item}
        </foreach>
    </update>

    <select id="countMessageBoxByPhone" resultType="cn.com.glsx.dj.mindworkplate.dto.script.PadMessageSummaryDetail">
        SELECT module_type as moduleType, ifnull(count(0),0) as count
        FROM pad_message_box
        WHERE phone =  #{phone}
        AND del_flag='N'
        and module_type in(1,2,3,4)
        <if test="status != null">
            AND status = #{status}
        </if>
        <if test="businessType != null">
            AND (business_type = #{businessType} OR business_type IS NULL)
        </if>
        group by module_type
    </select>



    <select id="selectLatestActivityMsg" resultType="cn.com.glsx.dj.mindworkplate.model.PadMessageBox">
        select t1.created_time as createdTime, t1.module_type as moduleType
        from pad_message_box t1
        <where>
            t1.del_flag = 'N'
            and t1.phone = #{phone}
            and t1.uuid = #{uuid}
            and t1.module_type = 5
            <if test="businessType != null">
                and t1.business_type = #{businessType}
            </if>
        </where>
        order by t1.status, t1.created_time desc
    </select>

    <select id="activityMessagePage"
            resultType="cn.com.glsx.dj.mindworkplate.dto.messagebox.ActivityMessageRespDTO">
        select
            t1.created_time as createTime,
            t1.id as msgId,
            '活动中心' as title,
            case t2.type when 0 then '有新的活动请及时查看' else '有新的活动获奖名单,请及时查看' end as content,
            t1.status
        from pad_message_box t1
        left join activity_msg_relation t2 on t1.id = t2.msg_box_id
        <where>
            t1.del_flag = 'N'
            and t1.module_type = 5
            <if test="uuid != null and uuid != ''">
                and t1.uuid = #{uuid}
            </if>
            <if test="readFlag != null">
                and t1.status = if(#{readFlag}, 1, 0)
            </if>
            <if test="businessType != null">
                and t1.business_type = #{businessType}
            </if>
        </where>
        order by t1.status, t1.created_time desc
    </select>


    <select id="countMessageBoxByUuid"
            resultType="cn.com.glsx.dj.mindworkplate.dto.script.PadMessageSummaryDetail">
        SELECT module_type as moduleType, ifnull(count(0),0) as count
        FROM pad_message_box
        <where>
            uuid = #{uuid}
            AND del_flag='N'
            and module_type in
            <foreach item="item" collection="moduleTypes" separator="," open="(" close=")" index="index">
                #{item}
            </foreach>
            <if test="status != null">
                AND status = #{status}
            </if>
            <if test="businessType != null">
                AND (business_type = #{businessType} OR business_type IS NULL)
            </if>
            group by module_type
        </where>
    </select>

    <select id="getActivityMsgPopUpWindow"
            resultType="cn.com.glsx.dj.mindworkplate.dto.messagebox.ActivityMessagePopUpWindowRespDTO">
        select
            t2.rel_id as relId,
            t2.`type`,
            t1.id as msgId
        from pad_message_box t1
        inner join activity_msg_relation t2 on t1.id = t2.msg_box_id
        where
        t1.del_flag = 'N'
        and t1.module_type = '5'
        and t1.uuid = #{uuid}
        and t1.business_type = #{businessType}
        and t1.status = 0
        and t1.created_time >= DATE_SUB(CURDATE(), interval 6 day)
        order by t2.`type` desc, t1.created_time desc
        limit 1
    </select>
</mapper>