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

import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisCoke;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisPower;
import cn.cecep.talroad.mapper.analysis.SRaRealTimeAnalysisPowerMapper;
import cn.cecep.talroad.service.analysis.ISRaRealTimeAnalysisPowerService;
import cn.cecep.talroad.vo.EChartsVO;
import cn.cecep.talroad.vo.query.analysis.SRaRealTimeAnalysisPowerQuery;
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 SRaRealTimeAnalysisPowerServiceImpl extends ServiceImpl<SRaRealTimeAnalysisPowerMapper,SRaRealTimeAnalysisPower> implements ISRaRealTimeAnalysisPowerService
{
    @Autowired
    private SRaRealTimeAnalysisPowerMapper sRaRealTimeAnalysisPowerMapper;

    /**
     * 查询关联分析系统-企业生产过程分析-机组负荷分析列表
     *
     * @param sRaRealTimeAnalysisPower 关联分析系统-企业生产过程分析-机组负荷分析
     * @return 关联分析系统-企业生产过程分析-机组负荷分析
     */
    @Override
    public List<SRaRealTimeAnalysisPower> selectSRaRealTimeAnalysisPowerList(SRaRealTimeAnalysisPowerQuery sRaRealTimeAnalysisPower)
    {
        Page<SRaRealTimeAnalysisPower> page=new Page<>(1,999999);

        return sRaRealTimeAnalysisPowerMapper.selectSRaRealTimeAnalysisPowerList(page,sRaRealTimeAnalysisPower);
    }

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

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

    @Override
    public EChartsVO resultCurve(SRaRealTimeAnalysisPowerQuery sRaRealTimeAnalysisCoa) {
        EChartsVO eChartsVO=new EChartsVO();
        List<SRaRealTimeAnalysisPower> sRaRealTimeAnalysisRuns = sRaRealTimeAnalysisPowerMapper.resultCurve(sRaRealTimeAnalysisCoa);
        List<String> list=new ArrayList<>();
        List<EChartsVO.SeriesObj> items= new ArrayList<>();
        EChartsVO.SeriesObj ser = new EChartsVO.SeriesObj();
        ser.setName("机组负荷");
        ser.setProp("powerNumber");
        ser.setUnit("MW");
        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.getPowerNumber());
        });
        eChartsVO.setXData(list);
        eChartsVO.setSeries(items);
        return eChartsVO;
    }

    @Override
    public List<Map<String, Object>> pullDeviceNameOptions(String factoryName) {

        return sRaRealTimeAnalysisPowerMapper.pullDeviceNameOptions(factoryName);
    }
}
