<?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.nantian.cloud.jly.mapper.CheckGaugesTypeReportAmendMapper">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.nantian.cloud.jly.entity.CheckGaugesTypeReport" id="checkGaugesTypeReportAmendMap">
        <!--        <result property="id" column="id"/>-->
        <!--        <result property="checkPlanId" column="check_plan_id"/>-->
        <!--        <result property="epc" column="epc"/>-->
        <!--        <result property="num" column="num"/>-->
        <!--        <result property="userid" column="userid"/>-->
        <!--        <result property="updateTime" column="update_time"/>-->
        <!--        <result property="delFlag" column="del_flag"/>-->
        <!--        <result property="deptId" column="dept_id"/>-->
        <!--        <result property="item" column="item"/>-->
        <!--        <result property="name" column="name"/>-->
        <!--        <result property="inoutShouldMatch" column="inout_should_match"/>-->
        <!--        <result property="inoutRealMatch" column="inout_real_match"/>-->
        <!--        <result property="inoutRate" column="inout_rate"/>-->
        <!--        <result property="secondaryShouldMatch" column="secondary_should_match"/>-->
        <!--        <result property="secondaryRealMatch" column="secondary_real_match"/>-->
        <!--        <result property="secondaryRate" column="secondary_rate"/>-->
        <!--        <result property="mainShouldMatch" column="main_should_match"/>-->
        <!--        <result property="mainRealMatch" column="main_real_match"/>-->
        <!--        <result property="mainRate" column="main_rate"/>-->
        <!--        <result property="otherShouldMatch" column="other_should_match"/>-->
        <!--        <result property="otherRealMatch" column="other_real_match"/>-->
        <!--        <result property="otherRate" column="other_rate"/>-->
    </resultMap>
    <insert id="insertByEpcAndNum" parameterType="com.nantian.cloud.jly.vo.CheckGaugesTypeReportAmendSubVo">
        INSERT INTO `jly_app`.`check_gauges_type_report_amend`
        <trim prefix="(`epc`, `num`, `name`" suffix=")" suffixOverrides=",">
            <if test="subVo.flag == 1 and subVo.flag != null">
                ,`inout_should_match`,`inout_real_match`,`inout_rate`,`inout_state`,`inout_ex`
            </if>
            <if test="subVo.flag == 2 and subVo.flag != null">
                ,`secondary_should_match`,`secondary_real_match`,`secondary_rate`,`secondary_state`,`secondary_ex`
            </if>
            <if test="subVo.flag == 3 and subVo.flag != null">
                ,`main_should_match`,`main_real_match`,`main_rate`,`main_state`,`main_ex`
            </if>
        </trim>

        VALUES (#{subVo.epc}, #{subVo.num}, #{subVo.name},#{subVo.outfit},#{subVo.realOutfit},
          #{subVo.realOutfitRate},#{subVo.conclusion},#{subVo.instructions})
    </insert>
    <update id="updateAllocation">
        UPDATE `check_gauges_type_report_amend`
        <set>
            <if test="subVo.flag == 1 and subVo.flag != null">
                `inout_should_match`=#{subVo.outfit},`inout_rate`=#{subVo.realOutfitRate},
                `inout_real_match` = #{subVo.}, `inout_state` = #{subVo.conclusion}, `inout_ex` = #{subVo.instructions}
                WHERE `epc`=#{subVo.epc} AND `num`=#{subVo.num}
            </if>
            <if test="subVo.flag == 2 and subVo.flag != null">
                `secondary_should_match`=#{subVo.outfit},`secondary_rate`=#{subVo.realOutfitRate},
                `secondary_real_match` = #{subVo.}, `secondary_state` = #{subVo.conclusion}, `secondary_ex` = #{subVo.instructions}
                WHERE `epc`=#{subVo.epc} AND `num`=#{subVo.num}
            </if>
            <if test="subVo.flag == 3 and subVo.flag != null">
                `main_should_match`=#{subVo.outfit},`main_rate`=#{subVo.realOutfitRate},
                `main_real_match` = #{subVo.}, `main_state` = #{subVo.conclusion}, `main_ex` = #{subVo.instructions}
                WHERE `epc`=#{subVo.epc} AND `num`=#{subVo.num}
            </if>
        </set>

    </update>
    <delete id="deleteByCheckPlanIdAndEpc">
        delete from check_gauges_type_report_amend where check_plan_id = #{checkPlanId} and epc = #{epc}
    </delete>


</mapper>