SysCommandCentreController.java 17.8 KB
package com.skua.modules.dataAnalysis.controller;
import com.skua.common.constant.ReportConstant;
import com.skua.common.report.vo.ReportItemVO;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.dataAnalysis.service.ICommandCentreService;
import com.skua.modules.algorithm.service.impl.ReportItemvService;
import com.skua.modules.algorithm.vo.DepartLoadRateResultVO;
import com.skua.modules.algorithm.vo.StackedAreaChartDataVO;
import com.skua.modules.algorithm.vo.WaterTreatmentVO;
import com.skua.modules.common.vo.DateVO;
import com.skua.modules.guest.util.DateUtil;
import com.skua.modules.report.vo.DepartDrugResult;
import com.skua.modules.report.vo.FRportlCommandCenterVO;
import com.skua.modules.report.vo.ReportDateTrendVO;
import com.skua.modules.report.vo.ReportItemvParam;
import com.skua.modules.system.service.ISysFactoryInfoService;
import com.skua.tool.util.DateUtils;
import com.skua.tool.util.JSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * 统计功能配置表
 */
@Slf4j
@Api(tags="指挥中心")
@RestController
@RequestMapping("/v1/algorithm/commandCentre")
public class SysCommandCentreController {

    @Autowired
    private ISysFactoryInfoService factoryInfoService;
    @Autowired
    private ICommandCentreService  commandCentreService;
    @Autowired
    private ReportItemvService reportItemvService;

    /**
     * 分页列表查询
     * @return
     */
    @AutoLog(value = "指挥中心-水量查询")
    @ApiOperation(value="指挥中心-水量查询", notes="指挥中心-水量查询")
    @GetMapping(value = "/statisticsByWaterData")
    public Result<List<FRportlCommandCenterVO>> statisticsByWaterData(ReportItemvParam reportItemvParam) {
        Result<List<FRportlCommandCenterVO> > result = new Result<>();
        List<FRportlCommandCenterVO>  fReportItemvList  = new ArrayList<>();//返回集合对象
        DateVO dateVO = new DateVO(reportItemvParam.getStartDate());
        String departIds = BaseContextHandler.getDeparts();
        if(reportItemvParam.getDepartIds()!=null){
            departIds = reportItemvParam.getDepartIds();
        }
        //本月数据
        String monthCSL = reportItemvService.getSumCSL(departIds, dateVO.getNowMonthStartDate(), dateVO.getNowMonthEndDate());
        //环比 上月数据
        String lastMonthCSL = reportItemvService.getSumCSL(departIds, dateVO.getNowMonthStartDate(), dateVO.getNowMonthEndDate());
        //同比 去年数据
        String lastYearCSL = reportItemvService.getSumCSL(departIds, dateVO.getLastYearMonthStartTime(), dateVO.getLastYearMonthEndTime());

        long nowDifferDay = DateUtils.differenceDay(dateVO.getNowMonthStartDate(),dateVO.getNowMonthEndDate());
        long lastMonthDifferDay = DateUtils.differenceDay(dateVO.getLastMonthStartTime(),dateVO.getLastMonthEndTime());
        long lastYearDifferDay = DateUtils.differenceDay(dateVO.getLastYearMonthStartTime(),dateVO.getLastYearMonthEndTime());
        //月对象数据 value, valueTb, valueHb
        FRportlCommandCenterVO  monthDataVO = new FRportlCommandCenterVO("月汇总数据",JSUtils.divide(monthCSL,10000),JSUtils.divide(lastMonthCSL,10000),JSUtils.divide(lastYearCSL,10000));
        //日处理对象
        FRportlCommandCenterVO  avgDayDataVO = new FRportlCommandCenterVO("日均处理水量",JSUtils.divide(monthCSL,nowDifferDay*10000),JSUtils.divide(lastMonthCSL,lastMonthDifferDay*10000),JSUtils.divide(lastYearCSL,lastYearDifferDay*10000));
        fReportItemvList.add( monthDataVO);
        fReportItemvList.add( avgDayDataVO );

        //年数据统计:
        String total = factoryInfoService.querySumProScale();
        total = String.format("%.2f", Double.parseDouble(total));
        fReportItemvList.add( new FRportlCommandCenterVO(  total,"0","0"));

        result.setSuccess(true);
        result.setResult(fReportItemvList);
        return result;
    }


