<?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.ruoyi.web.stock.mapper.WarehouseOperPerfMapper">

    <resultMap id="OperPerfResult" type="com.ruoyi.web.stock.domain.WarehouseOperPerf">
        <id property="id" column="id"/>
        <result property="feeDate" column="fee_date"/>
        <result property="sheetNo" column="sheet_no"/>
        <result property="rebHead" column="reb_head"/>
        <result property="othInc" column="oth_inc"/>
        <result property="othExp" column="oth_exp"/>
        <result property="taxSurch" column="tax_surch"/>
        <result property="impairLoss" column="impair_loss"/>
        <result property="nonopInc" column="nonop_inc"/>
        <result property="nonopExp" column="nonop_exp"/>
        <result property="incTaxExp" column="inc_tax"/>
        <result property="freightBills" column="freight_bill"/>
        <result property="delFlag" column="del_flag"/>
        <result property="orgId" column="org_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="baseSelect">
        select id, fee_date, sheet_no, reb_head, oth_inc, oth_exp, tax_surch, impair_loss,
               nonop_inc, nonop_exp, inc_tax, freight_bill, del_flag, org_id,
               create_by, create_time, update_by, update_time
        from warehouse_oper_perf
    </sql>

    <select id="selectById" parameterType="Long" resultMap="OperPerfResult">
        <include refid="baseSelect"/>
        where id = #{id} and del_flag = '0'
    </select>

    <select id="selectList" parameterType="com.ruoyi.web.stock.domain.WarehouseOperPerf" resultMap="OperPerfResult">
        <include refid="baseSelect"/>
        <where>
            del_flag = '0'
            <if test="orgId != null and orgId != ''">
                and org_id = #{orgId}
            </if>
            <if test="feeDate != null">
                and fee_date = #{feeDate}
            </if>
            <if test="sheetNo != null and sheetNo != ''">
                and sheet_no = #{sheetNo}
            </if>
        </where>
        order by id desc
    </select>

    <insert id="insert" parameterType="com.ruoyi.web.stock.domain.WarehouseOperPerf" useGeneratedKeys="true" keyProperty="id">
        insert into warehouse_oper_perf (
            fee_date, sheet_no, reb_head, oth_inc, oth_exp, tax_surch, impair_loss,
            nonop_inc, nonop_exp, inc_tax, freight_bill,
            del_flag, create_by, create_time, update_by, update_time, org_id
        ) values (
            #{feeDate}, #{sheetNo}, #{rebHead}, #{othInc}, #{othExp}, #{taxSurch}, #{impairLoss},
            #{nonopInc}, #{nonopExp}, #{incTaxExp}, #{freightBills},
            #{delFlag}, #{createBy}, now(), #{updateBy}, now(), #{orgId}
        )
    </insert>

    <update id="updateById" parameterType="com.ruoyi.web.stock.domain.WarehouseOperPerf">
        update warehouse_oper_perf
        <set>
            fee_date = #{feeDate},
            sheet_no = #{sheetNo},
            reb_head = #{rebHead},
            oth_inc = #{othInc},
            oth_exp = #{othExp},
            tax_surch = #{taxSurch},
            impair_loss = #{impairLoss},
            nonop_inc = #{nonopInc},
            nonop_exp = #{nonopExp},
            inc_tax = #{incTaxExp},
            freight_bill = #{freightBills},
            update_by = #{updateBy},
            update_time = now()
        </set>
        where id = #{id}
          and del_flag = '0'
          and org_id = #{orgId}
    </update>

    <update id="deleteById">
        update warehouse_oper_perf
        set del_flag = '2',
            update_by = #{updateBy},
            update_time = now()
        where id = #{id}
          and del_flag = '0'
          and org_id = #{orgId}
    </update>

    <select id="selectTodayMaxSeq" resultType="java.lang.Integer">
        select max(cast(right(sheet_no, 4) as unsigned))
        from warehouse_oper_perf
        where org_id = #{orgId}
          and date_format(fee_date, '%Y%m%d') = #{dateText}
          and del_flag = '0'
    </select>
</mapper>

