package com.lutao.cloud.oil.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lutao.cloud.common.core.util.MessageInfo;
import com.lutao.cloud.common.core.util.StringUtil;
import com.lutao.cloud.oil.mapper.MinisteriaSupervisionDetailMapper;
import com.lutao.cloud.oil.pojo.param.BaseParam;
import com.lutao.cloud.oil.pojo.param.MinisteriaSupervisionDetailParam;
import com.lutao.cloud.oil.pojo.vo.MinisteriaSupervisionDetailVO;
import com.lutao.cloud.oil.pojo.vo.ProblemRectifyProportionVO;
import com.lutao.cloud.oil.service.MinisteriaSupervisionDetailService;
import com.lutao.entity.MinisteriaSupervisionDetail;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Service
public class MinisteriaSupervisionDetailServiceImpl extends ServiceImpl<MinisteriaSupervisionDetailMapper, MinisteriaSupervisionDetail> implements MinisteriaSupervisionDetailService {
    @Override
    public MessageInfo<IPage<MinisteriaSupervisionDetailVO>> getMinisteriaSupervisionDetailPage(Page page, MinisteriaSupervisionDetailParam param) {
        return MessageInfo.ok(this.baseMapper.getMinisteriaSupervisionDetailPage(page,param));
    }

    @Override
    public MessageInfo<ProblemRectifyProportionVO> getMinisteriaSupervisionDetailChart(BaseParam param) {
        //问题隐患数量
        int problemNumber = count(
                Wrappers.lambdaQuery(MinisteriaSupervisionDetail.class)
                        .eq(StringUtil.isNotBlank(param.getAppId()),MinisteriaSupervisionDetail::getAppId, param.getAppId())
                        .eq(StringUtil.isNotBlank(param.getPlatformId()),MinisteriaSupervisionDetail::getPlatformId, param.getPlatformId())
                        .between(MinisteriaSupervisionDetail::getInputTime, LocalDate.of(LocalDate.now().getYear(), 1, 1), LocalDate.of(LocalDate.now().getYear(), 12, 31))
        );

        //问题隐患整改完成数量
        int rectifyNumber = count(
                Wrappers.lambdaQuery(MinisteriaSupervisionDetail.class)
                        .eq(StringUtil.isNotBlank(param.getAppId()),MinisteriaSupervisionDetail::getAppId, param.getAppId())
                        .eq(StringUtil.isNotBlank(param.getPlatformId()),MinisteriaSupervisionDetail::getPlatformId, param.getPlatformId())
                        .eq(MinisteriaSupervisionDetail::getHiddenProblemsState, "002")
                        .between(MinisteriaSupervisionDetail::getInputTime, LocalDate.of(LocalDate.now().getYear(), 1, 1), LocalDate.of(LocalDate.now().getYear(), 12, 31))

        );

        ProblemRectifyProportionVO problemRectifyProportionVO = new ProblemRectifyProportionVO().setProblemNumber(problemNumber).setRectifyNumber(rectifyNumber);

        return MessageInfo.ok(problemRectifyProportionVO);
    }
}
