package thyyxxk.webserver.dao.his.jiekou;

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.datamodify.MzChargeDetail;
import thyyxxk.webserver.entity.login.UserInfo;
import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.YshYjReq;

import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 * 描述： 对深圳博英接口文档
 * </p>
 *
 * @author xc
 * @date 2021-07-13 08:03
 */
@Mapper
public interface DuiWaiJieKouDao {

    @Select("select patient_id, times, item_no, receipt_no, order_no, req_no " +
            "from mz_yj_req " +
            "where req_no = #{reqNo} " +
            "order by req_no desc")
    MzChargeDetail getFeeInfoByReqNo(Integer reqNo);


    @Update("update mz_yj_req " +
            "set confirm_flag = #{flag}, " +
            "    receive_flag =#{flag}, " +
            "    confirm_time = #{date}, " +
            "    exec_dept    = #{dept}, " +
            "    confirm_id   = #{userId} " +
            "where req_no = #{reqNo}")
    int confirmOutpatientYjReq(String flag, String userId, String dept, Date date, Integer reqNo);

    @Update("update mz_charge_detail " +
            "set confirm_flag = #{flag}, " +
            "    receive_flag =#{flag}, " +
            "    confirm_time = #{date}, " +
            "    exec_dept    = #{dept}, " +
            "    confirm_id   = #{userId} " +
            "where patient_id = #{mz.patientId} " +
            "  and times = #{mz.times} " +
            "  and receipt_no = #{mz.receiptNo} " +
            "  and order_no = #{mz.orderNo} " +
            "  and req_no = #{mz.reqNo}")
    int confirmOutPatientFee(@Param("flag") String flag,
                             @Param("userId") String userId,
                             @Param("dept") String dept,
                             @Param("date") Date date,
                             @Param("reqNo") Integer reqNo,
                             @Param("mz") MzChargeDetail mz);


    @Select("select act_order_no, confirm_flag,inpatient_no,admiss_times,req_no " +
            "from ysh_yj_req where req_no = #{reqNo}")
    YshYjReq selectedYshJyReqOne(Integer reqNo);


    @Select("select count(1) " +
            "from yz_zy_patient_fee where act_order_no = #{orderNo} ")
    int whetherToGenerateAConfirmationFee(BigDecimal orderNo);

    @Update("update ysh_yj_req " +
            "set confirm_flag = ${flag}, " +
            "    confirm_id   = #{confirmId}, " +
            "    confirm_time = #{date}," +
            "    exec_dept = #{deptCode} " +
            "where req_no = #{reqNo} ")
    int updateYshYjReqFlag(String confirmId,
                           Integer reqNo,
                           Date date,
                           String deptCode,
                           int flag);

    @Update("update yz_zy_patient_fee " +
            "set charge_status = '${flag}', " +
            "    op_id         = #{confirmId}, " +
            "    op_date       = #{date}," +
            "    exec_unit     = #{deptCode} " +
            "where inpatient_no = #{patNo} and admiss_times = #{times} and act_order_no = #{orderNo}")
    int confirmTheIntermediateTable(String confirmId,
                                    BigDecimal orderNo,
                                    Date date,
                                    String deptCode,
                                    String patNo,
                                    Integer times,
                                    int flag);


    @Select("select code,dept_code from a_employee_mi where code = '${code}' and isnull(del_flag ,'0') = '0' ")
    UserInfo getUserInfo(String code);
}
