电价-实时收入实时计算
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
package com.xzzn.ems.service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.xzzn.ems.domain.EmsEnergyPriceConfig;
|
||||
import com.xzzn.ems.domain.vo.EnergyPriceVo;
|
||||
|
||||
@ -63,4 +66,6 @@ public interface IEmsEnergyPriceConfigService
|
||||
public void initCurrentMonthPrice();
|
||||
// 获取指定站点的当月电价
|
||||
public EnergyPriceVo getCurrentMonthPrice(String siteId);
|
||||
// 获取指定站点的总收益和当日实时收益
|
||||
public Map<String, BigDecimal> getDayRevenueMap(String siteId);
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.xzzn.ems.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -9,9 +11,11 @@ import com.xzzn.common.constant.RedisKeyConstants;
|
||||
import com.xzzn.common.core.redis.RedisCache;
|
||||
import com.xzzn.common.utils.DateUtils;
|
||||
import com.xzzn.common.utils.StringUtils;
|
||||
import com.xzzn.ems.domain.EmsDailyEnergyData;
|
||||
import com.xzzn.ems.domain.EmsPriceTimeConfig;
|
||||
import com.xzzn.ems.domain.vo.EnergyPriceTimeRange;
|
||||
import com.xzzn.ems.domain.vo.EnergyPriceVo;
|
||||
import com.xzzn.ems.mapper.EmsDailyEnergyDataMapper;
|
||||
import com.xzzn.ems.mapper.EmsPriceTimeConfigMapper;
|
||||
import com.xzzn.ems.mapper.EmsSiteSettingMapper;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@ -37,7 +41,7 @@ public class EmsEnergyPriceConfigServiceImpl implements IEmsEnergyPriceConfigSer
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
@Autowired
|
||||
private EmsSiteSettingMapper emsSiteSettingMapper;
|
||||
private EmsDailyEnergyDataMapper emsDailyEnergyDataMapper;
|
||||
|
||||
/**
|
||||
* 查询电价配置
|
||||
@ -263,4 +267,43 @@ public class EmsEnergyPriceConfigServiceImpl implements IEmsEnergyPriceConfigSer
|
||||
}
|
||||
return priceVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, BigDecimal> getDayRevenueMap(String siteId) {
|
||||
Map<String, BigDecimal> currentDayRevenue = new HashMap<>();
|
||||
// 默认0
|
||||
BigDecimal totalRevenue = BigDecimal.ZERO;
|
||||
BigDecimal dayRevenue = BigDecimal.ZERO;
|
||||
// 当日实时数据
|
||||
String today = DateUtils.getDate();
|
||||
EmsDailyEnergyData todayData = emsDailyEnergyDataMapper.getDataByDate(siteId,today);
|
||||
if (todayData == null) {
|
||||
Map<String, BigDecimal> lastData = emsDailyEnergyDataMapper.getRealTimeRevenue(siteId);
|
||||
if (lastData != null) {
|
||||
totalRevenue = lastData.get("totalRevenue") == null ? BigDecimal.ZERO : lastData.get("totalRevenue");
|
||||
}
|
||||
} else {
|
||||
totalRevenue = todayData.getTotalRevenue() == null ? BigDecimal.ZERO : todayData.getTotalRevenue();
|
||||
// 获取当月电价
|
||||
int currentMonth = LocalDate.now().getMonthValue();
|
||||
int currentYear = LocalDate.now().getYear();
|
||||
EmsEnergyPriceConfig priceConfig = emsEnergyPriceConfigMapper.getConfigListByYearAndMonth(siteId, String.valueOf(currentYear), String.valueOf(currentMonth));
|
||||
if (priceConfig != null) {
|
||||
// 计算各个时段单独收益=(放电量-充电量)*电价,累加即当日实时收益
|
||||
BigDecimal peakRevenue = todayData.getPeakDischargeDiff().subtract(todayData.getPeakChargeDiff())
|
||||
.multiply(priceConfig.getPeak() == null ? BigDecimal.ZERO : priceConfig.getPeak());
|
||||
BigDecimal highRevenue = todayData.getHighDischargeDiff().subtract(todayData.getHighChargeDiff())
|
||||
.multiply(priceConfig.getHigh() == null ? BigDecimal.ZERO : priceConfig.getHigh());
|
||||
BigDecimal flatRevenue = todayData.getFlatDischargeDiff().subtract(todayData.getFlatChargeDiff())
|
||||
.multiply(priceConfig.getFlat() == null ? BigDecimal.ZERO : priceConfig.getFlat());
|
||||
BigDecimal valleyRevenue = todayData.getValleyDischargeDiff().subtract(todayData.getValleyChargeDiff())
|
||||
.multiply(priceConfig.getValley() == null ? BigDecimal.ZERO : priceConfig.getValley());
|
||||
dayRevenue = dayRevenue.add(peakRevenue).add(highRevenue).add(flatRevenue).add(valleyRevenue)
|
||||
.setScale(4, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
currentDayRevenue.put("totalRevenue", totalRevenue);
|
||||
currentDayRevenue.put("dayRevenue", dayRevenue);
|
||||
return currentDayRevenue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,6 +82,8 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
private EmsEnergyPriceConfigMapper emsEnergyPriceConfigMapper;
|
||||
@Autowired
|
||||
private IEmsEnergyPriceConfigService emsEnergyPriceConfigService;
|
||||
@Autowired
|
||||
private IEmsEnergyPriceConfigService iEmsEnergyPriceConfigService;
|
||||
|
||||
// 构造方法(调用父类构造)
|
||||
public FXXDataProcessServiceImpl(ObjectMapper objectMapper) {
|
||||
@ -907,7 +909,8 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
energyData.setTotalRevenue(totalRevenue);
|
||||
|
||||
// 存redis便于下次取用
|
||||
String redisKey = RedisKeyConstants.FXX_REALTIME_REVENUE + SITE_ID;
|
||||
String today = DateUtils.getDate();
|
||||
String redisKey = RedisKeyConstants.FXX_REALTIME_REVENUE + SITE_ID + "_" + today;
|
||||
Map<String, BigDecimal> realTimeRevenue = new HashMap<>();
|
||||
realTimeRevenue.put("totalRevenue", totalRevenue);
|
||||
realTimeRevenue.put("dayRevenue",dayRevenue);
|
||||
@ -916,10 +919,12 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
|
||||
private Map<String, BigDecimal> getRealTimeData(String siteId) {
|
||||
// fx取实时总收益和当天实时收益
|
||||
String redisKey = RedisKeyConstants.FXX_REALTIME_REVENUE + siteId;
|
||||
String today = DateUtils.getDate();
|
||||
String redisKey = RedisKeyConstants.FXX_REALTIME_REVENUE + siteId + "_" + today;
|
||||
Map<String, BigDecimal> realTimeRevenue = redisCache.getCacheObject(redisKey);
|
||||
if (realTimeRevenue == null) {
|
||||
realTimeRevenue = emsDailyEnergyDataMapper.getRealTimeRevenue(siteId);
|
||||
// 查数据库
|
||||
realTimeRevenue = iEmsEnergyPriceConfigService.getDayRevenueMap(SITE_ID);
|
||||
if (realTimeRevenue == null) {
|
||||
realTimeRevenue = new HashMap<>();
|
||||
realTimeRevenue.put("totalRevenue", BigDecimal.ZERO);
|
||||
|
||||
@ -10,6 +10,7 @@ import com.xzzn.common.utils.StringUtils;
|
||||
import com.xzzn.ems.domain.*;
|
||||
import com.xzzn.ems.domain.vo.*;
|
||||
import com.xzzn.ems.mapper.*;
|
||||
import com.xzzn.ems.service.IEmsEnergyPriceConfigService;
|
||||
import com.xzzn.ems.service.ISingleSiteService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -66,6 +67,8 @@ public class SingleSiteServiceImpl implements ISingleSiteService {
|
||||
private EmsDailyEnergyDataMapper emsDailyEnergyDataMapper;
|
||||
@Autowired
|
||||
private EmsEnergyPriceConfigMapper emsEnergyPriceConfigMapper;
|
||||
@Autowired
|
||||
private IEmsEnergyPriceConfigService iEmsEnergyPriceConfigService;
|
||||
|
||||
@Override
|
||||
public SiteMonitorHomeVo getSiteMonitorDataVo(String siteId) {
|
||||
@ -82,7 +85,11 @@ public class SingleSiteServiceImpl implements ISingleSiteService {
|
||||
}
|
||||
|
||||
// 总收入+当日实时收入
|
||||
setRevenueInfo(siteMonitorHomeVo,siteId);
|
||||
Map<String, BigDecimal> dayRevenueMap = iEmsEnergyPriceConfigService.getDayRevenueMap(siteId);
|
||||
siteMonitorHomeVo.setTotalRevenue(
|
||||
dayRevenueMap.get("totalRevenue") == null ? BigDecimal.ZERO : dayRevenueMap.get("totalRevenue"));
|
||||
siteMonitorHomeVo.setDayRevenue(
|
||||
dayRevenueMap.get("dayRevenue") == null ? BigDecimal.ZERO :dayRevenueMap.get("dayRevenue"));
|
||||
|
||||
// 实时告警数据 名称+状态+告警内容
|
||||
List<SiteMonitorHomeAlarmVo> siteMonitorHomeAlarmVo = emsAlarmRecordsMapper.getAlarmRecordsBySiteId(siteId);
|
||||
@ -125,42 +132,6 @@ public class SingleSiteServiceImpl implements ISingleSiteService {
|
||||
return siteMonitorHomeVo;
|
||||
}
|
||||
|
||||
private void setRevenueInfo(SiteMonitorHomeVo siteMonitorHomeVo, String siteId) {
|
||||
// 默认0
|
||||
BigDecimal totalRevenue = BigDecimal.ZERO;
|
||||
BigDecimal dayRevenue = BigDecimal.ZERO;
|
||||
// 当日实时数据
|
||||
String today = DateUtils.getDate();
|
||||
EmsDailyEnergyData todayData = emsDailyEnergyDataMapper.getDataByDate(siteId,today);
|
||||
if (todayData == null) {
|
||||
Map<String, BigDecimal> lastData = emsDailyEnergyDataMapper.getRealTimeRevenue(siteId);
|
||||
if (lastData != null) {
|
||||
totalRevenue = lastData.get("totalRevenue") == null ? BigDecimal.ZERO : lastData.get("totalRevenue");
|
||||
}
|
||||
} else {
|
||||
totalRevenue = todayData.getTotalRevenue() == null ? BigDecimal.ZERO : todayData.getTotalRevenue();
|
||||
// 获取当月电价
|
||||
int currentMonth = LocalDate.now().getMonthValue();
|
||||
int currentYear = LocalDate.now().getYear();
|
||||
EmsEnergyPriceConfig priceConfig = emsEnergyPriceConfigMapper.getConfigListByYearAndMonth(siteId, String.valueOf(currentYear), String.valueOf(currentMonth));
|
||||
if (priceConfig != null) {
|
||||
// 计算各个时段单独收益=(放电量-充电量)*电价,累加即当日实时收益
|
||||
BigDecimal peakRevenue = todayData.getPeakDischargeDiff().subtract(todayData.getPeakChargeDiff())
|
||||
.multiply(priceConfig.getPeak() == null ? BigDecimal.ZERO : priceConfig.getPeak());
|
||||
BigDecimal highRevenue = todayData.getHighDischargeDiff().subtract(todayData.getHighChargeDiff())
|
||||
.multiply(priceConfig.getHigh() == null ? BigDecimal.ZERO : priceConfig.getHigh());
|
||||
BigDecimal flatRevenue = todayData.getFlatDischargeDiff().subtract(todayData.getFlatChargeDiff())
|
||||
.multiply(priceConfig.getFlat() == null ? BigDecimal.ZERO : priceConfig.getFlat());
|
||||
BigDecimal valleyRevenue = todayData.getValleyDischargeDiff().subtract(todayData.getValleyChargeDiff())
|
||||
.multiply(priceConfig.getValley() == null ? BigDecimal.ZERO : priceConfig.getValley());
|
||||
dayRevenue = dayRevenue.add(peakRevenue).add(highRevenue).add(flatRevenue).add(valleyRevenue)
|
||||
.setScale(4, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
siteMonitorHomeVo.setTotalRevenue(totalRevenue);
|
||||
siteMonitorHomeVo.setDayRevenue(dayRevenue);
|
||||
}
|
||||
|
||||
// 获取单站监控实时运行头部数据
|
||||
@Override
|
||||
public SiteMonitorRunningHeadInfoVo getSiteRunningHeadInfo(String siteId) {
|
||||
|
||||
Reference in New Issue
Block a user