package com.shkpr.service.aimodelpower.bizmgr; import com.shkpr.service.aimodelpower.dbdao.DBMgrProxy; import com.shkpr.service.aimodelpower.dbdao.shizilaishuiDataSource.service.intef.WaterCollecationService; import com.shkpr.service.aimodelpower.dbdao.shizilaishuiDataSource.service.intef.WaterTapWaterService; import com.shkpr.service.aimodelpower.dto.ResponseCode; import com.shkpr.service.aimodelpower.dto.ResponseRes; import com.shkpr.service.aimodelpower.dto.zilaishuiModel.InPumpModel; import com.shkpr.service.aimodelpower.jsonbean.zilaishui.JPTbMHourWater; import com.shkpr.service.aimodelpower.jsonbean.zilaishui.JPTbMWater; import org.springframework.util.CollectionUtils; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; /** * @ClassName KprAimWaterCollecationBizFun * @Description: TODO * @Author LX * @Date 2024/5/27 * @Version V1.0 **/ public class KprAimWaterCollecationBizFun { private static final String MSG_SUCCESS = "success."; private static final String MSG_FAILED = "failed."; private static final String mStrClassName = "KprAimTapWaterBizFun"; private static final String EMPTY_NULL = "NULL"; public static WaterCollecationService getWaterTapWaterApi(){ return DBMgrProxy.getInstance().applyWaterCollecationService(); } static DateTimeFormatter formater = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); static DateTimeFormatter formater2 = DateTimeFormatter.ofPattern("yyyy-MM-dd"); //TODO 查询日取水量预测接口 /** * 1.传入水厂Id及起止日期(日期格式为YYYY-MM-DD),返回日期内,每天的预测取水量数据和实际取水量数据 * 2.同时返回指定截止日期之后,未来4天的预测水量数据和实际水量(如没有,则返回为空数据) */ public static ResponseRes selectTbWaterList(JPTbMWater jpTbMWater){ ResponseRes responseRes = new ResponseRes(); List> list =new ArrayList<>(); Map map = new HashMap<>(); map.put("ID",null); map.put("Date",null); map.put("Max_temperature",null); map.put("Min_temperature",null); map.put("Weather",null); map.put("Month",null); map.put("Week",null); map.put("Holiday",null); map.put("LastActualWaterWithdrawals",null); map.put("LastActualWaterSupply",null); map.put("ActualWaterWithdrawals",null); map.put("ActualWaterSupply",null); map.put("ForecastWaterWithdrawals",null); map.put("ForecastActualWaterSupply",null); map.put("isAbnormal",null); map.put("isForecast",null); map.put("LastModifyTime",null); list.add(map); responseRes.setResdata(list); responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode()); responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg()); try { // List> resList = getWaterTapWaterApi().getTbMWater(jpTbMWater.getIsPage(), jpTbMWater.getLimit(), jpTbMWater.getOffset(), jpTbMWater.getForDateStr()); if(!CollectionUtils.isEmpty(resList)){ responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode()); responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg()); responseRes.setResdata(resList); } return responseRes; }catch(Exception ex){ return responseRes; } } //TODO 小时取水量预测接口 /** * 传入水厂id及日期,返回指定日期内的小时取水量预测数据和实际小时取水量数据 */ public static ResponseRes selectTbHourWaterList(JPTbMHourWater jpTbMHourWater){ ResponseRes responseRes = new ResponseRes(); List> list =new ArrayList<>(); Map map = new HashMap<>(); map.put("ID",null); map.put("Date",null); map.put("Hour",null); map.put("HourForecastWaterWithdrawals",null); map.put("HourForecastActualWaterSupply",null); map.put("WaterWithdrawalsEnergy",null); map.put("WaterSupplyEnergy",null); map.put("RealWaterWithdrawalsEnergy",null); map.put("RealWaterSupplyEnergy",null); map.put("LastModifyTime",null); map.put("HourActualWaterWithdrawals",null); map.put("HourActualWaterSupply ",null); list.add(map); responseRes.setResdata(list); responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode()); responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg()); try { // List> resList = getWaterTapWaterApi().getTbMHourwater(jpTbMHourWater.getIsPage(), jpTbMHourWater.getLimit(), jpTbMHourWater.getOffset(), jpTbMHourWater.getForDateStr()); if(!CollectionUtils.isEmpty(resList)){ responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode()); responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg()); responseRes.setResdata(resList); } return responseRes; }catch(Exception ex){ return responseRes; } } //TODO 小时取水泵房电耗预测接口 /** * 传入水厂id及日期 */ public static ResponseRes selectTbMHourwaterWaterwithdrawals(JPTbMHourWater jpTbMHourWater,String subType){ ResponseRes responseRes = new ResponseRes(); //TODO 默认值 List defaultModels = new ArrayList<>(); InPumpModel entity = new InPumpModel(); entity.setOrgId(null); entity.setPumpId(null); entity.setSubType(subType); List> defaultRes = new ArrayList<>(); Map map = new HashMap<>(); map.put("ID",null); map.put("Date",null); map.put("Hour",null); map.put("PumpID",null); map.put("PumpStatus",null); map.put("HourForecastWaterWithdrawals",null); map.put("PumpWater",null); map.put("RealPumpStatus",null); map.put("PumpEnergy",null); map.put("RealPumpEnergy",null); map.put("LastModifyTime",null); map.put("orgId",null); defaultRes.add(map); defaultModels.add(entity); responseRes.setResdata(defaultModels); responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode()); responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg()); try { List> resList = getWaterTapWaterApi().getTbMHourwaterWaterwithdrawals(jpTbMHourWater.getIsPage(), jpTbMHourWater.getLimit(), jpTbMHourWater.getOffset(), jpTbMHourWater.getForDateStr()); //TODO 按水厂分组 Map>> groupedData = resList.stream().collect(Collectors.groupingBy(item -> item.get("orgId"))); //TODO 查询水厂的取水泵,然后将数据拼接 List inPumpModels = new ArrayList<>(); for (Object key:groupedData.keySet()) { InPumpModel model = new InPumpModel(); List> zoonList = getWaterTapWaterApi().getZoonInfoList(key.toString(),subType); if(!CollectionUtils.isEmpty(zoonList)){ model.setPumpId(zoonList.get(0).get("uid").toString()); } model.setOrgId(key.toString()); model.setSubType(subType); List> dataList = groupedData.get(key); //TODO 将年月日时作为分组条件 Map>> dataMap = dataList.stream() .collect(Collectors.groupingBy(emp -> emp.get("Date") + " " + emp.get("Hour") // 创建复合键 )); model.setDataList(dataMap); //TODO 查询相应方案数据 List> drawalsList = getWaterTapWaterApi().getTbMWaterwithdrawalspump(false, 20,0," AND orgId = '"+key.toString()+"'"); model.setDrawalsList(drawalsList); inPumpModels.add(model); } if(!CollectionUtils.isEmpty(inPumpModels)){ responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode()); responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg()); responseRes.setResdata(inPumpModels); } return responseRes; }catch(Exception ex){ return responseRes; } } //TODO 小时供水泵房电耗预测接口 /** * 传入水厂id及日期 */ public static ResponseRes selectTbMHourwaterWatersupply(JPTbMHourWater jpTbMHourWater,String subType){ ResponseRes responseRes = new ResponseRes(); //TODO 默认值 List defaultModels = new ArrayList<>(); InPumpModel entity = new InPumpModel(); entity.setOrgId(null); entity.setPumpId(null); entity.setSubType(subType); List> defaultRes = new ArrayList<>(); Map map = new HashMap<>(); map.put("ID",null); map.put("Date",null); map.put("Hour",null); map.put("PumpID",null); map.put("PumpStatus",null); map.put("HourForecastActualWaterSupply",null); map.put("PumpWater",null); map.put("RealPumpStatus",null); map.put("PumpEnergy",null); map.put("RealPumpEnergy",null); map.put("LastModifyTime",null); map.put("orgId",null); defaultRes.add(map); defaultModels.add(entity); responseRes.setResdata(defaultModels); responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode()); responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg()); try { // List> resList = getWaterTapWaterApi().getTbMHourwaterWatersupply(jpTbMHourWater.getIsPage(), jpTbMHourWater.getLimit(), jpTbMHourWater.getOffset(), jpTbMHourWater.getForDateStr()); //TODO 按水厂分组 Map>> groupedData = resList.stream().collect(Collectors.groupingBy(item -> item.get("orgId"))); //TODO 查询水厂的取水泵,然后将数据拼接 List inPumpModels = new ArrayList<>(); for (Object key:groupedData.keySet()) { InPumpModel model = new InPumpModel(); List> zoonList = getWaterTapWaterApi().getZoonInfoList(key.toString(),subType); if(!CollectionUtils.isEmpty(zoonList)){ model.setPumpId(zoonList.get(0).get("uid").toString()); } model.setOrgId(key.toString()); model.setSubType(subType); List> dataList = groupedData.get(key); //TODO 将年月日时作为分组条件 Map>> dataMap = dataList.stream() .collect(Collectors.groupingBy(emp -> emp.get("Date") + " " + emp.get("Hour") // 创建复合键 )); model.setDataList(dataMap); //TODO 查询相应方案数据 List> drawalsList = getWaterTapWaterApi().getTbMWatersupplypump(false, 20,0," AND orgId = '"+key.toString()+"'"); model.setDrawalsList(drawalsList); inPumpModels.add(model); } if(!CollectionUtils.isEmpty(inPumpModels)){ responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode()); responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg()); responseRes.setResdata(inPumpModels); } return responseRes; }catch(Exception ex){ return responseRes; } } }