    @AutoLog(value = "指挥中心-运行负荷率分析")
    @ApiOperation(value="指挥中心-运行负荷率分析", notes="指挥中心-运行负荷率分析")
    //指挥中心-运行负荷率分析
    @GetMapping(value = "/statisticsByLoadRate")
    public Result<DepartLoadRateResultVO >  statisticsByLoadRate(ReportItemvParam reportItemvParam) {
        Result<DepartLoadRateResultVO > result = new Result<>();
        String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
        if(reportItemvParam.getDepartIds()!=null){
            departIds = reportItemvParam.getDepartIds();
        }
        Integer loadRateType = reportItemvParam.getLoadRateType();
        if(loadRateType == null ) loadRateType = 1;
        DepartLoadRateResultVO departLoadRateResultVO = reportItemvService.statisticsByLoadRate( departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate(), loadRateType);
        result.setSuccess(true);
        result.setResult(departLoadRateResultVO);
        return result;
    }

    //指挥中心----运行负荷率分析----处理水量详情
    @AutoLog(value = "指挥中心-处理水量详情")
    @ApiOperation(value="指挥中心-处理水量详情")
    @GetMapping("/getCLSLXQ")
    public  Result<List<WaterTreatmentVO>> getCLSLXQ(ReportItemvParam reportItemvParam){
        Result<List<WaterTreatmentVO>> result = new Result<>();
        String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
        if(reportItemvParam.getDepartIds()!=null){
            departIds = reportItemvParam.getDepartIds();
        }
        List<WaterTreatmentVO>  waterTrendVOList =  commandCentreService.statisticsCLSLXQ(reportItemvParam.getStartDate(),reportItemvParam.getEndDate(), departIds);
        result.setResult(waterTrendVOList );
        return result;
    }

