package thyyxxk.webserver.dao.his;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.*;
import thyyxxk.webserver.entity.casefrontsheet.YshHzRecord;
import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.entity.login.UserInfo;
import thyyxxk.webserver.entity.login.UserInfoSelect;
import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyPatientInfo;
import thyyxxk.webserver.entity.publicapi.ItemDrug;
import thyyxxk.webserver.entity.publicapi.ZkList;
import thyyxxk.webserver.entity.socketmessage.SocketMessage;
import thyyxxk.webserver.entity.inpatient.ZyActpatient;
import thyyxxk.webserver.entity.zhuyuanyisheng.PatientAllergenInfo;
import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzActOrderCy;
import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.YshYjReq;
import thyyxxk.webserver.entity.zhuyuanyisheng.shoushu.OpRecord;
import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.YaoPinXiangMu;

import javax.print.DocFlavor;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 描述： 公共接口
 * </p>
 *
 * @author xc
 * @date 2021-09-17 10:54
 */
@Mapper
public interface PublicDao {
    /**
     * 查询医嘱
     *
     * @return 返回医嘱号
     */
    @Select("select cast(act_order_no as decimal(14)) as act_order_no from yz_sequence WITH (TABLOCKX)")
    BigDecimal getActOrderNo();


    @Select("select cast(order_code as decimal(14)) as act_order_no from yz_sequence WITH (TABLOCKX)")
    BigDecimal getOrderCode();

    @Update("update yz_sequence set order_code = #{newId} where order_code = #{oldId} ")
    int updateOrderNo(BigDecimal newId, BigDecimal oldId);


    @Select("select supply_code from yz_sequence")
    int getSupply();

    @Select("select max(supply_code) from mz_zd_supply_type")
    int getMzSupply();

    @Update("update yz_sequence set supply_code = #{newSupply} where supply_code = #{oldSupply} ")
    int updateSupply(int oldSupply,int newSupply);

    /**
     * @return 获取模板的自增id
     */
    @Select("select pattern_code from yz_sequence WITH (TABLOCKX) ")
    Integer getPatternCode();

    @Update("update yz_sequence set pattern_code = #{newId} where pattern_code = #{oldId} ")
    int updatePatternCode(Integer newId, Integer oldId);

    @Select("select cast(p_act_order_no as decimal(9)) from yz_sequence WITH (TABLOCKX)")
    BigDecimal getPatternOrderCode();

    @Update("update yz_sequence set p_act_order_no = #{newId} where p_act_order_no = #{oldId} ")
    int updatePatternOrderCode(BigDecimal newId, BigDecimal oldId);

    @Update("update yz_sequence set act_order_no = #{newOrderNo} where act_order_no = #{oldOrderNo} ")
    int updateActOrderNo(BigDecimal newOrderNo, BigDecimal oldOrderNo);

    @Select("select req_no from ysh_config WITH (TABLOCKX) ")
    Integer getReqNo();

    @Update("update ysh_config set req_no =#{newId} where req_no = #{oldId} ")
    int updateReqNo(Integer newId, Integer oldId);

    @Select("select yj_template_no from ysh_config WITH (TABLOCKX) ")
    Integer tempNo();

    @Update("update ysh_config set yj_template_no = #{newId} where yj_template_no = #{oldId} ")
    int updateTempNo(Integer newId, Integer oldId);

    /**
     * 获取 这个科室 的子科室
     *
     * @param deptCode 科室编码
     * @return 返回自生和子科室
     */
    @Select("select RTRIM(code) " +
            "from zd_unit_code " +
            "where (parent_code = #{deptCode}) " +
            "  and isnull(del_flag, 0) = 0;")
    List<String> getKeShiLieBiao(String deptCode);

    @Select("select RTRIM(code) " +
            "from zd_unit_code " +
            "where ${ew.sqlSegment}" +
            "and isnull(del_flag, 0) = 0")
    List<String> selectChildDeptByCodeList(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);

