package thyyxxk.webserver.dao.his.executeItem;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.datamodify.YzActOrder;
import thyyxxk.webserver.entity.executeItem.YzChangeParam;

import java.util.List;

/**
 * @Description:
 * @Author:lihong
 * @Date: 2023/11/8
 */
@Mapper
public interface YzExecuteSignDao {
    /**
     * @description:查询医嘱签名数据
     * @author: lihong
     * @date: 2023/11/8 11:21
     * @param: page
     * @param: param
     * @return: java.util.List<thyyxxk.webserver.entity.datamodify.YzActOrder>
     **/
    @Select("<script>" +
            "select top ${pageSize} * from (" +
            "SELECT yz_act_order.act_order_no,\n" +
            " ROW_NUMBER() OVER (order by cast(bed_no as float) ) row_index," +
            "       yz_act_order.inpatient_no,\n" +
            "       yz_act_order.admiss_times,\n" +
            "       zy_actpatient.name patient_name,\n" +
            "       zy_actpatient.bed_no bed_no_name,\n" +
            "       yz_act_order.order_name,\n" +
            "       yz_act_order.start_time,\n" +
            "       yz_act_order.drug_specification,\n" +
            "       yz_act_order.drug_quan,\n" +
            "       yz_supply_type.supply_name supply_code,\n" +
            "       yz_act_order.dose,\n" +
            "       (select z.name from yp_zd_unit z where z.code = yz_act_order.dose_unit) as dose_unit,\n" +
            "       exec_time,\n" +
            "       yz_act_order.instruction,\n" +
            "       (select name from a_employee_mi a where a.code= yz_act_order.exec_id ) as exec_id,\n" +
            "       yz_act_order.confirm_time\n" +
            " FROM yz_act_order\n" +
            " INNER JOIN zy_actpatient ON yz_act_order.inpatient_no = zy_actpatient.inpatient_no AND yz_act_order.admiss_times = zy_actpatient.admiss_times\n" +
            " LEFT JOIN yz_supply_type ON yz_act_order.supply_code = yz_supply_type.supply_code\n" +
            " WHERE yz_act_order.status_flag &gt; '1'\n" +
            "  AND doctor_flag = '1'\n" +
            "  AND zy_actpatient.ward = #{wardCode}\n" +
            " <if test=\" startBedNo !=null and  startBedNo !='' \">" +
            "  AND zy_actpatient.bed_no &gt;= cast(#{startBedNo} as float)\n" +
            " </if>" +
            " <if test=\" endBedNo !=null and  endBedNo !='' \">" +
            "  AND zy_actpatient.bed_no &lt;= cast(#{endBedNo} as float)\n" +
            " </if>" +
            " <if test=\" signFlag =='0'.toString  \">" +
            "  AND isnull(exec_id, '') like ''\n" +
            "  AND isnull(exec_id, '') != '###'\n" +
            " </if>" +
            " <if test=\" signFlag =='1'.toString  \">" +
            "  AND isnull(exec_id, '') != ''\n" +
            " </if>" +
            " )t where row_index &gt; ${pageSize}*(${currentPage}-1)" +
            "</script>")
    List<YzActOrder> selectYzSign(YzChangeParam param);


    @Select("<script>" +
            "SELECT count(*)\n" +
            " FROM yz_act_order\n" +
            " INNER JOIN zy_actpatient ON yz_act_order.inpatient_no = zy_actpatient.inpatient_no \n" +
            "   AND yz_act_order.admiss_times = zy_actpatient.admiss_times\n" +
            " LEFT JOIN yz_supply_type ON yz_act_order.supply_code = yz_supply_type.supply_code\n" +
            " WHERE yz_act_order.status_flag &gt; '1'\n" +
            "  AND doctor_flag = '1'\n" +
            "  AND zy_actpatient.ward = #{wardCode}\n" +
            " <if test=\" startBedNo !=null and  startBedNo !='' \">" +
            "  AND zy_actpatient.bed_no &gt;= cast(#{startBedNo} as float)\n" +
            " </if>" +
            " <if test=\" endBedNo !=null and  endBedNo !='' \">" +
            "  AND zy_actpatient.bed_no &lt;= cast(#{endBedNo} as float)\n" +
            " </if>" +
            " <if test=\" signFlag =='0'.toString  \">" +
            "  AND isnull(exec_id, '') like ''\n" +
            "  AND isnull(exec_id, '') != '###'\n" +
            " </if>" +
            " <if test=\" signFlag =='1'.toString  \">" +
            "  AND isnull(exec_id, '') != ''\n" +
            " </if>" +
            "</script>")
    Long selectYzSignTotal(YzChangeParam param);

    /**
     * @description:更新执行人
     * @author: lihong
     * @date: 2023/11/8 11:32
     * @param: userId
     * @param: date
     * @param: actOrderNos
     **/
    @Update(" UPDATE yz_act_order\n" +
            " SET exec_time = #{date},\n" +
            "    exec_id   = #{userId}\n" +
            " where act_order_no in (${actOrderNos})")
    void updateExcute(String userId, String date, String actOrderNos);


}
