package thyyxxk.webserver.dao.his.medicalinsurance.costcontrol;

import org.apache.ibatis.annotations.*;
import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
import thyyxxk.webserver.entity.medicalinsurance.costcontrol.*;
import thyyxxk.webserver.entity.medicalinsurance.inpatient.BatjBa4;
import thyyxxk.webserver.entity.medicalinsurance.inpatient.YbZyDisDiag;

import java.util.List;
import java.util.Map;

/**
 *@Author hsh
 *@Description // 长沙市医保导入
 *@Date 2022/8/31 11:24
 *@Param
 *@Return
 **/
@Mapper
public interface YbCssTjDao {

    @Select("<script> " +
            " select df.dept_id as deptId, df.dept_name as deptName,  " +
            " sum(df.zfy) zfy,  " +
            " sum(df.tczf) tczf,  " +
            " sum(df.yjzf) yjzf, " +
            " sum(df.bal) bal, " +
            " sum(df.zfz) zfz, " +
            " round(sum(df.tczf)/sum(df.zfy)*100, 2) bxbl, " +
            " sum(df.rs) zrs, " +
            " sum(case when yb.declaration_type = '有对照' then df.rs else 0 end) ydzrs, " +
            " sum(case when yb.declaration_type = '有对照' then df.bal else 0 end) ydzbal, " +
            " sum(case when yb.declaration_type = '无对照' then df.rs else 0 end) wdzrs, " +
            " sum(case when yb.declaration_type = '无对照' then df.bal else 0 end) wdzbal, " +
            " sum(case when yb.declaration_type = '难度系数' then df.rs else 0 end) ndxsrs, " +
            " sum(case when yb.declaration_type = '难度系数' then df.bal else 0 end) ndxsbal, " +
            " sum(case when yb.declaration_type = '治疗未完成' then df.rs else 0 end) wwcrs, " +
            " sum(case when yb.declaration_type = '治疗未完成' then df.bal else 0 end) wwcbal, " +
            " sum(case when yb.declaration_type = '转科' then df.rs else 0 end) zkrs, " +
            " sum(case when yb.declaration_type = '转科' then df.bal else 0 end) zkbal, " +
            " sum(case when yb.declaration_type = '单列' then df.rs else 0 end) dlrs " +
            " from yb_css_setl_info yb, " +
            " (select ks.setl_id, ks.dept_id, ks.dept_name, sum(ks.medical_total_fee) zfy, sum(ks.reimburse_amount) tczf, " +
            " sum(ks.estimated_payment) yjzf, sum(ks.bal) bal, sum(ks.real_score) zfz, " +
            " sum(convert(INTEGER, ks.short_no)) rs  " +
            " from yb_css_setl_dept_info ks" +
            " where ks.flag = 'Y' " +
            " and ks.settl_time &gt;= #{beginTime} " +
            " and ks.settl_time &lt;= #{endTime} " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and ks.medins_type = #{insurName} " +
            " </if> " +
            " group by ks.setl_id, ks.dept_id, ks.dept_name) df " +
            " where yb.flag = '0' " +
            " and yb.setl_id = df.setl_id " +
            " and yb.settl_time &gt;= #{beginTime} " +
            " and yb.settl_time &lt;= #{endTime} " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and yb.medins_type = #{insurName} " +
            " </if> " +
            " group by df.dept_id, df.dept_name " +
            " </script> ")
    List<Map<String, Object>> selectCssYbJsTj(@Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("deptId") String deptId, @Param("insurName") String insurName);

