<?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="com.casic.missiles.mapper.business.BusinessLabExecutiveTemplateInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.casic.missiles.model.business.BusinessLabExecutiveTemplateInfo">
        <id column="id" property="id" />
        <result column="template_code" property="templateCode" />
        <result column="sample_type_id" property="sampleTypeId" />
        <result column="sample_id" property="sampleId" />
        <result column="measure_dept_id" property="measureDeptId" />
        <result column="measure_person_id" property="measurePersonId" />
        <result column="measure_item" property="measureItem" />
        <result column="execute_sequence" property="executeSequence" />
        <result column="remark" property="remark" />
        <result column="create_user" property="createUser" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, template_code, sample_type_id, sample_id, measure_dept_id, measure_person_id, measure_item, execute_sequence, remark, is_del, create_user, create_time, update_time
    </sql>

    <select id="selectExecutiveList" resultType="com.casic.missiles.dto.business.labExecutive.SampleHandOutInitListResponse">
        SELECT bleti.measure_dept_id AS measureSegmentId, sd.SIMPLE_NAME AS measureSegment,
            bleti.measure_person_id, ms.name AS measurePerson, bleti.update_time
        FROM business_lab_executive_template_info bleti
        JOIN sys_dept sd ON bleti.measure_dept_id = sd.ID
        LEFT JOIN meter_staff ms ON bleti.measure_person_id = ms.id
        WHERE bleti.sample_id = #{request.sampleId}
        ORDER BY bleti.execute_sequence ASC
    </select>

    <select id="selectMaxTemplateNo" resultType="java.lang.Long">
        SELECT IFNULL(max(RIGHT(template_code, 12)), 0) from business_lab_executive_template_info
    </select>
</mapper>
