<?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.aucma.report.mapper.RecordQualityMaterialMapper">

    <resultMap type="RecordQualityMaterial" id="RecordQualityMaterialResult">
        <result property="objId" column="obj_id"/>
        <result property="orderCode" column="order_code"/>
        <result property="materialCode" column="material_code"/>
        <result property="materialName" column="material_name"/>
        <result property="materialModel" column="material_model"/>
        <result property="infoType" column="info_type"/>
        <result property="zhengFaQiF" column="zheng_fa_qi_f"/>
        <result property="zhengFaQiZ" column="zheng_fa_qi_z"/>
        <result property="zuHeJiMi" column="zu_he_ji_mi"/>
        <result property="yiQingSuanZhi" column="yi_qing_suan_zhi"/>
        <result property="wenKongQi" column="wen_kong_qi"/>
        <result property="yaSuoQi" column="ya_suo_qi"/>
        <result property="neiLengNingQi" column="nei_leng_ning_qi"/>
        <result property="waiLengNingQi" column="wai_leng_ning_qi"/>
        <result property="fengJi" column="feng_ji"/>
        <result property="maoXiGuan" column="mao_xi_guan"/>
        <result property="dianYuanXian" column="dian_yuan_xian"/>
        <result property="dianNaoBan" column="dian_nao_ban"/>
        <result property="dengZuo" column="deng_zuo"/>
        <result property="menDengKaiGuan" column="men_deng_kai_guan"/>
        <result property="createdBy" column="created_by"/>
        <result property="createdTime" column="created_time"/>
        <result property="updatedBy" column="updated_by"/>
        <result property="updatedTime" column="updated_time"/>
    </resultMap>

    <sql id="selectRecordQualityMaterialVo">
        select rqm.obj_id,
               rqm.order_code,
               bo.MATERIAL_CODE           material_code,
               bm.MATERIAL_NAME           material_name,
               bm.MATERIAL_SPECIFICATIONS material_model,
               rqm.info_type,
               rqm.zheng_fa_qi_f,
               rqm.zheng_fa_qi_z,
               rqm.zu_he_ji_mi,
               rqm.yi_qing_suan_zhi,
               rqm.wen_kong_qi,
               rqm.ya_suo_qi,
               rqm.nei_leng_ning_qi,
               rqm.wai_leng_ning_qi,
               rqm.feng_ji,
               rqm.mao_xi_guan,
               rqm.dian_yuan_xian,
               rqm.dian_nao_ban,
               rqm.deng_zuo,
               rqm.men_deng_kai_guan,
               rqm.created_by,
               rqm.created_time,
               rqm.updated_by,
               rqm.updated_time
        from record_quality_material rqm
                 left join BASE_ORDERINFO bo on bo.ORDER_CODE = rqm.ORDER_CODE
                 left join BASE_MATERIALINFO bm on bm.MATERIAL_CODE = bo.MATERIAL_CODE
    </sql>

    <select id="selectRecordQualityMaterialList" parameterType="RecordQualityMaterial"
            resultMap="RecordQualityMaterialResult">
        <include refid="selectRecordQualityMaterialVo"/>
        <where>
            <if test="orderCode != null  and orderCode != ''">and rqm.order_code = #{orderCode}</if>
            <if test="materialCode != null  and materialCode != ''">and rqm.material_code = #{materialCode}</if>
            <if test="materialName != null  and materialName != ''">and rqm.material_name like concat(concat('%',
                #{materialName}), '%')
            </if>
            <if test="materialModel != null  and materialModel != ''">and rqm.material_model = #{materialModel}</if>
            <if test="infoType != null  and infoType != ''">and rqm.info_type = #{infoType}</if>
            <if test="zhengFaQiF != null  and zhengFaQiF != ''">and zheng_fa_qi_f = #{zhengFaQiF}</if>
            <if test="zhengFaQiZ != null  and zhengFaQiZ != ''">and zheng_fa_qi_z = #{zhengFaQiZ}</if>
            <if test="zuHeJiMi != null  and zuHeJiMi != ''">and zu_he_ji_mi = #{zuHeJiMi}</if>
            <if test="yiQingSuanZhi != null  and yiQingSuanZhi != ''">and yi_qing_suan_zhi = #{yiQingSuanZhi}</if>
            <if test="wenKongQi != null  and wenKongQi != ''">and wen_kong_qi = #{wenKongQi}</if>
            <if test="yaSuoQi != null  and yaSuoQi != ''">and ya_suo_qi = #{yaSuoQi}</if>
            <if test="neiLengNingQi != null  and neiLengNingQi != ''">and nei_leng_ning_qi = #{neiLengNingQi}</if>
            <if test="waiLengNingQi != null  and waiLengNingQi != ''">and wai_leng_ning_qi = #{waiLengNingQi}</if>
            <if test="fengJi != null  and fengJi != ''">and feng_ji = #{fengJi}</if>
            <if test="maoXiGuan != null  and maoXiGuan != ''">and mao_xi_guan = #{maoXiGuan}</if>
            <if test="dianYuanXian != null  and dianYuanXian != ''">and dian_yuan_xian = #{dianYuanXian}</if>
            <if test="dianNaoBan != null  and dianNaoBan != ''">and dian_nao_ban = #{dianNaoBan}</if>
            <if test="dengZuo != null  and dengZuo != ''">and deng_zuo = #{dengZuo}</if>
            <if test="menDengKaiGuan != null  and menDengKaiGuan != ''">and men_deng_kai_guan = #{menDengKaiGuan}</if>
            <if test="createdBy != null  and createdBy != ''">and created_by = #{createdBy}</if>
            <if test="createdTime != null ">and created_time = #{createdTime}</if>
            <if test="updatedBy != null  and updatedBy != ''">and updated_by = #{updatedBy}</if>
            <if test="updatedTime != null ">and updated_time = #{updatedTime}</if>
        </where>
        order by rqm.created_time desc
    </select>

    <select id="selectRecordQualityMaterialByObjId" parameterType="Long" resultMap="RecordQualityMaterialResult">
        <include refid="selectRecordQualityMaterialVo"/>
        where rqm.obj_id = #{objId}
    </select>

    <insert id="insertRecordQualityMaterial" parameterType="RecordQualityMaterial">
        <selectKey keyProperty="objId" resultType="long" order="BEFORE">
            SELECT seq_record_quality_material.NEXTVAL as objId FROM DUAL
        </selectKey>
        insert into record_quality_material
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">obj_id,</if>
            <if test="orderCode != null">order_code,</if>
            <if test="materialCode != null">material_code,</if>
            <if test="materialName != null">material_name,</if>
            <if test="materialModel != null">material_model,</if>
            <if test="infoType != null">info_type,</if>
            <if test="zhengFaQiF != null">zheng_fa_qi_f,</if>
            <if test="zhengFaQiZ != null">zheng_fa_qi_z,</if>
            <if test="zuHeJiMi != null">zu_he_ji_mi,</if>
            <if test="yiQingSuanZhi != null">yi_qing_suan_zhi,</if>
            <if test="wenKongQi != null">wen_kong_qi,</if>
            <if test="yaSuoQi != null">ya_suo_qi,</if>
            <if test="neiLengNingQi != null">nei_leng_ning_qi,</if>
            <if test="waiLengNingQi != null">wai_leng_ning_qi,</if>
            <if test="fengJi != null">feng_ji,</if>
            <if test="maoXiGuan != null">mao_xi_guan,</if>
            <if test="dianYuanXian != null">dian_yuan_xian,</if>
            <if test="dianNaoBan != null">dian_nao_ban,</if>
            <if test="dengZuo != null">deng_zuo,</if>
            <if test="menDengKaiGuan != null">men_deng_kai_guan,</if>
            <if test="createdBy != null">created_by,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="updatedBy != null">updated_by,</if>
            <if test="updatedTime != null">updated_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objId != null">#{objId},</if>
            <if test="orderCode != null">#{orderCode},</if>
            <if test="materialCode != null">#{materialCode},</if>
            <if test="materialName != null">#{materialName},</if>
            <if test="materialModel != null">#{materialModel},</if>
            <if test="infoType != null">#{infoType},</if>
            <if test="zhengFaQiF != null">#{zhengFaQiF},</if>
            <if test="zhengFaQiZ != null">#{zhengFaQiZ},</if>
            <if test="zuHeJiMi != null">#{zuHeJiMi},</if>
            <if test="yiQingSuanZhi != null">#{yiQingSuanZhi},</if>
            <if test="wenKongQi != null">#{wenKongQi},</if>
            <if test="yaSuoQi != null">#{yaSuoQi},</if>
            <if test="neiLengNingQi != null">#{neiLengNingQi},</if>
            <if test="waiLengNingQi != null">#{waiLengNingQi},</if>
            <if test="fengJi != null">#{fengJi},</if>
            <if test="maoXiGuan != null">#{maoXiGuan},</if>
            <if test="dianYuanXian != null">#{dianYuanXian},</if>
            <if test="dianNaoBan != null">#{dianNaoBan},</if>
            <if test="dengZuo != null">#{dengZuo},</if>
            <if test="menDengKaiGuan != null">#{menDengKaiGuan},</if>
            <if test="createdBy != null">#{createdBy},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedBy != null">#{updatedBy},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
        </trim>
    </insert>

    <update id="updateRecordQualityMaterial" parameterType="RecordQualityMaterial">
        update record_quality_material
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderCode != null">order_code = #{orderCode},</if>
            <if test="materialCode != null">material_code = #{materialCode},</if>
            <if test="materialName != null">material_name = #{materialName},</if>
            <if test="materialModel != null">material_model = #{materialModel},</if>
            <if test="infoType != null">info_type = #{infoType},</if>
            <if test="zhengFaQiF != null">zheng_fa_qi_f = #{zhengFaQiF},</if>
            <if test="zhengFaQiZ != null">zheng_fa_qi_z = #{zhengFaQiZ},</if>
            <if test="zuHeJiMi != null">zu_he_ji_mi = #{zuHeJiMi},</if>
            <if test="yiQingSuanZhi != null">yi_qing_suan_zhi = #{yiQingSuanZhi},</if>
            <if test="wenKongQi != null">wen_kong_qi = #{wenKongQi},</if>
            <if test="yaSuoQi != null">ya_suo_qi = #{yaSuoQi},</if>
            <if test="neiLengNingQi != null">nei_leng_ning_qi = #{neiLengNingQi},</if>
            <if test="waiLengNingQi != null">wai_leng_ning_qi = #{waiLengNingQi},</if>
            <if test="fengJi != null">feng_ji = #{fengJi},</if>
            <if test="maoXiGuan != null">mao_xi_guan = #{maoXiGuan},</if>
            <if test="dianYuanXian != null">dian_yuan_xian = #{dianYuanXian},</if>
            <if test="dianNaoBan != null">dian_nao_ban = #{dianNaoBan},</if>
            <if test="dengZuo != null">deng_zuo = #{dengZuo},</if>
            <if test="menDengKaiGuan != null">men_deng_kai_guan = #{menDengKaiGuan},</if>
            <if test="createdBy != null">created_by = #{createdBy},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="updatedBy != null">updated_by = #{updatedBy},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteRecordQualityMaterialByObjId" parameterType="Long">
        delete
        from record_quality_material
        where obj_id = #{objId}
    </delete>

    <delete id="deleteRecordQualityMaterialByObjIds" parameterType="String">
        delete from record_quality_material where obj_id in
        <foreach item="objId" collection="array" open="(" separator="," close=")">
            #{objId}
        </foreach>
    </delete>
</mapper>