<?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.saye.hospitalgd.mapper.HisbillsHistoryMapper">
    <insert id="saveHisHistoryData" parameterType="HashMap">

        insert into hisbills_history (BRNM,
                                      BRID,
                                      ZFJE,
                                      HISDDH,
                                      GHDDH,
                                      ZFFS,
                                      CZY,
                                      JYRQ,
                                      JYSJ,
                                      XTJSH,
                                      ZDH,
                                      JYKH,
                                      ZFZT)
        values (#{name}, #{brid}, #{zfje}, #{hisddh},
                #{ghddh}, #{zffs}, #{czy}, #{jyrq}, #{jysj},
                #{xtjsh}, #{zdh}, #{jykh}, #{zfzt})
    </insert>
    <select id="findHisBillsByDate" parameterType="HashMap" resultType="HashMap">
        select HisOperCode
             , PayMethod
             , TradingStatus
             , BizType
             , PayType
             , TradeTime
             , Amount
             , PlatformTransId
             , HisTransId
             , PatientID
             , PatientName
             , source
             , trade_date
        from hisbills_history
        where trade_date = #{trade_date}
    </select>

    <select id="findHisDetailByParam" parameterType="HashMap" resultType="HashMap">
        select HisOperCode
        ,PayMethod
        ,TradingStatus
        ,BizType
        ,PayType
        ,TradeTime
        ,Amount
        ,PlatformTransId
        ,HisTransId
        ,PatientID
        ,PatientName
        ,source
        ,trade_date


        from hisbills_history
        where trade_date=#{trade_date}
        <if test="tranID!=null and tranID!=''">
            and HisTransId=#{tranID}
        </if>
        <if test="h_jylx!=null and h_jylx!=''">
            and TradingStatus=#{h_jylx}
        </if>

        <if test="orderby_je!=null and orderby_je!=''">
            order by Amount desc
        </if>
    </select>
    <delete id="deleteOriginalDataByDate" parameterType="HashMap">
        delete
        from hisbills_original
        where trade_date = #{trade_date}
    </delete>
    <delete id="deleteHistoryDataByDate" parameterType="HashMap">
        delete
        from hisbills_history
        where trade_date = #{trade_date}
    </delete>
    <insert id="insertHisBillsOriginalList" parameterType="java.util.List">
        insert into
        hisbills_original(
        HisOperCode
        ,PayMethod
        ,TradingStatus
        ,BizType
        ,PayType
        ,TradeTime
        ,Amount
        ,PlatformTransId
        ,HisTransId
        ,PatientID
        ,PatientName
        ,source
        ,trade_date
        )
        values
        <foreach collection="hisBillList" index="index" item="itm" separator=",">
            (
            #{itm.HisOperCode},#{itm.PayMethod},#{itm.TradingStatus},#{itm.BizType},#{itm.PayType},#{itm.TradeTime},#{itm.Amount},#{itm.PlatformTransId},#{itm.HisTransId},#{itm.patientId},#{itm.PatientName},#{itm.source},#{itm.trade_date}
            )
        </foreach>
    </insert>
    <insert id="insertHisbillsHistoryList" parameterType="java.util.List">
        insert into
        hisbills_history(
        HisOperCode
        ,PayMethod
        ,TradingStatus
        ,BizType
        ,PayType
        ,TradeTime
        ,Amount
        ,PlatformTransId
        ,HisTransId
        ,PatientID
        ,PatientName
        ,source
        ,trade_date
        )
        values
        <foreach collection="list" index="index" item="itm" separator=",">
            (
            #{itm.HisOperCode},#{itm.PayMethod},#{itm.TradingStatus},#{itm.BizType},#{itm.PayType},#{itm.TradeTime},#{itm.Amount},#{itm.PlatformTransId},#{itm.HisTransId},#{itm.patientId},#{itm.PatientName},#{itm.source},#{itm.trade_date}
            )
        </foreach>
    </insert>
</mapper>