    @Select("<script>" +
            "select code from zd_unit_code where (parent_code in " +
            "<foreach collection='deptCodeList' item='item' index='index' open='(' close=')' separator=','>" +
            " #{item,jdbcType = CHAR}" +
            "</foreach> " +
            "or code in " +
            "<foreach collection='deptCodeList' item='item' index='index' open='(' close=')' separator=','>" +
            "#{item,jdbcType = CHAR}" +
            "</foreach>" +
            ") and isnull(del_flag,0) = 0" +
            "</script>")
    List<String> getKeShiLieBiaoList(@Param("deptCodeList") List<String> deptCodeList);

    /**
     * 获取人员信息
     *
     * @param code 人员代码
     * @return 返回人员
     */
    @Select("<script>" +
            "select distinct rtrim(code) as code,rtrim(name) as name,py_code, d_code as w_code," +
            " dept_name = (select rtrim(name) from zd_unit_code where zd_unit_code.code = dept_code)," +
            " emp_tit_name  = (select rtrim(name) from zd_emp_title where zd_emp_title.code = emp_tit_code)," +
            " rtrim(yb_code) as  yb_code " +
            "from a_employee_mi where " +
            "(code like #{code} or name like #{code} or code_rs like #{code} or py_code like #{code}) " +
            "and isnull(del_flag,0) = 0 " +
            "<if test=\"deptCode != null and deptCode != '' \">" +
            "and dept_code = #{deptCode} " +
            "</if>" +
            "</script>")
    List<GetDropdownBox> getRenYuan(String code, String deptCode);

    /**
     * @param pyCode 拼音编码
     * @return 获取项目的名称和code
     */
    @Select("select distinct code,name from  zd_charge_item where (py_code like #{pyCode} or code like #{pyCode} or name like #{pyCode})" + "union all " + "select distinct code,name from  yp_zd_dict where (py_code like #{pyCode} or code like #{pyCode} or name like #{pyCode})")
    List<GetDropdownBox> getChargeCode(String pyCode);

    @Select("select distinct rtrim(code) + '_' + rtrim(serial) as code, name " + "from yp_zd_dict " + "where (code like #{name} or name like #{name} or py_code like #{name} or d_code like #{name})")
    List<GetDropdownBox> getDrugInfo(String name);

    @Select("select rtrim(code) code,rtrim(name) name , rtrim(py_code) as py_code , rtrim(d_code) as dcode from zd_unit_code where isnull(del_flag,'0') <> '1'")
    List<GetDropdownBox> getDept();

    @Select("select rtrim(code) code,rtrim(name) name from zd_unit_code with(nolock)" +
            "where isnull(del_flag,0) = 0 and code not like '8%' and " +
            "(py_code like #{pyCode} or name like #{pyCode} or code like #{pyCode})")
    List<GetDropdownBox> queryDept(String pyCode);


    @Select("select isnull(max(ledger_sn),1)  from zy_ledger_file where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes}")
    Integer getLedgerSn(@Param("inpatientNo") String inpatient, @Param("admissTimes") Integer admissTimes);


    @Select("select rtrim(inpatient_no) inpatient_no,admiss_times,admiss_date,dis_date,name, " +
            "responce_name = (select rtrim(name) name from zy_zd_responce_type where code = responce_type)," +
            "responce_type,  " + "rtrim(zk_ward) as dept,ward,ward_name = (select rtrim(name) name from zd_unit_code where code = ward), " +
            "ledger_sn = (select max(ledger_sn) from zy_ledger_file where a.inpatient_no = zy_ledger_file.inpatient_no and a.admiss_times = zy_ledger_file.admiss_times), " +
            "chu_yuan_yi_zhu = (case when (select count(1) from yz_act_order where inpatient_no= a.inpatient_no and admiss_times= a.admiss_times " +
            "and status_flag > '2' and isnull(group_no,'00' )='00' and order_code in " +
            "(select order_code from yz_zd_order_item_confirm where item_name in (N'出院',N'死亡'))) > 0 " +
            "then 1 " +
            "when (select count(1) from yz_inact_order where inpatient_no= a.inpatient_no and admiss_times= a.admiss_times " +
            "and status_flag > '2' and isnull(group_no,'00' )='00' and order_code in " +
            "(select order_code from yz_zd_order_item_confirm where item_name in (N'出院',N'死亡'))) > 0 " +
            "then 1 else 0 end  ), " + "bed_no,total_charge,balance,zy_serial_no " +
            " from zy_actpatient a " +
            "where inpatient_no = #{inpatientNo} ")
    ZyActpatient getHuanZheJiBenXinXi(@Param("inpatientNo") String inpatientNo);