    @Select("<script> " +
            " select '合计' as deptName,  " +
            " sum(df.zfy) zfy,  " +
            " sum(df.tczf) tczf,  " +
            " sum(df.yjzf) yjzf, " +
            " sum(df.bal) bal, " +
            " sum(df.zfz) zfz, " +
            " round(sum(df.tczf)/sum(df.zfy)*100, 2) bxbl, " +
            " sum(df.rs) zrs, " +
            " sum(case when yb.declaration_type = '有对照' then df.rs else 0 end) ydzrs, " +
            " sum(case when yb.declaration_type = '有对照' then df.bal else 0 end) ydzbal, " +
            " sum(case when yb.declaration_type = '无对照' then df.rs else 0 end) wdzrs, " +
            " sum(case when yb.declaration_type = '无对照' then df.bal else 0 end) wdzbal, " +
            " sum(case when yb.declaration_type = '难度系数' then df.rs else 0 end) ndxsrs, " +
            " sum(case when yb.declaration_type = '难度系数' then df.bal else 0 end) ndxsbal, " +
            " sum(case when yb.declaration_type = '治疗未完成' then df.rs else 0 end) wwcrs, " +
            " sum(case when yb.declaration_type = '治疗未完成' then df.bal else 0 end) wwcbal, " +
            " sum(case when yb.declaration_type = '转科' then df.rs else 0 end) zkrs, " +
            " sum(case when yb.declaration_type = '转科' then df.bal else 0 end) zkbal, " +
            " sum(case when yb.declaration_type = '单列' then df.rs else 0 end) dlrs " +
            " from yb_css_setl_info yb, " +
            " (select ks.setl_id, ks.dept_id, ks.dept_name, sum(ks.medical_total_fee) zfy, sum(ks.reimburse_amount) tczf, " +
            " sum(ks.estimated_payment) yjzf, sum(ks.bal) bal, sum(ks.real_score) zfz, " +
            " sum(convert(INTEGER, ks.short_no)) rs  " +
            " from yb_css_setl_dept_info ks" +
            " where ks.flag = 'Y' " +
            " and ks.settl_time &gt;= #{beginTime} " +
            " and ks.settl_time &lt;= #{endTime} " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and ks.medins_type = #{insurName} " +
            " </if> " +
            " group by ks.setl_id, ks.dept_id, ks.dept_name) df " +
            " where yb.flag = '0' " +
            " and yb.setl_id = df.setl_id " +
            " and yb.settl_time &gt;= #{beginTime} " +
            " and yb.settl_time &lt;= #{endTime} " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and yb.medins_type = #{insurName} " +
            " </if> " +
            " </script> ")
    Map<String, Object> selectCssYbJsTjTotal(@Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("deptId") String deptId, @Param("insurName") String insurName);

    @Select("<script> " +
            " select df.dept_id as deptId, df.dept_name as deptName,  " +
            " df.doctor_id as doctorId, df.doctor, " +
            " sum(df.zfy) zfy,  " +
            " sum(df.tczf) tczf,  " +
            " sum(df.yjzf) yjzf, " +
            " sum(df.bal) bal, " +
            " sum(df.zfz) zfz, " +
            " round(sum(df.tczf)/sum(df.zfy)*100, 2) bxbl, " +
            " sum(df.rs) zrs, " +
            " sum(case when yb.declaration_type = '有对照' then df.rs else 0 end) ydzrs, " +
            " sum(case when yb.declaration_type = '有对照' then df.bal else 0 end) ydzbal, " +
            " sum(case when yb.declaration_type = '无对照' then df.rs else 0 end) wdzrs, " +
            " sum(case when yb.declaration_type = '无对照' then df.bal else 0 end) wdzbal, " +
            " sum(case when yb.declaration_type = '难度系数' then df.rs else 0 end) ndxsrs, " +
            " sum(case when yb.declaration_type = '难度系数' then df.bal else 0 end) ndxsbal, " +
            " sum(case when yb.declaration_type = '治疗未完成' then df.rs else 0 end) wwcrs, " +
            " sum(case when yb.declaration_type = '治疗未完成' then df.bal else 0 end) wwcbal, " +
            " sum(case when yb.declaration_type = '转科' then df.rs else 0 end) zkrs, " +
            " sum(case when yb.declaration_type = '转科' then df.bal else 0 end) zkbal, " +
            " sum(case when yb.declaration_type = '单列' then df.rs else 0 end) dlrs " +
            " from yb_css_setl_info yb, " +
            " (select ks.setl_id, ks.dept_id, ks.dept_name, ks.doctor_id, ks.doctor, " +
            " sum(ks.medical_total_fee) zfy, sum(ks.reimburse_amount) tczf, " +
            " sum(ks.estimated_payment) yjzf, sum(ks.bal) bal, sum(ks.real_score) zfz, " +
            " sum(convert(INTEGER, ks.short_no)) rs  " +
            " from yb_css_setl_dept_info ks" +
            " where ks.flag = 'Y' " +
            " and ks.settl_time &gt;= #{beginTime} " +
            " and ks.settl_time &lt;= #{endTime} " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and ks.medins_type = #{insurName} " +
            " </if> " +
            " group by ks.setl_id, ks.dept_id, ks.dept_name, ks.doctor_id, ks.doctor) df " +
            " where yb.flag = '0' " +
            " and yb.setl_id = df.setl_id " +
            " and df.dept_id = #{deptId} " +
            " and yb.settl_time &gt;= #{beginTime} " +
            " and yb.settl_time &lt;= #{endTime} " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and yb.medins_type = #{insurName} " +
            " </if> " +
            " group by df.dept_id, df.dept_name, df.doctor_id, df.doctor " +
            " </script> ")
    List<Map<String, Object>> selectYsJsTj(@Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("deptId") String deptId, @Param("insurName") String insurName);

