package thyyxxk.webserver.dao.his.executeItem;

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

import java.util.List;

/**
 * (YzActOcc)表数据库访问层
 *
 * @author lihong
 * @since 2024-01-08 16:13:37
 */
@Mapper
public interface YzActOccDao extends BaseMapper<YzActOcc> {
    /**
     * @description: status_flag 改为删除状态  生成药品或生成诊疗后最后执行的更新状态
     * @author: lihong
     * @date: 2024/1/8 17:32
     * @param: wardCode
     * @return: int
     **/
    @Update(" update yz_act_occ " +
            " set status_flag ='d' " +
            " from yz_act_order " +
            " where yz_act_occ.dept_code = #{wardCode} " +
            "  and yz_act_occ.ward_code = #{wardCode} " +
            "  and yz_act_occ.occ_time > yz_act_order.end_time " +
            "  and (yz_act_occ.status_flag <> 'd' or yz_act_occ.status_flag is null) " +
            "  and yz_act_order.frequ_code <> 'ONCE' " +
            "  and (yz_act_occ.act_order_no = yz_act_order.act_order_no or - yz_act_occ.act_order_no = yz_act_order.act_order_no)")
    int updateStatusFlag(String wardCode);
    @Insert("<script> " +
            " INSERT INTO yz_act_occ (act_order_no, admiss_times, always_flag, bed_no, charge_code, dept_code, ward_code, discription, " +
            "                        infant_flag, inpatient_name, inpatient_no, occ_name, occ_time, occ_type, phy_name, parent_no, " +
            "                        specification, occ_oper, parent_sort, exec_unit, dose, page_no, order_name, pay_self, group_no, " +
            "                        self_flag, frequ_code, retprice, serial, dose_unit, page_class,drug_quan,status_flag,instruction,supply_code,drug_quan2,zy_serial_no)  VALUES " +
            "<foreach collection='list' item='item'  separator=','>"+
            "  (${item.actOrderNoStr}, #{item.admissTimes}, #{item.alwaysFlag},  #{item.bedNo}, #{item.chargeCode},  #{item.deptCode},  #{item.wardCode},  #{item.discription}," +
            "  #{item.infantFlag}, #{item.inpatientName}, #{item.inpatientNo},#{item.occName},#{item.occTime,jdbcType=TIMESTAMP},#{item.occType},#{item.phyName},#{item.parentNo,jdbcType=DECIMAL}, " +
            "  #{item.specification}, #{item.occOper},  #{item.parentSort}, #{item.execUnit}, #{item.dose},  #{item.pageNo}, #{item.orderName},#{item.paySelf}, #{item.groupNo}," +
            "  #{item.selfFlag}, #{item.frequCode}, #{item.retprice}, #{item.serial}, #{item.doseUnit},#{item.pageClass},#{item.drugQuan,jdbcType=DECIMAL},#{item.statusFlag},#{item.instruction},#{item.supplyCode},#{item.drugQuan2,jdbcType=DECIMAL},#{item.zySerialNo})" +
            "</foreach>" +
            "</script>")
    int batchInsertYzActOcc(List<YzActOcc> list);

}

