package com.ozs.plan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ozs.base.domain.BaseAgency;
import com.ozs.plan.doman.MonthlyReconciliation;
import com.ozs.plan.doman.vo.requestVo.MonthlyReconciliationPageReqVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface MonthlyReconciliationMapper extends BaseMapper<MonthlyReconciliation> {

    @Select("select p.* from " +
            " pm_demand p left join plan_practical pp on p.plan_id = pp.plan_practical_id" +
            " left join pm_audit_dept_ref r  on pp.plan_practical_id = r.ref_id   " +
            " where ( #{isAdmin} " +
            " or if(#{roleFlay},(r.dept_id = #{deptId} and  r.ref_type = 1), p.purchase_dept_id = #{deptId}  ) " +
            " )" +
            " and (#{projectName} is null  or   p.project_name like concat('%',#{projectName},'%'))  " +
            " and (#{purchaseServices} is null  or   p.purchase_services = #{purchaseServices})  " +
            " and (#{projectStatus} is null  or   p.project_status = #{projectStatus})  " +
            " and (#{warnStatus} is null  or   p.warn_status = #{warnStatus})  " +
            " and (#{startTime} is null  or   to_days(p.plan_demand_sub_time) >= to_days(#{startTime}) ) " +
            " and (#{entTime} is null  or   to_days(p.plan_demand_sub_time) <= to_days(#{entTime}) ) " +
            "  group by p.demand_id  order by p.create_time desc")
    List<MonthlyReconciliation> query(MonthlyReconciliationPageReqVo vo);
}
