电价配置-增加站点id

This commit is contained in:
2025-10-11 16:28:50 +08:00
parent e33b26fc05
commit b79f9caa2d
9 changed files with 76 additions and 22 deletions

View File

@ -20,6 +20,10 @@ public class EmsEnergyPriceConfig extends BaseEntity
/** */
private Long id;
/** 站点id */
@Excel(name = "站点id")
private String siteId;
/** 年份如2025 */
@Excel(name = "年份如2025")
private String year;
@ -54,6 +58,16 @@ public class EmsEnergyPriceConfig extends BaseEntity
return id;
}
public void setSiteId(String siteId)
{
this.siteId = siteId;
}
public String getSiteId()
{
return siteId;
}
public void setYear(String year)
{
this.year = year;
@ -118,6 +132,7 @@ public class EmsEnergyPriceConfig extends BaseEntity
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("siteId", getSiteId())
.append("year", getYear())
.append("month", getMonth())
.append("peak", getPeak())

View File

@ -12,6 +12,9 @@ import java.util.List;
public class EnergyPriceVo {
/** */
private Long id;
/** 站点id */
@Excel(name = "站点id")
private String siteId;
/** 年份 */
@Excel(name = "年份")
private String year;
@ -41,6 +44,14 @@ public class EnergyPriceVo {
this.id = id;
}
public String getSiteId() {
return siteId;
}
public void setSiteId(String siteId) {
this.siteId = siteId;
}
public String getYear() {
return year;
}

View File

@ -62,11 +62,15 @@ public interface EmsEnergyPriceConfigMapper
public int deleteEmsEnergyPriceConfigByIds(Long[] ids);
// 查询当年电价配置列表
public List<EmsEnergyPriceConfig> getCurrentYearConfigList(int currentYear);
// 根据指定年月获取电价配置
public EmsEnergyPriceConfig getConfigListByYearAndMonth(@Param("currentYear") String currentYear, @Param("month")String month);
public List<EmsEnergyPriceConfig> getCurrentYearConfigList(@Param("siteId")String siteId,@Param("currentYear")int currentYear);
// 站点指定年月获取电价配置
public EmsEnergyPriceConfig getConfigListByYearAndMonth(@Param("siteId")String siteId,
@Param("currentYear") String currentYear,
@Param("month")String month);
// 插入或更新
public void insertOrUpdateEmsEnergyPriceConfig(EmsEnergyPriceConfig priceConfig);
// 获取指定年月的电价时间配置
public List<EnergyPriceTimeRange> getTimeRangeByDate(@Param("currentYear")int currentYear, @Param("currentMonth")int currentMonth);
public List<EnergyPriceTimeRange> getTimeRangeByDate(@Param("siteId")String siteId,
@Param("currentYear")int currentYear,
@Param("currentMonth")int currentMonth);
}

View File

@ -90,4 +90,6 @@ public interface EmsSiteSettingMapper
* @return
*/
public List<SiteDeviceListVo> getAllSiteDeviceList(String siteId);
public List<String> getAllSiteId();
}

View File

@ -25,7 +25,7 @@ public interface IEmsEnergyPriceConfigService
*
* @return 电价配置集合
*/
public List<EnergyPriceVo> selectEmsEnergyPriceConfigList(String startTime,String endTime);
public List<EnergyPriceVo> selectEmsEnergyPriceConfigList(String siteId, String startTime,String endTime);
/**
* 新增电价配置-按月

View File

@ -1,9 +1,7 @@
package com.xzzn.ems.service.impl;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@ -15,6 +13,7 @@ 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.EmsPriceTimeConfigMapper;
import com.xzzn.ems.mapper.EmsSiteSettingMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -37,6 +36,8 @@ public class EmsEnergyPriceConfigServiceImpl implements IEmsEnergyPriceConfigSer
private EmsPriceTimeConfigMapper emsPriceTimeConfigMapper;
@Autowired
private RedisCache redisCache;
@Autowired
private EmsSiteSettingMapper emsSiteSettingMapper;
/**
* 查询电价配置
@ -68,14 +69,14 @@ public class EmsEnergyPriceConfigServiceImpl implements IEmsEnergyPriceConfigSer
* @return 电价配置
*/
@Override
public List<EnergyPriceVo> selectEmsEnergyPriceConfigList(String startTime,String endTime)
public List<EnergyPriceVo> selectEmsEnergyPriceConfigList(String siteId,String startTime,String endTime)
{
List<EnergyPriceVo> responses = new ArrayList<>();
// 根据时间截取年份
String[] startTimeArr = startTime.split("-");
int currentYear = Integer.valueOf(startTimeArr[0]);
List<EmsEnergyPriceConfig> priceConfigs = emsEnergyPriceConfigMapper.getCurrentYearConfigList(currentYear);
List<EmsEnergyPriceConfig> priceConfigs = emsEnergyPriceConfigMapper.getCurrentYearConfigList(siteId,currentYear);
if (priceConfigs != null && priceConfigs.size() > 0) {
for (EmsEnergyPriceConfig priceConfig : priceConfigs) {
@ -106,14 +107,14 @@ public class EmsEnergyPriceConfigServiceImpl implements IEmsEnergyPriceConfigSer
{
String year = priceVo.getYear();
String month = priceVo.getMonth();
String siteId = priceVo.getSiteId();
// 判断入参
if(StringUtils.isEmpty(year) || StringUtils.isEmpty(month)){
if(StringUtils.isEmpty(siteId) || StringUtils.isEmpty(year) || StringUtils.isEmpty(month)){
return 0;
}
// 校验当前月电价设置是否已存在,不存在则新增,存在则更新
EmsEnergyPriceConfig priceConfig = emsEnergyPriceConfigMapper.getConfigListByYearAndMonth(year,month);
EmsEnergyPriceConfig priceConfig = emsEnergyPriceConfigMapper.getConfigListByYearAndMonth(siteId,year,month);
if (priceConfig != null){
return 0;
} else {
@ -214,9 +215,15 @@ public class EmsEnergyPriceConfigServiceImpl implements IEmsEnergyPriceConfigSer
int currentMonth = LocalDate.now().getMonthValue();
int currentYear = LocalDate.now().getYear();
List<EnergyPriceTimeRange> timeRanges = emsEnergyPriceConfigMapper.getTimeRangeByDate(currentYear,currentMonth);
List<String> siteIds = emsSiteSettingMapper.getAllSiteId();
if (siteIds == null || siteIds.size() == 0) {
return;
}
for (String siteId : siteIds) {
List<EnergyPriceTimeRange> timeRanges = emsEnergyPriceConfigMapper.getTimeRangeByDate(siteId,currentYear,currentMonth);
String key = RedisKeyConstants.ENERGY_PRICE_TIME + siteId + "_" + currentYear + currentMonth;
redisCache.setCacheObject(key,timeRanges, 31, TimeUnit.DAYS);
}
String key = RedisKeyConstants.ENERGY_PRICE_TIME + currentYear + currentMonth;
redisCache.setCacheObject(key,timeRanges, 31, TimeUnit.DAYS);
}
}