<?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.BusinessOutsourceCertificateMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.casic.missiles.model.business.BusinessOutsourceCertificate">
        <id column="id" property="id" />
        <result column="certificate_code" property="certificateCode" />
        <result column="certificate_name" property="certificateName" />
        <result column="outsourcer_id" property="outsourcerId" />
        <result column="order_id" property="orderId" />
        <result column="sample_id" property="sampleId" />
        <result column="original_record_file" property="originalRecordFile" />
        <result column="certificate_file" property="certificateFile" />
        <result column="print_status" property="printStatus" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, certificate_code, certificate_name, outsourcer_id, order_id, sample_id, original_record_file, certificate_file, create_time, update_time
    </sql>

    <select id="selectListPage" resultType="com.casic.missiles.dto.business.outsource.OutsourceCertificateListResponse">
        SELECT boc.id, boc.certificate_code, boc.certificate_name, boc.original_record_file, boc.certificate_file, boc.print_status,
            boc.create_time, csi.sample_no, csi.sample_name, csi.sample_model, csi.manufacturing_no, boi.outsourcer_name
        FROM business_outsource_certificate boc
        LEFT JOIN customer_sample_info csi ON boc.sample_id = csi.id
        LEFT JOIN business_outsourcer_info boi ON boc.outsourcer_id = boi.id
        WHERE 1=1
        <if test="request.certificateCode != null and request.certificateCode !=''">
            and boc.certificate_code like concat('%',#{request.certificateCode},'%')
        </if>
        <if test="request.certificateName != null and request.certificateName !=''">
            and boc.certificate_name like concat('%',#{request.certificateName},'%')
        </if>
        <if test="request.sampleNo != null and request.sampleNo !=''">
            and csi.sample_no like concat('%',#{request.sampleNo},'%')
        </if>
        <if test="request.sampleName != null and request.sampleName !=''">
            and csi.sample_name like concat('%',#{request.sampleName},'%')
        </if>
        <if test="request.outsourcerId != null and request.outsourcerId !=''">
            and boc.outsourcer_id = #{request.outsourcerId}
        </if>
        <if test="request.printStatus != null and request.printStatus !=''">
            and boc.print_status = #{request.printStatus}
        </if>
    </select>

    <select id="selectList" resultType="com.casic.missiles.dto.business.outsource.OutsourceCertificateListResponse">
        SELECT boc.certificate_code, boc.certificate_name, boc.original_record_file, boc.certificate_file, boc.print_status,
        boc.create_time, csi.sample_no, csi.sample_name, csi.sample_model, csi.manufacturing_no, boi.outsourcer_name
        FROM business_outsource_certificate boc
        LEFT JOIN customer_sample_info csi ON boc.sample_id = csi.id
        LEFT JOIN business_outsourcer_info boi ON boc.outsourcer_id = boi.id
        WHERE 1=1
        <if test="request.certificateCode != null and request.certificateCode !=''">
            and boc.certificate_code like concat('%',#{request.certificateCode},'%')
        </if>
        <if test="request.certificateName != null and request.certificateName !=''">
            and boc.certificate_name like concat('%',#{request.certificateName},'%')
        </if>
        <if test="request.sampleNo != null and request.sampleNo !=''">
            and csi.sample_no like concat('%',#{request.sampleNo},'%')
        </if>
        <if test="request.sampleName != null and request.sampleName !=''">
            and csi.sample_name like concat('%',#{request.sampleName},'%')
        </if>
        <if test="request.outsourcerId != null and request.outsourcerId !=''">
            and boc.outsourcer_id = #{request.outsourcerId}
        </if>
        <if test="request.printStatus != null and request.printStatus !=''">
            and boc.print_status = #{request.printStatus}
        </if>
    </select>

    <select id="selectListByCertificateIds" resultType="com.casic.missiles.dto.business.outsource.OutsourceCertificateListResponse">
        SELECT boc.certificate_code, boc.certificate_name, boc.original_record_file, boc.certificate_file, boc.print_status,
        boc.create_time, csi.sample_no, csi.sample_name, csi.sample_model, csi.manufacturing_no, boi.outsourcer_name
        FROM business_outsource_certificate boc
        LEFT JOIN customer_sample_info csi ON boc.sample_id = csi.id
        LEFT JOIN business_outsourcer_info boi ON boc.outsourcer_id = boi.id
        WHERE boc.id IN
        <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>
</mapper>