    @Update("update zy_detail_charge set ori_detail_sn = null where inpatient_no = #{inpatientNo} " + "and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} and ori_detail_sn = -1 and charge_amount > 0")
    void chongZhiZhenLiuShui(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes, @Param("ledgerSn") Integer ledgerSn);

    @Select("select ori_detail_sn from zy_detail_charge where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} " + "and ori_detail_sn is not null " + "and  charge_amount < 0")
    List<Integer> huoQuTuiFeiYuanLiuShui(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes, @Param("ledgerSn") Integer ledgerSn);

    @Update("<script>" + "update zy_detail_charge set ori_detail_sn = -1 where inpatient_no = '${inpatientNo}' and admiss_times = ${admissTimes} and ledger_sn = ${ledgerSn} " + "and charge_amount &gt; 0 and detail_sn in " + "<foreach collection='list' item='item' index='index' open='(' close=')' separator=','>" + "${item}" + "</foreach>" + "</script>")
    void genXingFuShuDuiYingZhenLiuShui(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes, @Param("ledgerSn") Integer ledgerSn, @Param("list") List<Integer> detailSnList);

    @Select("select ori_detail_sn,sum(charge_fee) charge_fee,sum(charge_amount) charge_amount " + "from zy_detail_charge a " + "where inpatient_no=#{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn}  and order_no <> 6 and trans_flag_yb <> 2 " + "  and ori_detail_sn is not null and charge_amount<0 " + "group by ori_detail_sn having count(1) > 1")
    List<ZyDetailCharge> chongFuTuiFeiLiuShui(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes, @Param("ledgerSn") Integer ledgerSn);

    @Select("<script>" + "select detail_sn,charge_fee,charge_amount from zy_detail_charge where inpatient_no=#{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} " + "and detail_sn in " + "<foreach collection='oriSn' item='sn' open='(' close=')' separator=','>" + "#{sn}" + "</foreach>" + "</script>")
    List<ZyDetailCharge> getZhenShuLiuShui(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes, @Param("ledgerSn") Integer ledgerSn, @Param("oriSn") Set<Integer> oriSn);

    @Update("<script>" + "<foreach collection='list' item='item' separator=';'>" + "update zy_detail_charge set ori_detail_sn = null  where  inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn =  #{ledgerSn} " + "and (detail_sn = #{item} or ori_detail_sn = #{item}) " + "</foreach>" + "</script>")
    void chongFuTuiFeiChongZhi(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes, @Param("ledgerSn") Integer ledgerSn, @Param("list") List<Integer> oriDetailSn);

    @Select("select isnull(sum(charge_fee),0)  from zy_detail_charge  " + "where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} and trans_flag_yb=2")
    BigDecimal zhenFuXingDiFeiYong(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes, @Param("ledgerSn") Integer ledgerSn);

    @Update("update zy_detail_charge set trans_flag_yb = 0 where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} and " + "trans_flag_yb = 2")
    void chongXingZhengFuXiangDi(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes, @Param("ledgerSn") Integer ledgerSn);

    @Select("select detail_sn from zy_detail_charge where inpatient_no= #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} " + "and trans_flag_yb <> 2 and charge_amount > 0 and ori_detail_sn is not null")
    List<Integer> zhenShuLiuShui(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes, @Param("ledgerSn") Integer ledgerSn);

    @Select("select ori_detail_sn from zy_detail_charge where  inpatient_no= #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} " + "and trans_flag_yb <> 2 and charge_amount < 0 and ori_detail_sn is not null")
    List<Integer> fuShuLiuShui(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes, @Param("ledgerSn") Integer ledgerSn);

