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

import cn.cecep.talroad.common.core.utils.StringUtils;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisCo;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisCoal;
import cn.cecep.talroad.mapper.analysis.SRaRealTimeAnalysisCoalMapper;
import cn.cecep.talroad.service.analysis.ISRaRealTimeAnalysisCoalService;
import cn.cecep.talroad.vo.EChartsVO;
import cn.cecep.talroad.vo.query.analysis.SRaRealTimeAnalysisCoalQuery;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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


/**
 * 装煤推焦次数分析Service业务层处理
 *
 * @author szhpt
 * @date 2023-03-24*/
@Service
public class SRaRealTimeAnalysisCoalServiceImpl extends ServiceImpl<SRaRealTimeAnalysisCoalMapper, SRaRealTimeAnalysisCoal> implements ISRaRealTimeAnalysisCoalService
{
    @Autowired
    private SRaRealTimeAnalysisCoalMapper sRaRealTimeAnalysisCoalMapper;

    /**
     * 查询装煤推焦次数分析列表
     *
     * @param sRaRealTimeAnalysisCoal 装煤推焦次数分析
     * @return 装煤推焦次数分析
     */
    @Override
    public List<SRaRealTimeAnalysisCoal> selectSRaRealTimeAnalysisCoalList(SRaRealTimeAnalysisCoalQuery sRaRealTimeAnalysisCoal)
    {
        Page<SRaRealTimeAnalysisCoal> page=new Page<>(1,999999);
        return sRaRealTimeAnalysisCoalMapper.selectSRaRealTimeAnalysisCoalList(page,sRaRealTimeAnalysisCoal);
    }

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

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

    @Override
    public List<SRaRealTimeAnalysisCoal> statisticsExport(SRaRealTimeAnalysisCoalQuery sRaRealTimeAnalysisCoal) {
        Page<SRaRealTimeAnalysisCoal> iPage=new  Page<SRaRealTimeAnalysisCoal>(1,999999);
        List<SRaRealTimeAnalysisCoal> list=new ArrayList<>();
        if(sRaRealTimeAnalysisCoal.getType().equals("1")){
            list=sRaRealTimeAnalysisCoalMapper.statisticsList(iPage,sRaRealTimeAnalysisCoal);
        }else {
            list=sRaRealTimeAnalysisCoalMapper.statisticsListByDevice(iPage,sRaRealTimeAnalysisCoal);
        }
        return list;
    }

    @Override
    public EChartsVO resultCurve(SRaRealTimeAnalysisCoalQuery sRaRealTimeAnalysisCoa) {
        EChartsVO eChartsVO=new EChartsVO();
        List<SRaRealTimeAnalysisCoal> sRaRealTimeAnalysisRuns = sRaRealTimeAnalysisCoalMapper.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);
        EChartsVO.SeriesObj ser1 = new EChartsVO.SeriesObj();
        ser1.setName("装煤次数");
        ser1.setProp("coalNumber");
        ser1.setUnit("");
        ser1.setValues(new ArrayList<>());
        items.add(ser1);
        sRaRealTimeAnalysisRuns.forEach(item->{
            list.add(DateUtil.format(item.getAnalyseTime(), DatePattern.NORM_DATETIME_FORMATTER));
            items.get(0).getValues().add(item.getCokeNumber());
            items.get(1).getValues().add(item.getCoalNumber());
        });
        eChartsVO.setXData(list);
        eChartsVO.setSeries(items);
        return eChartsVO;
    }
}
