package com.iailab.module.prod.service.impl; import com.iailab.common.dto.echarts.BarLineDTO; import com.iailab.common.dto.echarts.SeriesItem; import com.iailab.common.enums.CdbmEnum; import com.iailab.common.utils.HttpsRequest; import com.iailab.module.data.dto.FeignQueryPointDTO; import com.iailab.module.data.dto.ApiDataDTO; import com.iailab.module.data.api.IFeignDataApi; import com.iailab.module.param.service.PageParmService; import com.iailab.module.prod.dto.PageCharsDTO; import com.iailab.module.quality.service.QualityQualityTrendDayService; import com.iailab.module.prod.service.*; import javax.annotation.Resource; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.*; @Service public class PageCharsServiceImpl implements PageCharsService { @Resource private IFeignDataApi iFeignDataApi; @Resource private HttpsRequest httpsRequest; @Resource private PageParmService pageParmService; @Resource private PrdCurrentPerformanceService prdCurrentPerformanceService; @Resource private PrdCurrentSaleService prdCurrentSaleService; @Resource private PrdDayProdService prdDayProdService; @Resource private PrdPlanMonService prdPlanMonService; @Resource private PrdPlanYearService prdPlanYearService; @Resource private QualityQualityTrendDayService qualityQualityTrendDayService; @Override public List getData(String page) { String chars = pageParmService.selectValue(page, "chars"); String length = pageParmService.selectValue(page, "length"); String pointLength = pageParmService.selectValue(page, "point_length"); String coal = pageParmService.selectValue(page, "coal"); String point = pageParmService.selectValue(page, "point")==null?"":pageParmService.selectValue(page, "point"); List coalList = Arrays.asList(coal.split(";")); List pointList = Arrays.asList(point.split(";")); List charsCodeList = Arrays.asList(chars.split(";")); List list = new ArrayList<>(); charsCodeList.stream().forEach( item -> { //如果数据源为报表,类型为煤质或产量,传一个煤种参数 if(CdbmEnum.HF.getCode().equals(item)||CdbmEnum.LF.getCode().equals(item)||CdbmEnum.SF.getCode().equals(item)||CdbmEnum.RZ.getCode().equals(item)||CdbmEnum.CL.getCode().equals(item)) { coalList.stream().forEach( coalItem->{ list.add(getPageChars(item, length,coalItem)); } ); }else if(item.equals("point")){ //如果数据源为point,传一个测点参数 pointList.stream().forEach( pointItem->{ list.add(getPageChars(item,pointLength,pointItem)); } ); }else { list.add(getPageChars(item, length,"")); } } ); return list; } public PageCharsDTO getPageChars(String charsCode, String length,String param) { PageCharsDTO dto = new PageCharsDTO(); BarLineDTO barLine; try { switch (charsCode) { case "plan": //计划 barLine = prdPlanMonService.barLine(length); dto.setCurrentValue(prdPlanMonService.currentValue()==null?new BigDecimal(0):prdPlanMonService.currentValue()); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByCode("plan").getUnit()); dto.setLength(length); //调用模型方法 this.run(dto); break; case "cl": //产量 barLine = prdDayProdService.barLine(length,param); dto.setCurrentValue(prdDayProdService.currentValue(param)==null?new BigDecimal(0):prdDayProdService.currentValue(param)); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByCode("cl").getUnit()); dto.setLength(length); //调用模型方法 this.run(dto); break; case "groundsales": //地销混煤 barLine = prdCurrentSaleService.barLine(length,"groundsales"); dto.setCurrentValue(prdCurrentSaleService.currentValue("groundsales")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("groundsales")); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByCode("groundsales").getUnit()); dto.setLength(length); //调用模型方法 this.run(dto); break; case "medblock": //洗中块外运 barLine = prdCurrentSaleService.barLine(length,"medblock"); dto.setCurrentValue(prdCurrentSaleService.currentValue("medblock")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("medblock")); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByCode("medblock").getUnit()); dto.setLength(length); //调用模型方法 this.run(dto); break; case "nubmeasure": //洗小块外运 barLine = prdCurrentSaleService.barLine(length,"nubmeasure"); dto.setCurrentValue(prdCurrentSaleService.currentValue("nubmeasure")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("nubmeasure")); dto.setBarLineDTO(barLine); dto.setLength(length); dto.setUnit(CdbmEnum.getEumByCode("nubmeasure").getUnit()); //调用模型方法 this.run(dto); break; case "gangue": //矸石外运 barLine = prdCurrentSaleService.barLine(length,"gangue"); dto.setCurrentValue(prdCurrentSaleService.currentValue("gangue")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("gangue")); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByCode("gangue").getUnit()); dto.setLength(length); //调用模型方法 this.run(dto); break; case "reshipped": //小块转载 barLine = prdCurrentSaleService.barLine(length,"reshipped"); dto.setCurrentValue(prdCurrentSaleService.currentValue("reshipped")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("reshipped")); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByCode("reshipped").getUnit()); dto.setLength(length); //调用模型方法 this.run(dto); break; case "trainTon": //火车外运吨数 barLine = prdCurrentSaleService.barLine(length,"trainTon"); dto.setCurrentValue(prdCurrentSaleService.currentValue("trainTon")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("trainTon")); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByCode("trainTon").getUnit()); //调用模型方法 this.run(dto); break; case "trainCount": //火车外运列数 barLine = prdCurrentSaleService.barLine(length,"trainCount"); dto.setCurrentValue(prdCurrentSaleService.currentValue("trainCount")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("trainCount")); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByCode("trainCount").getUnit()); dto.setLength(length); //调用模型方法 this.run(dto); break; case "dbl": //达标率 dto.setUnit(CdbmEnum.getEumByCode("dbl").getUnit()); barLine = prdDayProdService.barLine(length,"dbl"); dto.setCurrentValue(prdDayProdService.currentValue("dbl")==null?new BigDecimal(0):prdDayProdService.currentValue("dbl")); dto.setBarLineDTO(barLine); dto.setLength(length); //调用模型方法 this.run(dto); break; case "hf": //灰分 barLine = qualityQualityTrendDayService.barLine(length,"hf",param); dto.setCurrentValue(qualityQualityTrendDayService.currentValue(param,"hf")==null?new BigDecimal(0):qualityQualityTrendDayService.currentValue(param,"hf")); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByCode("hf").getUnit()); dto.setLength(length); //调用模型方法 this.run(dto); break; case "lf": //硫分 barLine = qualityQualityTrendDayService.barLine(length,"lf",param); dto.setCurrentValue(qualityQualityTrendDayService.currentValue(param,"lf")==null?new BigDecimal(0):qualityQualityTrendDayService.currentValue(param,"lf")); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByCode("lf").getUnit()); dto.setLength(length); //调用模型方法 this.run(dto); break; case "sf": //水分 barLine = qualityQualityTrendDayService.barLine(length,"sf",param); dto.setCurrentValue(qualityQualityTrendDayService.currentValue(param,"sf")==null?new BigDecimal(0):qualityQualityTrendDayService.currentValue(param,"sf")); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByCode("sf").getUnit()); dto.setLength(length); //调用模型方法 this.run(dto); break; case "rz": //热值 barLine = qualityQualityTrendDayService.barLine(length,"rz",param); dto.setCurrentValue(qualityQualityTrendDayService.currentValue(param,"rz")==null?new BigDecimal(0):qualityQualityTrendDayService.currentValue(param,"rz")); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByCode("rz").getUnit()); dto.setLength(length); //调用模型方法 this.run(dto); break; case "point": //测点 barLine = this.pointBarline(param,length); dto.setBarLineDTO(barLine); dto.setUnit(CdbmEnum.getEumByName(param).getUnit()); dto.setLength(length); //调用模型方法 this.run(dto); break; default: break; } }catch (Exception e){ e.printStackTrace(); System.out.println(charsCode+"查图表渲染异常" + e.getMessage()); } return dto; } private BarLineDTO pointBarline(String param,String length) { FeignQueryPointDTO dto = new FeignQueryPointDTO(); dto.setEndTime(new Date()); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.add(Calendar.DAY_OF_YEAR, -Integer.parseInt(length)); dto.setStartTime(calendar.getTime()); dto.setPointCode(CdbmEnum.getEumByName(param).getCode()); dto.setType("float"); List list = iFeignDataApi.queryPointValues(dto); //封装echarsDto BarLineDTO barLineDTO = new BarLineDTO(); List legend = new ArrayList<>(); List categories = new ArrayList<>(); List series = new ArrayList<>(); SeriesItem seriesItem = new SeriesItem(); seriesItem.setName(CdbmEnum.getEumByName(param).getDesc()); List seriesData = new ArrayList<>(); for (ApiDataDTO entity : list) { // 将数据作为图表数据 seriesData.add(new Object[]{entity.getTimeStamp(), entity.getDataValue()}); } seriesItem.setData(seriesData); series.add(seriesItem); barLineDTO.setLegend(legend); barLineDTO.setSeries(series); barLineDTO.setValueName(CdbmEnum.getEumByName(param).getDesc()); return barLineDTO; } private PageCharsDTO run(PageCharsDTO dto){ dto.setSuggest("暂无建议"); dto.setSuggestTime(new Date()); dto.setAvg(""); dto.setMax(""); dto.setMin(""); return dto; } }