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

import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisCo;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisCoke;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisConverter;
import cn.cecep.talroad.mapper.analysis.SRaRealTimeAnalysisCokeMapper;
import cn.cecep.talroad.service.analysis.ISRaRealTimeAnalysisCokeService;
import cn.cecep.talroad.vo.EChartsVO;
import cn.cecep.talroad.vo.query.analysis.SRaRealTimeAnalysisCokeQuery;
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 SRaRealTimeAnalysisCokeServiceImpl extends ServiceImpl<SRaRealTimeAnalysisCokeMapper,SRaRealTimeAnalysisCoke> implements
    ISRaRealTimeAnalysisCokeService
{
    @Autowired
    private SRaRealTimeAnalysisCokeMapper sRaRealTimeAnalysisCokeMapper;

    /**
     * 查询关联分析系统-企业生产过程分析-焦炭产量分析列表
     *
     * @param sRaRealTimeAnalysisCoke 关联分析系统-企业生产过程分析-焦炭产量分析
     * @return 关联分析系统-企业生产过程分析-焦炭产量分析
     */
    @Override
    public List<SRaRealTimeAnalysisCoke> selectSRaRealTimeAnalysisCokeList(SRaRealTimeAnalysisCokeQuery sRaRealTimeAnalysisCoke)
    {
        Page<SRaRealTimeAnalysisCoke> page=new Page<>(1,999999);
        return sRaRealTimeAnalysisCokeMapper.selectSRaRealTimeAnalysisCokeList(page,sRaRealTimeAnalysisCoke);
    }

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

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

    @Override
    public EChartsVO resultCurve(SRaRealTimeAnalysisCokeQuery sRaRealTimeAnalysisCoa) {
        EChartsVO eChartsVO=new EChartsVO();
        List<SRaRealTimeAnalysisCoke> sRaRealTimeAnalysisRuns = sRaRealTimeAnalysisCokeMapper.resultCurve(sRaRealTimeAnalysisCoa);
        List<String> list=new ArrayList<>();
        List<EChartsVO.SeriesObj> items= new ArrayList<>();
        EChartsVO.SeriesObj ser = new EChartsVO.SeriesObj();
        ser.setName("焦炭产量");
        ser.setProp("cokeNumber");
        ser.setUnit("");
        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.getCokeNumber());
        });
        eChartsVO.setXData(list);
        eChartsVO.setSeries(items);
        return eChartsVO;
    }

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