    @Select("<script> " +
            " select '合计' as deptName,  " +
            " sum(df.zfy) zfy,  " +
            " sum(df.tczf) tczf,  " +
            " sum(df.yjzf) yjzf, " +
            " sum(df.bal) bal, " +
            " sum(df.zfz) zfz, " +
            " round(sum(df.tczf)/sum(df.zfy)*100, 2) bxbl, " +
            " sum(df.rs) zrs, " +
            " sum(case when yb.declaration_type = '有对照' then df.rs else 0 end) ydzrs, " +
            " sum(case when yb.declaration_type = '有对照' then df.bal else 0 end) ydzbal, " +
            " sum(case when yb.declaration_type = '无对照' then df.rs else 0 end) wdzrs, " +
            " sum(case when yb.declaration_type = '无对照' then df.bal else 0 end) wdzbal, " +
            " sum(case when yb.declaration_type = '难度系数' then df.rs else 0 end) ndxsrs, " +
            " sum(case when yb.declaration_type = '难度系数' then df.bal else 0 end) ndxsbal, " +
            " sum(case when yb.declaration_type = '治疗未完成' then df.rs else 0 end) wwcrs, " +
            " sum(case when yb.declaration_type = '治疗未完成' then df.bal else 0 end) wwcbal, " +
            " sum(case when yb.declaration_type = '转科' then df.rs else 0 end) zkrs, " +
            " sum(case when yb.declaration_type = '转科' then df.bal else 0 end) zkbal, " +
            " sum(case when yb.declaration_type = '单列' then df.rs else 0 end) dlrs " +
            " from yb_css_setl_info yb, " +
            " (select ks.setl_id, ks.dept_id, ks.dept_name, ks.doctor_id, ks.doctor, " +
            " sum(ks.medical_total_fee) zfy, sum(ks.reimburse_amount) tczf, " +
            " sum(ks.estimated_payment) yjzf, sum(ks.bal) bal, sum(ks.real_score) zfz, " +
            " sum(convert(INTEGER, ks.short_no)) rs  " +
            " from yb_css_setl_dept_info ks" +
            " where ks.flag = 'Y' " +
            " and ks.settl_time &gt;= #{beginTime} " +
            " and ks.settl_time &lt;= #{endTime} " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and ks.medins_type = #{insurName} " +
            " </if> " +
            " group by ks.setl_id, ks.dept_id, ks.dept_name, ks.doctor_id, ks.doctor) df " +
            " where yb.flag = '0' " +
            " and yb.setl_id = df.setl_id " +
            " and df.dept_id = #{deptId} " +
            " and yb.settl_time &gt;= #{beginTime} " +
            " and yb.settl_time &lt;= #{endTime} " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and yb.medins_type = #{insurName} " +
            " </if> " +
            " </script> ")
    Map<String, Object> selectYsJsTjTotal(@Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("deptId") String deptId, @Param("insurName") String insurName);

