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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.casic.missiles.model.business.BusinessOutsourceProjectSampleRelation">
        <id column="id" property="id" />
        <result column="project_id" property="projectId" />
        <result column="sample_id" property="sampleId" />
        <result column="order_id" property="orderId" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, project_id, sample_id, create_time, update_time
    </sql>

    <select id="selectSampleList" resultType="com.casic.missiles.dto.business.outsource.OrderSampleResponseDTO">
        SELECT csi.id AS sample_id, csi.sample_no, csi.sample_name, csi.sample_model, csi.manufacturing_no, bo.order_code, csi.customer_name
        FROM business_outsource_project_sample_relation bopsr
        LEFT JOIN customer_sample_info csi ON bopsr.sample_id = csi.id
        LEFT JOIN business_order bo ON bo.id = bopsr.order_id
        WHERE bopsr.project_id = #{projectId}
    </select>

    <select id="selectSampleList2" resultType="com.casic.missiles.dto.business.outsource.OrderSampleResponseDTO">
        SELECT csi.id AS sample_id, csi.sample_no, csi.sample_name, csi.sample_model, csi.manufacturing_no,
            bopsr.order_id, bo.order_code, csi.customer_name
        FROM business_outsource_project_sample_relation bopsr
        LEFT JOIN customer_sample_info csi ON bopsr.sample_id = csi.id
        LEFT JOIN business_order bo ON bo.id = bopsr.order_id
        WHERE bopsr.project_id = #{projectId}
        <if test="sampleNo != null and sampleNo !=''">
            AND csi.sample_no = #{sampleNo}
        </if>
        <if test="sampleName != null and sampleName !=''">
            AND csi.sample_name = #{sampleName}
        </if>
    </select>
</mapper>