    //cement水泥  electricity
    @AutoLog(value = "指挥中心-泥量统计")
    @ApiOperation(value="指挥中心-泥量统计", notes="指挥中心-泥量统计")
    @GetMapping(value = "/statisticsByCement")
    public Result<List<FRportlCommandCenterVO>> statisticsByCement(ReportItemvParam reportItemvParam) {
        Result<List<FRportlCommandCenterVO>> result = new Result();
        String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
        if(reportItemvParam.getDepartIds()!=null){
            departIds = reportItemvParam.getDepartIds();
        }
        List<FRportlCommandCenterVO> dataList =  reportItemvService.statisticsByCement(departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
        result.setResult(dataList  );
        return result;
    }
   @AutoLog(value = "指挥中心-泥量统计")
    @ApiOperation(value="指挥中心-泥量统计--详情列表", notes="指挥中心-泥量统计--详情列表")
    //指挥中心-泥量统计--详情列表
    @GetMapping(value = "/statisticsByCementList")
    public Result<List<ReportItemVO>> statisticsByCementList(ReportItemvParam reportItemvParam) {
        Result<List<ReportItemVO>> result = new Result();
        String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
       if(reportItemvParam.getDepartIds()!=null){
           departIds = reportItemvParam.getDepartIds();
       }
        List<ReportItemVO> dataList =  reportItemvService.statisticsByCementList(departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
        result.setResult(dataList  );
        return result;
    }


    //cement水泥  electricity
    @AutoLog(value = "指挥中心-能耗分析")
    @ApiOperation(value="指挥中心-能耗分析", notes="指挥中心-能耗分析")
    @GetMapping(value = "/statisticsByElectricity")
    public Result<List<FRportlCommandCenterVO>> statisticsByElectricity(ReportItemvParam reportItemvParam) {
        Result<List<FRportlCommandCenterVO>> result = new Result();
        String departId = BaseContextHandler.getDeparts();
        if(reportItemvParam.getDepartIds()!=null){
            departId = reportItemvParam.getDepartIds();
        }
        List<FRportlCommandCenterVO> dataList =  reportItemvService.statisticsByElectricity(departId,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
        result.setResult(dataList  );
        return result;
    }

    @AutoLog(value = "指挥中心-药耗分析")
    @ApiOperation(value="指挥中心-药耗分析", notes="指挥中心-药耗分析")
    @GetMapping(value = "/statisticsByYh")
    public Result<List<FRportlCommandCenterVO>> statisticsByYh(ReportItemvParam reportItemvParam) {
        Result<List<FRportlCommandCenterVO>> result = new Result();
        String departId = BaseContextHandler.getDeparts();
        if(reportItemvParam.getDepartIds()!=null){
            departId = reportItemvParam.getDepartIds();
        }
        List<FRportlCommandCenterVO> dataList = reportItemvService.statisticsByYh(departId,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
        result.setResult(dataList);
        return result;
    }

    @AutoLog(value = "指挥中心-能耗分析")
    @ApiOperation(value="指挥中心-能耗分析--详情列表", notes="指挥中心-能耗分析--详情列表")
    @GetMapping(value = "/statisticsByElectricityList")
    public Result<List<ReportItemVO>> statisticsByElectricityList(ReportItemvParam reportItemvParam) {
        Result<List<ReportItemVO>> result = new Result();
        String departIds = BaseContextHandler.getDeparts();//1818214519948836864,1711662624459804674
        if(reportItemvParam.getDepartIds()!=null){
            departIds = reportItemvParam.getDepartIds();
        }
        List<ReportItemVO> dataList =  reportItemvService.statisticsByElectricityList(departIds,reportItemvParam.getStartDate(),reportItemvParam.getEndDate());
        result.setResult(dataList  );
        return result;
    }

    @AutoLog(value = "指挥中心-水量电耗趋势")
    @ApiOperation(value="指挥中心-水量电耗趋势", notes="指挥中心-水量电耗趋势")
    @GetMapping(value = "/statisticsBySewage")
    public Result<StackedAreaChartDataVO> statisticsBySewage(ReportItemvParam reportItemvParam) {
       List<String >  dateList  = new ArrayList<>();//日期数据
        List<String> electricityList =  new ArrayList<>();//电能数据数据;
        List<String> waterList =  new ArrayList<>();// 水集合
        List<String> consumeList =  new ArrayList<>();//电耗集合
        String departIds = BaseContextHandler.getDeparts();
        if(reportItemvParam.getDepartIds()!=null){
            departIds = reportItemvParam.getDepartIds();
        }
        List<ReportDateTrendVO> dlhjDateList = reportItemvService.getDayDateFieldList(ReportConstant.view3a24, "DLHJ", departIds, reportItemvParam.getStartDate(), reportItemvParam.getEndDate());
        List<ReportDateTrendVO> cslDateList = reportItemvService.getDayDateFieldList(ReportConstant.view2119, "CSL", departIds, reportItemvParam.getStartDate(), reportItemvParam.getEndDate());

        List<String >  dateTimeList = DateUtil.getInstance().getBetweenDate(reportItemvParam.getStartDate(),reportItemvParam.getEndDate(),null);
        String dlhj  = null;    String csl = null; String dh  = null;
        if(dateTimeList != null){

            for(String dateTime : dateTimeList){
                csl = null;
                dlhj  = null;
                dateList.add(  DateUtil.getInstance().formatDate(dateTime,"MM-dd") ) ;
                //水
                if( cslDateList != null ){
                    for(ReportDateTrendVO cslVo : cslDateList){
                        if(dateTime.equals(cslVo.getTime())){
                            csl = cslVo.getValue();
                            break;
                        }
                    }
                }
                waterList.add(JSUtils.divide(csl,10000));
                //电
                if( dlhjDateList != null ){
                    for(ReportDateTrendVO dlhjVo : dlhjDateList){
                        if(dateTime.equals(dlhjVo.getTime())){
                            dlhj = dlhjVo.getValue();
                            break;
                        }
                    }
                }
                electricityList.add(JSUtils.divide(dlhj,10000));
                //电耗
                consumeList.add(JSUtils.divide(JSUtils.divide(dlhj,csl),10000) );
            }
        }
        StackedAreaChartDataVO  stackedAreaChartDataVO = new StackedAreaChartDataVO();
        stackedAreaChartDataVO.setElectricityList(electricityList);//电集合
        stackedAreaChartDataVO.setWaterList(waterList);//水集合
        stackedAreaChartDataVO.setConsumeList( consumeList);//电耗集合
        stackedAreaChartDataVO.setDateList(dateList   );//日期集合

        stackedAreaChartDataVO.setXAxis(dateList);

        List<String> yaXisList = new ArrayList<String>();
        yaXisList.addAll(electricityList ) ;//电
        yaXisList.addAll( waterList) ;//水
        yaXisList.addAll(consumeList ) ;//电耗
        stackedAreaChartDataVO.setYAxis( yaXisList );

        Result<StackedAreaChartDataVO> result = new Result<>();
        result.setSuccess(true);
        result.setResult(stackedAreaChartDataVO);
        return  result;
    }


    @AutoLog(value = "指挥中心-费用趋势")
    @ApiOperation(value="指挥中心-费用趋势", notes="指挥中心-费用趋势")
    @GetMapping(value = "/statisticsByFy")
    public Result<StackedAreaChartDataVO> statisticsByFy(ReportItemvParam reportItemvParam) {
        //费用
        String startDate = reportItemvParam.getStartDate();
        String endDate = reportItemvParam.getEndDate();
        reportItemvParam.setStartDate( DateUtils.formatDate(startDate ,"YYYY-MM"));
        reportItemvParam.setEndDate( DateUtils.formatDate(endDate ,"YYYY-MM"));
        String departIds =  BaseContextHandler.getDeparts();
        if(reportItemvParam.getDepartIds()!=null){
            departIds = reportItemvParam.getDepartIds();
        }
        reportItemvParam.setDepartIds( JSUtils.quoteEach(departIds,","));
        List<ReportDateTrendVO> fyDataList =  commandCentreService.getFyData(reportItemvParam);

        List<ReportDateTrendVO> waterDataList =  reportItemvService.getDateFieldList(ReportConstant.view2119,"CSL", departIds, startDate,endDate);
        //水集合

        List<String> fyList =  new ArrayList<>();//电能数据数据;
        List<String> waterList =  new ArrayList<>();// 水集合

        List<String> dateTimeList = getMonthsBetween(startDate,endDate);
        for(String dateTime : dateTimeList){
            if(fyDataList != null ){
                for( ReportDateTrendVO dateTrendVO : fyDataList){
                    if( dateTime.equals( dateTrendVO.getTime() )){
                        fyList.add(ConvertUtils.getString( dateTrendVO.getValue() ,"0")) ;
                        break;
                    }
                }
            }
            if(waterDataList != null ){
                for( ReportDateTrendVO dateTrendVO : waterDataList){
                    if( dateTime.equals( dateTrendVO.getTime() )){
                        waterList.add(ConvertUtils.getString( dateTrendVO.getValue() ,"0")) ;
                        break;
                    }
                }
            }
        }
        StackedAreaChartDataVO  stackedAreaChartDataVO = new StackedAreaChartDataVO();
        stackedAreaChartDataVO.setElectricityList(fyList);//费用集合
        stackedAreaChartDataVO.setWaterList(waterList);//水集合
        stackedAreaChartDataVO.setDateList(dateTimeList);//日期集合
        stackedAreaChartDataVO.setXAxis(dateTimeList);

        List<String> yaXisList = new ArrayList<String>();
        yaXisList.addAll(fyList) ;//费用
        yaXisList.addAll(waterList) ;//水
        stackedAreaChartDataVO.setYAxis( yaXisList );

        Result<StackedAreaChartDataVO> result = new Result<>();
        result.setSuccess(true);
        result.setResult(stackedAreaChartDataVO);
        return  result;
    }


    @AutoLog(value = "指挥中心-药剂趋势")
    @ApiOperation(value="指挥中心-药剂趋势", notes="指挥中心-药剂趋势")
    @GetMapping(value = "/statisticsByYjqs")
    public Result<DepartDrugResult> statisticsByYjqs(@RequestParam(name = "month", required = true)String month) {
        DateVO dateVO = new DateVO(month);
        DepartDrugResult departDrugResult = commandCentreService.getYhTotal(dateVO.getNowMonth());
        Result<DepartDrugResult> result = new Result<>();
        result.setSuccess(true);
        result.setResult(departDrugResult);
        return result;
    }



    /**
     * 获取时间之间的月份
     * @param start
     * @param end
     * @return
     */
    private  List<String> getMonthsBetween(String start, String end) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        // 解析日期
        LocalDate startDate = LocalDate.parse(start, formatter);
        LocalDate endDate = LocalDate.parse(end, formatter);
        List<String> months = new ArrayList<>();
        // 获取起始和结束月份
        YearMonth startMonth = YearMonth.from(startDate);
        YearMonth endMonth = YearMonth.from(endDate);
        // 遍历月份并添加到列表
        YearMonth currentMonth = startMonth;
        while (!currentMonth.isAfter(endMonth)) {
            months.add(currentMonth.toString()); // 格式化为 yyyy-MM
            currentMonth = currentMonth.plusMonths(1);
        }
        return months;
    }

}