package thyyxxk.webserver.dao.his.medicine;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
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.YpPlanInfo;

import java.util.List;

@Mapper
public interface YpPlanInfoDao extends BaseMapper<YpPlanInfo> {

    @Select("<script>" +
            " select pl.* from yp_plan_info as pl " +
            " <where> " +
            "<if test=\" fileId != null and fileId != '' \">" +
            " and (pl.file_id like '%${fileId}%' or pl.file_name like '%${fileId}%' ) " +
            "</if>" +
            "<if test=\" startTime != null and startTime != '' \">" +
            " and pl.apply_date &gt;= #{startTime} " +
            "</if>" +
            "<if test=\" endTime != null and endTime != '' \">" +
            " and pl.apply_date &lt;= #{endTime} " +
            "</if>" +
            "<if test=\" ztFlag == '1'.toString \">" +
            " and pl.trial_audit = '1' " +
            "</if>" +
            "<if test=\" ztFlag == '2'.toString \">" +
            " and pl.trial_audit != '1' " +
            "</if>" +
            "<if test=\" ztFlag == '3'.toString \">" +
            " and pl.review_audit = '1' " +
            "</if>" +
            "<if test=\" ztFlag == '4'.toString \">" +
            " and pl.review_audit != '1' " +
            "</if>" +
            "<if test=\" ztFlag == '5'.toString \">" +
            " and pl.final_audit = '1' " +
            "</if>" +
            "<if test=\" ztFlag == '6'.toString \">" +
            " and pl.final_audit != '1' " +
            "</if>" +
            " </where> " +
            " order by pl.apply_date " +
            "</script>")
    List<YpPlanInfo> selectYpPlanInfo(YpPlanInfo info);

    @Select(" select * from yp_plan_info where file_id = #{fileId} ")
    YpPlanInfo selectYpPlanInfoById(@Param("fileId") String fileId);

    @Delete(" delete from yp_plan_info where file_id = #{fileId} ")
    void deleteYpPlanInfoById(@Param("fileId") String fileId);

    @Update("<script>" +
            "update yp_plan_info " +
            "<trim prefix=\"set\" suffixOverrides=\",\">" +
            "<if test=\"totalFee != null \">" +
            "total_fee = #{totalFee}, " +
            "</if>" +
            "<if test=\"type == 1 \">" +
            "trial_audit = #{trialAudit}, trial_content = #{trialContent}, trial_id = #{trialId}, trial_name = #{trialName}, " +
            "</if>" +
            "<if test=\"type == 2 \">" +
            "review_audit = #{reviewAudit}, review_content = #{reviewContent}, review_id = #{reviewId}, review_name = #{reviewName},  " +
            "</if>" +
            "<if test=\"type == 3 \">" +
            "final_audit = #{finalAudit}, final_content = #{finalContent}, final_id = #{finalId}, final_name = #{finalName},  " +
            "</if>" +
            "</trim>" +
            "where file_id = #{fileId} " +
            "</script>")
    int updateYpPlanAuditById(YpPlanInfo info);

}
