20250808优化-充放电逻辑修改
This commit is contained in:
@ -0,0 +1,151 @@
|
||||
package com.xzzn.ems.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.xzzn.common.core.domain.BaseEntity;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.xzzn.common.annotation.Excel;
|
||||
|
||||
/**
|
||||
* 站点每日充放电数据对象 ems_daily_charge_data
|
||||
*
|
||||
* @author xzzn
|
||||
* @date 2025-08-27
|
||||
*/
|
||||
public class EmsDailyChargeData extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** $column.columnComment */
|
||||
private Long id;
|
||||
|
||||
/** 站点id */
|
||||
@Excel(name = "站点id")
|
||||
private String siteId;
|
||||
|
||||
/** 设备唯一标识符 */
|
||||
@Excel(name = "设备唯一标识符")
|
||||
private String deviceId;
|
||||
|
||||
/** 数据日期:yyyy-MM-dd */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "数据日期:yyyy-MM-dd", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date dateTime;
|
||||
|
||||
/** 总充电量 */
|
||||
@Excel(name = "总充电量")
|
||||
private BigDecimal totalChargeData;
|
||||
|
||||
/** 总放电量 */
|
||||
@Excel(name = "总放电量")
|
||||
private BigDecimal totalDischargeData;
|
||||
|
||||
/** 当日充电量 */
|
||||
@Excel(name = "当日充电量")
|
||||
private BigDecimal chargeData;
|
||||
|
||||
/** 当日放电量 */
|
||||
@Excel(name = "当日放电量")
|
||||
private BigDecimal dischargeData;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setSiteId(String siteId)
|
||||
{
|
||||
this.siteId = siteId;
|
||||
}
|
||||
|
||||
public String getSiteId()
|
||||
{
|
||||
return siteId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId)
|
||||
{
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getDeviceId()
|
||||
{
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDateTime(Date dateTime)
|
||||
{
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
public Date getDateTime()
|
||||
{
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setTotalChargeData(BigDecimal totalChargeData)
|
||||
{
|
||||
this.totalChargeData = totalChargeData;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalChargeData()
|
||||
{
|
||||
return totalChargeData;
|
||||
}
|
||||
|
||||
public void setTotalDischargeData(BigDecimal totalDischargeData)
|
||||
{
|
||||
this.totalDischargeData = totalDischargeData;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalDischargeData()
|
||||
{
|
||||
return totalDischargeData;
|
||||
}
|
||||
|
||||
public void setChargeData(BigDecimal chargeData)
|
||||
{
|
||||
this.chargeData = chargeData;
|
||||
}
|
||||
|
||||
public BigDecimal getChargeData()
|
||||
{
|
||||
return chargeData;
|
||||
}
|
||||
|
||||
public void setDischargeData(BigDecimal dischargeData)
|
||||
{
|
||||
this.dischargeData = dischargeData;
|
||||
}
|
||||
|
||||
public BigDecimal getDischargeData()
|
||||
{
|
||||
return dischargeData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("siteId", getSiteId())
|
||||
.append("deviceId", getDeviceId())
|
||||
.append("dateTime", getDateTime())
|
||||
.append("totalChargeData", getTotalChargeData())
|
||||
.append("totalDischargeData", getTotalDischargeData())
|
||||
.append("chargeData", getChargeData())
|
||||
.append("dischargeData", getDischargeData())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("remark", getRemark())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
package com.xzzn.ems.mapper;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import com.xzzn.ems.domain.EmsAmmeterData;
|
||||
import com.xzzn.ems.domain.vo.AmmeterStatisListVo;
|
||||
import com.xzzn.ems.domain.vo.StatisAmmeterDateRequest;
|
||||
import com.xzzn.ems.domain.vo.*;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
@ -71,4 +71,17 @@ public interface EmsAmmeterDataMapper
|
||||
|
||||
// 获取昨天最晚数据
|
||||
public EmsAmmeterData getYestLatestDate(@Param("siteId")String siteId, @Param("deviceId")String deviceId, @Param("yestData")String yestData);
|
||||
|
||||
// 获取可统计站点每个月的时间范围
|
||||
public List<MonthlyTimeRange> getMonthlyTimeRanges();
|
||||
|
||||
// 批量获取站点时间节点的充放电数据
|
||||
public List<TimePointValue> batchGetTimePointValues(List<TimePointQuery> timePointQueries);
|
||||
|
||||
// 概率统计-电量指标(按小时)
|
||||
public List<SiteMonitorDataVo> getChargeDataByHour(@Param("siteId")String siteId, @Param("deviceId")String deviceId,@Param("startDate")Date startDate);
|
||||
|
||||
// 概率统计-电量指标(按月)
|
||||
public List<SiteMonitorDataVo> getChargeDataByMonth(@Param("siteId")String siteId, @Param("deviceId")String deviceId,@Param("startDate")Date startDate,@Param("endDate")Date endDate);
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,79 @@
|
||||
package com.xzzn.ems.mapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.xzzn.ems.domain.EmsDailyChargeData;
|
||||
import com.xzzn.ems.domain.vo.SiteMonitorDataVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 站点每日充放电数据Mapper接口
|
||||
*
|
||||
* @author xzzn
|
||||
* @date 2025-08-27
|
||||
*/
|
||||
public interface EmsDailyChargeDataMapper
|
||||
{
|
||||
/**
|
||||
* 查询站点每日充放电数据
|
||||
*
|
||||
* @param id 站点每日充放电数据主键
|
||||
* @return 站点每日充放电数据
|
||||
*/
|
||||
public EmsDailyChargeData selectEmsDailyChargeDataById(Long id);
|
||||
|
||||
/**
|
||||
* 查询站点每日充放电数据列表
|
||||
*
|
||||
* @param emsDailyChargeData 站点每日充放电数据
|
||||
* @return 站点每日充放电数据集合
|
||||
*/
|
||||
public List<EmsDailyChargeData> selectEmsDailyChargeDataList(EmsDailyChargeData emsDailyChargeData);
|
||||
|
||||
/**
|
||||
* 新增站点每日充放电数据
|
||||
*
|
||||
* @param emsDailyChargeData 站点每日充放电数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertEmsDailyChargeData(EmsDailyChargeData emsDailyChargeData);
|
||||
|
||||
/**
|
||||
* 修改站点每日充放电数据
|
||||
*
|
||||
* @param emsDailyChargeData 站点每日充放电数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateEmsDailyChargeData(EmsDailyChargeData emsDailyChargeData);
|
||||
|
||||
/**
|
||||
* 删除站点每日充放电数据
|
||||
*
|
||||
* @param id 站点每日充放电数据主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteEmsDailyChargeDataById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除站点每日充放电数据
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteEmsDailyChargeDataByIds(Long[] ids);
|
||||
|
||||
// 插入或更新站点每日充放电数据
|
||||
public void insertOrUpdateData(EmsDailyChargeData emsDailyChargeData);
|
||||
|
||||
// 获取所有站点总充总放
|
||||
public Map<String, BigDecimal> getAllSiteChargeData(@Param("nowData")String nowData, @Param("siteId")String siteId);
|
||||
|
||||
// 获取单站点时间范围内每日充放电数据
|
||||
public List<SiteMonitorDataVo> getSingleSiteChargeData(@Param("siteId")String siteId, @Param("startDate")Date startDate, @Param("endDate")Date endDate);
|
||||
|
||||
// 按天获取站点每日总充总放
|
||||
public List<SiteMonitorDataVo> getTotalChargeDataByDay(@Param("siteId")String siteId,@Param("startDate")Date startDate, @Param("endDate")Date endDate);
|
||||
}
|
||||
@ -909,8 +909,8 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
BigDecimal dailyDisChargeDate = new BigDecimal(0);
|
||||
BigDecimal dailyChargeDate = new BigDecimal(0);
|
||||
|
||||
BigDecimal nowTotalDisChargeDate = StringUtils.getBigDecimal(obj.get("DQZXZYGDN"));
|
||||
BigDecimal nowTotalChargeDate = StringUtils.getBigDecimal(obj.get("DQFXZYGDN"));
|
||||
BigDecimal nowTotalDisChargeDate = StringUtils.getBigDecimal(obj.get("DQFXZYGDN"));
|
||||
BigDecimal nowTotalChargeDate = StringUtils.getBigDecimal(obj.get("DQZXZYGDN"));
|
||||
// 初始化当日数据
|
||||
EmsDailyChargeData emsDailyChargeData = new EmsDailyChargeData();
|
||||
emsDailyChargeData.setSiteId(SITE_ID);
|
||||
@ -929,19 +929,18 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
if (yestDate == null) {
|
||||
// redis没有这查电表总数据表
|
||||
yestDate = emsAmmeterDataMapper.getYestLatestDate(SITE_ID,deviceId,yestData);
|
||||
// 数据存redis-有效期1天
|
||||
redisCache.setCacheObject(yestDateRedisKey, yestDate , Constants.DATE_VALID_TIME, TimeUnit.DAYS);
|
||||
}
|
||||
if (yestDate != null) {
|
||||
// 今日总数据-昨日总数据=今日充放电
|
||||
BigDecimal yestTotalDisChargeDate = yestDate.getCurrentForwardActiveTotal();
|
||||
BigDecimal yestTotalChargeDate = yestDate.getCurrentReverseActiveTotal();
|
||||
BigDecimal yestTotalDisChargeDate = yestDate.getCurrentReverseActiveTotal();
|
||||
BigDecimal yestTotalChargeDate = yestDate.getCurrentForwardActiveTotal();
|
||||
|
||||
dailyChargeDate = nowTotalChargeDate.subtract(yestTotalChargeDate);
|
||||
dailyDisChargeDate = nowTotalDisChargeDate.subtract(yestTotalDisChargeDate);
|
||||
emsDailyChargeData.setChargeData(dailyChargeDate);
|
||||
emsDailyChargeData.setDischargeData(dailyDisChargeDate);
|
||||
|
||||
// 最新数据存redis
|
||||
redisCache.setCacheObject(yestDateRedisKey, yestDate , Constants.DATE_VALID_TIME, TimeUnit.DAYS);
|
||||
}
|
||||
|
||||
// 插入或更新每日充放电数据表
|
||||
|
||||
@ -68,24 +68,31 @@ public class EmsStatsReportServiceImpl implements IEmsStatsReportService
|
||||
electricDataInfoVo.setTotalChargedCap(totalCharge);
|
||||
electricDataInfoVo.setEfficiency(efficiency);
|
||||
|
||||
String siteId = requestVo.getSiteId();
|
||||
String deviceId = requestVo.getDeviceId();
|
||||
if ("021_DDS_01".equals(siteId)){
|
||||
deviceId = "METE";
|
||||
} else if ("021_FXX_01".equals(siteId)){
|
||||
deviceId = "LOAD";
|
||||
}
|
||||
// 日期筛选
|
||||
List<SiteMonitorDataVo> dataList = new ArrayList();
|
||||
// 开始日期和结束日期同一天,展示 0-24 小时数据
|
||||
if (DateUtils.isSameDay(startDate, endDate)){
|
||||
electricDataInfoVo.setUnit("时");
|
||||
endDate = DateUtils.addDays(endDate, 1);
|
||||
dataList = emsPcsDataMapper.getPcsDataByHour(requestVo.getSiteId(), startDate, endDate);
|
||||
//endDate = DateUtils.addDays(endDate, 1);
|
||||
//dataList = emsPcsDataMapper.getPcsDataByHour(requestVo.getSiteId(), startDate, endDate);
|
||||
dataList = emsAmmeterDataMapper.getChargeDataByHour(siteId,deviceId,startDate);
|
||||
} else if (DateUtils.differentDaysByMillisecond(endDate, startDate) >= 1
|
||||
&& DateUtils.differentDaysByMillisecond(endDate, startDate) < 30){
|
||||
electricDataInfoVo.setUnit("日");
|
||||
endDate = DateUtils.addDays(endDate, 1);
|
||||
// 开始日期-结束日期大于 1 天,小于30 天,按天展示数据
|
||||
dataList = emsPcsDataMapper.getPcsDataByDay(requestVo.getSiteId(), startDate, endDate);
|
||||
//dataList = emsPcsDataMapper.getPcsDataByDay(requestVo.getSiteId(), startDate, endDate);
|
||||
dataList = emsDailyChargeDataMapper.getTotalChargeDataByDay(siteId,startDate,endDate);
|
||||
} else if (DateUtils.differentDaysByMillisecond(endDate, startDate) >= 30){
|
||||
electricDataInfoVo.setUnit("月");
|
||||
endDate = DateUtils.addDays(endDate, 1);
|
||||
// 开始日期-结束日期大于 1 个月,按月展示数据
|
||||
dataList = emsPcsDataMapper.getPcsDataByMonth(requestVo.getSiteId(), startDate, endDate);
|
||||
dataList = emsAmmeterDataMapper.getChargeDataByMonth(requestVo.getSiteId(),deviceId, startDate, endDate);
|
||||
}
|
||||
// 根据时间获取每天的充放电量
|
||||
if (!CollectionUtils.isEmpty(dataList)){
|
||||
|
||||
@ -86,7 +86,7 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
return;
|
||||
}
|
||||
|
||||
/*if (deviceId.contains("BMSD")) {
|
||||
if (deviceId.contains("BMSD")) {
|
||||
batteryStackDataProcess(deviceId, jsonData);
|
||||
|
||||
} else if (deviceId.contains("BMSC")) {
|
||||
@ -97,11 +97,11 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
} else if (deviceId.contains("PCS")) {
|
||||
pcsDataProcess(deviceId, jsonData);
|
||||
pcsBranchDataProcess(deviceId, jsonData);
|
||||
} else*/ if (deviceId.contains("LOAD")) {
|
||||
} else if (deviceId.contains("LOAD")) {
|
||||
loadDataProcess(deviceId, jsonData);
|
||||
} /*else if (deviceId.contains("METE")) {
|
||||
} else if (deviceId.contains("METE")) {
|
||||
meteDataProcess(deviceId, jsonData);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -576,8 +576,8 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
BigDecimal dailyChargeDate = new BigDecimal(0);
|
||||
BigDecimal dailyDisChargeDate = new BigDecimal(0);
|
||||
|
||||
BigDecimal nowTotalDisChargeDate = StringUtils.getBigDecimal(obj.get("DQZXYGZDN"));
|
||||
BigDecimal nowTotalChargeDate = StringUtils.getBigDecimal(obj.get("DQFXYGZDN"));
|
||||
BigDecimal nowTotalDisChargeDate = StringUtils.getBigDecimal(obj.get("DQFXYGZDN"));
|
||||
BigDecimal nowTotalChargeDate = StringUtils.getBigDecimal(obj.get("DQZXYGZDN"));
|
||||
// 初始化当日数据
|
||||
EmsDailyChargeData emsDailyChargeData = new EmsDailyChargeData();
|
||||
emsDailyChargeData.setSiteId(SITE_ID);
|
||||
@ -596,18 +596,18 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
if (yestDate == null) {
|
||||
// redis没有这查电表总数据表
|
||||
yestDate = emsAmmeterDataMapper.getYestLatestDate(SITE_ID,deviceId,yestData);
|
||||
// 数据redis-有效期1天
|
||||
redisCache.setCacheObject(yestDateRedisKey, yestDate , Constants.DATE_VALID_TIME, TimeUnit.DAYS);
|
||||
}
|
||||
if (yestDate != null) {
|
||||
// 今日总数据-昨日总数据=今日充放电
|
||||
BigDecimal yestTotalDisChargeDate = yestDate.getCurrentForwardActiveTotal();
|
||||
BigDecimal yestTotalChargeDate = yestDate.getCurrentReverseActiveTotal();
|
||||
BigDecimal yestTotalDisChargeDate = yestDate.getCurrentReverseActiveTotal();
|
||||
BigDecimal yestTotalChargeDate = yestDate.getCurrentForwardActiveTotal();
|
||||
|
||||
dailyChargeDate = nowTotalChargeDate.subtract(yestTotalChargeDate);
|
||||
dailyDisChargeDate = nowTotalDisChargeDate.subtract(yestTotalDisChargeDate);
|
||||
emsDailyChargeData.setChargeData(dailyChargeDate);
|
||||
emsDailyChargeData.setDischargeData(dailyDisChargeDate);
|
||||
// 存下redis-有效期1天
|
||||
redisCache.setCacheObject(yestDateRedisKey, yestDate , Constants.DATE_VALID_TIME, TimeUnit.DAYS);
|
||||
}
|
||||
// 插入或更新每日充放电数据表
|
||||
emsDailyChargeDataMapper.insertOrUpdateData(emsDailyChargeData);
|
||||
|
||||
@ -4,10 +4,7 @@ import com.xzzn.common.utils.DateUtils;
|
||||
import com.xzzn.common.utils.StringUtils;
|
||||
import com.xzzn.ems.domain.EmsSiteSetting;
|
||||
import com.xzzn.ems.domain.vo.*;
|
||||
import com.xzzn.ems.mapper.EmsAlarmRecordsMapper;
|
||||
import com.xzzn.ems.mapper.EmsDailyChargeDataMapper;
|
||||
import com.xzzn.ems.mapper.EmsPcsDataMapper;
|
||||
import com.xzzn.ems.mapper.EmsSiteSettingMapper;
|
||||
import com.xzzn.ems.mapper.*;
|
||||
import com.xzzn.ems.service.IEmsSiteService;
|
||||
import com.xzzn.ems.service.IHomePageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -17,6 +14,7 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 首页看板+站点地图 服务层实现
|
||||
@ -37,6 +35,8 @@ public class HomePageServiceImpl implements IHomePageService
|
||||
private EmsAlarmRecordsMapper alarmRecordsMapper;
|
||||
@Autowired
|
||||
private EmsDailyChargeDataMapper emsDailyChargeDataMapper;
|
||||
@Autowired
|
||||
private EmsAmmeterDataMapper emsAmmeterDataMapper;
|
||||
|
||||
@Override
|
||||
public SiteTotalInfoVo getSiteTotalInfo() {
|
||||
@ -114,7 +114,8 @@ public class HomePageServiceImpl implements IHomePageService
|
||||
public HomePageDataViewVo getHomePageDataList() {
|
||||
HomePageDataViewVo homePageDataViewVo = new HomePageDataViewVo();
|
||||
// 电量指标
|
||||
List<ElectricIndexList> electricDataList = emsPcsDataMapper.getElectDataList();
|
||||
//List<ElectricIndexList> electricDataList = emsPcsDataMapper.getElectDataList();
|
||||
List<ElectricIndexList> electricDataList = getElectricDataList();
|
||||
homePageDataViewVo.setElecDataList(electricDataList);
|
||||
// 系统效率
|
||||
List<SystemEfficiencyList> systemEfficiencyLists = new ArrayList<>();
|
||||
@ -160,6 +161,97 @@ public class HomePageServiceImpl implements IHomePageService
|
||||
return homePageDataViewVo;
|
||||
}
|
||||
|
||||
private List<ElectricIndexList> getElectricDataList() {
|
||||
List<ElectricIndexList> electricDataList = new ArrayList<>();
|
||||
// 获取每个月最早和最晚的时间
|
||||
List<MonthlyTimeRange> timeRanges = emsAmmeterDataMapper.getMonthlyTimeRanges();
|
||||
if (timeRanges.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 遍历收集所有需要查询的时间点(最早+最晚)
|
||||
List<TimePointQuery> timePointQueries = new ArrayList<>();
|
||||
for (MonthlyTimeRange range : timeRanges) {
|
||||
timePointQueries.add(new TimePointQuery(range.getSiteId(),range.getFirstDataTime()));
|
||||
timePointQueries.add(new TimePointQuery(range.getSiteId(),range.getLastDataTime()));
|
||||
}
|
||||
// 批量获取所有时间点对应的数据值转化为map
|
||||
List<TimePointValue> timePointValues = emsAmmeterDataMapper.batchGetTimePointValues(timePointQueries);
|
||||
Map<String, TimePointValue> valueMap = timePointValues.stream()
|
||||
.collect(Collectors.toMap(
|
||||
v -> v.getSiteId() + "_" + v.getDataUpdateTime().toString(),
|
||||
v -> v
|
||||
));
|
||||
// 缓存每个站点的上月最晚电量 key=siteId, value=上月最晚时间对应数据
|
||||
Map<String, TimePointValue> lastMonthMap = new HashMap<>();
|
||||
|
||||
// 组装结果-key=统计月,value=统计月的数据
|
||||
Map<String, ElectricIndexList> elecDataMap = new HashMap<>();
|
||||
for (MonthlyTimeRange timeRange : timeRanges) {
|
||||
String dataMonth = timeRange.getMonth();
|
||||
String siteId = timeRange.getSiteId();
|
||||
|
||||
BigDecimal totalChargeData = new BigDecimal(0);
|
||||
BigDecimal totalDisChargeData = new BigDecimal(0);
|
||||
// 获取本月最晚数据
|
||||
TimePointValue monthLastValue = valueMap.get(siteId +"_"+timeRange.getLastDataTime());
|
||||
BigDecimal lastChargeValue = new BigDecimal(0);
|
||||
BigDecimal lastDisChargeValue = new BigDecimal(0);
|
||||
if (monthLastValue != null) {
|
||||
lastChargeValue = monthLastValue.getTotalChargeData() == null ? BigDecimal.ZERO : monthLastValue.getTotalChargeData();
|
||||
lastDisChargeValue = monthLastValue.getTotalDischargeData() == null ? BigDecimal.ZERO : monthLastValue.getTotalDischargeData();
|
||||
|
||||
}// 看是否有缓存上个月最晚电量,没有则是首月
|
||||
if (!lastMonthMap.containsKey(siteId)) {
|
||||
// 首月充放电 = 本月最晚数据 - 本月最早数据
|
||||
TimePointValue monthFirstValue = valueMap.get(siteId +"_"+timeRange.getFirstDataTime());
|
||||
BigDecimal firstChargeValue = new BigDecimal(0);
|
||||
BigDecimal firstDisChargeValue = new BigDecimal(0);
|
||||
if (monthLastValue != null) {
|
||||
firstChargeValue = monthFirstValue.getTotalChargeData() == null ? BigDecimal.ZERO : monthFirstValue.getTotalChargeData();
|
||||
firstDisChargeValue = monthFirstValue.getTotalDischargeData() == null ? BigDecimal.ZERO : monthFirstValue.getTotalDischargeData();
|
||||
}
|
||||
totalChargeData = lastChargeValue.subtract(firstChargeValue);
|
||||
totalDisChargeData = lastDisChargeValue.subtract(firstDisChargeValue);
|
||||
} else {// 非本月充放电 = 本月最晚数据 - 上月最晚数据
|
||||
TimePointValue lastValue = lastMonthMap.get(siteId);
|
||||
if (lastValue == null) {// 缓存找不到上月数据,则取本月最早数据
|
||||
lastValue = valueMap.get(siteId +"_"+timeRange.getFirstDataTime());
|
||||
}
|
||||
BigDecimal lastMonthChargeValue = new BigDecimal(0);
|
||||
BigDecimal lastMonthDisChargeValue = new BigDecimal(0);
|
||||
if (lastValue != null) {
|
||||
lastMonthChargeValue = lastValue.getTotalChargeData() == null ? BigDecimal.ZERO : lastValue.getTotalChargeData();
|
||||
lastMonthDisChargeValue = lastValue.getTotalDischargeData() == null ? BigDecimal.ZERO : lastValue.getTotalDischargeData();
|
||||
}totalChargeData = lastChargeValue.subtract(lastMonthChargeValue);
|
||||
totalDisChargeData = lastDisChargeValue.subtract(lastMonthDisChargeValue);
|
||||
}
|
||||
// 缓存最晚数据
|
||||
lastMonthMap.put(siteId,monthLastValue);
|
||||
|
||||
ElectricIndexList electricIndexList = new ElectricIndexList();
|
||||
// 判断map里面是否已经有排序月份
|
||||
if (elecDataMap.containsKey(dataMonth)) {
|
||||
electricIndexList = elecDataMap.get(dataMonth);
|
||||
totalChargeData = totalChargeData.add(electricIndexList.getChargeEnergy());
|
||||
totalDisChargeData = totalDisChargeData.add(electricIndexList.getDisChargeEnergy());
|
||||
}
|
||||
electricIndexList.setDateMonth(dataMonth);
|
||||
electricIndexList.setChargeEnergy(totalChargeData);
|
||||
electricIndexList.setDisChargeEnergy(totalDisChargeData);
|
||||
elecDataMap.put(dataMonth,electricIndexList);
|
||||
}
|
||||
|
||||
electricDataList = elecDataMap.values().stream().collect(Collectors.toList());
|
||||
return electricDataList;
|
||||
}
|
||||
// 从timeRangeList中获取指定站点+月份的时间范围
|
||||
private MonthlyTimeRange getSiteRangeByMonth(List<MonthlyTimeRange> rangeList, String siteId, String month) {
|
||||
return rangeList.stream()
|
||||
.filter(r -> siteId.equals(r.getSiteId()) && month.equals(r.getMonth()))
|
||||
.findFirst() .orElse(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<SiteMonitorDataVo> getSevenChargeData(DateSearchRequest requestVo) {
|
||||
String siteId = requestVo.getSiteId();
|
||||
@ -185,9 +277,6 @@ public class HomePageServiceImpl implements IHomePageService
|
||||
endDate = new Date();
|
||||
requestVo.setStartDate(startDate);
|
||||
requestVo.setEndDate(endDate);
|
||||
} else if (endDate != null) {
|
||||
endDate = DateUtils.addDays(endDate, 1);
|
||||
requestVo.setEndDate(endDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -891,4 +891,75 @@
|
||||
and DATE(data_update_time) = #{yestData}
|
||||
order by data_update_time desc limit 1
|
||||
</select>
|
||||
|
||||
<select id="getMonthlyTimeRanges" resultType="com.xzzn.ems.domain.vo.MonthlyTimeRange">
|
||||
SELECT site_id as siteId,
|
||||
DATE_FORMAT(data_update_time, '%Y-%m') AS month,
|
||||
MIN(data_update_time) AS firstDataTime,
|
||||
MAX(data_update_time) AS lastDataTime
|
||||
FROM ems_ammeter_data
|
||||
WHERE (site_id = '021_DDS_01' AND device_id = 'METE')
|
||||
OR (site_id = '021_FXX_01' AND device_id = 'LOAD')
|
||||
GROUP BY site_id, DATE_FORMAT(data_update_time, '%Y-%m')
|
||||
ORDER BY site_id, month
|
||||
</select>
|
||||
|
||||
<select id="batchGetTimePointValues" resultType="com.xzzn.ems.domain.vo.TimePointValue">
|
||||
SELECT site_id as siteId, data_update_time as dataUpdateTime,
|
||||
current_forward_active_total AS totalChargeData,
|
||||
current_reverse_active_total AS totalDischargeData
|
||||
FROM ems_ammeter_data
|
||||
WHERE (site_id, data_update_time) IN
|
||||
<foreach collection="list" item="item" separator="," open="(" close=")">
|
||||
(#{item.siteId}, #{item.dataTime})
|
||||
</foreach>
|
||||
AND ((site_id = '021_DDS_01' AND device_id = 'METE')
|
||||
OR (site_id = '021_FXX_01' AND device_id = 'LOAD'))
|
||||
</select>
|
||||
|
||||
<select id="getChargeDataByHour" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
|
||||
SELECT hour AS ammeterDate,
|
||||
data_update_time AS dataUpdateTime,
|
||||
current_forward_active_total AS chargedCap,
|
||||
current_reverse_active_total AS disChargedCap
|
||||
FROM (
|
||||
SELECT data_update_time,
|
||||
current_forward_active_total,
|
||||
current_reverse_active_total,
|
||||
DATE_FORMAT(data_update_time, '%H:00') AS hour,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY DATE_FORMAT(data_update_time, '%H:00')
|
||||
ORDER BY data_update_time DESC
|
||||
) AS rn
|
||||
FROM ems_ammeter_data
|
||||
WHERE site_id = #{siteId}
|
||||
AND device_id = #{deviceId}
|
||||
AND DATE(data_update_time) = #{startDate}
|
||||
) AS hourly_data
|
||||
WHERE rn = 1
|
||||
ORDER BY ammeterDate
|
||||
</select>
|
||||
|
||||
<select id="getChargeDataByMonth" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
|
||||
SELECT month as ammeterDate,
|
||||
data_update_time AS dataUpdateTime,
|
||||
current_forward_active_total AS chargedCap,
|
||||
current_reverse_active_total AS disChargedCap
|
||||
FROM (
|
||||
SELECT DATE_FORMAT(data_update_time, '%Y-%m') AS month,
|
||||
data_update_time,
|
||||
current_forward_active_total,
|
||||
current_reverse_active_total,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY DATE_FORMAT(data_update_time, '%Y-%m')
|
||||
ORDER BY data_update_time DESC
|
||||
) AS rn
|
||||
FROM ems_ammeter_data
|
||||
WHERE site_id = #{siteId}
|
||||
AND device_id = #{deviceId}
|
||||
AND data_update_time BETWEEN #{startDate} AND #{endDate}
|
||||
) AS monthly_data
|
||||
WHERE rn = 1
|
||||
ORDER BY ammeterDate
|
||||
</select>
|
||||
</mapper>
|
||||
@ -0,0 +1,177 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.xzzn.ems.mapper.EmsDailyChargeDataMapper">
|
||||
|
||||
<resultMap type="EmsDailyChargeData" id="EmsDailyChargeDataResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="siteId" column="site_id" />
|
||||
<result property="deviceId" column="device_id" />
|
||||
<result property="dateTime" column="date_time" />
|
||||
<result property="totalChargeData" column="total_charge_Data" />
|
||||
<result property="totalDischargeData" column="total_discharge_Data" />
|
||||
<result property="chargeData" column="charge_data" />
|
||||
<result property="dischargeData" column="discharge_data" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectEmsDailyChargeDataVo">
|
||||
select id, site_id, device_id, date_time, total_charge_Data, total_discharge_Data, charge_data, discharge_data, create_by, create_time, update_by, update_time, remark from ems_daily_charge_data
|
||||
</sql>
|
||||
|
||||
<select id="selectEmsDailyChargeDataList" parameterType="EmsDailyChargeData" resultMap="EmsDailyChargeDataResult">
|
||||
<include refid="selectEmsDailyChargeDataVo"/>
|
||||
<where>
|
||||
<if test="siteId != null and siteId != ''"> and site_id = #{siteId}</if>
|
||||
<if test="deviceId != null and deviceId != ''"> and device_id = #{deviceId}</if>
|
||||
<if test="dateTime != null "> and date_time = #{dateTime}</if>
|
||||
<if test="totalChargeData != null "> and total_charge_Data = #{totalChargeData}</if>
|
||||
<if test="totalDischargeData != null "> and total_discharge_Data = #{totalDischargeData}</if>
|
||||
<if test="chargeData != null "> and charge_data = #{chargeData}</if>
|
||||
<if test="dischargeData != null "> and discharge_data = #{dischargeData}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectEmsDailyChargeDataById" parameterType="Long" resultMap="EmsDailyChargeDataResult">
|
||||
<include refid="selectEmsDailyChargeDataVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertEmsDailyChargeData" parameterType="EmsDailyChargeData" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into ems_daily_charge_data
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="siteId != null">site_id,</if>
|
||||
<if test="deviceId != null and deviceId != ''">device_id,</if>
|
||||
<if test="dateTime != null">date_time,</if>
|
||||
<if test="totalChargeData != null">total_charge_Data,</if>
|
||||
<if test="totalDischargeData != null">total_discharge_Data,</if>
|
||||
<if test="chargeData != null">charge_data,</if>
|
||||
<if test="dischargeData != null">discharge_data,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="siteId != null">#{siteId},</if>
|
||||
<if test="deviceId != null and deviceId != ''">#{deviceId},</if>
|
||||
<if test="dateTime != null">#{dateTime},</if>
|
||||
<if test="totalChargeData != null">#{totalChargeData},</if>
|
||||
<if test="totalDischargeData != null">#{totalDischargeData},</if>
|
||||
<if test="chargeData != null">#{chargeData},</if>
|
||||
<if test="dischargeData != null">#{dischargeData},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateEmsDailyChargeData" parameterType="EmsDailyChargeData">
|
||||
update ems_daily_charge_data
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="siteId != null">site_id = #{siteId},</if>
|
||||
<if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
|
||||
<if test="dateTime != null">date_time = #{dateTime},</if>
|
||||
<if test="totalChargeData != null">total_charge_Data = #{totalChargeData},</if>
|
||||
<if test="totalDischargeData != null">total_discharge_Data = #{totalDischargeData},</if>
|
||||
<if test="chargeData != null">charge_data = #{chargeData},</if>
|
||||
<if test="dischargeData != null">discharge_data = #{dischargeData},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteEmsDailyChargeDataById" parameterType="Long">
|
||||
delete from ems_daily_charge_data where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteEmsDailyChargeDataByIds" parameterType="String">
|
||||
delete from ems_daily_charge_data where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<insert id="insertOrUpdateData" parameterType="EmsDailyChargeData">
|
||||
INSERT into ems_daily_charge_data (
|
||||
id,
|
||||
site_id,
|
||||
device_id,
|
||||
date_time,
|
||||
total_charge_Data,
|
||||
total_discharge_Data,
|
||||
charge_data,
|
||||
discharge_data,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time,
|
||||
remark
|
||||
) values (
|
||||
#{id},
|
||||
#{siteId},
|
||||
#{deviceId},
|
||||
#{dateTime},
|
||||
#{totalChargeData},
|
||||
#{totalDischargeData},
|
||||
#{chargeData},
|
||||
#{dischargeData},
|
||||
#{createBy},
|
||||
#{createTime},
|
||||
#{updateBy},
|
||||
#{updateTime},
|
||||
#{remark}
|
||||
)
|
||||
on duplicate key update
|
||||
total_charge_Data = #{totalChargeData},
|
||||
total_discharge_Data = #{totalDischargeData},
|
||||
charge_data = #{chargeData},
|
||||
discharge_data = #{dischargeData},
|
||||
update_time = NOW()
|
||||
</insert>
|
||||
|
||||
<select id="getAllSiteChargeData" resultType="map">
|
||||
SELECT SUM(t.total_charge_data) AS totalChargedCap,
|
||||
SUM(t.total_discharge_data) AS totalDischargedCap
|
||||
FROM ems_daily_charge_data t
|
||||
LEFT JOIN ems_site_setting ss ON t.site_id = ss.site_id
|
||||
WHERE t.date_time = #{nowData}
|
||||
<if test="siteId != null">
|
||||
and t.site_id = #{siteId}
|
||||
</if>
|
||||
AND t.total_charge_data IS NOT NULL
|
||||
AND t.total_discharge_data IS NOT NULL
|
||||
</select>
|
||||
|
||||
<select id="getSingleSiteChargeData" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
|
||||
SELECT t.charge_data AS chargedCap,
|
||||
t.discharge_data AS disChargedCap,
|
||||
t.date_time AS ammeterDate
|
||||
FROM ems_daily_charge_data t
|
||||
WHERE t.site_id = #{siteId}
|
||||
AND t.date_time BETWEEN #{startDate} AND #{endDate}
|
||||
order by ammeterDate
|
||||
</select>
|
||||
|
||||
<select id="getTotalChargeDataByDay" resultType="com.xzzn.ems.domain.vo.SiteMonitorDataVo">
|
||||
SELECT t.date_time AS ammeterDate,
|
||||
t.total_charge_Data as chargedCap,
|
||||
t.total_discharge_Data as disChargedCap
|
||||
FROM ems_daily_charge_data t
|
||||
WHERE t.site_id = #{siteId}
|
||||
AND t.date_time BETWEEN #{startDate} AND #{endDate}
|
||||
order by ammeterDate
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user