package thyyxxk.webserver.dao.his.executeItem;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.executeItem.YzYpZyOrder;

/**
 * (YzYpZyOrder)表数据库访问层
 *
 * @author lihong
 * @since 2024-01-08 16:18:32
 */
@Mapper
public interface YzYpZyOrderDao extends BaseMapper<YzYpZyOrder> {
    /**
     * @description: 生成药品或生成诊疗后最后执行的更新状态
     * @author: lihong
     * @date: 2024/1/8 17:21
     * @param: wardCode
     * @return: int
     **/
  @Update(" update yz_yp_zy_order" +
          " set status_flag ='2'" +
          " from yz_act_order" +
          " where yz_yp_zy_order.dept_code = #{wardCode}" +
          "  and yz_yp_zy_order.ward_code = #{wardCode}" +
          "  and yz_yp_zy_order.occ_time > yz_act_order.end_time" +
          "  and yz_yp_zy_order.status_flag <> '0'" +
          "  and yz_yp_zy_order.status_flag <> '4'" +
          "  and yz_act_order.frequ_code <> 'ONCE'" +
          "  and yz_yp_zy_order.act_order_no = yz_act_order.act_order_no" +
          "  and (yz_yp_zy_order.amount > 0 or isnull(yz_act_order.drug_quan, 1) < 0) ")
  int updateStatusFlag(String wardCode);
  /**
   * @description: 金额改为负 状态改为 初始 生成药品或生成诊疗后最后执行的更新状态
   * @author: lihong
   * @date: 2024/1/8 17:32
   * @param: wardCode
   * @return: int
   **/
  @Update(" update yz_yp_zy_order" +
          " set amount      =0 - amount," +
          "    status_flag ='1'" +
          " from yz_act_order" +
          " where yz_yp_zy_order.dept_code = #{wardCode}" +
          "  and yz_yp_zy_order.ward_code = #{wardCode}" +
          "  and yz_yp_zy_order.occ_time > yz_act_order.end_time" +
          "  and (yz_yp_zy_order.status_flag = '0' or yz_yp_zy_order.pay_self >= '2')" +
          "  and yz_yp_zy_order.amount > 0" +
          "  and yz_act_order.frequ_code <> 'ONCE'" +
          "  and yz_yp_zy_order.act_order_no = yz_act_order.act_order_no")
  int updateAmountAndStatusFlag(String wardCode);
}

