DigitalManagementTemplateMapper.xml 5.23 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.DigitalManagementTemplateMapper" >
  <resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.digitalmanagement.DigitalManagementTemplate" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="code" property="code" jdbcType="VARCHAR" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="type" property="type" jdbcType="VARCHAR" />
    <result column="type_name" property="typeName" jdbcType="VARCHAR" />
    <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="display_summary" property="displaySummary" jdbcType="INTEGER" />
    <result column="extend_field" property="extendField" jdbcType="VARCHAR" />
    <result column="scene_type" property="sceneType" jdbcType="INTEGER" />
    <result column="business_type" property="businessType" jdbcType="INTEGER" />
    <result column="report_type" property="reportType" jdbcType="INTEGER" />
  </resultMap>
  <resultMap id="SimpleDTOResult" type="cn.com.glsx.dj.mindworkplate.dto.digitalmanagement.DigitalManagementTemplateDTO" extends="BaseResultMap" />
  <resultMap id="DTOResult" type="cn.com.glsx.dj.mindworkplate.dto.digitalmanagement.DigitalManagementTemplateDTO" extends="BaseResultMap">
    <collection property="types"
                resultMap="cn.com.glsx.dj.mindworkplate.mapper.digitalmanagement.DigitalManagementTemplateItemMapper.DTOResult"
                columnPrefix="item_" />
  </resultMap>
  <sql id="Base_Column_List" >
    <!--
      WARNING - @mbg.generated
    -->
    id, code, name, type, type_name, created_by, created_date, updated_by, updated_date, 
    deleted_flag,extend_field, display_summary ,scene_type ,business_type ,report_type
  </sql>

  <select id="findAllType" resultMap="SimpleDTOResult">
    select type, max(type_name) as type_name
    from digital_management_template
    where deleted_flag = 'N' group by type
  </select>

  <select id="findLastOne" resultMap="SimpleDTOResult">
    select *
    from digital_management_template t
    <where>
      t.deleted_flag = 'N'
      <if test="typeName != null and typeName != ''">
        and t.type_name = #{typeName}
      </if>
      <if test="createdDate != null">
        and date(t.created_date) &lt;= date(#{createdDate})
      </if>
    </where>
    order by t.created_date desc
    limit 1
  </select>

  <select id="findDetail" resultMap="DTOResult"
          parameterType="cn.com.glsx.dj.mindworkplate.dto.digitalmanagement.DigitalManagementTemplateDTO">
    select t.*,
    <include refid="cn.com.glsx.dj.mindworkplate.mapper.digitalmanagement.DigitalManagementTemplateItemMapper.Prefix_Column">
      <property name="prefix" value="item"/>
    </include>
    from digital_management_template t
    left join digital_management_template_item item on t.code = item.template_code
    <where>
      t.deleted_flag = 'N' and item.deleted_flag = 'N'
      and t.code = #{code}
      <if test="createdDate != null">
        and date(t.created_date) &lt;= date(#{createdDate})
      </if>
      <if test="endTime != null">
        and date(t.created_date) &lt;= date(#{endTime})
      </if>
    </where>
    order by t.created_date desc
  </select>

  <select id="queryUserTemplate" resultMap="BaseResultMap">
    SELECT
      t.*
    FROM digital_management_template t
    inner join digital_management_template_staff_ref r1 on r1.template_code = t.code
    inner join (
      SELECT r2.template_code as template_code, max(r2.id) as id
      FROM digital_management_template_staff_ref r2
      where r2.deleted_flag = 'N'
      <if test="includeTempCode != null and includeTempCode != ''">
        and r2.template_code = #{includeTempCode}
      </if>
      <if test="excludeTempCode != null and excludeTempCode != ''">
        and r2.template_code != #{excludeTempCode}
      </if>
      and r2.effective_date &lt;= date(#{date})
      group by r2.template_code
    ) temp on temp.template_code = r1.template_code
    where FIND_IN_SET(#{uuid}, r1.staff_uuid_list) > 0
    and r1.effective_date &lt;= date(#{date})
    and r1.id = temp.id
    and r1.deleted_flag = 'N'
    order by r1.id desc
    limit 1
  </select>

  <select id="findStaffTemplateByDate" resultMap="BaseResultMap">
    select
      t.*
    from digital_management_template t
    inner join digital_management_template_staff_ref tsr on tsr.template_code = t.code
    where t.deleted_flag = 'N'
    and tsr.deleted_flag = 'N'
    and FIND_IN_SET(#{uuid}, tsr.staff_uuid_list) > 0
    and tsr.effective_date &lt;= date(#{date})
    order by tsr.effective_date desc
    limit 1
  </select>

  <select id="findByCode" resultMap="DTOResult">
    select * from digital_management_template
    where deleted_flag = 'N' and code = #{code}
  </select>
</mapper>