package com.njcn.harmonic.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.param.StatisticsBizBaseParam;
import com.njcn.harmonic.mapper.RStatLimitTargetDMapper;
import com.njcn.harmonic.pojo.param.StatSubstationBizBaseParam;
import com.njcn.harmonic.pojo.po.day.RStatLimitTargetDPO;
import com.njcn.harmonic.pojo.vo.RStatLimitTargetCountVO;
import com.njcn.harmonic.service.IRStatLimitTargetDService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 合格率统计日表(是否越限) 服务实现类
 * </p>
 *
 * @author wr
 * @since 2023-04-23
 */
@Service
public class RStatLimitTargetDServiceImpl extends ServiceImpl<RStatLimitTargetDMapper, RStatLimitTargetDPO> implements IRStatLimitTargetDService {

    @Override
    public List<String> getLinesTarget(StatSubstationBizBaseParam param) {
        return this.baseMapper.getLinesTarget(param.getIds(),param.getStartTime(),param.getEndTime());
    }

    @Override
    public List<String> getLinesHarmTarget(StatSubstationBizBaseParam param) {
        return this.baseMapper.getLinesHarmTarget(param.getIds(), param.getStartTime(), param.getEndTime());
    }

    @Override
    public RStatLimitTargetCountVO getGridDiagramTargetData(StatisticsBizBaseParam param) {
        List<RStatLimitTargetCountVO> sumTargetDetails = this.baseMapper.getSumTargetCountDayes(Arrays.asList(param.getId()),
                DateUtil.beginOfDay(DateUtil.parse(param.getStartTime())).toString(),
                DateUtil.endOfDay(DateUtil.parse(param.getEndTime())).toString());
        if(CollUtil.isNotEmpty(sumTargetDetails)){
            return sumTargetDetails.get(0);
        }
        return new RStatLimitTargetCountVO() ;
    }
}
