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

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

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

/**
 * @description: 长沙市病种统计
 * @author: hsh
 * @date: 2022/9/20 10:41
 **/
@Mapper
public interface YbCssBzDao {

    @Select(" <script> " +
            " select main_diagn_code as zdbm, main_diagn_name as zdmc, count(setl_id) rs, " +
            " cast(sum(estimated_payment)/count(setl_id) as decimal(10, 2)) as cjyjzf, " +
            " cast(sum(reimburse_amount)/count(setl_id) as decimal(10, 2)) as cjtczf, " +
            " sum(reimburse_amount) as tczf, sum(estimated_payment) as yjzf, sum(bal) bal " +
            " from yb_css_setl_info where flag = '0' " +
            " and settl_time &gt;= #{beginTime} " +
            " and settl_time &lt;= #{endTime} " +
            " <if test=\"dept != null and dept != '' \">" +
            " and dept_name = #{dept} " +
            " </if> " +
            " <if test=\"doctor != null and doctor != '' \">" +
            " and doctor = #{doctor} " +
            " </if> " +
            " <if test=\"bzmc != null and bzmc != '' \">" +
            " and main_diagn_name like '%' + #{bzmc} + '%' " +
            " </if> " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and medins_type = #{insurName} " +
            " </if> " +
            " group by main_diagn_code, main_diagn_name " +
            " order by sum(bal) desc" +
            " </script> ")
    List<Map<String, Object>> selectCssYbBzTj(@Param("beginTime") String beginTime, @Param("endTime") String endTime,
        @Param("dept") String dept, @Param("insurName") String insurName, @Param("bzmc") String bzmc, @Param("doctor") String doctor);

    @Select(" <script> " +
            " select main_diagn_code as zdbm, main_diagn_name as zdmc, " +
            " treatment as zlfs, declaration_type as sblx, real_score as fz, " +
            " estimated_payment as yjzf, reimburse_amount as tczf, bal " +
            " from yb_css_setl_info where flag = '0' " +
            " and settl_time &gt;= #{beginTime} " +
            " and settl_time &lt;= #{endTime} " +
            " <if test=\"dept != null and dept != '' \">" +
            " and dept_name = #{dept} " +
            " </if> " +
            " <if test=\"doctor != null and doctor != '' \">" +
            " and doctor = #{doctor} " +
            " </if> " +
            " <if test=\"bzmc != null and bzmc != '' \">" +
            " and main_diagn_name like '%' + #{bzmc} + '%' " +
            " </if> " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and medins_type = #{insurName} " +
            " </if> " +
            " </script> ")
    List<Map<String, Object>> selectCssYbBzTjMx(@Param("beginTime") String beginTime, @Param("endTime") String endTime,
        @Param("dept") String dept, @Param("insurName") String insurName, @Param("bzmc") String bzmc, @Param("doctor") String doctor);

    @Select(" <script> " +
            " select main_diagn_code as zdbm, main_diagn_name as zdmc, " +
            " dept_id as deptId, dept_name as dept, " +
            " doctor_id as doctorId, doctor, medins_type as insurName, " +
            " treatment as zlfs, declaration_type as sblx, " +
            " sum(medical_total_fee) as zfy, sum(real_score) as fz, count(setl_id) rs, " +
            " sum(estimated_payment) as yjzf, sum(reimburse_amount) as tczf, sum(bal) bal, " +
            " cast(sum(medical_total_fee)/count(setl_id) as decimal(10, 2)) as cjzfy, " +
            " cast(sum(estimated_payment)/count(setl_id) as decimal(10, 2)) as cjyjzf, " +
            " cast(sum(reimburse_amount)/count(setl_id) as decimal(10, 2)) as cjtczf " +
            " from yb_css_setl_info where flag = '0' " +
            " and settl_time &gt;= #{beginTime} " +
            " and settl_time &lt;= #{endTime} " +
            " <if test=\"dept != null and dept != '' \">" +
            " and dept_name = #{dept} " +
            " </if> " +
            " and treatment = #{zlfs} " +
            " and declaration_type = #{sblx} " +
            " and main_diagn_name = #{bzmc} " +
            " <if test=\"doctor != null and doctor != '' \">" +
            " and doctor = #{doctor} " +
            " </if> " +
            " <if test=\"insurName != null and insurName != '' \">" +
            " and medins_type = #{insurName} " +
            " </if> " +
            " group by main_diagn_code, main_diagn_name, dept_id, dept_name, doctor_id, doctor, medins_type, treatment, declaration_type  " +
            " </script> ")
    List<Map<String, Object>> selectBzDbTj(@Param("beginTime") String beginTime, @Param("endTime") String endTime,
        @Param("dept") String dept, @Param("insurName") String insurName, @Param("bzmc") String bzmc, @Param("doctor") String doctor,
        @Param("zlfs") String zlfs, @Param("sblx") String sblx);

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

}
