<?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.zg.project.wisdom.mapper.GysJhMapper">
    
    <resultMap type="GysJh" id="GysJhResult">
        <result property="id"    column="id"    />
        <result property="indexNo"    column="index_no"    />
        <result property="xj"    column="xj"    />
        <result property="xmNo"    column="xm_no"    />
        <result property="xmMs"    column="xm_ms"    />
        <result property="wlNo"    column="wl_no"    />
        <result property="wlMs"    column="wl_ms"    />
        <result property="gysNo"    column="gys_no"    />
        <result property="gysMc"    column="gys_mc"    />
        <result property="jhAmt"    column="jh_amt"    />
        <result property="htDj"    column="ht_dj"    />
        <result property="sapNo"    column="sap_no"    />
        <result property="xh"    column="xh"    />
        <result property="jhQty"    column="jh_qty"    />
        <result property="htQty"    column="ht_qty"    />
        <result property="dw"    column="dw"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDelete"    column="is_delete"    />
    </resultMap>

    <sql id="selectGysJhVo">
        select id, index_no, xj, xm_no, xm_ms, wl_no, wl_ms, gys_no, gys_mc, jh_amt, ht_dj, sap_no, xh, jh_qty, ht_qty, dw, status, remark, create_by, create_time, update_by, update_time, is_delete from gys_jh
    </sql>

    <select id="selectGysJhList" parameterType="GysJh" resultMap="GysJhResult">
        <include refid="selectGysJhVo"/>
        <where>  
            <if test="xmNo != null  and xmNo != ''"> and xm_no like concat('%', #{xmNo}, '%')</if>
            <if test="wlNo != null  and wlNo != ''"> and wl_no like concat('%', #{wlNo}, '%')</if>
            <if test="gysMc != null  and gysMc != ''"> and gys_mc like concat('%', #{gysMc}, '%')</if>
            <if test="sapNo != null  and sapNo != ''"> and sap_no like concat('%', #{sapNo}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="isDelete != null  and isDelete != ''"> and is_delete = #{isDelete}</if>
        </where>
    </select>
    
    <select id="selectGysJhById" parameterType="Long" resultMap="GysJhResult">
        <include refid="selectGysJhVo"/>
        where id = #{id}
    </select>

    <select id="getBySapNo" parameterType="java.lang.String" resultMap="GysJhResult">
        <include refid="selectGysJhVo"/>
        WHERE sap_no = #{sapNo}
        AND status = '0'
    </select>

    <insert id="insertGysJh" parameterType="GysJh" useGeneratedKeys="true" keyProperty="id">
        insert into gys_jh
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="indexNo != null">index_no,</if>
            <if test="xj != null">xj,</if>
            <if test="xmNo != null">xm_no,</if>
            <if test="xmMs != null">xm_ms,</if>
            <if test="wlNo != null">wl_no,</if>
            <if test="wlMs != null">wl_ms,</if>
            <if test="gysNo != null">gys_no,</if>
            <if test="gysMc != null">gys_mc,</if>
            <if test="jhAmt != null">jh_amt,</if>
            <if test="htDj != null">ht_dj,</if>
            <if test="sapNo != null">sap_no,</if>
            <if test="xh != null">xh,</if>
            <if test="jhQty != null">jh_qty,</if>
            <if test="htQty != null">ht_qty,</if>
            <if test="dw != null">dw,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDelete != null">is_delete,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="indexNo != null">#{indexNo},</if>
            <if test="xj != null">#{xj},</if>
            <if test="xmNo != null">#{xmNo},</if>
            <if test="xmMs != null">#{xmMs},</if>
            <if test="wlNo != null">#{wlNo},</if>
            <if test="wlMs != null">#{wlMs},</if>
            <if test="gysNo != null">#{gysNo},</if>
            <if test="gysMc != null">#{gysMc},</if>
            <if test="jhAmt != null">#{jhAmt},</if>
            <if test="htDj != null">#{htDj},</if>
            <if test="sapNo != null">#{sapNo},</if>
            <if test="xh != null">#{xh},</if>
            <if test="jhQty != null">#{jhQty},</if>
            <if test="htQty != null">#{htQty},</if>
            <if test="dw != null">#{dw},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDelete != null">#{isDelete},</if>
         </trim>
    </insert>

    <update id="updateGysJh" parameterType="GysJh">
        update gys_jh
        <trim prefix="SET" suffixOverrides=",">
            <if test="indexNo != null">index_no = #{indexNo},</if>
            <if test="xj != null">xj = #{xj},</if>
            <if test="xmNo != null">xm_no = #{xmNo},</if>
            <if test="xmMs != null">xm_ms = #{xmMs},</if>
            <if test="wlNo != null">wl_no = #{wlNo},</if>
            <if test="wlMs != null">wl_ms = #{wlMs},</if>
            <if test="gysNo != null">gys_no = #{gysNo},</if>
            <if test="gysMc != null">gys_mc = #{gysMc},</if>
            <if test="jhAmt != null">jh_amt = #{jhAmt},</if>
            <if test="htDj != null">ht_dj = #{htDj},</if>
            <if test="sapNo != null">sap_no = #{sapNo},</if>
            <if test="xh != null">xh = #{xh},</if>
            <if test="jhQty != null">jh_qty = #{jhQty},</if>
            <if test="htQty != null">ht_qty = #{htQty},</if>
            <if test="dw != null">dw = #{dw},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateStatusById" parameterType="Long">
        update gys_jh
        set status = '1'
        where id = #{id}
    </update>

    <update id="resetGysJhStatusBySapNos">
        UPDATE gys_jh
        SET status = 0
        WHERE sap_no IN
        <foreach collection="sapNos" item="sapNo" open="(" separator="," close=")">
            #{sapNo}
        </foreach>
    </update>
    <delete id="deleteGysJhById" parameterType="Long">
        delete from gys_jh where id = #{id}
    </delete>

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