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

import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisCoke;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisGlass;
import cn.cecep.talroad.mapper.analysis.SRaRealTimeAnalysisGlassMapper;
import cn.cecep.talroad.service.analysis.ISRaRealTimeAnalysisGlassService;
import cn.cecep.talroad.vo.EChartsVO;
import cn.cecep.talroad.vo.query.analysis.SRaRealTimeAnalysisGlassQuery;
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-02*/
@Service
public class SRaRealTimeAnalysisGlassServiceImpl extends ServiceImpl<SRaRealTimeAnalysisGlassMapper,SRaRealTimeAnalysisGlass> implements ISRaRealTimeAnalysisGlassService
{
    @Autowired
    private SRaRealTimeAnalysisGlassMapper sRaRealTimeAnalysisGlassMapper;

    /**
     * 查询关联分析系统-企业生产过程分析-玻璃产量分析列表
     *
     * @param sRaRealTimeAnalysisGlass 关联分析系统-企业生产过程分析-玻璃产量分析
     * @return 关联分析系统-企业生产过程分析-玻璃产量分析
     */
    @Override
    public List<SRaRealTimeAnalysisGlass> selectSRaRealTimeAnalysisGlassList(SRaRealTimeAnalysisGlassQuery sRaRealTimeAnalysisGlass)
    {
        Page<SRaRealTimeAnalysisGlass> page=new Page<>(1,999999);

        return sRaRealTimeAnalysisGlassMapper.selectSRaRealTimeAnalysisGlassList(page,sRaRealTimeAnalysisGlass);
    }

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

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

    @Override
    public EChartsVO resultCurve(SRaRealTimeAnalysisGlassQuery sRaRealTimeAnalysisCoa) {
        EChartsVO eChartsVO=new EChartsVO();
        List<SRaRealTimeAnalysisGlass> sRaRealTimeAnalysisRuns = sRaRealTimeAnalysisGlassMapper.resultCurve(sRaRealTimeAnalysisCoa);
        List<String> list=new ArrayList<>();
        List<EChartsVO.SeriesObj> items= new ArrayList<>();
        EChartsVO.SeriesObj ser = new EChartsVO.SeriesObj();
        ser.setName("玻璃产量");
        ser.setProp("glassNumber");
        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.getGlassNumber());
        });
        eChartsVO.setXData(list);
        eChartsVO.setSeries(items);
        return eChartsVO;
    }

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