    @Select("<script> " +
            " select ks.dept_id as deptId, ks.dept_name as deptName, ks.doctor, ks.doctor_id as doctorId,  " +
            " yb.pat_no as zyh, yb.psn_name as xm, yb.medins_type as yblx, " +
            " ks.medical_total_fee as zfy,  " +
            " ks.reimburse_amount as tczf,  " +
            " ks.estimated_payment as yjzf, " +
            " round(ks.reimburse_amount/ks.medical_total_fee * 100, 2) bxbl, " +
            " ks.real_score as zfz, ks.bal,  " +
            " yb.treatment as zlfs, " +
            " yb.declaration_type as sblx, " +
            " yb.settl_time as jssj, " +
            " yb.main_diagn_code as zdbm, yb.main_diagn_name as zdmc, " +
            " yb.main_operate_code as ssbm, yb.main_operate_name as ssmc " +
            " from yb_css_setl_info yb, yb_css_setl_dept_info ks " +
            " where yb.flag = '0' and ks.flag = 'Y' " +
            " and ks.setl_id = yb.setl_id " +
            " and ks.settl_time &gt;= #{beginTime} " +
            " and ks.settl_time &lt;= #{endTime} " +
            " and ks.dept_id = #{deptId} " +
            " <if test=\"doctorId != null and doctorId != '' \">" +
            " and ks.doctor_id = #{doctorId} " +
            " </if> " +
            " <if test=\"doctorId == null || doctorId == '' \">" +
            " and (ks.doctor_id is null or ks.doctor_id = '') " +
            " </if> " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and ks.medins_type = #{insurName} " +
            " </if> " +
            " </script> ")
    List<Map<String, Object>> selectBrJsTj(@Param("beginTime") String beginTime, @Param("endTime") String endTime,
                                           @Param("deptId") String deptId, @Param("doctorId") String doctorId, @Param("insurName") String insurName);

    @Select("<script> " +
            " select '合计' as deptName,  " +
            " sum(ks.medical_total_fee) as zfy,  " +
            " sum(ks.reimburse_amount) as tczf,  " +
            " sum(ks.estimated_payment) as yjzf, " +
            " round(sum(ks.reimburse_amount)/sum(ks.medical_total_fee) * 100, 2) bxbl, " +
            " sum(ks.real_score) as zfz, sum(ks.bal) bal  " +
            " from yb_css_setl_info yb, yb_css_setl_dept_info ks " +
            " where yb.flag = '0' and ks.flag = 'Y' " +
            " and ks.setl_id = yb.setl_id " +
            " and ks.settl_time &gt;= #{beginTime} " +
            " and ks.settl_time &lt;= #{endTime} " +
            " and ks.dept_id = #{deptId} " +
            " <if test=\"doctorId != null and doctorId != '' \">" +
            " and ks.doctor_id = #{doctorId} " +
            " </if> " +
            " <if test=\"doctorId == null || doctorId == '' \">" +
            " and (ks.doctor_id is null or ks.doctor_id = '') " +
            " </if> " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and ks.medins_type = #{insurName} " +
            " </if> " +
            " </script> ")
    Map<String, Object> selectBrJsTjTotal(@Param("beginTime") String beginTime, @Param("endTime") String endTime,
                                      @Param("deptId") String deptId, @Param("doctorId") String doctorId, @Param("insurName") String insurName);

    @Select(" select * from yb_imp_info where imp_flag = '0' and imp_insur_name = #{insurName} ")
    List<YbImpInfo> getImpXh(@Param("insurName") String insurName);

