package com.unis.projectManagement.modular.analysisInfo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unis.projectManagement.modular.analysisInfo.entity.AnalysisCountParam;
import com.unis.projectManagement.modular.analysisInfo.entity.AnalysisPageListParam;
import com.unis.projectManagement.modular.analysisInfo.entity.AnalysisPageParam;
import com.unis.projectManagement.modular.analysisInfo.mapper.AnalysisMapper;
import com.unis.projectManagement.modular.pmBudget.entity.PmBudget;
import com.unis.projectManagement.modular.pmBudget.mapper.PmBudgetMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author qingsong.han
 * @description:
 * @create 2024-05-31 17:23
 */
public interface AnalysisService extends IService<AnalysisPageListParam> {

    Page<AnalysisPageListParam> getPage(AnalysisPageParam param);

    AnalysisCountParam getCount();

    @Service
    class AnalysisServiceImpl extends ServiceImpl<AnalysisMapper, AnalysisPageListParam> implements AnalysisService {
        @Resource
        private AnalysisMapper analysisMapper;

        @Override
        public Page<AnalysisPageListParam> getPage(AnalysisPageParam param) {
            QueryWrapper<AnalysisPageListParam> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotEmpty(param.getProjectName()))
                wrapper.like("bpa.project_name", param.getProjectName());
            if (StringUtils.isNotEmpty(param.getProjectLegalUnit()))
                wrapper.like("bpa.project_legal_unit", param.getProjectLegalUnit());
            if (StringUtils.isNotEmpty(param.getProjectName()))
                wrapper.like("ppi.completion_status", param.getCompletionStatus());
            if (ObjectUtils.isNotEmpty(param.getProjectType()))
                wrapper.like("bpa.project_type", param.getProjectType());
            if (ObjectUtils.isNotEmpty(param.getFundsSource()))
                wrapper.like("bpb.funds_scale", param.getFundsSource());
            if (ObjectUtils.isNotEmpty(param.getScheduleStartDate()) && ObjectUtils.isNotEmpty(param.getScheduleEndDate()))
                wrapper.between("bpa.planned_start_time", param.getScheduleStartDate(), param.getScheduleEndDate());
            return analysisMapper.getPage(new Page<>(param.getCurrent(), param.getSize()), wrapper);
        }

        @Override
        public AnalysisCountParam getCount() {
            return analysisMapper.getCount();
        }
    }

}
