package thyyxxk.webserver.dao.his.outpatient.thmz;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.executeItem.ZdChargeItem;
import thyyxxk.webserver.service.outpatient.thmz.ZdVisitTypeNew;

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

/**
 * @Description: 股东卡
 * @Author:lihong
 * @Date: 2024/1/12
 */
@Mapper
public interface ShareholderCardDao {
    @Delete(" delete from  zd_visit_type_user where  patient_id =#{patientId} ")
    int delZdVisitTypeUser(String patientId);
    @Insert("<script>" +
            " insert into  zd_visit_type_user (visit_type, patient_id,op_id,op_date) values " +
            " <foreach collection='list' item='item' index='index' separator=','>"+
            " (#{item.id},#{item.patientId},#{item.opId},#{item.opDate})"+
            " </foreach>"+
            "</script> ")
    int insertZdVisitTypeUser(@Param("list") List<ZdVisitTypeNew> list);
    @Select(" select top 1 t1.patient_id ,t2.id,t2.name " +
            " from zd_visit_type_user t1 " +
            "         join zd_visit_type_new t2 on t1.visit_type = t2.id " +
            " where t1.patient_id = #{patientId}")
    ZdVisitTypeNew selectByPatientId(String patientId);
    /**
     * @description: 查询病人信息
     * @author: lihong
     * @date: 2024/1/12 14:58
     * @param: keyWard
     * @return: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     **/
    @Select("<script>" +
            "select t1.patient_id patientId,social_no socialNo,name,case when sex ='1' then '男' when sex ='2' then '女' else '未知' end sex  from mz_patient_mi t1 left join  zd_visit_type_user t2 on t1.patient_id=t2.patient_id " +
            " where 1=1 "+
            " <if test=\" id !=null and id !=0  \">"+
            " and t2.visit_type = #{id}"+
            " </if>"+
            " <if test=\" keyWard !=null and keyWard!='' \">"+
            " <bind name=\"keyWardPatten\" value=\"keyWard+'%'\"/>"+
            " and  (t1.patient_id like #{keyWardPatten} or name like #{keyWardPatten} or social_no like #{keyWardPatten}) " +
            " </if>"+
            "</script>")
    List<Map<String, Object>> selectPatientInfo(@Param("page") Page page, @Param("keyWard") String keyWard,@Param("id")Integer id);
    @Select(" select  1 from zd_visit_type_user where  patient_id = #{patientId} ")
    Integer selectZdVisitTypeUserBypatienId(String patientId);
    @Update(" update zd_visit_type_user set visit_type =#{id},op_id=#{opId},op_date = #{opDate}  where patient_id = #{patientId}")
    int updateZdVisitTypeUserBypatienId(ZdVisitTypeNew params);
    @Select(" <script>" +
            "select top 40 rtrim(code) code,rtrim(name) name from zy_zd_audit_item where 1=1 " +
            "<if test = \" keyWard !=null and keyWard !='' \">"+
            "<bind name=\"keyWardPatten\" value=\"'%'+keyWard+'%'\" />"+
            "  and ( code like #{keyWardPatten} or name like #{keyWardPatten} )" +
            " </if>"+
            " </script>")
    List<ZdChargeItem> selectZyAuditItem(String keyWard);
    @Select("  <script> " +
            " select top 40 code,name,charge_amount from zd_charge_item where   del_flag='0' " +
            "<if test = \" keyWard !=null and keyWard !='' \">"+
            "<bind name=\"keyWardPatten\" value=\"'%'+keyWard+'%'\" />"+
            " and ( code like #{keyWardPatten} or name like #{keyWardPatten} ) "+
            " </if>"+
            "</script>")
    List<ZdChargeItem> selcetZdChargeItem(String keyWard);
    @Select(" <script>" +
            " select top 40 tc_no code,tc_name name  from mz_tc where del_flag = '0'" +
            "  and tc_no in ( select t1.tc_no from mz_tc_detail t1  join zd_charge_item  t2 on t1.charge_code=t2.code )" +
            " <if test = \" keyWard !=null and keyWard !='' \">"+
            " <bind name=\"keyWardPatten\" value=\"'%'+keyWard+'%'\" />"+
            " and ( tc_no like #{keyWardPatten} or tc_name like #{keyWardPatten} ) "+
            " </if>"+
            "</script>")
    List<ZdChargeItem> selectMzTc(String keyWard);
    @Select(" select code,name,charge_amount from zd_charge_item where audit_code=#{auditCode} ")
    List<ZdChargeItem> selcetZdChargeItemByCode(String auditCode);
    @Select(" select t2.code,t2.name,t2.charge_amount from mz_tc_detail t1  join zd_charge_item  t2 on t1.charge_code=t2.code " +
            "    where t1.tc_no = #{tcNo} ")
    List<ZdChargeItem> selectTcDeatil(String tcNo);

    @Select({"<script>",
            " SELECT ",
            "<when test='pageSize!=null'>",
            " top ${pageSize} ",
            "</when>",
            "rtrim(code) code,name,py_code,d_code wb_code,class ,exec_unit,type='1',rtrim(sample_code) sample_code,bw_code='' ",
            "    FROM jy_zd_item WITH(NOLOCK) ",
            "where  isnull(del_flag,'') <![CDATA[<>]]> '1' ",
            "<when test='commonParams!=null'>",
            "and (py_code like #{commonParams} collate Chinese_PRC_CI_AS or ",
            "         d_code  like #{commonParams} collate Chinese_PRC_CI_AS or ",
            "         code    like #{commonParams} collate Chinese_PRC_CI_AS or ",
            "         name    like #{commonParams} collate Chinese_PRC_CI_AS )  ",
            "</when>",
            " UNION ALL ",
            "    SELECT ",
            "<when test='pageSize!=null'>",
            " top ${pageSize} ",
            "</when>",
            "rtrim(code) code,name,py_code,d_code wb_code,class ,exec_unit,type='2',sample_code='',rtrim(bw_code) bw_code ",
            "    FROM jc_zd_item  WITH(NOLOCK) ",
            "where  isnull(del_flag,'') <![CDATA[<>]]> '1' ",
            "<when test='commonParams!=null'>",
            "and (py_code like #{commonParams} collate Chinese_PRC_CI_AS or ",
            "         d_code  like #{commonParams} collate Chinese_PRC_CI_AS or ",
            "         code    like #{commonParams} collate Chinese_PRC_CI_AS or ",
            "         name    like #{commonParams} collate Chinese_PRC_CI_AS )  ",
            "</when>",
            "</script>"})
    List<ZdChargeItem> selectJcJyItemByCommonParams(@Param("commonParams") String commonParams, @Param("pageSize") Integer pageSize);
    @Select("<script>" +
            " select t2.code,t2.charge_amount,t2.name from " +
            "<if test=\" jyjcType == '1'.toString  \">"+
            "  jy_item_charge t1 " +
            "</if>"+
            "<if test=\" jyjcType != '1'.toString  \">"+
            "  jc_item_charge t1 " +
            "</if>"+
            " join zd_charge_item t2 on t1.charge_code=t2.code\n" +
            " where t1.code=#{chargeItem}"+
            "</script> ")
    List<ZdChargeItem> selectJcJyZdChargeItemByCode(String chargeItem, String jyjcType);
}
