电价配置-增加站点id
This commit is contained in:
@ -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())
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -90,4 +90,6 @@ public interface EmsSiteSettingMapper
|
||||
* @return
|
||||
*/
|
||||
public List<SiteDeviceListVo> getAllSiteDeviceList(String siteId);
|
||||
|
||||
public List<String> getAllSiteId();
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
/**
|
||||
* 新增电价配置-按月
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
<resultMap type="EmsEnergyPriceConfig" id="EmsEnergyPriceConfigResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="siteId" column="site_id" />
|
||||
<result property="year" column="year" />
|
||||
<result property="month" column="month" />
|
||||
<result property="peak" column="peak" />
|
||||
@ -20,19 +21,19 @@
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectEmsEnergyPriceConfigVo">
|
||||
select id, year, month, peak, high, flat, valley, create_by, create_time, update_by, update_time, remark from ems_energy_price_config
|
||||
select id, site_id, year, month, peak, high, flat, valley, create_by, create_time, update_by, update_time, remark from ems_energy_price_config
|
||||
</sql>
|
||||
|
||||
<select id="selectEmsEnergyPriceConfigList" parameterType="EmsEnergyPriceConfig" resultMap="EmsEnergyPriceConfigResult">
|
||||
<include refid="selectEmsEnergyPriceConfigVo"/>
|
||||
<where>
|
||||
<if test="siteId != null and siteId != ''"> and site_id = #{siteId}</if>
|
||||
<if test="year != null and year != ''"> and year = #{year}</if>
|
||||
<if test="month != null and month != ''"> and month = #{month}</if>
|
||||
<if test="peak != null "> and peak = #{peak}</if>
|
||||
<if test="high != null "> and high = #{high}</if>
|
||||
<if test="flat != null "> and flat = #{flat}</if>
|
||||
<if test="valley != null "> and valley = #{valley}</if>
|
||||
<if test="siteId != null and siteId != ''"> and site_id = #{siteId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
@ -44,6 +45,7 @@
|
||||
<insert id="insertEmsEnergyPriceConfig" parameterType="EmsEnergyPriceConfig" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into ems_energy_price_config
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="siteId != null">site_id,</if>
|
||||
<if test="year != null and year != ''">year,</if>
|
||||
<if test="month != null and month != ''">month,</if>
|
||||
<if test="peak != null">peak,</if>
|
||||
@ -57,6 +59,7 @@
|
||||
<if test="remark != null">remark,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="siteId != null">#{siteId},</if>
|
||||
<if test="year != null and year != ''">#{year},</if>
|
||||
<if test="month != null and month != ''">#{month},</if>
|
||||
<if test="peak != null">#{peak},</if>
|
||||
@ -74,6 +77,7 @@
|
||||
<update id="updateEmsEnergyPriceConfig" parameterType="EmsEnergyPriceConfig">
|
||||
update ems_energy_price_config
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="siteId != null">site_id = #{siteId},</if>
|
||||
<if test="year != null and year != ''">year = #{year},</if>
|
||||
<if test="month != null and month != ''">month = #{month},</if>
|
||||
<if test="peak != null">peak = #{peak},</if>
|
||||
@ -104,6 +108,9 @@
|
||||
<include refid="selectEmsEnergyPriceConfigVo"/>
|
||||
<where>
|
||||
year = #{currentYear}
|
||||
<if test="siteId != null and siteId != ''">
|
||||
and site_id = #{siteId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
@ -111,6 +118,7 @@
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO ems_energy_price_config (
|
||||
id,
|
||||
site_id,
|
||||
year,
|
||||
month,
|
||||
peak,
|
||||
@ -124,6 +132,7 @@
|
||||
remark
|
||||
) VALUES (
|
||||
#{id},
|
||||
#{siteId},
|
||||
#{year},
|
||||
#{month},
|
||||
#{peak},
|
||||
@ -145,7 +154,8 @@
|
||||
|
||||
<select id="getConfigListByYearAndMonth" resultMap="EmsEnergyPriceConfigResult">
|
||||
<include refid="selectEmsEnergyPriceConfigVo"/>
|
||||
where year = #{currentYear}
|
||||
where site_id = #{siteId}
|
||||
and year = #{currentYear}
|
||||
and month = #{month}
|
||||
</select>
|
||||
|
||||
@ -155,7 +165,8 @@
|
||||
t2.end_time as endTime
|
||||
from ems_energy_price_config t
|
||||
left join ems_price_time_config t2 on t.id = t2.price_id
|
||||
where t.`year` = #{currentYear}
|
||||
where t.site_id = #{siteId}
|
||||
and t.`year` = #{currentYear}
|
||||
and t.`month` = #{currentMonth}
|
||||
</select>
|
||||
</mapper>
|
||||
@ -147,4 +147,8 @@
|
||||
and es.site_id = #{siteId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getAllSiteId" resultType="String">
|
||||
select distinct site_id from ems_site_setting
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user