package cn.cecep.talroad.service.impl.analysis;

import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisPower;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisRubbish;
import cn.cecep.talroad.mapper.analysis.SRaRealTimeAnalysisRubbishMapper;
import cn.cecep.talroad.service.analysis.ISRaRealTimeAnalysisRubbishService;
import cn.cecep.talroad.vo.EChartsVO;
import cn.cecep.talroad.vo.query.analysis.SRaRealTimeAnalysisRubbishQuery;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 关联分析系统-企业生产过程分析-垃圾处理量分析Service业务层处理
 *
 * @author szhpt
 * @date 2023-04-03*/
@Service
public class SRaRealTimeAnalysisRubbishServiceImpl extends ServiceImpl<SRaRealTimeAnalysisRubbishMapper,SRaRealTimeAnalysisRubbish> implements ISRaRealTimeAnalysisRubbishService
{
    @Autowired
    private SRaRealTimeAnalysisRubbishMapper sRaRealTimeAnalysisRubbishMapper;

    /**
     * 查询关联分析系统-企业生产过程分析-垃圾处理量分析列表
     *
     * @param sRaRealTimeAnalysisRubbish 关联分析系统-企业生产过程分析-垃圾处理量分析
     * @return 关联分析系统-企业生产过程分析-垃圾处理量分析
     */
    @Override
    public List<SRaRealTimeAnalysisRubbish> selectSRaRealTimeAnalysisRubbishList(SRaRealTimeAnalysisRubbishQuery sRaRealTimeAnalysisRubbish)
    {
        Page<SRaRealTimeAnalysisRubbish> page=new Page<>(1,999999);

        return sRaRealTimeAnalysisRubbishMapper.selectSRaRealTimeAnalysisRubbishList(page,sRaRealTimeAnalysisRubbish);
    }

    @Override
    public IPage<SRaRealTimeAnalysisRubbish> statisticsList(SRaRealTimeAnalysisRubbishQuery sRaRealTimeAnalysisRubbish) {
        Page<SRaRealTimeAnalysisRubbish> iPage=new  Page<SRaRealTimeAnalysisRubbish>(sRaRealTimeAnalysisRubbish.getPageNum(),sRaRealTimeAnalysisRubbish.getPageSize());
        List<SRaRealTimeAnalysisRubbish> list=new ArrayList<>();
        if(sRaRealTimeAnalysisRubbish.getType().equals("1")){
            list=sRaRealTimeAnalysisRubbishMapper.statisticsList(iPage,sRaRealTimeAnalysisRubbish);
        }else {
            list=sRaRealTimeAnalysisRubbishMapper.statisticsListByDevice(iPage,sRaRealTimeAnalysisRubbish);
        }
        list.forEach(item->{
            item.setAnalyseTimeStr(sRaRealTimeAnalysisRubbish.getAnalyseStartTime()+"至"+sRaRealTimeAnalysisRubbish.getAnalyseEndTime());
        });
        iPage.setRecords(list);
        return iPage;
    }

    @Override
    public List<SRaRealTimeAnalysisRubbish> statisticsExport(SRaRealTimeAnalysisRubbishQuery sRaRealTimeAnalysisRubbish) {
        Page<SRaRealTimeAnalysisRubbish> iPage=new  Page<SRaRealTimeAnalysisRubbish>(1,999999);
        List<SRaRealTimeAnalysisRubbish> list=new ArrayList<>();
        if(sRaRealTimeAnalysisRubbish.getType().equals("1")){
            list=sRaRealTimeAnalysisRubbishMapper.statisticsList(iPage,sRaRealTimeAnalysisRubbish);
        }else {
            list=sRaRealTimeAnalysisRubbishMapper.statisticsListByDevice(iPage,sRaRealTimeAnalysisRubbish);
        }
        list.forEach(item->{
            item.setAnalyseTimeStr(sRaRealTimeAnalysisRubbish.getAnalyseStartTime()+"至"+sRaRealTimeAnalysisRubbish.getAnalyseEndTime());
        });
        return list;
    }

    @Override
    public EChartsVO resultCurve(SRaRealTimeAnalysisRubbishQuery sRaRealTimeAnalysisCoa) {
        EChartsVO eChartsVO=new EChartsVO();
        List<SRaRealTimeAnalysisRubbish> sRaRealTimeAnalysisRuns = sRaRealTimeAnalysisRubbishMapper.resultCurve(sRaRealTimeAnalysisCoa);
        List<String> list=new ArrayList<>();
        List<EChartsVO.SeriesObj> items= new ArrayList<>();
        EChartsVO.SeriesObj ser = new EChartsVO.SeriesObj();
        ser.setName("垃圾处理量");
        ser.setProp("rubbishNumber");
        ser.setUnit("kg");
        ser.setValues(new ArrayList<>());
        items.add(ser);
        sRaRealTimeAnalysisRuns.forEach(item->{
            list.add(DateUtil.format(item.getAnalyseTime(), DatePattern.NORM_DATETIME_FORMATTER));
            items.get(0).getValues().add(item.getRubbishNumber());
        });
        eChartsVO.setXData(list);
        eChartsVO.setSeries(items);
        return eChartsVO;
    }

    @Override
    public List<Map<String, Object>> pullDeviceNameOptions(String factoryName) {
        return sRaRealTimeAnalysisRubbishMapper.pullDeviceNameOptions(factoryName);
    }
}