    @Update("<script>" + "<foreach collection='list' item='item' separator=';'>" + "update zy_detail_charge set ori_detail_sn = null where inpatient_no= #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} " + "and charge_fee &lt; 0 and ori_detail_sn = #{item}" + "</foreach>" + "</script> ")
    void chongZhiFuShuYuanLiuShui(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes, @Param("ledgerSn") Integer ledgerSn, @Param("list") List<Integer> oriDetailSn);

    @Select("select top(1) code,dept_code,name,code_rs,rtrim(yb_code) yb_code" + " from a_employee_mi where (code = #{code}  or code_rs = #{code}) and isnull(del_flag,0) = 0 ")
    UserInfo huoQuYuanGongBianMa(String code);

    @Select("SELECT small_dept FROM zd_dept_all where dept = #{deptCode}")
    List<String> bingFangSuoSuKeShi(String deptCode);

    // 重置 流水号
    @Select("select row_number() over (order by charge_date ) row_index, " + "       ledger_sn, " + "       detail_sn " + "from zy_detail_charge " + "where inpatient_no = '${patNo}' " + "  and admiss_times = ${times} ")
    List<ZyDetailCharge> huoQuZhongYeFeiYong(@Param("patNo") String patNo, @Param("times") Integer times);

    @Select("select count(1) " + "from zy_detail_charge " + "where inpatient_no = '${patNo}' " + "  and admiss_times = ${times}")
    int maxDetailSn(@Param("patNo") String patNo, @Param("times") Integer times);


    @Update("<script>" + "<foreach collection='list' item='item' separator=';' index='index' >" + "update zy_detail_charge set detail_sn = ${item.rowIndex} + ${maxDetailSn} " + "where inpatient_no= '${patNo}' and admiss_times = ${times} and ledger_sn = ${item.ledgerSn}  and detail_sn = ${item.detailSn}" + "</foreach>" + "</script>")
    void chongZhiLiuShui(@Param("patNo") String patNo, @Param("times") Integer times, @Param("list") List<ZyDetailCharge> list, @Param("maxDetailSn") int maxDetailSn);


    @Select("select rtrim(code) code,rtrim(name) name from zd_anaesthesia")
    List<GetDropdownBox> maZuiFangShi();

    @Update("update ysh_config set tc_no =tc_no")
    void jianYanJianChaSuo();

    @Select("select tc_no from ysh_config ")
    Integer jianYanJianChaXuHao();

    @Update("update ysh_config set tc_no = #{tcNo}")
    void genXingJianYanJianChaXuHao(Integer tcNo);

    @Update("update op_config set op_record_id =op_record_id ")
    void suoZhuShouShu();

    @Select("select op_record_id from op_config")
    Integer shouShuXuHao();

    @Update("update op_config set op_record_id =#{code} ")
    void genXingShouShuXuHao(Integer code);

    @Select("select page_no from yz_sequence WITH (TABLOCKX) ")
    Integer caoYaoDanHao();

    @Select("EXEC get_the_drug_list_no")
    Integer caoYaoDanHaot();

    @Update("update yz_sequence set page_no = #{newId} where page_no = #{oldId} ")
    int genXingCaoYaoDanHao(@Param("newId") Integer newId, @Param("oldId") Integer oldId);

    @Select("select card_no from crb_config")
    Integer oldCrbNo();

    @Update("update crb_config set card_no =#{newId} where card_no = #{oldId}")
    int updateCrbNo(Integer newId, Integer oldId);

    @Select("select top (1) cast(settle_type as int) as settle_type " + "from zy_ledger_file " + "where inpatient_no = #{patNo} " + "  and admiss_times = #{times} " + "order by ledger_sn desc")
    Integer jieSuanXinXi(@Param("patNo") String patNo, @Param("times") Integer times);

    @Select("select * " + "from ysh_hz_record " + "where act_order_no = #{actOrder}")
    YshHzRecord huiZhen(BigDecimal actOrder);

    @Select("select * " + "from ysh_yj_req " + "where act_order_no = #{actOrder}")
    YshYjReq yiJi(BigDecimal actOrder);

