package com.whyc.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.whyc.dto.Real.CompareDto; import com.whyc.dto.Real.PwrHisRealAcInDto; import com.whyc.dto.Real.PwrHisRealDcoutInDto; import com.whyc.dto.Real.QuarterDto; import com.whyc.dto.Response; import com.whyc.dto.Statistic.QuarterPwr7Res; import com.whyc.mapper.CommonMapper; import com.whyc.pojo.db_data_history.BattRealdataId; import com.whyc.pojo.db_data_history.PwrdevHistorydataId; import com.whyc.pojo.db_param.AppParam; import com.whyc.pojo.db_param.ApptimeParam; import com.whyc.pojo.db_param.PowerPropertyParam; import com.whyc.pojo.db_station.PowerInf; import com.whyc.util.ActionUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class PwrdevHistorydataIdService { @Autowired private SubTablePageInfoService subTablePageInfoService; @Resource private CommonMapper commonMapper; @Autowired private PowerInfService powerInfService; @Autowired private AppParamService appParamService; @Autowired private ApptimeParamService apptimeParamService; @Autowired private PowerPropertyParamService propertyParamService; //系统概览获取半小时交流输入统计 public Response getHalfHourPwrHisAcinData(Integer powerId,Integer granularity) { String dateTime = ActionUtil.sdfwithOutday.format(new Date()); //获取前半个小时数据 LocalDateTime now = LocalDateTime.now(); // 计算半小时前的时间点 LocalDateTime halfHourAgo = now.minusMinutes(30); // 格式化输出 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String halfHourAgoTime=halfHourAgo.format(formatter); String tableName ="db_data_history.tb_pwrdev_historydata_"+powerId+"_"+dateTime; String existTableName = commonMapper.existTable("db_data_history", "tb_pwrdev_historydata_"+powerId+"_"+dateTime); if(existTableName == null){ return new Response().set(1,false,"当前电池组不存在前面小时数据"); } List datalist=subTablePageInfoService.getHalfHourPwrHisAcinData(tableName,granularity,halfHourAgoTime); return new Response().setII(1,datalist.size()>0,datalist,"获取半小时内交流输入统计"); } //系统概览获取半小时直流输出统计 public Response getHalfHourPwrHisDcoutData(Integer powerId,Integer granularity) { String dateTime = ActionUtil.sdfwithOutday.format(new Date()); //获取前半个小时数据 LocalDateTime now = LocalDateTime.now(); // 计算半小时前的时间点 LocalDateTime halfHourAgo = now.minusMinutes(30); // 格式化输出 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String halfHourAgoTime=halfHourAgo.format(formatter); String tableName ="db_data_history.tb_pwrdev_historydata_"+powerId+"_"+dateTime; String existTableName = commonMapper.existTable("db_data_history", "tb_pwrdev_historydata_"+powerId+"_"+dateTime); if(existTableName == null){ return new Response().set(1,false,"当前电源不存在前面小时数据"); } List datalist=subTablePageInfoService.getHalfHourPwrHisDcoutData(tableName,granularity,halfHourAgoTime); Long modelCfg=0l; PowerInf pinf=powerInfService.getPowerInfById(powerId); if(pinf!=null){ modelCfg=pinf.getModelCfg(); } return new Response().setIII(1,datalist.size()>0,datalist,modelCfg,"获取半小时内直流输出统计"); } //1.2.7优良电源统计上一季度的电源某一属性和参数阈值超过的次数 public Integer getPwrQuarter7(Integer powerId,Integer powerType) { Map map=new HashMap<>(); //获取优良电源性能统计在平台上的时间参数设置表 ApptimeParam apptimeParam=apptimeParamService.getPwrPerformanceStrartTime(powerId); //获取指定时间到当前时间一共多少月的集合 List datelist=ActionUtil.getDateListBetweenDates(apptimeParam.getParamValue(), new Date()); //获取电源优良判断的标准参数值 List paramList=propertyParamService.getPwrStandardParam(powerType); Map paramValues=new HashMap<>(); for (PowerPropertyParam param : paramList) { paramValues.put(param.getPropertyName()+"_upper", param.getBasisVal()*param.getAlarmLimithUpper()); paramValues.put(param.getPropertyName()+"_lower", param.getBasisVal()*param.getAlarmLimithLowper()); map.put(param.getPropertyName(), 0); } for (int i=0;i datalist=subTablePageInfoService.getPwrQuarter7(tableName); // 遍历 dataList 并比较属性值 for (QuarterPwr7Res data : datalist) { if(paramValues.get("acin1_vola_upper")!=null){ if ((data.getAcin1Vola() > paramValues.get("acin1_vola_upper"))||(data.getAcin1Vola() < paramValues.get("acin1_vola_lower"))) { map.put("acin1_vola", map.get("acin1_vola") + 1); } } if(paramValues.get("acout_curra_upper")!=null) { if ((data.getAcoutCurra() > paramValues.get("acout_curra_upper")) || (data.getAcoutCurra() < paramValues.get("acout_curra_lower"))) { map.put("acout_curra", map.get("acout_curra") + 1); } } if(paramValues.get("dcout_vol_upper")!=null) { if ((data.getDcoutVol() > paramValues.get("dcout_vol_upper")) || (data.getDcoutVol() < paramValues.get("dcout_vo_lower"))) { map.put("dcout_vol", map.get("dcout_vol") + 1); } } if(paramValues.get("dcout_curr_upper")!=null) { if ((data.getDcoutCurr() > paramValues.get("dcout_curr_upper")) || (data.getDcoutCurr() < paramValues.get("dcout_curr_lower"))) { map.put("dcout_curr", map.get("dcout_curr") + 1); } } } } return 1; } //判断优良电源性能 private Integer judgePwrPerformence(Map map){ //获取apps中优良电源判断参数 List appParamList=appParamService.getPwrPerformenceParam(); Float excellentVal=0f; Float commonlyVal=0f; Float warningVal=0f; for (AppParam appParam : appParamList) { if(appParam.getParamNamePsx().equals("power_excellent_val")){ excellentVal=appParam.getParamValue(); } if(appParam.getParamNamePsx().equals("power_commonly_val")){ commonlyVal=appParam.getParamValue(); } if(appParam.getParamNamePsx().equals("power_warning_val")){ warningVal=appParam.getParamValue(); } } return 1; } }