package thyyxxk.webserver.dao.his.medicalinsurance;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.medicalinsurance.inpatient.BriefChargeInfo;
import thyyxxk.webserver.entity.medicalinsurance.inpatient.SiLimitRequest;
import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZdChargeLimitation;

import java.util.LinkedList;
import java.util.List;

@Mapper
public interface SiChargeLimitDao {

    @Select("<script>" +
            "select * from zd_charge_limitations " +
            "where del_flag=0 and limit_day>0 and charge_code in " +
            "<foreach collection='list' item='item' separator=',' open='(' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<ZdChargeLimitation> getChargeLimitations(List<String> list);

    @Select("select detail_sn as sn,ori_detail_sn as oriSn, " +
            "charge_amount as amount,date=convert(varchar(10),charge_date,21) " +
            "from zy_detail_charge " +
            "where inpatient_no=#{patNo} and admiss_times=#{times} " +
            "and ledger_sn=#{ledgerSn} and charge_code_mx=#{currentCode} " +
            "and isnull(yb_self_flag,'0')!='1' " +
            "order by detail_sn")
    LinkedList<BriefChargeInfo> getChargeInfos(SiLimitRequest request);

    @Update("update zy_detail_charge set ori_detail_sn=#{oriSn} " +
            "where inpatient_no=#{patNo} and admiss_times=#{times} and detail_sn=#{sn};" +
            "update zy_detail_charge set ori_detail_sn=-1 " +
            "where inpatient_no=#{patNo} and admiss_times=#{times} and detail_sn=#{oriSn};")
    void updatePairSn(SiLimitRequest request);
}
