package thyyxxk.webserver.dao.his.medicine;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.medicine.YpCodgUpload;
import thyyxxk.webserver.entity.medicine.YpInvinfoModify;

import java.util.List;

public interface YpInvinfoDao {

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

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

    @Update("<script> " +
            " update yp_invinfo_modify set upload_flag = '-2' where fixmedins_bchno in " +
            " <foreach collection='list' item='item' open='(' separator=',' close=')'> " +
            " #{item.fixmedinsBchno} " +
            " </foreach> " +
            " </script>")
    int updateYpInvinfoBatchByCode(List<YpCodgUpload> list);

    @Insert("<script> " +
            " insert into yp_invinfo_modify (med_list_codg, inv_chg_type, fixmedins_hilist_id, fixmedins_hilist_name, fixmedins_bchno, pric, cnt, rx_flag, inv_chg_time, inv_chg_opter_name, memo, trdn_flag, charge_code, charge_name, serial, upload_flag, msg_err, docu_no, seri, group_no, group_no_out, manu_no, producing_date, eff_date, create_time, inv_chg_type_name, type) values " +
            " <foreach collection='list' item='item'  separator=','> " +
            " (#{item.medListCodg},#{item.invChgType},#{item.fixmedinsHilistId},#{item.fixmedinsHilistName},#{item.fixmedinsBchno},#{item.pric},#{item.cnt},#{item.rxFlag},#{item.invChgTime},#{item.invChgOpterName},#{item.memo},#{item.trdnFlag},#{item.chargeCode},#{item.chargeName},#{item.serial},#{item.uploadFlag},#{item.msgErr},#{item.docuNo},#{item.seri},#{item.groupNo},#{item.groupNoOut},#{item.manuNo},#{item.producingDate},#{item.effDate},#{item.createTime},#{item.invChgTypeName},#{item.type}) " +
            " </foreach> " +
            "</script>")
    int saveYpInvinfoBatch(List<YpInvinfoModify> list);

    @Select("<script> " +
            " select mo.* from yp_invinfo_modify as mo " +
            " where mo.group_no = #{dto.groupNo} " +
            " <if test=\"dto.startTime != null and dto.startTime != ''\"> " +
            " and mo.inv_chg_time &gt;= #{dto.startTime} " +
            " </if> " +
            " <if test=\"dto.endTime != null and dto.endTime != ''\"> " +
            " and mo.inv_chg_time &lt;= #{dto.endTime} " +
            " </if> " +
            " <if test=\"dto.docuNo != null and dto.docuNo != ''\"> " +
            " and mo.docu_no = #{dto.docuNo} " +
            " </if> " +
            " <if test=\"dto.chargeCode != null and dto.chargeCode != ''\"> " +
            " and mo.charge_code = #{dto.chargeCode} " +
            " </if> " +
            " <if test=\"dto.uploadFlag != null and dto.uploadFlag != ''\"> " +
            " and mo.upload_flag = #{dto.uploadFlag} " +
            " </if> " +
            " <if test=\"dto.invChgType != null and dto.invChgType != ''\"> " +
            " and mo.inv_chg_type = #{dto.invChgType} " +
            " </if> " +
            " order by mo.docu_no, mo.seri " +
            "</script>")
    List<YpInvinfoModify> selectYpInvinfoResult(@Param("dto") YpCodgUpload dto);

}
