diff --git a/business-service-api/src/main/java/com/ho/business/vo/resp/ShipStationRespVO.java b/business-service-api/src/main/java/com/ho/business/vo/resp/ShipStationRespVO.java new file mode 100644 index 0000000..0e4bb4d --- /dev/null +++ b/business-service-api/src/main/java/com/ho/business/vo/resp/ShipStationRespVO.java @@ -0,0 +1,47 @@ +package com.ho.business.vo.resp; + +import com.alibaba.fastjson.JSONArray; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 主监控汇总信息 + */ +@Data +public class ShipStationRespVO { + + @ApiModelProperty(value = "储能系统累计收益,单位(元)") + private Float incomeSum; + @ApiModelProperty(value = "储能系统昨⽇收益") + private Float incomeYesterday; + @ApiModelProperty(value = "储能系统累计充电量,单位(kWh)") + private Float positivePowerSum; + @ApiModelProperty(value = "储能系统累计放电量,单位(kWh)") + private Float reversePowerSum; + @ApiModelProperty(value = "储能系统今⽇充电量,单位(kWh)") + private Float positivePowerToday; + @ApiModelProperty(value = "储能系统今⽇放电量,单位(kWh)") + private Float reversePowerToday; + @ApiModelProperty(value = "储能系统实时功率,单位(kw)") + private Float realTimePower; + @ApiModelProperty(value = "关⼝表电压,单位(v)") + private Float voltage; + @ApiModelProperty(value = "储能系统剩余电量,单位(kwh)") + private Float surplus; + @ApiModelProperty(value = "储能系统剩余SOC") + private Float soc; + @ApiModelProperty(value = "储能系统装机容量,单位(kWh)") + private Integer capacity; + @ApiModelProperty(value = "储能系统投运时⻓,单位(天)") + private Integer operationTime; + @ApiModelProperty(value = "储能系统能量链数量,单位(条)") + private Integer eLinkNumber; + @ApiModelProperty(value = "储能系统在线能量链数量,单位(条)") + private Integer eLinkOnline; + @ApiModelProperty(value = "储能系统能量块数量,单位(个)") + private Integer eBLockNumber; + @ApiModelProperty(value = "储能系统在线能量块数量,单位(个)") + private Integer eBlockOnline; + @ApiModelProperty(value = "储能系统今⽇功率和soc曲线") + private JSONArray historyDataList; +} diff --git a/business-service-dao/src/main/java/com/ho/business/mapper/EarningsCalculateMapper.java b/business-service-dao/src/main/java/com/ho/business/mapper/EarningsCalculateMapper.java index 37e2689..fbb74e0 100644 --- a/business-service-dao/src/main/java/com/ho/business/mapper/EarningsCalculateMapper.java +++ b/business-service-dao/src/main/java/com/ho/business/mapper/EarningsCalculateMapper.java @@ -28,7 +28,7 @@ public interface EarningsCalculateMapper { int insertSelective(EarningsCalculate record); int deleteByDay(@Param("day") String day, @Param("typeList") List typeList); - + int deleteByStationAndDay(@Param("day") String day, @Param("typeList") List typeList, @Param("stationId") Integer stationId); int insertBatch(List list); // 类型是传入多个 //List selectList(@Param("stationId") Integer stationId, @Param("typeList") List typeList, @Param("beginTime") String beginTime, @Param("endTime") String endTime); diff --git a/business-service-dao/src/main/java/com/ho/business/service/ShipEnergyService.java b/business-service-dao/src/main/java/com/ho/business/service/ShipEnergyService.java index 49ce30d..bb7179f 100644 --- a/business-service-dao/src/main/java/com/ho/business/service/ShipEnergyService.java +++ b/business-service-dao/src/main/java/com/ho/business/service/ShipEnergyService.java @@ -1,22 +1,34 @@ package com.ho.business.service; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Maps; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.ho.business.constant.DeviceTypeConstant; +import com.ho.business.entity.EarningsCalculate; +import com.ho.business.entity.ElecMeterValue; +import com.ho.business.entity.Station; +import com.ho.business.mapper.EarningsCalculateMapper; import com.ho.business.vo.req.StationReqVO; +import com.ho.business.vo.resp.ShipStationRespVO; import com.ho.common.tools.constant.CommonConstant; +import com.ho.common.tools.exception.BaseResponseCode; +import com.ho.common.tools.exception.BusinessException; import com.ho.common.tools.service.RedisService; import com.ho.common.tools.util.HttpUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.web.jsf.FacesContextUtils; import java.io.IOException; import java.math.BigDecimal; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import java.text.SimpleDateFormat; +import java.util.*; import java.util.concurrent.TimeUnit; /** @@ -29,10 +41,6 @@ import java.util.concurrent.TimeUnit; @Slf4j public class ShipEnergyService { - /** - * token 缓存 key - */ - private static final String SHIP_ENERGY_TOKEN_KEY = "ShipEnergyToken"; /** * 获取token 参数 platform @@ -58,6 +66,10 @@ public class ShipEnergyService { * 寄点能源- 主监控汇总 Url */ private static final String MAIN_URL = "https://www.emind2000.cloud/rest-api/getMainTotal"; + /** + * 寄点能源- 历史收益 Url + */ + private static final String INCOME_HIS_URL = "https://www.emind2000.cloud/rest-api/getIncomeHis"; @Autowired private RedisService redisService; @@ -65,27 +77,36 @@ public class ShipEnergyService { @Autowired private StationService stationService; + @Autowired + ElecMeterValueService elecMeterValueService; + + @Autowired + EarningsCalculateMapper earningsCalculateMapper; + /** * 寄点能源 - 获取token * @return token */ public String getToken(){ String token = null; - if(redisService.hasKey(SHIP_ENERGY_TOKEN_KEY)){ - token = (String)redisService.get(SHIP_ENERGY_TOKEN_KEY); + if(redisService.hasKey(CommonConstant.SHIP_ENERGY_TOKEN_KEY)){ + token = (String)redisService.get(CommonConstant.SHIP_ENERGY_TOKEN_KEY); + return token; } Map params = Maps.newHashMap(); params.put("platform",PLATFORM); params.put("platformsecret",PLATFORM_SECRET); try { String json = HttpUtils.getWithForm(TOKEN_URL,params); + log.info("json:" + TOKEN_URL); + log.info("json:" + json); JSONObject jsonObject = JSONObject.parseObject(json); Integer code = jsonObject.getInteger("code"); if(CommonConstant.HttpCode.SUCCESS_CODE.equals(code)){ JSONObject data = jsonObject.getJSONObject("data"); token = data.getString("access_token"); //redis 缓存 - redisService.set(SHIP_ENERGY_TOKEN_KEY,token,10, TimeUnit.HOURS); + redisService.set(CommonConstant.SHIP_ENERGY_TOKEN_KEY,token,10, TimeUnit.HOURS); } } catch (IOException e) { throw new RuntimeException(e); @@ -98,11 +119,12 @@ public class ShipEnergyService { * @return 项目列表 json 字符串 */ public String getStations(){ - String Authorization = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjo5Nzg2LCJ1c2VyX2tleSI6Ijk3ODY6N2RkNjU0MTgtNDg5ZS00MzgzLWI1ZmYtMTU2MmI5ZTY0NDFkIiwidXNlcm5hbWUiOiJ6emt5YXBpIn0.fQLMlOHaEjmfHeyEu5EcxZmQ8UjRBOUoteNV-tJ2ttAwyJmQidOk7xqL25K_wRIC-OQKt0vFVOpTzMFdH71uhw"; Map headers = new HashMap<>(); - headers.put("Authorization",Authorization); + headers.put("Authorization", getToken()); try { String json = HttpUtils.getWithHeaders(STATION_URL,null,headers); + log.info("json:" + STATION_URL); + log.info("json:" + json); JSONObject jsonObject = JSONObject.parseObject(json); Integer code = jsonObject.getInteger("code"); if(CommonConstant.HttpCode.SUCCESS_CODE.equals(code)){ @@ -121,14 +143,42 @@ public class ShipEnergyService { * @param stationId 电站id * @return 返回对应电站汇总信息 */ - public String getMainTotal(String stationId){ - String Authorization = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjo5Nzg2LCJ1c2VyX2tleSI6Ijk3ODY6MmE5YjUzODUtNjNiNC00OWRiLWFjODEtNzhmNWRmNjE0ZDgyIiwidXNlcm5hbWUiOiJ6emt5YXBpIn0.WMi4PgYQByeYXBfOGVM0mc4P5GcyAcGRkDo8F7TK8fXIkj9QZ9D34WmugiVX3GxRGODFs3u1ujH7qJyuQAM99w"; + public String getMainTotal(Integer stationId){ Map headers = new HashMap<>(); - headers.put("Authorization",Authorization); + headers.put("Authorization", getToken()); Map params = new HashMap<>(); - params.put("stationId",stationId); + params.put("stationId",stationId.toString()); try { + Thread.sleep(2000); String json = HttpUtils.getWithHeaders(MAIN_URL,params,headers); + log.info("MAIN_URL:" + MAIN_URL); + log.info("json:" + json); + JSONObject jsonObject = JSONObject.parseObject(json); + Integer code = jsonObject.getInteger("code"); + if(CommonConstant.HttpCode.SUCCESS_CODE.equals(code)){ + return jsonObject.getString("data"); + } + } catch (IOException e) { + throw new RuntimeException(e); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return null; + } + /** + * 寄点能源 - 获取 历史收益查询 + */ + public String getIncomeHis(Integer stationId,String beginTime){ + Map headers = new HashMap<>(); + headers.put("Authorization", getToken()); + Map params = new HashMap<>(); + params.put("stationId",stationId.toString()); + params.put("startTime",beginTime+CommonConstant.START_SUFFIX_TIMESTAMP); + params.put("endTime",beginTime+CommonConstant.END_SUFFIX_TIMESTAMP); + try { + String json = HttpUtils.getWithHeaders(INCOME_HIS_URL,params,headers); + log.info("INCOME_HIS_URL:" + INCOME_HIS_URL); + log.info("json:" + json); JSONObject jsonObject = JSONObject.parseObject(json); Integer code = jsonObject.getInteger("code"); if(CommonConstant.HttpCode.SUCCESS_CODE.equals(code)){ @@ -145,8 +195,8 @@ public class ShipEnergyService { * 寄点能源 - 电站信息融合储能平台处理 */ public void addShipEnergyStation(){ - String stationJson = getStations(); - JSONArray jsonStation = JSON.parseArray(stationJson); + String json = getStations(); + JSONArray jsonStation = JSON.parseArray(json); jsonStation.forEach(i->{ JSONObject jsonObj = (JSONObject) i; Integer stationId = jsonObj.getInteger("stationId"); @@ -169,9 +219,224 @@ public class ShipEnergyService { vo.setRatePower(maxPower); vo.setGridTime(commossioningTime); vo.setGroupId(155); - vo.setDeptId(155); + vo.setDeptId(592); + vo.setStatus(1); + vo.setType(7); + vo.setPId(0); + vo.setIsDailyCount(0); + vo.setTopologyType(1); + vo.setCupboardType(2); + Station station = stationService.selectByName(vo.getName()); + if (station != null) { + throw new BusinessException(BaseResponseCode.STATION_ALREADY_EXISTS); + } stationService.insertStation(vo); }); } + /** + * 寄点能源 - 缓存电站监控信息 + */ + public void getShipEnergyTotal(){ + String stations = getStations(); + JSONArray jsonStation = JSON.parseArray(stations); + jsonStation.forEach(i->{ + JSONObject jsonObj = (JSONObject) i; + Integer stationId = jsonObj.getInteger("stationId"); + String json = getMainTotal(stationId); + String mainKey = CommonConstant.SHIP_ENERGY_MAIN + stationId; + redisService.set(mainKey,json); + }); + } + + /** + * 寄点能源 - 获取寄点电站历史收益 并存储 + */ + public void getStationIncomeHis(String beginTime){ + DateTime yesterday = DateUtil.yesterday(); + String yesterdayStr = DateUtil.formatDate(yesterday); + if(beginTime==null){ + beginTime = yesterdayStr; + } + String stations = getStations(); + JSONArray jsonStation = JSON.parseArray(stations); + String finalBeginTime = beginTime; + jsonStation.forEach(i->{ + JSONObject jsonObj = (JSONObject) i; + Integer stationId = jsonObj.getInteger("stationId"); + String incomeHis = getIncomeHis(stationId, finalBeginTime); + JSONArray incomes = JSON.parseArray(incomeHis); + incomes.forEach(j->{ + JSONObject income = (JSONObject) j; + String date=income.getString("date"); + String price = income.getString("price"); + JsonObject jsonPrice = JsonParser.parseString(price).getAsJsonObject(); + List list = new ArrayList<>(); + List elecList = new ArrayList<>(); + BigDecimal inTotalIncome = BigDecimal.ZERO; + BigDecimal outTotalIncome = BigDecimal.ZERO; + if(finalBeginTime.equals(date)){ + //收益-充-尖 + EarningsCalculate inSharp = new EarningsCalculate(); + BigDecimal positiveSharp = income.getBigDecimal("sum_e_positive_sharp"); + inSharp.setElec(positiveSharp); + inSharp.setType(0); + inSharp.setRateType(CommonConstant.RateType.TIP); + BigDecimal inSharpPrice = jsonPrice.get("in_sharp_price").getAsBigDecimal(); + inSharp.setPrice(inSharpPrice); + inSharp.setDigital(positiveSharp.multiply(inSharpPrice)); + inTotalIncome = inTotalIncome.add(inSharp.getDigital()); + inSharp.setTotal(BigDecimal.ZERO); + list.add(inSharp); + //收益-充-峰 + EarningsCalculate inPeak = new EarningsCalculate(); + BigDecimal positivePeak = income.getBigDecimal("sum_e_positive_peak"); + inPeak.setElec(positivePeak); + inPeak.setType(0); + inPeak.setRateType(CommonConstant.RateType.PEAK); + BigDecimal inPeakPrice = jsonPrice.get("in_peak_price").getAsBigDecimal(); + inPeak.setPrice(inPeakPrice); + inPeak.setDigital(positivePeak.multiply(inPeakPrice)); + inTotalIncome = inTotalIncome.add(inPeak.getDigital()); + inPeak.setTotal(BigDecimal.ZERO); + list.add(inPeak); + //收益-充-平 + EarningsCalculate inFlat = new EarningsCalculate(); + BigDecimal positiveFlat = income.getBigDecimal("sum_e_positive_flat"); + inFlat.setElec(positiveFlat); + inFlat.setType(0); + inFlat.setRateType(CommonConstant.RateType.FLAT); + BigDecimal inFlatPrice = jsonPrice.get("in_flat_price").getAsBigDecimal(); + inFlat.setPrice(inFlatPrice); + inFlat.setDigital(positiveFlat.multiply(inFlatPrice)); + inTotalIncome = inTotalIncome.add(inFlat.getDigital()); + inFlat.setTotal(BigDecimal.ZERO); + list.add(inFlat); + //收益-充-谷 + EarningsCalculate inValley = new EarningsCalculate(); + BigDecimal positiveValley = income.getBigDecimal("sum_e_positive_valley"); + inValley.setElec(positiveValley); + inValley.setType(0); + inValley.setRateType(CommonConstant.RateType.VALLEY); + BigDecimal inValleyPrice = jsonPrice.get("in_valley_price").getAsBigDecimal(); + inValley.setPrice(inValleyPrice); + inValley.setDigital(positiveValley.multiply(inValleyPrice)); + inTotalIncome = inTotalIncome.add(inValley.getDigital()); + inValley.setTotal(BigDecimal.ZERO); + list.add(inValley); + //收益-充-深谷 + EarningsCalculate inDeepValley = new EarningsCalculate(); + BigDecimal positiveDeepValley = income.getBigDecimal("sum_e_positive_deep_valley"); + inDeepValley.setElec(positiveDeepValley); + inDeepValley.setType(0); + inDeepValley.setRateType(CommonConstant.RateType.DEEP_VALLEY); + BigDecimal inDeepValleyPrice = jsonPrice.get("in_deep_valley_price").getAsBigDecimal(); + inDeepValley.setPrice(inDeepValleyPrice); + inDeepValley.setDigital(positiveDeepValley.multiply(inDeepValleyPrice)); + inTotalIncome = inTotalIncome.add(inValley.getDigital()); + inDeepValley.setTotal(inTotalIncome); + list.add(inDeepValley); + //收益-放-尖 + EarningsCalculate outSharp = new EarningsCalculate(); + BigDecimal reverseSharp = income.getBigDecimal("sum_e_reverse_sharp"); + outSharp.setElec(reverseSharp); + outSharp.setType(1); + outSharp.setRateType(CommonConstant.RateType.TIP); + BigDecimal outSharpPrice = jsonPrice.get("out_sharp_price").getAsBigDecimal(); + outSharp.setPrice(outSharpPrice); + outSharp.setDigital(reverseSharp.multiply(outSharpPrice)); + outTotalIncome = outTotalIncome.add(outSharp.getDigital()); + outSharp.setTotal(BigDecimal.ZERO); + list.add(outSharp); + //收益-放-峰 + EarningsCalculate outPeak = new EarningsCalculate(); + BigDecimal reversePeak = income.getBigDecimal("sum_e_reverse_peak"); + outPeak.setElec(reversePeak); + outPeak.setType(1); + outPeak.setRateType(CommonConstant.RateType.PEAK); + BigDecimal outPeakPrice = jsonPrice.get("out_peak_price").getAsBigDecimal(); + outPeak.setPrice(outPeakPrice); + outPeak.setDigital(reversePeak.multiply(outPeakPrice)); + outTotalIncome = outTotalIncome.add(outPeak.getDigital()); + outPeak.setTotal(BigDecimal.ZERO); + list.add(outPeak); + //收益-放-平 + EarningsCalculate outFlat = new EarningsCalculate(); + BigDecimal reverseFlat = income.getBigDecimal("sum_e_reverse_flat"); + outFlat.setElec(reverseFlat); + outFlat.setType(1); + outFlat.setRateType(CommonConstant.RateType.FLAT); + BigDecimal outFlatPrice = jsonPrice.get("out_flat_price").getAsBigDecimal(); + outFlat.setPrice(outFlatPrice); + outFlat.setDigital(reverseFlat.multiply(outFlatPrice)); + outTotalIncome = outTotalIncome.add(outFlat.getDigital()); + outFlat.setTotal(BigDecimal.ZERO); + list.add(outFlat); + //收益-放-谷 + EarningsCalculate outValley = new EarningsCalculate(); + BigDecimal reverseValley = income.getBigDecimal("sum_e_reverse_valley"); + outValley.setElec(reverseValley); + outValley.setType(1); + outValley.setRateType(CommonConstant.RateType.VALLEY); + BigDecimal outValleyPrice = jsonPrice.get("out_valley_price").getAsBigDecimal(); + outValley.setPrice(outValleyPrice); + outValley.setDigital(reverseValley.multiply(outValleyPrice)); + outTotalIncome = outTotalIncome.add(outValley.getDigital()); + outValley.setTotal(BigDecimal.ZERO); + list.add(outValley); + //收益-放-深谷 + EarningsCalculate outDeepValley = new EarningsCalculate(); + BigDecimal reverseDeepValley = income.getBigDecimal("sum_e_reverse_deep_valley"); + outDeepValley.setElec(reverseDeepValley); + outDeepValley.setType(1); + outDeepValley.setRateType(CommonConstant.RateType.DEEP_VALLEY); + BigDecimal outDeepValleyPrice = jsonPrice.get("out_deep_valley_price").getAsBigDecimal(); + outDeepValley.setPrice(outDeepValleyPrice); + outDeepValley.setDigital(reverseDeepValley.multiply(outDeepValleyPrice)); + outTotalIncome = outTotalIncome.add(outDeepValley.getDigital()); + outDeepValley.setTotal(outTotalIncome); + list.add(outDeepValley); + // 充电 + ElecMeterValue charge = new ElecMeterValue(); + BigDecimal sumEPositive = income.getBigDecimal("sum_e_positive"); + charge.setDigital(sumEPositive); + charge.setType(DeviceTypeConstant.ELEC_METER_VALUE_TYPE.CHARGE); + charge.setStatus(CommonConstant.STATUS_FLAG); + elecList.add(charge); + // 放电 + ElecMeterValue disCharge = new ElecMeterValue(); + BigDecimal sumEReverse = income.getBigDecimal("sum_e_reverse"); + disCharge.setDigital(sumEReverse); + disCharge.setType(DeviceTypeConstant.ELEC_METER_VALUE_TYPE.DISCHARGE); + disCharge.setStatus(CommonConstant.STATUS_FLAG); + elecList.add(disCharge); + } + if(elecList.size()>0){ + //删除 + elecMeterValueService.deleteByStationAndDay(stationId+10000,date,null); + elecList.forEach(eleMeter -> { + eleMeter.setGroupId(155); + eleMeter.setStationId(stationId+10000); + eleMeter.setCreateTime(new Date()); + eleMeter.setDay(date); + //新增 + elecMeterValueService.insert(eleMeter); + }); + } + if(list.size()>0){ + //删除 + earningsCalculateMapper.deleteByStationAndDay(date,null,stationId+10000); + list.forEach(a->{ + a.setGroupId(155); + a.setStationId(stationId+10000); + a.setCreateTime(new Date()); + a.setDay(date); + a.setDiscount(BigDecimal.ONE); + //新增 + earningsCalculateMapper.insertSelective(a); + }); + } + }); + }); + } } diff --git a/business-service-dao/src/main/java/com/ho/business/service/impl/EarningsCalculateServiceImpl.java b/business-service-dao/src/main/java/com/ho/business/service/impl/EarningsCalculateServiceImpl.java index 0e469c6..17ae4e7 100644 --- a/business-service-dao/src/main/java/com/ho/business/service/impl/EarningsCalculateServiceImpl.java +++ b/business-service-dao/src/main/java/com/ho/business/service/impl/EarningsCalculateServiceImpl.java @@ -6,6 +6,7 @@ import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.StringUtils; +import com.alibaba.fastjson.JSON; import com.ho.business.constant.DeviceTypeConstant; import com.ho.business.entity.*; import com.ho.business.feignclient.UserFeignClient; @@ -25,6 +26,7 @@ import com.ho.business.vo.req.report.ReportReqVO; import com.ho.business.vo.resp.CountEleData; import com.ho.business.vo.resp.DeviceRespVO; import com.ho.business.vo.resp.InverterResp.PowerGenerateRespVO; +import com.ho.business.vo.resp.ShipStationRespVO; import com.ho.business.vo.resp.cabin.EarningsCalculateCountResp; import com.ho.business.vo.resp.cabin.EarningsCalculateResp; import com.ho.business.vo.resp.colCount.ColCountResp; @@ -1445,6 +1447,17 @@ public class EarningsCalculateServiceImpl implements EarningsCalculateService { revenueOverview.setStationName(station.getName()); revenueOverview.setCapacity(station.getCapacity()); revenueOverview.setOperationDays((int) operationDays); + if(station.getId()==11003 || station.getId()==10942){ + // 寄点电站数据 + Integer stationId = station.getId()-10000; + String mainKey = CommonConstant.SHIP_ENERGY_MAIN + stationId; + String json = (String)redisService.get(mainKey); + ShipStationRespVO respVO = JSON.parseObject(json,ShipStationRespVO.class); + revenueOverview.setCharging(BigDecimal.valueOf(respVO.getPositivePowerSum())); + revenueOverview.setDischarging(BigDecimal.valueOf(respVO.getReversePowerSum())); + revenueOverview.setTotalRevenue(BigDecimal.valueOf(respVO.getIncomeSum())); + return revenueOverview; + } List list = getRevenueOverviewData(vo); diff --git a/business-service-dao/src/main/java/com/ho/business/service/impl/IargeScreenShowServiceImpl.java b/business-service-dao/src/main/java/com/ho/business/service/impl/IargeScreenShowServiceImpl.java index 259becd..d95f8db 100644 --- a/business-service-dao/src/main/java/com/ho/business/service/impl/IargeScreenShowServiceImpl.java +++ b/business-service-dao/src/main/java/com/ho/business/service/impl/IargeScreenShowServiceImpl.java @@ -3,6 +3,7 @@ package com.ho.business.service.impl; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; import com.ho.business.constant.DeviceTypeConstant; import com.ho.business.entity.Device; import com.ho.business.entity.ElecMeterValue; @@ -17,6 +18,7 @@ import com.ho.business.vo.req.colCount.ColCountReq; import com.ho.business.vo.resp.CountEleData; import com.ho.business.vo.resp.DeviceRespVO; import com.ho.business.vo.resp.ProvinceStation; +import com.ho.business.vo.resp.ShipStationRespVO; import com.ho.business.vo.resp.colCount.ColCountResp; import com.ho.business.vo.resp.iargeScreen.*; import com.ho.business.vo.resp.mppt.MpptActiveVo; @@ -287,22 +289,10 @@ public class IargeScreenShowServiceImpl implements IargeScreenShowService { BigDecimal dayCharge = BigDecimal.ZERO; BigDecimal dayDischarge = BigDecimal.ZERO; StringBuffer stationDayLog = new StringBuffer(); -// ColCountReq colCountReq = new ColCountReq(); -// colCountReq.setCol(DataCollectConstant.Elec_Meter.TOTAL_CHARGE); -// List ids = stations.stream().map(Station::getId).collect(Collectors.toList()); -// colCountReq.setIds(ids); -// List colCountResps = colCountService.selectByParam(colCountReq); -// Map stationMapAndType = new HashMap<>(); -// if (colCountResps != null) { -// stationMapAndType = colCountResps.stream().collect(Collectors.toMap(ColCountResp::getStationId, ColCountResp::getDeviceType, (k1, k2) -> k1)); -// } + for (Station station : stations) { -// StationReq req = new StationReq(); -// req.setStationId(station.getId()); -// req.setDeviceType(stationMapAndType.get(req.getStationId())); BigDecimal dailyChargeElec = BigDecimal.ZERO; BigDecimal dailyDischargeElec = BigDecimal.ZERO; - // CountEleData countEleData = stationHomeService.getCountEleData(req); CountEleData countEleData = getByRedisData(station.getId()); if (null == countEleData || null == countEleData.getDailyChargeElec() || null == countEleData.getDailyDischargeElec()) { dailyChargeElec = BigDecimal.ZERO; @@ -357,6 +347,20 @@ public class IargeScreenShowServiceImpl implements IargeScreenShowService { annualOverviewResp.setTotalCharge(incomeShow1.getYearCharge()); annualOverviewResp.setTotalDischarge(incomeShow1.getYearDischarge()); } + // 寄点站点数据融合 + stations.forEach(s->{ + if(s.getId()==11003 || s.getId()==10942) { + // 寄点电站数据 + Integer stationId = s.getId() - 10000; + String mainKey = CommonConstant.SHIP_ENERGY_MAIN + stationId; + String json = (String) redisService.get(mainKey); + ShipStationRespVO respVO = JSON.parseObject(json, ShipStationRespVO.class); + // 日充 + annualOverviewResp.setDayCharge(annualOverviewResp.getDayCharge().add(BigDecimal.valueOf(respVO.getPositivePowerToday()))); + // 日放 + annualOverviewResp.setDayDischarge(annualOverviewResp.getDayDischarge().add(BigDecimal.valueOf(respVO.getReversePowerToday()))); + } + }); return annualOverviewResp; } diff --git a/business-service-dao/src/main/java/com/ho/business/service/impl/OutApiServiceImpl.java b/business-service-dao/src/main/java/com/ho/business/service/impl/OutApiServiceImpl.java index 08444b7..e032fb9 100644 --- a/business-service-dao/src/main/java/com/ho/business/service/impl/OutApiServiceImpl.java +++ b/business-service-dao/src/main/java/com/ho/business/service/impl/OutApiServiceImpl.java @@ -176,6 +176,7 @@ public class OutApiServiceImpl implements OutApiService { } String deviceType = DeviceTypeConstant.BMS; log.info("stations.size:" + stations.size()); + stations = stations.stream().filter(i->i.getId()!=11003 && i.getId()!=10942).collect(Collectors.toList()); for (Station station : stations) { try { //先删除站的当日数据 diff --git a/business-service-dao/src/main/java/com/ho/business/service/impl/StationHomeServiceImpl.java b/business-service-dao/src/main/java/com/ho/business/service/impl/StationHomeServiceImpl.java index da5ec3d..2b946f3 100644 --- a/business-service-dao/src/main/java/com/ho/business/service/impl/StationHomeServiceImpl.java +++ b/business-service-dao/src/main/java/com/ho/business/service/impl/StationHomeServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ho.business.constant.DeviceTypeConstant; import com.ho.business.entity.*; @@ -959,6 +960,15 @@ public class StationHomeServiceImpl implements StationHomeService { dailyDischargeElec = new BigDecimal(dailyDischargeElecStr); pcsElecData.setChargeElec(dailyChargeElec); pcsElecData.setDischargeElec(dailyDischargeElec); + if(req.getStationId()==11003 || req.getStationId()==10942){ + // 寄点电站数据 + Integer stationId = req.getStationId()-10000; + String mainKey = CommonConstant.SHIP_ENERGY_MAIN + stationId; + String json = (String)redisService.get(mainKey); + ShipStationRespVO vo = JSON.parseObject(json,ShipStationRespVO.class); + pcsElecData.setChargeElec(BigDecimal.valueOf(vo.getPositivePowerToday())); + pcsElecData.setDischargeElec(BigDecimal.valueOf(vo.getReversePowerToday())); + } } } } diff --git a/business-service/src/main/java/com/ho/business/controller/OpenStationController.java b/business-service/src/main/java/com/ho/business/controller/OpenStationController.java index d4d061a..8b646ed 100644 --- a/business-service/src/main/java/com/ho/business/controller/OpenStationController.java +++ b/business-service/src/main/java/com/ho/business/controller/OpenStationController.java @@ -1,6 +1,8 @@ package com.ho.business.controller; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.ho.business.constant.DeviceTypeConstant; import com.ho.business.entity.Station; import com.ho.business.service.*; @@ -11,6 +13,7 @@ import com.ho.business.vo.req.dynamicConfig.DynamicConfigQuery; import com.ho.business.vo.req.pcsStation.PcsStationReq; import com.ho.business.vo.resp.DeviceRespVO; import com.ho.business.vo.resp.InverterResp.PowerGenerateRespVO; +import com.ho.business.vo.resp.ShipStationRespVO; import com.ho.business.vo.resp.cabin.CircleCtrlResp; import com.ho.business.vo.resp.cabin.EarningsCalculateCountResp; import com.ho.business.vo.resp.openStationHome.OpenStationMiddle; @@ -47,6 +50,8 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.math.BigDecimal; import java.text.ParseException; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; @@ -92,6 +97,9 @@ public class OpenStationController { @Autowired EarningsCalculateService earningsCalculateService; + @Autowired + ShipEnergyService shipEnergyService; + @PostMapping("statusMonitor") @ApiOperation(value = "状态监控") public DataResult statusMonitor(@RequestBody StationReq stationReq) { @@ -105,10 +113,42 @@ public class OpenStationController { @PostMapping("/realtimeCurve") @ApiOperation(value = "实时曲线") + @TokenIgnore //@Cacheable(cacheManager = "towMinuteCacheManager", value = "stationRealtimeCurve", key = "#stationReq.stationId", sync = true) public DataResult> realtimeCurve(@RequestBody StationReq stationReq) { log.info("realtimeCurve.stationRealtimeCurve:" + stationReq); List resList = stationHomeService.getRealtimeCurve(stationReq); + // 寄点电站功率、soc曲线 + if(stationReq.getStationId()==11003 || stationReq.getStationId()==10942){ + // 寄点电站数据 + Integer stationId = stationReq.getStationId()-10000; + String mainKey = CommonConstant.SHIP_ENERGY_MAIN + stationId; + String json = (String)redisService.get(mainKey); + ShipStationRespVO vo = JSON.parseObject(json,ShipStationRespVO.class); + JSONArray historyDataList = vo.getHistoryDataList(); + NewRealTimeCurveVo soc = new NewRealTimeCurveVo(); + soc.setName("SOC"); + List soclist =new ArrayList<>(); + NewRealTimeCurveVo p = new NewRealTimeCurveVo(); + p.setName("实时功率"); + List plist =new ArrayList<>(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(CommonConstant.DATE); + historyDataList.forEach(i->{ + JSONObject obj = (JSONObject) i; + StationHomeRespVo socCurve = new StationHomeRespVo(); + socCurve.setDate(ZonedDateTime.parse(obj.getString("record_time")).format(formatter)); + socCurve.setDigital(obj.getBigDecimal("soc")); + soclist.add(socCurve); + StationHomeRespVo pCurve = new StationHomeRespVo(); + pCurve.setDate(ZonedDateTime.parse(obj.getString("record_time")).format(formatter)); + pCurve.setDigital(obj.getBigDecimal("p_total")); + plist.add(pCurve); + }); + soc.setList(soclist); + p.setList(plist); + resList.add(soc); + resList.add(p); + } //返回值的BigDecimal类型保留两位小数 for (NewRealTimeCurveVo newRealTimeCurveVo : resList) { List list = newRealTimeCurveVo.getList(); @@ -224,6 +264,20 @@ public class OpenStationController { req.setDeviceType(deviceType); } PcsTotalData data = stationHomeService.getPcsTotalData(req); + if(req.getStationId()==11003 || req.getStationId()==10942){ + // 寄点电站数据 + Integer stationId = req.getStationId()-10000; + String mainKey = CommonConstant.SHIP_ENERGY_MAIN + stationId; + String json = (String)redisService.get(mainKey); + ShipStationRespVO vo = JSON.parseObject(json,ShipStationRespVO.class); + // 数据转换 + data.setTotalChargeElec(BigDecimal.valueOf(vo.getPositivePowerSum())); + data.setTotalDischargeElec(BigDecimal.valueOf(vo.getReversePowerSum())); + data.setDailyChargeElec(BigDecimal.valueOf(vo.getPositivePowerToday())); + data.setDailyDischargeElec(BigDecimal.valueOf(vo.getReversePowerToday())); + data.setCurrentPower(BigDecimal.valueOf(vo.getRealTimePower())); + data.setSystemEfficiency(data.getTotalDischargeElec().divide(data.getTotalChargeElec(), 4, BigDecimal.ROUND_HALF_UP)); + } BigDecimal systemEfficiency = data.getSystemEfficiency(); bigDecimalUtil.keepTwoDecimalPlaces(data); bigDecimalUtil.ifIsNUll(data); diff --git a/business-service/src/main/java/com/ho/business/controller/ShipEnergyController.java b/business-service/src/main/java/com/ho/business/controller/ShipEnergyController.java index bf0e90a..821b044 100644 --- a/business-service/src/main/java/com/ho/business/controller/ShipEnergyController.java +++ b/business-service/src/main/java/com/ho/business/controller/ShipEnergyController.java @@ -1,6 +1,7 @@ package com.ho.business.controller; import com.ho.business.service.ShipEnergyService; +import com.ho.business.vo.resp.ShipStationRespVO; import com.ho.common.tools.annotation.TokenIgnore; import com.ho.common.tools.constant.ContextConstant; import com.ho.common.tools.exception.DataResult; @@ -11,6 +12,8 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @RequestMapping(ContextConstant.BUSINESS + "shipEnergyStation") @RestController @Api(tags = "业务模块-寄点能源电站管理") @@ -29,4 +32,20 @@ public class ShipEnergyController { return DataResult.success(); } + @PostMapping("getMainTotal") + @ApiOperation(value = "获取主监控汇总信息") + @TokenIgnore + public DataResult getMainTotal() { + shipEnergyService.getShipEnergyTotal(); + return DataResult.success(); + } + + @PostMapping("getStationIncomeHis") + @ApiOperation(value = "获取寄点电站历史收益") + @TokenIgnore + public DataResult getStationIncomeHis(String beginTime) { + shipEnergyService.getStationIncomeHis(beginTime); + return DataResult.success(); + } + } diff --git a/common-tools/src/main/java/com/ho/common/tools/constant/CommonConstant.java b/common-tools/src/main/java/com/ho/common/tools/constant/CommonConstant.java index 6408e20..e14fd2f 100644 --- a/common-tools/src/main/java/com/ho/common/tools/constant/CommonConstant.java +++ b/common-tools/src/main/java/com/ho/common/tools/constant/CommonConstant.java @@ -1041,4 +1041,13 @@ public interface CommonConstant { // 调用成功code Integer SUCCESS_CODE = 200; } + + /** + * 寄点 token 缓存 key + */ + String SHIP_ENERGY_TOKEN_KEY = "ShipEnergyToken"; + /** + * 监控数据 + */ + String SHIP_ENERGY_MAIN = "ShipEnergyMain:"; } diff --git a/xxl-job/src/main/java/com/ho/xxljob/JobHandler.java b/xxl-job/src/main/java/com/ho/xxljob/JobHandler.java index db9adfa..afe0f3b 100644 --- a/xxl-job/src/main/java/com/ho/xxljob/JobHandler.java +++ b/xxl-job/src/main/java/com/ho/xxljob/JobHandler.java @@ -267,4 +267,30 @@ public class JobHandler { log.info("jobUpdateMessageInfo end !"); return ReturnT.SUCCESS; } + + /** + * 寄点-站点监控数据 + * @param param + * @return + */ + @XxlJob("jobCacheShipEnergyMainInfo") + public ReturnT jobCacheShipEnergyMainInfo(String param){ + log.info("jobCacheShipEnergyMainInfo start !"); + businessFeignClient.jobCacheShipEnergyMainInfo(); + log.info("jobCacheShipEnergyMainInfo end !"); + return ReturnT.SUCCESS; + } + + /** + * 寄点-站点充放电数据 + * @param param + * @return + */ + @XxlJob("jobCacheShipEleIncome") + public ReturnT jobCacheShipEleIncome(String param){ + log.info("jobCacheShipEnergyEle start !"); + businessFeignClient.jobCacheShipEleIncome(param); + log.info("jobCacheShipEnergyEle end !"); + return ReturnT.SUCCESS; + } } diff --git a/xxl-job/src/main/java/com/ho/xxljob/feignclient/BusinessFeignClient.java b/xxl-job/src/main/java/com/ho/xxljob/feignclient/BusinessFeignClient.java index e2ea2f6..a3f58d7 100644 --- a/xxl-job/src/main/java/com/ho/xxljob/feignclient/BusinessFeignClient.java +++ b/xxl-job/src/main/java/com/ho/xxljob/feignclient/BusinessFeignClient.java @@ -72,5 +72,9 @@ public interface BusinessFeignClient { */ @PostMapping(value = ContextConstant.ROOT_CONTEXT + ContextConstant.BUSINESS + "messageInfo/jobUpdateMessageInfo") void jobUpdateMessageInfo(); + @PostMapping(value = ContextConstant.ROOT_CONTEXT + ContextConstant.BUSINESS + "shipEnergyStation/getMainTotal") + void jobCacheShipEnergyMainInfo(); + @PostMapping(value = ContextConstant.ROOT_CONTEXT + ContextConstant.BUSINESS + "shipEnergyStation/getStationIncomeHis") + void jobCacheShipEleIncome(@RequestBody String dateTime); } diff --git a/xxl-job/src/main/java/com/ho/xxljob/feignclient/BusinessFeignClientFallback.java b/xxl-job/src/main/java/com/ho/xxljob/feignclient/BusinessFeignClientFallback.java index e57f520..86dba4f 100644 --- a/xxl-job/src/main/java/com/ho/xxljob/feignclient/BusinessFeignClientFallback.java +++ b/xxl-job/src/main/java/com/ho/xxljob/feignclient/BusinessFeignClientFallback.java @@ -111,4 +111,16 @@ public class BusinessFeignClientFallback implements BusinessFeignClient { throw new BusinessException(BaseResponseCode.FEIGN_CALL_FAIL); } + @Override + public void jobCacheShipEnergyMainInfo() { + log.error("BusinessFeignClient.jobCacheShipEnergyMainInfo error!"); + throw new BusinessException(BaseResponseCode.FEIGN_CALL_FAIL); + } + + @Override + public void jobCacheShipEleIncome(String dateTime) { + log.error("BusinessFeignClient.jobCacheShipEleIncome error!"); + throw new BusinessException(BaseResponseCode.FEIGN_CALL_FAIL); + } + }