<?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.sunxung.factoring.mapper.salescontractmanagement.SalesContractSupplementGoodsInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.sunxung.factoring.entity.salescontractmanagement.SalesContractSupplementGoodsInfo">
        <result column="id" property="id" />
        <result column="user_create" property="userCreate" />
        <result column="user_modified" property="userModified" />
        <result column="gmt_create" property="gmtCreate" />
        <result column="gmt_modified" property="gmtModified" />
        <result column="goods_name" property="goodsName" />
        <result column="goods_factory" property="goodsFactory" />
        <result column="model_number" property="modelNumber" />
        <result column="units" property="units" />
        <result column="quantity" property="quantity" />
        <result column="is_clear_price" property="clearPrice" />
        <result column="sales_price" property="salesPrice" />
        <result column="remark" property="remark" />
        <result column="sales_contract_supplement_info_id" property="salesContractSupplementInfoId" />
    </resultMap>
    <select id="getGoodsInfosWithSupplementGoods"
            resultType="com.sunxung.factoring.entity.salescontractmanagement.SalesContractSupplementGoodsInfo">
        select t1.* from (
                             (
                                 SELECT
                                     t5.id id,
                                     t5.goods_factory goods_factory ,
                                     t5.goods_name goods_name ,
                                     t5.model_number model_number ,
                                     t5.quantity quantity,
                                     t5.remark remark,
                                     t5.gmt_create gmt_create,
                                     t5.units units,
                                     0 supplement,
                                     t5.sales_price

                                 FROM c_sales_contract_goods_info t5
                                 WHERE t5.c_sales_contract_basic_info_id = 1
                             )
                             union  all(
                                 SELECT
                                     t2.id id,
                                     t2.goods_factory goods_factory ,
                                     t2.goods_name goods_name ,
                                     t2.model_number model_number ,
                                     t2.quantity quantity,
                                     t2.remark remark,
                                     t2.gmt_create gmt_create,
                                     t2.units units,
                                     1 supplement,
                                     t2.sales_price
                                 FROM
                                     c_sales_contract_supplement_info t1
                                         left join c_sales_contract_supplement_goods_info t2 on t1.id = t2.c_sales_contract_supplement_basic_info_id
                                         left join sales_contract_supplement_approval t3 on t1.id = t3.c_sales_contract_supplement_info_id
                                 WHERE  c_sales_contract_management_id = 11 and t3.approval_conclusion = 'pass'
                             )
                         )t1 where t1.id is not null
        order by t1.id ASC
    </select>

</mapper>
