package thyyxxk.webserver.dao.his.medicine;

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.medicine.MzDrugTracCodg;

import java.util.List;

@Mapper
public interface MzDrugTracCodgDao {

    @Select(" select * from mz_drug_trac_codg " +
            " where patient_id = #{patientId} " +
            " and times = #{times} " +
            " and receipt_no = #{receiptNo} " +
            " and order_no = #{orderNo} " +
            " and flag = '0' ")
    List<MzDrugTracCodg> selectMzDrugTracCodgByCode(MzDrugTracCodg codg);

    @Delete(" delete from mz_drug_trac_codg " +
            " where patient_id = #{patientId} " +
            " and times = #{times} " +
            " and receipt_no = #{receiptNo} " +
            " and order_no = #{orderNo} ")
    int deleteMzDrugTracCodgByCode(MzDrugTracCodg codg);

    @Update(" update mz_drug_trac_codg set flag = '-1', drug_trac_codg = #{drugTracCodg} + '_1' " +
            " where patient_id = #{patientId} and times = #{times} " +
            " and receipt_no = #{receiptNo} and order_no = #{orderNo} " +
            " and flag = '0' ")
    void updateMzDrugTracCodgFlagByCode(MzDrugTracCodg codg);

    @Insert("<script> " +
            " insert into mz_drug_trac_codg (drug_trac_codg, patient_id, times, receipt_no, order_no, item_no, charge_item_code, serial, flag, group_no, confirm_id, confirm_time, confirm_name, real_no, drug_name, specification, abbr_name, unit_price, manu_no, manu_date, expy_end, match_flag, match_message) values " +
            " <foreach collection='list' item='item' separator=','> " +
            " (#{item.drugTracCodg},#{item.patientId},#{item.times},#{item.receiptNo},#{item.orderNo},#{item.itemNo},#{item.chargeItemCode},#{item.serial},#{item.flag},#{item.groupNo},#{item.confirmId},#{item.confirmTime},#{item.confirmName},#{item.realNo},#{item.drugName},#{item.specification},#{item.abbrName},#{item.unitPrice},#{item.manuNo},#{item.manuDate},#{item.expyEnd},#{item.matchFlag},#{item.matchMessage}) " +
            " </foreach> " +
            "</script>")
    int insertMzDrugTracCodgBatch(List<MzDrugTracCodg> list);

    @Update(" update mz_charge_detail set confirm_flag = 5 " +
            " where confirm_flag in (0,2) and patient_id = #{patNo} and times = #{times} " +
            " and order_no = #{orderNo} and group_no = #{groupNo} ")
    void updateMzChargeDetailConfirmFlag(@Param("patNo") String patNo, @Param("times") Integer times,
                                        @Param("orderNo") Integer orderNo, @Param("groupNo") String groupNo);

}
