<?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.hzya.frame.grpU8.nxproof.oerdjjsfs.dao.impl.OerDjjsfsDaoImpl">
    <resultMap id="get-OerDjjsfsEntity-result" type="com.hzya.frame.grpU8.nxproof.oerdjjsfs.entity.OerDjjsfsEntity">
        <result property="mlId" column="mlId" />
        <result property="djlxId" column="djlxId" />
        <result property="gsdm" column="gsdm" />
        <result property="kjnd" column="kjnd" />
        <result property="jsfsdm" column="jsfsdm" />
        <result property="jsfsmc" column="jsfsmc"/>
        <result property="xh" column="xh" />
        <result property="skr" column="skr" />
        <result property="khyh" column="khyh" />
        <result property="yhzh" column="yhzh" />
        <result property="kmdm" column="kmdm" />
        <result property="kmmc" column="kmmc" />
        <result property="je" column="je" />
        <result property="gwkh" column="gwkh" />
        <result property="gwkxfsj" column="gwkxfsj" />
        <result property="yh" column="yh" />
        <result property="yhhh" column="yhhh" />
        <result property="city" column="city" />
        <result property="rytype" column="rytype" />
        <result property="grdm" column="grdm" />
        <result property="yt" column="yt" />
        <result property="skrbz" column="skrbz" />

    </resultMap>

   <sql id="OerDjjsfsEntity_Base_Column_List">
GSDM,KJND
   </sql>

    <insert id="OerDjjsfsEntity_insert" parameterType="com.hzya.frame.grpU8.nxproof.oerdjjsfs.entity.OerDjjsfsEntity">
        insert into OER_DJJSFS(
        <if test="kjnd != null and kjnd !='' ">KJND, </if>
        <if test="djlxId != null and djlxId !='' "> DJLXID, </if>
        <if test="mlId != null and mlId !='' "> MLID, </if>
        <if test="xh != null and xh !='' "> XH, </if>
        <if test="jsfsdm != null and jsfsdm !=''"> JSFSDM, </if>
        <if test="jsfsmc != null and jsfsmc !='' "> JSFSMC, </if>
        <if test="kmdm != null and kmdm !='' "> KMDM, </if>
        <if test="kmmc != null and kmmc !='' "> KMMC,</if>
        <if test="skr != null and skr !='' "> SKR, </if>
        <if test="khyh != null and khyh !='' "> KHYH,</if>
        <if test="yhzh != null and yhzh !=''"> YHZH, </if>
        <if test="gwkh != null and gwkh !='' "> GWKH, </if>
        <if test="gwkxfsj != null and gwkxfsj !='' "> GWKXFSJ, </if>
        <if test="zph != null and zph !='' "> ZPH, </if>
        <if test="je != null and je !='' "> JE, </if>
        <if test="province != null and province !='' ">PROVINCE,</if>
        <if test="city != null and city !='' "> CITY,</if>
        <if test="yh != null and yh !='' "> YH, </if>
        <if test="yhhh != null and yhhh !='' "> YHHH,</if>
        <if test="rytype != null and rytype !='' "> RYType, </if>
        <if test="grdm != null and grdm !='' "> GRDM, </if>
        <if test="yt != null and yt !='' "> yt,</if>
        <if test="skrbz != null and skrbz !='' "> SKRBZ, </if>
        <if test="gsdm != null and gsdm !='' "> GSDM </if>
        )
        values (
        <if test="kjnd != null and kjnd !='' "> #{kjnd}, </if>
        <if test="djlxId != null and djlxId !='' "> #{djlxId}, </if>
        <if test="mlId != null and mlId !='' "> #{mlId}, </if>
        <if test="xh != null and xh !='' "> #{xh}, </if>
        <if test="jsfsdm != null and jsfsdm !=''"> #{jsfsdm}, </if>
        <if test="jsfsmc != null and jsfsmc !='' "> #{jsfsmc}, </if>
        <if test="kmdm != null and kmdm !='' "> #{kmdm}, </if>
        <if test="kmmc != null and kmmc !='' "> #{kmmc},</if>
        <if test="skr != null and skr !='' "> #{skr}, </if>
        <if test="khyh != null and khyh !='' "> #{khyh},</if>
        <if test="yhzh != null and yhzh !=''"> #{yhzh}, </if>
        <if test="gwkh != null and gwkh !='' "> #{gwkh}, </if>
        <if test="gwkxfsj != null and gwkxfsj !='' "> #{gwkxfsj}, </if>
        <if test="zph != null and zph !='' "> #{zph}, </if>
        <if test="je != null and je !='' "> #{je}, </if>
        <if test="province != null and province !='' ">#{province},</if>
        <if test="city != null and city !='' "> #{city},</if>
        <if test="yh != null and yh !='' "> #{yh}, </if>
        <if test="yhhh != null and yhhh !='' "> #{yhhh},</if>
        <if test="rytype != null and rytype !='' "> #{rytype}, </if>
        <if test="grdm != null and grdm !='' "> #{grdm}, </if>
        <if test="yt != null and yt !='' "> #{yt},</if>
        <if test="skrbz != null and skrbz !='' "> #{skrbz}, </if>
        <if test="gsdm != null and gsdm !='' "> #{gsdm} </if>
        )
    </insert>

    <update id="OerDjjsfsEntity_update" parameterType="com.hzya.frame.grpU8.nxproof.oerdjjsfs.entity.OerDjjsfsEntity">
        update oer_djjsfs set skrbz = '1'
        where gsdm = #{gsdm} and kjnd &lt;&gt; '-1'
        AND EXISTS (
        SELECT
        1
        FROM
        oer_djjsfs a
        WHERE
        gsdm = #{gsdm}
        AND kjnd = '-1'
        AND oer_djjsfs.skr = a.skr
        AND oer_djjsfs.khyh = a.KHYH
        AND oer_djjsfs.yhzh = a.yhzh
        )
    </update>

    <update id="OerDjjsfsEntity_update_pub" parameterType="com.hzya.frame.grpU8.nxproof.oerdjjsfs.entity.OerDjjsfsEntity">
        update Pub_fp set zt = '1',BXDID = #{mlId}
        WHERE
	FPID IN (
		SELECT
			FPID
		FROM
			oer_annex
		WHERE
			gsdm = #{gsdm}
		AND kjnd = #{kjnd}
		AND MLID = ${mlId}
		AND FJType = '电子发票'
	);
    </update>

    <!--单据删除  单据保存时使用-->
    <delete id="OerDjjsfsEntity_delete" parameterType="com.hzya.frame.grpU8.nxproof.oerdjjsfs.entity.OerDjjsfsEntity">
		delete FROM oer_djjsfs where GSDM =#{gsdm} and KJND=#{kjnd} and MLID=${mlId} and DJLXID=${djlxId}
	</delete>

    <!--单据删除  单据删除时使用-->
    <delete id="OerDjjsfsEntity_delete_del" parameterType="com.hzya.frame.grpU8.nxproof.oerdjjsfs.entity.OerDjjsfsEntity">
        DELETE FROM oer_djjsfs WHERE GSDM = #{gsdm} AND KJND = #{kjnd}  AND DJLXID = #{djlxId} AND MLID = #{mlId}
    </delete>
    <!--单据删除  单据删除时使用-->
    <delete id="OerDjjsfsEntity_delete_delMlid" parameterType="com.hzya.frame.grpU8.nxproof.oerdjjsfs.entity.OerDjjsfsEntity">
        DELETE FROM oer_djjsfs WHERE GSDM = #{gsdm}  AND MLID = #{mlId}
    </delete>

</mapper>