    @Select("select * " + "from op_record " + "where act_order_no = #{actOrder}")
    OpRecord shouShu(BigDecimal actOrder);

    @Select("select * " + "from yz_act_order_cy " + "where order_no = #{actOrder}")
    YzActOrderCy caoYao(BigDecimal actOrder);


    @Select("select cast(rtrim(isnull(nullif(del_flag, ''), 0)) as int) del_flag," + "national_code,rtrim(code) + '-' + rtrim(serial) code,rtrim(name) name, rtrim(name) as zd_name,rtrim(code) zd_code,rtrim(serial) serial " + "from yp_zd_dict " + "${ew.customSqlSegment}")
    List<YaoPinXiangMu> huoQuYaoPinPiPeiXinXi(@Param(Constants.WRAPPER) Wrapper<?> wp);


    @Select("<script>" +
            "select rtrim(a.order_code) code, " +
            "       rtrim(a.order_name) name, " +
            "       national_code, " +
            "       rtrim(c.code) as zd_code," +
            "       rtrim(c.name) as zd_name," +
            "       cast(rtrim(isnull(nullif(c.del_flag, ''), 0)) as int) del_flag," +
            "       serial = '00' " + "from yz_order_item a with (NOLOCK) , " +
            "     yz_order_occurence b with (NOLOCK) , " +
            "     zd_charge_item c with (NOLOCK)" +
            "where a.order_code in " +
            "<foreach collection='code' item='item' index='index' open='(' close=')' separator=','>" +
            "#{item}" +
            "</foreach>" +
            "  and a.order_code = b.order_code " +
            "  and b.occ_code = c.code" +
            "</script>")
    List<YaoPinXiangMu> huoQuXiangMuXinXi(List<String> code);


    /**
     * 获取患者的科室发送信息
     *
     * @param wardCode 科室编码
     * @return 数据
     */
    @Select("select code " +
            "from a_employee_mi " +
            "where dept_code = #{wardCode} " +
            "  and isnull(del_flag, 0) <> 1 " +
            "  and emp_tit_code = '010' ")
    List<String> huoQuHuanZheBingFangDeHuShi(String wardCode);


