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

import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisCoke;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisFurnace;
import cn.cecep.talroad.mapper.analysis.SRaRealTimeAnalysisFurnaceMapper;
import cn.cecep.talroad.service.analysis.ISRaRealTimeAnalysisFurnaceService;
import cn.cecep.talroad.vo.EChartsVO;
import cn.cecep.talroad.vo.query.analysis.SRaRealTimeAnalysisFurnaceQuery;
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 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 SRaRealTimeAnalysisFurnaceServiceImpl extends ServiceImpl<SRaRealTimeAnalysisFurnaceMapper, SRaRealTimeAnalysisFurnace> implements ISRaRealTimeAnalysisFurnaceService
{
    @Autowired
    private SRaRealTimeAnalysisFurnaceMapper sRaRealTimeAnalysisFurnaceMapper;

    /**
     * 查询高炉产量分析列表
     *
     * @param sRaRealTimeAnalysisFurnace 高炉产量分析
     * @return 高炉产量分析
     */
    @Override
    public List<SRaRealTimeAnalysisFurnace> selectSRaRealTimeAnalysisFurnaceList(SRaRealTimeAnalysisFurnaceQuery sRaRealTimeAnalysisFurnace)
    {
        Page<SRaRealTimeAnalysisFurnace> page=new Page<>(1,999999);
        return sRaRealTimeAnalysisFurnaceMapper.selectSRaRealTimeAnalysisFurnaceList(page,sRaRealTimeAnalysisFurnace);
    }

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

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

    @Override
    public EChartsVO resultCurve(SRaRealTimeAnalysisFurnaceQuery sRaRealTimeAnalysisCoa) {
        EChartsVO eChartsVO=new EChartsVO();
        List<SRaRealTimeAnalysisFurnace> sRaRealTimeAnalysisRuns = sRaRealTimeAnalysisFurnaceMapper.resultCurve(sRaRealTimeAnalysisCoa);
        List<String> list=new ArrayList<>();
        List<EChartsVO.SeriesObj> items= new ArrayList<>();
        EChartsVO.SeriesObj ser = new EChartsVO.SeriesObj();
        ser.setName("出铁量");
        ser.setProp("tapNumber");
        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.getTapNumber());
        });
        eChartsVO.setXData(list);
        eChartsVO.setSeries(items);
        return eChartsVO;
    }

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