package thyyxxk.webserver.dao.his.medicine;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
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 thyyxxk.webserver.entity.medicine.YpCodgUpload;
import thyyxxk.webserver.entity.medicine.YpPurcinfoBought;

import java.util.List;

@Mapper
public interface YpPurcinfoBoughtDao extends BaseMapper<YpPurcinfoBought> {

    @Delete("<script> " +
            " delete from yp_purcinfo_bought where fixmedins_bchno in " +
            " <foreach collection='list' item='item' open='(' separator=',' close=')'> " +
            " #{item.fixmedinsBchno} " +
            " </foreach> " +
            " </script>")
    void deleteYpPurcinfoBoughtBatchByIds(List<YpPurcinfoBought> list);

    @Insert("<script> " +
            " insert into yp_purcinfo_bought (med_list_codg, fixmedins_hilist_id, fixmedins_hilist_name, dynt_no, fixmedins_bchno, spler_name, spler_pmtno, manu_lotnum, prodentp_name, aprvno, manu_date, expy_end, finl_trns_pric, purc_retn_cnt, purc_invo_codg, purc_invo_no, rx_flag, purc_retn_stoin_time, purc_retn_opter_name, prod_geay_flag, memo, charge_name, serial, upload_flag, msg_err, in_docu_no, in_seri, create_time, group_no) values " +
            " <foreach collection='list' item='item'  separator=','> " +
            " (#{item.medListCodg},#{item.fixmedinsHilistId},#{item.fixmedinsHilistName},#{item.dyntNo},#{item.fixmedinsBchno},#{item.splerName},#{item.splerPmtno},#{item.manuLotnum},#{item.prodentpName},#{item.aprvno},#{item.manuDate},#{item.expyEnd},#{item.finlTrnsPric},#{item.purcRetnCnt},#{item.purcInvoCodg},#{item.purcInvoNo},#{item.rxFlag},#{item.purcRetnStoinTime},#{item.purcRetnOpterName},#{item.prodGeayFlag},#{item.memo},#{item.chargeName},#{item.serial},#{item.uploadFlag},#{item.msgErr},#{item.inDocuNo},#{item.inSeri},#{item.createTime},#{item.groupNo}) " +
            " </foreach> " +
            " </script>")
    int saveYpPurcinfoBoughtBatch(List<YpPurcinfoBought> list);

    @Select("<script> " +
            " select bo.* from yp_purcinfo_bought as bo " +
            " where bo.purc_retn_stoin_time &gt;= #{dto.startTime} " +
            " and bo.purc_retn_stoin_time &lt;= #{dto.endTime} " +
            " and bo.in_docu_no not like 'T%' " +
            " and bo.group_no = #{groupNo}  " +
            " <if test=\"dto.docuNo != null and dto.docuNo != ''\"> " +
            " and bo.in_docu_no = #{dto.inDocuNo} " +
            " </if> " +
            " <if test=\"dto.chargeCode != null and dto.chargeCode != ''\"> " +
            " and bo.charge_code = #{dto.chargeCode} " +
            " </if> " +
            " <if test=\"dto.uploadFlag != null and dto.uploadFlag != ''\"> " +
            " and bo.upload_flag = #{dto.uploadFlag} " +
            " </if> " +
            " order by bo.in_docu_no, bo.in_seri " +
            "</script>")
    List<YpPurcinfoBought> selectYpPurchaseGoodsResult(@Param("dto") YpCodgUpload dto, @Param("groupNo") String groupNo);

    @Select("<script> " +
            " select bo.* from yp_purcinfo_bought as bo " +
            " where bo.purc_retn_stoin_time &gt;= #{dto.startTime} " +
            " and bo.purc_retn_stoin_time &lt;= #{dto.endTime} " +
            " and bo.in_docu_no like 'T%' " +
            " and bo.group_no = #{groupNo}  " +
            " <if test=\"dto.docuNo != null and dto.docuNo != ''\"> " +
            " and bo.in_docu_no = #{dto.docuNo} " +
            " </if> " +
            " <if test=\"dto.chargeCode != null and dto.chargeCode != ''\"> " +
            " and bo.charge_code = #{dto.chargeCode} " +
            " </if> " +
            " <if test=\"dto.uploadFlag != null and dto.uploadFlag != ''\"> " +
            " and bo.upload_flag = #{dto.uploadFlag} " +
            " </if> " +
            " order by bo.in_docu_no, bo.in_seri " +
            "</script>")
    List<YpPurcinfoBought> selectYpPurchaseGoodsTkResult(@Param("dto") YpCodgUpload dto, @Param("groupNo") String groupNo);

}