    @Insert("<script> " +
            " insert into yb_css_imp " +
            " (psn_name, id_card, ill_code, ill_name, main_diagn_code, main_diagn_name, main_operate_code, main_operate_name, " +
            " indays, medical_total_fee, reimburse_amount, treatment, declaration_type, score, deduct_score, deduct_score_remark, " +
            " yb_dept_code, hospital_no, hospital_name, doctor, admission_time, discharge_time, settl_time, hospital_group, " +
            " pat_no, setl_id, medins_type, imp_time, imp_oprt, flag, remark) values " +
            " <foreach collection='list' item='item' separator=','> " +
            " (#{item.psnName}, #{item.idCard}, #{item.illCode}, #{item.illName}, #{item.mainDiagnCode}, #{item.mainDiagnName}, " +
            " #{item.mainOperateCode}, #{item.mainOperateName}, #{item.indays}, #{item.medicalTotalFee}, #{item.reimburseAmount}, " +
            " #{item.treatment}, #{item.declarationType}, #{item.score}, #{item.deductScore}, #{item.deductScoreRemark}, " +
            " #{item.ybDeptCode}, #{item.hospitalNo}, #{item.hospitalName}, #{item.doctor}, " +
            " #{item.admissionTime}, #{item.dischargeTime}, #{item.settlTime}, #{item.hospitalGroup}, #{item.patNo}, #{item.setlId}, " +
            " #{item.medinsType}, #{item.impTime}, #{item.impOprt}, #{item.flag}, #{item.remark}) " +
            " </foreach> " +
            " </script> ")
    void batchInsertImportData(@Param("list") List<YbCssImp> list);

    @Select("<script> " +
            " <foreach collection='list' item='item' separator='union all'> " +
            " select t.* from " +
            " (select sum(a.charge_fee) as charge_fee, a.ward_code, a.refer_physician, rtrim(a.inpatient_no) as inpatient_no, a.admiss_times, a.ledger_sn, " +
            " rtrim(z.name) as execUnitName, rtrim(e.name) as consultPhysician " +
            " from zy_detail_charge a " +
            " left join zd_unit_code z on a.ward_code = z.code " +
            " left join a_employee_mi e on a.refer_physician = e.code " +
            " where a.inpatient_no = #{item.patNo} and a.admiss_times = #{item.times} " +
            " group by a.ward_code, a.refer_physician, z.name, e.name, a.inpatient_no, a.admiss_times, a.ledger_sn) t " +
            " where t.charge_fee &lt;&gt; 0 " +
            " </foreach> " +
            " </script> ")
    List<ZyDetailCharge> selectDeptShareFee(@Param("list") List<YbSetlInfo> list);

    @Update("<script> " +
            " update yb_css_imp set flag = '-1' where medins_type = #{insurName} " +
            " and setl_id in " +
            " <foreach collection='list' item='item' open='(' close=')' separator=','> " +
            " #{item.setlId} " +
            " </foreach> " +
            " </script> ")
    void updateImportData(@Param("insurName") String insurName, @Param("list") List<YbCssImp> list);

    @Select(" select top 1 * from yb_param_info where param_type = 'setl_cc' and medins_type = #{insurName} and valid_year = #{year} ")
    YbParamInfo selectSetlYbParamInfo(@Param("insurName") String insurName, @Param("year") String year);

    @Select(" <script> " +
            " select * from yb_param_info " +
            " where valid_year = #{year} " +
            " <if test=\"type != null and type != '' \"> " +
            " and param_type = #{type} " +
            " </if> " +
            " </script> ")
    List<YbParamInfo> selectYbParamInfoByYear(@Param("year") String year, @Param("type") String type);

    @Select("<script> " +
            " select " +
            " rtrim(inpatient_no) inpatient_no, admiss_times, dis_diag_no, dis_diag_type, " +
            " case  when yb_code is null then rtrim(dis_diag) else rtrim(yb_code) end dis_diag, " +
            " case  when yb_name is null then rtrim(dis_diag_comment) else rtrim(yb_name) end dis_diag_comment, " +
            " op_id_code, op_diag_date, dis_diag_bzfx, dis_diag_status, operation, si_diag_type,admiss_cond, dept_code " +
            " from ${tableName} left join zd_icd_code_new on (dis_diag = code) " +
            " where inpatient_no = #{patNo} and admiss_times = #{times} " +
            " order by dis_diag_no " +
            " </script> ")
    List<YbZyDisDiag> selectYbDiganInfo(@Param("patNo") String patNo, @Param("times") Integer times, @Param("tableName") String tableName);

