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

import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisCement;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisFurnace;
import cn.cecep.talroad.mapper.analysis.SRaRealTimeAnalysisCementMapper;
import cn.cecep.talroad.service.analysis.ISRaRealTimeAnalysisCementService;
import cn.cecep.talroad.vo.EChartsVO;
import cn.cecep.talroad.vo.query.analysis.SRaRealTimeAnalysisCementQuery;
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 SRaRealTimeAnalysisCementServiceImpl extends ServiceImpl<SRaRealTimeAnalysisCementMapper,SRaRealTimeAnalysisCement> implements ISRaRealTimeAnalysisCementService
{
    @Autowired
    private SRaRealTimeAnalysisCementMapper sRaRealTimeAnalysisCementMapper;

    /**
     * 查询关联分析系统-企业生产过程分析-水泥熟料产量分析列表
     *
     * @param sRaRealTimeAnalysisCement 关联分析系统-企业生产过程分析-水泥熟料产量分析
     * @return 关联分析系统-企业生产过程分析-水泥熟料产量分析
     */
    @Override
    public List<SRaRealTimeAnalysisCement> selectSRaRealTimeAnalysisCementList(SRaRealTimeAnalysisCementQuery sRaRealTimeAnalysisCement)
    {
        Page<SRaRealTimeAnalysisCement> page =new Page<>(1,999999);
        return sRaRealTimeAnalysisCementMapper.selectSRaRealTimeAnalysisCementList(page,sRaRealTimeAnalysisCement);
    }

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

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

    @Override
    public EChartsVO resultCurve(SRaRealTimeAnalysisCementQuery sRaRealTimeAnalysisCoa) {
        EChartsVO eChartsVO=new EChartsVO();
        List<SRaRealTimeAnalysisCement> sRaRealTimeAnalysisRuns = sRaRealTimeAnalysisCementMapper.resultCurve(sRaRealTimeAnalysisCoa);
        List<String> list=new ArrayList<>();
        List<EChartsVO.SeriesObj> items= new ArrayList<>();
        EChartsVO.SeriesObj ser = new EChartsVO.SeriesObj();
        ser.setName("水泥熟料产量");
        ser.setProp("grogNumber");
        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.getGrogNumber());
        });
        eChartsVO.setXData(list);
        eChartsVO.setSeries(items);
        return eChartsVO;
    }

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