SopTaskDetailInfoMapper.xml 12.3 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.SopTaskDetailInfoMapper" >
  <resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.sop.SopTaskDetailInfo" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="sop_task_id" property="sopTaskId" jdbcType="INTEGER" />
    <result column="check_date" property="checkDate" jdbcType="VARCHAR" />
    <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="push_flag" property="pushFlag" jdbcType="INTEGER"/>
    <result column="push_count" property="pushCount" jdbcType="INTEGER"/>
    <result column="review_status" property="reviewStatus" jdbcType="INTEGER"/>
    <result column="punish_status" property="punishStatus" jdbcType="TINYINT"/>
    <result column="punish_flag" property="punishFlag" jdbcType="TINYINT"/>
    <result column="business_id" property="businessId" jdbcType="VARCHAR"/>
    <result column="complete_time" property="completeTime" jdbcType="TIMESTAMP"/>
    <result column="deadline" property="deadline" jdbcType="TIMESTAMP"/>
    <result column="punish_type" property="punishType" jdbcType="TINYINT"/>
  </resultMap>

  <resultMap id="DetailInfoMap" extends="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskDetailInsertDTO">
    <association property="sopTaskInfo" javaType="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskInfoDTO">
      <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="task_period" property="taskPeriod" jdbcType="INTEGER" />
      <result column="config_id" property="configId" jdbcType="INTEGER" />
    </association>
  </resultMap>

  <resultMap id="pageDetailMap" extends="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskDetailPageDTO">
    <result column="staff_name" property="staffName" jdbcType="VARCHAR" />
    <result column="staff_phone" property="staffPhone" jdbcType="VARCHAR" />
    <result column="business_scene_type_name" property="businessSceneTypeName" jdbcType="VARCHAR" />
    <result column="merchant_name" property="merchantName" jdbcType="VARCHAR" />
    <result column="main_brand" property="mainBrand" jdbcType="VARCHAR" />
    <result column="tag_name" property="tagNames" jdbcType="VARCHAR" />
    <result column="recording_info_count" property="recordingInfoCount" jdbcType="INTEGER" />
    <result column="tag_count" property="tagCount" jdbcType="INTEGER" />
    <result column="tag_finish_count" property="tagFinishCount" jdbcType="INTEGER" />
    <result column="detail_ids" property="detailIds" jdbcType="VARCHAR" />
  </resultMap>

  <sql id="Base_Column_List" >
    <!--
      WARNING - @mbg.generated
    -->
    id, sop_task_id, check_date, task_status, created_by, created_date, updated_by, updated_date, 
    deleted_flag
  </sql>

  <select id="selectDetailByCondition" parameterType="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskDetailInfoDTO" resultMap="BaseResultMap">
    select stdi.id,stdi.sop_task_id, stdi.check_date, stdi.task_status, stdi.business_id
    from sop_task_detail_info stdi
    inner join sop_task_info sti on stdi.sop_task_id = sti.id and sti.deleted_flag = 'N'
    <where>
      stdi.deleted_flag = 'N'
      <if test="staffPhone != null and staffPhone != ''">
        and sti.staff_phone = #{staffPhone}
      </if>
      <if test="checkDate != null and checkDate != ''">
        and stdi.check_date = #{checkDate}
      </if>
      <if test="createdDate != null">
        and date(stdi.check_date) = #{createdDate}
      </if>
      <if test="taskStatus != null">
        and stdi.task_status = #{taskStatus}
      </if>
      <if test="taskStatusList != null and taskStatusList.size() > 0">
        and stdi.task_status in
        <foreach item="item" collection="taskStatusList" separator="," open="(" close=")" index="">
          #{item}
        </foreach>
      </if>
    </where>
    order by stdi.id desc
  </select>
  
  
  <select id="listUnPushedDetailTask" resultMap="DetailInfoMap">
    select stdi.id, stdi.check_date,
    sti.sop_id,sti.staff_uuid,sti.staff_name,sti.merchant_id,sti.merchant_name,sti.staff_phone,sti.task_period, sti.config_id
    from sop_task_detail_info stdi
    inner join sop_task_info sti on stdi.sop_task_id = sti.id and sti.deleted_flag = 'N'
    where stdi.deleted_flag = 'N' and stdi.task_status = 5 and stdi.push_flag = 0
  </select>

  <select id="listUnEvaluateDetailTask" resultMap="DetailInfoMap">
    select stdi.id, stdi.check_date, stdi.review_status, stdi.task_status as task_status, stdi.created_date as created_date,
    sti.sop_id,sti.staff_uuid,sti.staff_name,sti.merchant_id,sti.merchant_name,sti.staff_phone,sti.task_period, sti.config_id
    from sop_task_detail_info stdi
    inner join sop_task_info sti on stdi.sop_task_id = sti.id and sti.deleted_flag = 'N'
    where stdi.deleted_flag = 'N' and stdi.task_status = 1 and stdi.business_id is null and stdi.check_date >= #{queryDate}
  </select>

  <update id="updatePushFlagById">
    update sop_task_detail_info
    set push_flag = 1, updated_date = now()
    where id = #{id}
  </update>

  <update id="updateTaskDetailBusinessId">
    update sop_task_detail_info
    set business_id = #{businessId}, task_status = #{status}, updated_date = now(), complete_time = now()
    where id in
    <foreach collection="ids" item="item" separator="," open="(" close=")">
      #{item}
    </foreach>
  </update>

  <update id="updatePunishFlagByIds">
    update sop_task_detail_info
    set punish_flag = #{status}, updated_date = now()
    where id in
    <foreach collection="ids" item="item" separator="," open="(" close=")">
      #{item}
    </foreach>
  </update>

  <update id="batchUpdateReviewStatus">
    <foreach collection="list" item="item" separator=";">
      update sop_task_detail_info
      set review_status = #{item.reviewStatus}, updated_date = #{item.updatedDate}
      where id = #{item.id}
    </foreach>
  </update>

  <select id="listSopDetailTask" parameterType="cn.com.glsx.dj.mindworkplate.model.sop.SopTaskDetailInfo" resultMap="DetailInfoMap">
    select stdi.*,
    sti.sop_id,sti.staff_uuid,sti.staff_name,sti.merchant_id,sti.merchant_name,sti.staff_phone,sti.task_period, sti.config_id
    from sop_task_detail_info stdi
    inner join sop_task_info sti on stdi.sop_task_id = sti.id and sti.deleted_flag = 'N'
    <where>
      stdi.deleted_flag = 'N'
      <if test="taskStatus != null">
        and stdi.task_status = #{taskStatus}
      </if>
      <if test="checkDate != null and checkDate != ''">
        and stdi.check_date = #{checkDate}
      </if>
      <if test="reviewStatus != null">
        and stdi.review_status = #{reviewStatus}
      </if>
      <if test="pushFlag != null">
        and stdi.push_flag = #{pushFlag}
      </if>
      <if test="pushCount != null">
        and  stdi.push_count &lt;= #{pushCount}
      </if>
      <if test="staffPhone != null and staffPhone != ''">
        and sti.staff_phone = #{staffPhone}
      </if>
      <if test="businessId != null and businessId != ''">
        and stdi.business_id = #{businessId}
      </if>
    </where>
  </select>

  <select id="listSopDetailTaskByIds" resultMap="DetailInfoMap">
    select stdi.id, stdi.check_date,stdi.created_by,stdi.push_count,stdi.created_date as created_date,
    sti.sop_id,sti.staff_uuid,sti.staff_name,sti.merchant_id,sti.merchant_name,sti.staff_phone,sti.task_period, sti.config_id
    from sop_task_detail_info stdi
    inner join sop_task_info sti on stdi.sop_task_id = sti.id and sti.deleted_flag = 'N'
    where stdi.deleted_flag = 'N' and stdi.id in
    <foreach collection="ids" item="item" separator="," open="(" close=")">
      #{item}
    </foreach>
  </select>

  <select id="pageStudyDetail" resultMap="pageDetailMap" parameterType="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskDetailPageDTO">
    select
      info.staff_name, info.staff_phone,
      max(info.merchant_name) as merchant_name,
      max(info.business_scene_type_name) as business_scene_type_name,
      max(info.main_brand) as main_brand,
      group_concat(distinct detail.id) as detail_ids,
      detail.check_date as check_date,
      if(sum(detail.task_status != 2) = 0, 2, 1) as task_status, <!-- 聚合任务状态,全部完成才算完成 -->
      case
        when sum(coalesce(detail.punish_status, 1) != 3) = 0 then 3
        when sum(coalesce(detail.punish_status, 1) = 2) > 0 then 2
        else 1
      end as punish_status, <!-- 聚合处罚状态,全部已完成,全部未触发,否则处罚中 -->
      detail.punish_flag as punish_flag,
      detail.punish_type as punish_type,
      max(detail.complete_time) as complete_time,
      detail.deadline as deadline,
      max(detail.created_date) as created_date,
      max(detail.updated_date) as updated_date,
      group_concat(distinct tag.tag_name) as tag_name,
      sum(if(tag.status != 0, 1, 0)) as tag_count,
      sum(if(tag.status = 2, 1, 0)) as tag_finish_count,
      count(distinct ar.id) as recording_info_count
    from sop_task_detail_info detail
    left join sop_task_info info on detail.sop_task_id = info.id and info.deleted_flag = 'N'
    left join sop_task_detail_agent_ref ar on ar.task_detail_id = detail.id and ar.deleted_flag = 'N'
    left join sop_task_detail_tag tag on tag.business_id = detail.business_id and tag.deleted_flag = 'N'
    <where>
      detail.deleted_flag = 'N'
      and detail.task_status not in (0)
      <if test="staffName != null and staffName != ''">
        and info.staff_name like concat('%', #{staffName}, '%')
      </if>
      <if test="staffPhone != null and staffPhone != ''">
        and info.staff_phone like concat('%', #{staffPhone}, '%')
      </if>
      <if test="businessSceneTypeName != null and businessSceneTypeName != ''">
        and info.business_scene_type_name like concat('%', #{businessSceneTypeName}, '%')
      </if>
      <if test="merchantName != null and merchantName != ''">
        and info.merchant_name like concat('%', #{merchantName}, '%')
      </if>
      <if test="mainBrand != null and mainBrand != ''">
        and info.main_brand like concat('%', #{mainBrand}, '%')
      </if>
      <if test="punishType != null">
        and detail.punish_type = #{punishType}
      </if>
      <if test="punishStatus != null">
        and detail.punish_status = #{punishStatus}
      </if>
      <if test="taskStatus != null">
        and detail.task_status = #{taskStatus}
      </if>
      <if test="taskStatusList != null and taskStatusList.size() > 0">
        and detail.task_status in
        <foreach collection="taskStatusList" item="item" separator="," open="(" close=")">
          #{item}
        </foreach>
      </if>
      <if test="checkStartTime != null">
        and detail.check_date >= date(#{checkStartTime})
      </if>
      <if test="checkEndTime != null">
        and detail.check_date &lt;= date(#{checkEndTime})
      </if>
      <if test="finishStartTime != null">
        and detail.complete_time >= #{finishStartTime}
      </if>
      <if test="finishEndTime != null">
        and detail.complete_time &lt;= #{finishEndTime}
      </if>
    </where>
    group by info.staff_phone, detail.check_date
    order by detail.check_date desc
  </select>

  <select id="findPadMessageIds" resultType="java.lang.Integer">
    select
      p.msg_bos_id
    from sop_task_detail_info d
    inner join sop_task_pad_push p on d.id = p.task_id and p.del_flag = 'N'
    where d.deleted_flag = 'N' and d.id in
    <foreach item="item" collection="detailIds" separator="," open="(" close=")">
      #{item}
    </foreach>
  </select>

</mapper>