    @Select("select ssys_name = (select top(1) rtrim(name) from a_employee_mi where code = ssys), " +
            "       sszsName1 = (select top(1) rtrim(name) from a_employee_mi where code = sszs1), " +
            "       sszsName2 = (select top(1) rtrim(name) from a_employee_mi where code = sszs2), " +
            "       mzys_name = (select top(1) rtrim(name) from a_employee_mi where code = mzys)," +
            "       bah, zyh, zycs, ssxh, ssrq, sstj, " +
            "       ssys , sszs1, sszs2, mzys ,op_start_date, op_end_date, anst_start_date, anst_end_date," +
            "       op_start_date as oprn_oprt_begntime," +
            "       op_end_date as  oprn_oprt_endtime," +
            "       anst_start_date as anst_begntime," +
            "       anst_end_date as anst_endtime, " +
            " case when yb_code is null then rtrim(ssbm) else rtrim(yb_code) end  ssbm ," +
            " case when yb_name is null then rtrim(ssmc) else rtrim(yb_name) end  ssmc," +
            " rtrim(mzff) mzff, rtrim(qkjb) qkjb," +
            "rtrim(yhqk) yhqk, ssbfz, fhqk, ssjb, cut_heal," +
            "(select top(1) yb_code from a_employee_mi where code = ssys) as oper_dr_code, " +
            "(select top(1) yb_code from a_employee_mi where code = mzys) as anst_dr_code " +
            "from ${tableName} left join zd_icd9_cm3 on (ssbm = zd_icd9_cm3.code)  " +
            "where zyh = #{patNo} and zycs = #{times} " +
            "order by ssxh")
    List<BatjBa4> selectYbOprtInfo(@Param("patNo") String patNo, @Param("times") Integer times, @Param("tableName") String tableName);

    @Select("<script> " +
            " select t.*, " +
            " rtrim(a.zk_ward) as deptId, rtrim(z.name) as deptName, " +
            " rtrim(a.refer_physician) as doctorId, rtrim(e.name) as doctor " +
            " from t_si_setlinfo t " +
            " left join zy_inactpatient a on t.pat_no = a.inpatient_no and t.times = a.admiss_times " +
            " left join zd_unit_code z on a.zk_ward = z.code " +
            " left join a_employee_mi e on a.refer_physician = e.code " +
            " where t.revoked = '0' and t.setl_id in " +
            " <foreach collection='list' item='item' open='(' close=')' separator=','> " +
            " #{item.setlId} " +
            " </foreach> " +
            " </script> ")
    List<YbSetlInfo> selectSetlInfo(@Param("list") List<YbCssImp> list);

    @Update("<script> " +
            " update yb_css_setl_info set flag = '-1' " +
            " where setl_id in " +
            " <foreach collection='list' item='item' open='(' close=')' separator=','> " +
            " #{item.setlId} " +
            " </foreach> " +
            " </script> ")
    void updateYbCssSetlInfoData(@Param("list") List<YbCssSetlInfo> list);

    @Insert("<script> " +
            " insert into yb_css_setl_info " +
            " (setl_id, pat_no, medins_type, dept_id, dept_name, psn_name, id_card, ill_code, ill_name, " +
            " main_diagn_code, main_diagn_name, main_operate_code, main_operate_name, " +
            " indays, medical_total_fee, reimburse_amount, treatment, declaration_type, score, deduct_score, " +
            " doctor, admission_time, discharge_time, settl_time, " +
            " flag, create_time, times, doctor_id, estimated_payment, bal, real_score, ledger_sn) values " +
            " <foreach collection='list' item='item' separator=','> " +
            " (#{item.setlId}, #{item.patNo}, #{item.medinsType}, #{item.deptId}, #{item.deptName}, #{item.psnName}, #{item.idCard}, " +
            " #{item.illCode}, #{item.illName}, #{item.mainDiagnCode}, #{item.mainDiagnName}, " +
            " #{item.mainOperateCode}, #{item.mainOperateName}, #{item.indays}, #{item.medicalTotalFee}, #{item.reimburseAmount}, " +
            " #{item.treatment}, #{item.declarationType}, #{item.score}, #{item.deductScore}, " +
            " #{item.doctor}, #{item.admissionTime}, #{item.dischargeTime}, #{item.settlTime}, " +
            " #{item.flag}, #{item.createTime}, #{item.times}, #{item.doctorId}, " +
            " #{item.estimatedPayment}, #{item.bal}, #{item.realScore}, #{item.ledgerSn}) " +
            " </foreach> " +
            " </script> ")
    void insertYbCssSetlInfoData(@Param("list") List<YbCssSetlInfo> list);

