SopTaskInfoMapper.xml 14.6 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.sop.SopTaskInfoMapper" >
  <resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.sop.SopTaskInfo" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="sop_id" property="sopId" jdbcType="VARCHAR" />
    <result column="staff_uuid" property="staffUuid" jdbcType="VARCHAR" />
    <result column="staff_name" property="staffName" jdbcType="VARCHAR" />
    <result column="merchant_id" property="merchantId" jdbcType="INTEGER" />
    <result column="merchant_name" property="merchantName" jdbcType="VARCHAR" />
    <result column="staff_phone" property="staffPhone" jdbcType="VARCHAR" />
    <result column="step" property="step" jdbcType="INTEGER" />
    <result column="task_status" property="taskStatus" jdbcType="INTEGER" />
    <result column="created_by" property="createdBy" jdbcType="VARCHAR" />
    <result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
    <result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
    <result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
    <result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
    <result column="task_period" property="taskPeriod" jdbcType="INTEGER" />
    <result column="config_id" property="configId" jdbcType="INTEGER" />
    <result column="business_scene_type_name" property="businessSceneTypeName" jdbcType="VARCHAR" />
    <result column="main_brand" property="mainBrand" jdbcType="VARCHAR" />
  </resultMap>

  <resultMap id="SopTaskInfoMap" extends="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskInfoDTO">
    <result column="total" property="total" />
    <result column="progress" property="progress" jdbcType="DECIMAL"/>
    <result column="ratio" property="ratio" jdbcType="DECIMAL"/>
  </resultMap>

  <resultMap id="SopTaskInfoDTO" extends="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskInfoDTO">
    <association property="config" javaType="cn.com.glsx.dj.mindworkplate.model.sop.SopTaskConfig">
      <id column="config_id" property="id" jdbcType="INTEGER" />
      <id column="store_penetration_monthly" property="storePenetrationMonthly" jdbcType="DECIMAL" />
      <id column="store_penetration_weekly" property="storePenetrationWeekly" jdbcType="DECIMAL" />
      <id column="inspection_score" property="inspectionScore" jdbcType="DECIMAL" />
      <id column="study_day" property="studyDay" jdbcType="INTEGER" />
      <id column="finish_time" property="finishTime" jdbcType="TIMESTAMP" />
      <id column="punish_type" property="punishType" jdbcType="TINYINT" />
      <id column="effective_type" property="effectiveType" jdbcType="TINYINT" />
      <id column="effective_time" property="effectiveTime" jdbcType="TIMESTAMP" />
    </association>
  </resultMap>

  <resultMap id="RecordingMap" type="cn.com.glsx.dj.mindworkplate.model.sop.RecordingInfo">
    <result column="recordingId" property="recordingId" />
    <result column="customerName" property="customerName" />
    <result column="customerCar" property="customerCar" />
    <result column="customerCharacter" property="customerCharacter" />
    <result column="duration" property="duration" />
    <result column="inspectionScore" property="inspectionScore" />
  </resultMap>


  <sql id="Base_Column_List" >
    <!--
      WARNING - @mbg.generated
    -->
    id, sop_id, staff_uuid, staff_name, merchant_id, merchant_name, staff_phone, step, 
    task_status, created_by, created_date, updated_by, updated_date, deleted_flag, task_period, config_id
  </sql>

  <select id="listLatestSopTaskInfo" parameterType="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskSearchDTO" resultMap="BaseResultMap">
    select t1.id, t1.sop_id, t1.staff_uuid, t1.staff_name, t1.merchant_id, t1.merchant_name, t1.staff_phone, t1.step, t1.created_date,t1.task_status
    from sop_task_info t1
    left join sop_task_info t2 on t1.staff_phone = t2.staff_phone and t1.created_date &lt; t2.created_date and t2.deleted_flag = 'N'
    <where>
      t1.deleted_flag = 'N' and t2.id is null
      <include refid="condition"></include>
    </where>
    order by t1.created_date desc
  </select>

  <select id="listLatestSopTaskInfoGroupStep" parameterType="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskSearchDTO" resultMap="BaseResultMap">
    select t1.id, t1.sop_id, t1.staff_uuid, t1.staff_name, t1.merchant_id, t1.merchant_name, t1.staff_phone, t1.step, t1.created_date,t1.task_status
    from sop_task_info t1
    inner join (
      select t1.staff_phone, t1.step, max(t1.created_date) as max_date
      from sop_task_info t1
      where t1.deleted_flag = 'N'
      <include refid="condition"></include>
      group by t1.staff_phone, t1.step
    ) t2 on t1.staff_phone = t2.staff_phone and t1.step = t2.step and t1.created_date = t2.max_date
    where t1.deleted_flag = 'N'
    order by t1.created_date desc
  </select>

  <select id="listUnfinishedLatestSopTaskInfoByUuids"  resultMap="BaseResultMap">
    select t1.sop_id, t1.staff_uuid, t1.staff_name,  t1.staff_phone, t1.step, t1.task_status,t1.merchant_id
    from sop_task_info t1
    left join sop_task_info t2 on t1.staff_uuid = t2.staff_uuid and t1.created_date &lt; t2.created_date and t1.merchant_id = t2.merchant_id and t2.deleted_flag = 'N'
    <where>
      t1.deleted_flag = 'N' and t2.id is null and t1.task_status in (0,2)
      and t1.staff_uuid in
      <foreach item="item" index="index" collection="idList" open="(" separator="," close=")">
        #{item}
      </foreach>
      <!--and date(t1.created_date + interval ifnull(t1.task_period, 0) day) &gt; current_date()-->
    </where>
  </select>

  <sql id="condition">
    <if test="staffPhone != null and staffPhone != ''">
      and t1.staff_phone = #{staffPhone}
    </if>
    <if test="staffPhoneList != null and staffPhoneList.size() > 0">
      and t1.staff_phone in
      <foreach item="item" index="index" collection="staffPhoneList" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="staffUuid != null and staffUuid != ''">
      and t1.staff_uuid = #{staffUuid}
    </if>
    <if test="step != null">
      and t1.step = #{step}
    </if>
    <if test="taskStatus != null">
      and t1.task_status = #{taskStatus}
    </if>
    <if test="stepList != null">
      and t1.step in
      <foreach item="item" index="index" collection="stepList" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="taskStatusList != null">
      and t1.task_status in
      <foreach item="item" index="index" collection="taskStatusList" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="startTime != null">
      and t1.created_date &gt;= #{startTime}
    </if>
    <if test="endTime != null">
      and t1.created_date &lt;= #{endTime}
    </if>
  </sql>

  <select id="listSopTaskInfoByIds" resultMap="BaseResultMap">
    select *
    from sop_task_info
    <where>
      deleted_flag = 'N' and step = #{step}
      <if test="sopIdList != null and sopIdList.size() > 0">
        and sop_id in
        <foreach item="item" index="index" collection="sopIdList" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
      <if test="phoneList != null and phoneList.size() > 0">
        and staff_phone in
        <foreach item="item" index="index" collection="phoneList" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
    </where>
  </select>

  <update id="batchUpdateTaskStatusById">
    <foreach collection="list" item="item" index="index" separator=";">
      update sop_task_info
      set task_status = #{item.taskStatus}, updated_date = #{item.updatedDate}, updated_by = #{item.updatedBy}
      where id = #{item.id}
    </foreach>
  </update>

  <update id="batchUpdateStep2TaskStatus">
    <foreach collection="list" item="item" index="index" separator=";">
      update sop_task_info
      set task_status = #{item.taskStatus}, updated_date = #{item.updatedDate}, updated_by = #{item.updatedBy}
      where step = 1 and sop_id = #{item.sopId} and staff_phone = #{item.staffPhone}
    </foreach>
  </update>

  <select id="countStaffTask" resultMap="SopTaskInfoMap">
    select staff_uuid, count(*) as total
    from sop_task_info
    <where>
      deleted_flag = 'N' and task_status in (0,2)
      and staff_uuid in
      <foreach item="item" index="index" collection="uuidList" open="(" separator="," close=")">
        #{item}
      </foreach>
    </where>
    group by staff_uuid
    having count(*) &gt; 0
  </select>

  <sql id="listSopTaskInfoCondition">
    t1.deleted_flag = 'N'
    <if test="staffPhone != null and staffPhone != ''">
      and t1.staff_phone = #{staffPhone}
    </if>
    <if test="staffUuid != null and staffUuid != ''">
      and t1.staff_uuid = #{staffUuid}
    </if>
    <if test="step != null">
      and t1.step = #{step}
    </if>
    <if test="taskStatus != null">
      and t1.task_status = #{taskStatus}
    </if>
    <if test="taskStatusList != null and taskStatusList.size() > 0">
      and t1.task_status in
      <foreach collection="taskStatusList" close=")" open="(" separator="," item="item">
        #{item}
      </foreach>
    </if>
  </sql>

  <select id="listSopTaskInfo" parameterType="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskInfoDTO" resultMap="BaseResultMap">
    select t1.id, t1.sop_id, t1.staff_uuid, t1.staff_name, t1.merchant_id, t1.merchant_name, t1.staff_phone, t1.step,
    t1.task_status, t1.created_date,  t1.task_period
    from sop_task_info t1
    <where>
      <include refid="listSopTaskInfoCondition" />
    </where>
  </select>

  <select id="listSopTaskInfoDTO" parameterType="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskInfoDTO" resultMap="SopTaskInfoDTO">
    select t1.*,
    t2.store_penetration_monthly, t2.store_penetration_weekly, t2.inspection_score, t2.study_day, t2.finish_time, t2.punish_type, t2.effective_type, t2.effective_time
    from sop_task_info t1
    left join sop_task_config t2 on t1.config_id = t2.id and t2.deleted_flag = 'N'
    <where>
      <include refid="listSopTaskInfoCondition" />
    </where>
  </select>


  <select id="listRecordingInfo" resultMap="RecordingMap">
    select t3.id as recordingId,t3.score as inspectionScore,t6.customer_type as customerCharacter,t1.customer_name as customerName,t1.car_model as customerCar,t2.recording_duration as duration
    from reception_customer_info t1
    left join inspection_badge_recordings t2 on t2.reception_id =t1.id
    left join inspection_conversation_batch t3 on t2.id =t3.record_id
    left join inspection_employee_badge t4 on t2.badge_id =t4.badge_id
    left join inspection_defence t6 on (t3.id=t6.batch_id and t6.deleted_flag ='N')
    left join (   select
    distinct dclgoc.customer_phone
    from dj_car_life_goods_order dclgo
    left join dj_car_life_goods_sub_order dclgso
    on dclgo.order_code = dclgso.order_code and dclgso.deleted_flag = 'N'
    left join dj_car_life_goods_order_customer dclgoc
    on dclgoc.order_code = dclgo.order_code and dclgoc.deleted_flag = 'N'
    left join dj_car_life_pay_order dclpo on dclpo.order_code = dclgo.order_code and dclpo.deleted_flag = 'N'
    where dclgo.deleted_flag = 'N' and dclgo.scene_type = 0
    and dclgo.status in (4, 6) and upgrade_flag = 'Y' and dclpo.success_date like  concat('%',#{checkDate},'%')) t5 on t1.phone_number =t5.customer_phone
    <where>
      t5.customer_phone is null and t3.id is not null and t2.check_type=1 and t3.score &lt; #{score} and t1.reception_start_time like concat('%',#{checkDate},'%')
      and t1.staff_uuid = #{uuid} and t1.merchant_id = #{merchantId}
    </where>
  </select>

  <select id="listBadLabels" resultType="java.lang.String">
    select t3.group_name
    from recording_check_result t1
    inner join recording_tag_value t2 on t1.tag_id =t2.id
    inner join recording_tag_group t3 on t2.tag_groupid =t3.id
    where t1.batch_id = #{batchId} and t2.value_name='差'
  </select>

  <select id="getStaffTodayTaskIndicators" resultMap="SopTaskInfoMap">
    select
    count(distinct stdt.id) total,
    ROUND(100 * count(distinct case when stdt.status = 2 then stdt.id end)
    / NULLIF(count(distinct case when stdt.status != 0 then stdt.id end), 0), 1) progress
    from sop_task_info sti
    left join sop_task_detail_info stdi on sti.id = stdi.sop_task_id and stdi.deleted_flag = 'N'
    left join sop_task_pad_push stpp on stpp.task_id = stdi.id
    left join pad_message_box pmb on pmb.id = stpp.msg_bos_id
    left join sop_task_detail_tag stdt on stdi.business_id = stdt.business_id and stdt.deleted_flag = 'N'
    where sti.deleted_flag = 'N' and stpp.del_flag = 'N' and pmb.del_flag = 'N'
    and stdi.created_date >= CURDATE() and sti.staff_phone = #{condition.staffPhone}
    group by sti.staff_phone
  </select>

  <select id="getStaffTodayTaskRatio" resultMap="SopTaskInfoMap">
    select valid_employees,total_employees,
    ROUND(100 * valid_employees / NULLIF(total_employees, 0), 2) AS ratio
    FROM (
    SELECT COUNT(DISTINCT sti.staff_phone) AS total_employees
    FROM sop_task_info sti
    LEFT JOIN sop_task_detail_info stdi ON sti.id = stdi.sop_task_id AND stdi.deleted_flag = 'N'
    WHERE sti.deleted_flag = 'N'
    AND stdi.created_date >= CURDATE()
    ) total_stats,
    (
    SELECT
    COUNT(DISTINCT sti.staff_phone) AS valid_employees
    FROM sop_task_info sti
    LEFT JOIN sop_task_detail_info stdi ON sti.id = stdi.sop_task_id AND stdi.deleted_flag = 'N'
    WHERE sti.deleted_flag = 'N'
    AND stdi.task_status = 2
    AND stdi.created_date >= CURDATE()
    ) valid_stats;
  </select>
  <select id="getSopInspectionChart" resultType="cn.com.glsx.dj.mindworkplate.model.RecordingCheckResult">
    select t3.group_name tagGroupName, avg(case when sti.id is not null then t1.score else 0 end) score
    from recording_tag_group t3
    left join recording_tag_value t2 on t2.tag_groupid =t3.id and t2.deleted_flag = 'N'
    left join recording_check_result t1 on t1.tag_id =t2.id and t1.deleted_flag = 'N'
    left join sop_task_detail_info stdi on stdi.batch_id = t1.batch_id and t1.deleted_flag = 'N'
    AND stdi.created_date >= DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY)
    AND stdi.created_date <![CDATA[ < ]]> DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
    left join sop_task_info sti on stdi.sop_task_id = sti.id and stdi.deleted_flag = 'N'
    <if test="condition.staffPhone != null and condition.staffPhone != ''">
      and sti.staff_phone = #{condition.staffPhone}
    </if>
    where t3.deleted_flag = 'N'
    group by t3.group_name
  </select>
</mapper>