    @Insert({"<script>" +
            "insert t_socket_message (id,sender, title, content,  pat_id) values " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.id},#{item.sender},#{item.title},#{item.content},#{item.patId})" +
            "</foreach>" +
            "</script>"})
    void chaRuTongZhiXinXi(@Param("list") List<SocketMessage> list);


    @Insert({"<script>" + "insert into t_socket_message_consumer (msg_id, sender, receiver) values " + "<foreach collection='list' item='item' separator=','>" + " (#{item.msgId}, #{item.sender}, #{item.receiver})" + "</foreach>" + "</script>"})
    void chaRuJieShouShuJu(@Param("list") List<SocketMessage> list);

    @Select("select rtrim(${id}) as code, rtrim(${name}) as name from ${table} where isnull(${pyColumn}, '')='' ")
    List<CodeName> originalList(@Param("table") String table, @Param("id") String id, @Param("name") String name, @Param("pyColumn") String pyColumn);

    @Select("select rtrim(${id}) as code, rtrim(${name}) as name from ${table} where isnull(${dColumn}, '')='' ")
    List<CodeName> originalDCodeList(@Param("table") String table, @Param("id") String id, @Param("name") String name, @Param("dColumn") String dColumn);

    @Update("update ${table} set ${pyColumn}='${pyCode}' where ${idColumn}='${id}' ")
    void updatePycode(@Param("table") String table, @Param("idColumn") String idColumn, @Param("id") String id, @Param("pyColumn") String pyColumn, @Param("pyCode") String pyCode);

    @Update("update ${table} set ${dColumn}='${dCode}' where ${idColumn}='${id}' ")
    void updateDcode(@Param("table") String table, @Param("idColumn") String idColumn, @Param("id") String id, @Param("dColumn") String dColumn, @Param("dCode") String dCode);

    @Select("select code, name " + "from zd_allergen " + "where (wb_code like #{name} or py_code like #{name} or name like #{name})")
    List<GetDropdownBox> getAllergens(@Param("name") String name);

    @Select("select allergen_code, (select name from zd_allergen where zd_allergen.code = allergen_code) as allergenName, id,type " + "from patient_allergen_info " + "where pat_no = #{patNo} " + "  and type = 0 " + "union all " + "select allergen_code, (select name from yp_zd_dict b where rtrim(b.code) + '_' + rtrim(b.serial) = allergen_code) as allergenName, id,type " + "from patient_allergen_info " + "where pat_no = #{patNo} " + "  and type = 1")
    List<PatientAllergenInfo> getPatientAllergens(@Param("patNo") String patNo);

    @Select("select count(1) from patient_allergen_info where pat_no = #{patNo}")
    int whetherThePatientHasAllergens(String patNo);

    @Insert("insert into patient_allergen_info (pat_no, allergen_code,type) values (#{patNo},#{allergenCode},#{type})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    void newPatientAllergens(PatientAllergenInfo param);

    @Delete("delete from patient_allergen_info where id = #{id}")
    void removePatientAllergens(Integer id);


    @Select("select * from bld_cat_code where (code = #{name} or name like #{name})")
    List<GetDropdownBox> getBldCat(String name);

    @Select("SELECT distinct rtrim(a.dept_code) as dept_code, " + "                rtrim(a.dept_name) as dept_name, " + "                rtrim(a.ward_code) as ward_code, " + "                rtrim(a.ward_name) as ward_name, " + "                rtrim(b.small_dept) as small_code, " + "                small_name = (select rtrim(name) name from zd_unit_code where code = small_dept) " + "FROM zy_adtward a, " + "     zd_dept_all b " + "where a.ward_code = b.dept")
    List<ZkList> getTheTransferList();

    @Select("select RTRIM(code) AS code,RTRIM(name) AS name from  zd_emp_position where isnull(del_flag,0) = 0")
    List<GetDropdownBox> getEmpPosition();

    @Select("select RTRIM(code) AS code,RTRIM(name) AS name " + "from zd_emp_inmark")
    List<GetDropdownBox> getEmpInmark();

    @Select("select RTRIM(code) AS code,RTRIM(name) AS name " + "from zd_ifcadre")
    List<GetDropdownBox> getZdIfcadre();

    @Select("select RTRIM(code) AS code,RTRIM(name) AS name " + "from zd_emp_title " + "where isnull(del_flag, 0) = 0")
    List<GetDropdownBox> getZdEmpTitle();

    @Select("select RTRIM(code) AS code,RTRIM(name) AS name " + "from mzy_zd_charge_type " + "where isnull(del_flag, 0) = 0")
    List<GetDropdownBox> getMzyZdChargeType();

    @Update("update rs_config " + "set rs_code =rs_code")
    void lockThePersonnelCodeTable();

    @Select("select rs_code + 1 " + "from rs_config")
    Integer getPersonnelCode();

    @Update("update rs_config " + "set rs_code = #{code}")
    void updateStaffCodeTable(Integer code);

    @Select("SELECT             rtrim(code_rs) as uid, " + "                   rtrim(name)    as displayName, " + "    manager      = '', /*1 就是有审核权限*/ " + "    oldUid       = '', " + "    userPassword = '123456', " + "    ou=            '001', " + "    _id          = 'Emr.model.EmrUsers-' + cast(row_number() over (order by code ) + 2 as varchar), " + "                   phone_no       as mobile " + "from a_employee_mi " + "where isnull(del_flag, 0) = 0 " + "  and (select role_id from dj_user_role where dj_user_role.user_code = a_employee_mi.code and role_id = 11) = 11")
    List<Map<String, String>> emrAdd();

    @Select("SELECT rtrim(dept_code)  code ,rtrim(dept_name) name  FROM zy_adtward WHERE PATINDEX('8%',ward_code)=0 ")
    List<GetDropdownBox> getZhuYuanDept();

    @Select("select group_name from yp_zd_group_name where group_no = #{groupNo} ")
    String getGroupName(String groupNo);

    @Select("select count(1) from new_act_order_recording where act_order_no = #{orderNo} ")
    int selectRecordByOrderNo(BigDecimal orderNo);

    @Insert("insert into new_act_order_recording (act_order_no, creation_id) values (#{orderNo},#{userCode})")
    void insertOrderNoRecord(BigDecimal orderNo,
                             String userCode);

    @Select("select          rtrim(inpatient_no) as inpatient_no, " +
            "                admiss_times, " +
            "                rtrim(name)         as name, " +
            "                rtrim(dept)         as dept_code, " +
            "                rtrim(zk_ward)      as ward_code, " +
            "                refer_physician, " +
            "                times_billed, " +
            "                admiss_date, " +
            "                small_dept, " +
            "                bed_no," +
            "                zk_ward, " +
            "    ledger_sn = (select max(ledger_sn) " +
            "                 from zy_ledger_file with (NOLOCK) " +
            "                 where a.inpatient_no = zy_ledger_file.inpatient_no " +
            "                   and a.admiss_times = zy_ledger_file.admiss_times), " +
            "                consult_physician, " +
            "                dept_director " +
            " from ${table} a with (NOLOCK)  " +
            "where inpatient_no = #{patNo} " +
            "  and admiss_times = #{times} ")
    ZyPatientInfo queryPatientInfo(@Param("patNo") String patNo,
                                   @Param("times") Integer times,
                                   @Param("table") String table);

    @Select("select code, " +
            "       code_rs," +
            "       rtrim(name) name, " +
            "       dept_code, " +
            "       dept_code_name = (select rtrim(name) from zd_unit_code where dept_code = zd_unit_code.code), " +
            "       rtrim(py_code) py_code, " +
            "       rtrim(d_code) d_code," +
            "       title=(select rtrim(name) from zd_emp_title where code=emp_tit_code) " +
            "from a_employee_mi " +
            "where isnull(del_flag, 0) = 0")
    List<UserInfoSelect> getPersonnelAll();

    @Select("select user_config " +
            "from dj_user_base where code = #{code} ")
    String getUserConfigByCode(String code);


    @Update("update dj_user_base set user_config = #{config} where  code = #{code}")
    void setUserConfigByCode(String code, String config);


    @Select("select rtrim(code) as code, rtrim(serial) as serial, rtrim(name) as name " +
            "from yp_zd_dict " +
            "where (name like '${code}' or py_code like '${code}' or d_code like '${code}' or name like '${code}' or code like '${code}') " +
            "union all " +
            "select rtrim(code) as code, '00' as serial, rtrim(name) as name " +
            "from zd_charge_item " +
            "where (name like '${code}' or py_code like '${code}' or d_code like '${code}' or name like '${code}' or code like '${code}')")
    List<ItemDrug> getItemDrug(@Param("code") String code);


    @Select("SELECT small_dept FROM zd_dept_all where dept = #{dept}")
    Set<String> chaXunZhiZXinKeShi(@Param("dept") String dept);

    @Select("select t.trade_no,c.fund_pay_sumamt,c.acct_pay,c.psn_cash_pay from ( " +
            "    select a.trade_no,b.patient_id,b.times,a.total_fee,a.cashpay_amt " +
            "from t_wechat_pay_order a,mz_deposit_file b " +
            "where a.trade_state='SUCCESS' and a.pay_datetime>='2024-05-01' and a.pay_datetime<'2024-06-01' " +
            "and a.order_type=2 and a.trade_no like 'NA%' and (a.fundpay_amt+a.acctpay_amt=0) " +
            "and a.trade_no=b.psordnum and a.total_fee=b.amount " +
            ") t,t_si_setlinfo c where c.pat_no=t.patient_id and c.times=t.times and c.revoked=0 " +
            "and c.psn_cash_pay!=c.medfee_sumamt and t.total_fee=c.medfee_sumamt")
    List<Map<String, Object>> test3();

    @Update("update t_wechat_pay_order set fundpay_amt=#{fundpay}," +
            "acctpay_amt=#{acctpay},cashpay_amt=#{cashpay} where trade_no=#{tradeNo}")
    void test3_1(String tradeNo, String fundpay, String acctpay, String cashpay);


}