    @Update("<script> " +
            " update yb_css_setl_dept_info set flag = 'N' " +
            " where setl_id in " +
            " <foreach collection='list' item='item' open='(' close=')' separator=','> " +
            " #{item.setlId} " +
            " </foreach> " +
            " </script> ")
    void updateYbCssSetlDeptInfo(@Param("list") List<YbCssSetlDeptInfo> list);

    @Insert("<script> " +
            " insert into yb_css_setl_dept_info " +
            " (setl_id, pat_no, times, medins_type, dept_id, dept_name, " +
            " doctor_id, doctor, short_no, medical_total_fee, reimburse_amount, real_score, " +
            " estimated_payment, bal, flag, create_time, settl_time, ledger_sn) values " +
            " <foreach collection='list' item='item' separator=','> " +
            " (#{item.setlId}, #{item.patNo}, #{item.times}, #{item.medinsType}, #{item.deptId}, #{item.deptName}, " +
            " #{item.doctorId}, #{item.doctor}, #{item.shortNo}, #{item.medicalTotalFee}, #{item.reimburseAmount}, " +
            " #{item.realScore}, #{item.estimatedPayment}, #{item.bal}, " +
            " #{item.flag}, #{item.createTime}, #{item.settlTime}, #{item.ledgerSn}) " +
            " </foreach> " +
            " </script> ")
    void insertYbCssSetlDeptInfo(@Param("list") List<YbCssSetlDeptInfo> list);

    @Select("<script> " +
            " select rtrim(b.code) as deptId, rtrim(b.name) as cyks, rtrim(a.name) as ryks, " +
            " rtrim(e.name) as doctor, rtrim(zy.refer_physician) as doctorId, " +
            " t.pat_no as zyh, t.times as zycs, t.psn_name as xm, t.medins_type as yblx, " +
            " t.medfee_sumamt as zfy, t.fund_pay_sumamt as tczf, t.setl_time as jssj, " +
            " round(t.fund_pay_sumamt/t.medfee_sumamt * 100, 2) bxbl, " +
            " zy.operation as zlfs, zy.dec_type as sblx " +
            " from t_si_setlinfo t, zy_inactpatient zy " +
            " left join zd_unit_code a on zy.small_dept = a.code " +
            " left join zd_unit_code b on zy.zk_ward = b.code " +
            " left join a_employee_mi e on e.code = zy.refer_physician " +
            " where t.revoked = '0' and t.setl_type = '21' " +
            " and t.pat_no = zy.inpatient_no " +
            " and t.times = zy.admiss_times " +
            " and t.medins_type in ('长沙市城职普通住院','长沙市城居普通住院') " +
            " and t.setl_time &gt;= #{beginTime} " +
            " and t.setl_time &lt;= #{endTime} " +
            " <if test=\"dept != null and dept != '' \">" +
            " and rtrim(b.name) = #{dept} " +
            " </if> " +
            " <if test=\"zyh != null and zyh != '' \">" +
            " and rtrim(t.pat_no) = #{zyh} " +
            " </if> " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and t.medins_type = #{insurName} " +
            " </if> " +
            " </script> ")
    List<Map<String, Object>> selectCssYbCsTj(@Param("beginTime") String beginTime, @Param("endTime") String endTime,
        @Param("dept") String dept, @Param("insurName") String insurName, @Param("zyh") String zyh);

}
