DigitalManagementTemplateStaffRefMapper.xml 5.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="cn.com.glsx.dj.mindworkplate.mapper.digitalmanagement.DigitalManagementTemplateStaffRefMapper" >
  <resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.digitalmanagement.DigitalManagementTemplateStaffRef" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="template_code" property="templateCode" jdbcType="VARCHAR" />
    <result column="staff_uuid_list" property="staffUuidListStr" jdbcType="VARCHAR" />
    <result column="effective_date" property="effectiveDate" jdbcType="DATE" />
    <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" />
  </resultMap>
  <resultMap id="DTOResult" type="cn.com.glsx.dj.mindworkplate.dto.digitalmanagement.DigitalManagementTemplateStaffRefDTO" extends="BaseResultMap"/>
  <sql id="Base_Column_List" >
    <!--
      WARNING - @mbg.generated
    -->
    id, template_code, staff_uuid_list, effective_date, created_by, created_date, updated_by, 
    updated_date, deleted_flag
  </sql>

  <select id="findCondition" resultMap="DTOResult"
          parameterType="cn.com.glsx.dj.mindworkplate.dto.digitalmanagement.DigitalManagementTemplateDTO">
    select *
    from digital_management_template_staff_ref
    where id in (
      select max(id) from digital_management_template_staff_ref
      <where>
        deleted_flag = 'N'
        <if test="code != null and code != ''">
          and template_code = #{code}
        </if>
        <if test="startTime != null">
          and effective_date &gt; date(#{startTime})
        </if>
        <if test="endTime != null">
          and effective_date &lt;= date(#{endTime})
        </if>
        <!-- 每日最新数据,旧数据不用管,反正修改圈人,记录也会被删除
        <if test="staffUuidList != null and staffUuidList.size() > 0">
          and
          <foreach collection="staffUuidList" item="item" open="(" separator=" OR " close=")">
            FIND_IN_SET(#{item}, staff_uuid_list) > 0
          </foreach>
        </if>
        -->
      </where>
      group by effective_date
    )
    union
    (select * from dj_smartcarlife.digital_management_template_staff_ref
    <where>
      deleted_flag = 'N'
      <if test="code != null and code != ''">
        and template_code = #{code}
      </if>
      <if test="startTime != null">
        and effective_date &lt;= date(#{startTime})
      </if>
      <if test="staffUuidList != null and staffUuidList.size() > 0">
        and
        <foreach collection="staffUuidList" item="item" open="(" separator=" OR " close=")">
          FIND_IN_SET(#{item}, staff_uuid_list) > 0
        </foreach>
      </if>
    </where>
    order by created_date desc limit 1)
    order by id;
  </select>

  <select id="findByCodeAndTime" resultMap="DTOResult">
    select *
    from digital_management_template_staff_ref
    where deleted_flag = 'N'
    and template_code = #{templateCode}
    and effective_date = date(#{date})
    order by created_date desc, id desc
    limit 1
  </select>

  <select id="findLatestByCode" resultMap="DTOResult">
    select *
    from digital_management_template_staff_ref
    where deleted_flag = 'N'
    and template_code = #{templateCode}
    order by created_date desc, id desc
    limit 1
  </select>

  <select id="getTemplateBindingStaff" resultType="string">
    select
      sr.staff_uuid_list
    from digital_management_template_staff_ref sr
    right join (
      select max(sr.template_code) as template_code, max(sr.created_date) as max_cd
      from digital_management_template_staff_ref sr
      left join digital_management_template t on t.code = sr.template_code
      where sr.deleted_flag = "N" and t.deleted_flag = "N"
      <if test="filterTemplateTypeName != null and filterTemplateTypeName != ''">
        and t.type_name != #{filterTemplateTypeName}
      </if>
      group by t.`type`
    ) as m on m.template_code = sr.template_code and sr.created_date = m.max_cd
    <where>
      <if test="staffUuids != null and staffUuids.size() > 0">
        and
        <foreach collection="staffUuids" item="item" open="(" separator=" OR " close=")">
          FIND_IN_SET(#{item}, staff_uuid_list) > 0
        </foreach>
      </if>
    </where>
  </select>


  <resultMap id="TemplateStaffRefDTO" type="cn.com.glsx.dj.mindworkplate.dto.digitalmanagement.TemplateStaffRefDTO" extends="BaseResultMap">
    <result column="target_date" property="targetDate" jdbcType="VARCHAR" />
  </resultMap>

  <select id="findLatestRecordsByDates"
          resultMap="TemplateStaffRefDTO">
    SELECT
      d.*,
      tmp.target_date
    FROM (
      <foreach collection="targetDates" item="date" index="index" separator=" UNION ALL ">
        SELECT #{date} AS target_date
      </foreach>
      ) tmp
    LEFT JOIN digital_management_template_staff_ref d ON d.id = (
        SELECT d1.id
        FROM digital_management_template_staff_ref d1
        WHERE d1.deleted_flag = 'N'
        AND d1.template_code = #{templateCode}
        AND d1.effective_date &lt;= tmp.target_date
        ORDER BY d1.effective_date DESC
        LIMIT 1
    )
    WHERE d.id IS NOT NULL
    ORDER BY tmp.target_date
  </select>
</mapper>