From 4ff5b9567741ac0761148a0277bbfc1cb6ce0531 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Mon, 26 Aug 2024 10:43:46 +0800 Subject: [PATCH] =?UTF-8?q?#=E9=80=9A=E8=AE=AF=E4=B8=AD=E6=96=AD=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=A2=9E=E5=8A=A0=E7=AB=99=E7=82=B9=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/electric/vo/ComprehensiveElectricVo.java | 22 ++++-- .../service/impl/ElectricReportServiceImpl.java | 79 ++++++++++++++++++++-- .../interruption/mapper/InterruptionMapper.java | 4 +- 3 files changed, 92 insertions(+), 13 deletions(-) diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/ComprehensiveElectricVo.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/ComprehensiveElectricVo.java index 6d4da72..06d4c44 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/ComprehensiveElectricVo.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/vo/ComprehensiveElectricVo.java @@ -1,5 +1,7 @@ package com.hnac.hzims.electric.vo; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -14,52 +16,60 @@ public class ComprehensiveElectricVo { private String month; @ApiModelProperty(value = "本月电量") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double monthGenerate; @ApiModelProperty(value = "去年同月") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double lastMonthGenerate; @ApiModelProperty(value = "月同比") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double lastMonthGenerateRate; @ApiModelProperty(value = "年发电量") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double yearGenerate; @ApiModelProperty(value = "去年同期") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double lastYearGenerate; @ApiModelProperty(value = "年同比") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double lastYearGenerateRate; @ApiModelProperty(value = "本月降雨") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double monthRain; @ApiModelProperty(value = "去年同月") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double lastMonthRain; - @ApiModelProperty(value = "月同比") - private Double lastMonthRainRate; - @ApiModelProperty(value = "年降雨量") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double yearRain; @ApiModelProperty(value = "去年同期") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double lastYearRain; - @ApiModelProperty(value = "年同比") - private Double lastYearRainRate; - @ApiModelProperty(value = "本月等效小时") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double monthEquivalent; @ApiModelProperty(value = "去年同月") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double lastMonthEquivalent; @ApiModelProperty(value = "年等效小时") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double yearEquivalent; @ApiModelProperty(value = "去年同期") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double lastYearEquivalent; } \ No newline at end of file diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java index 59276ea..4c53620 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ElectricReportServiceImpl.java @@ -1,7 +1,6 @@ package com.hnac.hzims.electric.service.impl; -import cn.hutool.core.io.unit.DataUnit; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -32,6 +31,8 @@ import org.springblade.system.feign.ISysClient; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; @@ -134,14 +135,82 @@ public class ElectricReportServiceImpl implements IElectricReportService { Date finish = calendar.getTime(); calendar.add(Calendar.YEAR,-1); Date current = calendar.getTime(); + // fixme 随机器模拟数据 + Random random = new Random(); + List electrics = new ArrayList<>(); while (current.compareTo(finish) < 0){ - - + ComprehensiveElectricVo comprehensive = new ComprehensiveElectricVo(); + comprehensive.setMonth(current.getMonth() + 1 + "月"); + String currentMon = DateUtil.format(calendar.getTime(),"yyyy-MM"); + String currentYear = DateUtil.format(calendar.getTime(),"yyyy"); + calendar.add(Calendar.YEAR,-1); + String lastMon = DateUtil.format(calendar.getTime(),"yyyy-MM"); + String lastYear = DateUtil.format(calendar.getTime(),"yyyy"); + calendar.add(Calendar.YEAR,1); + // 电量 + if(CollectionUtil.isNotEmpty(threes)){ + comprehensive.setMonthGenerate(threes.stream().filter(o->o.getStrMonth().contains(currentMon)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); + comprehensive.setLastMonthGenerate(threes.stream().filter(o->o.getStrMonth().contains(lastMon)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); + if(comprehensive.getMonthGenerate() > 0 && comprehensive.getLastMonthGenerate() > 0){ + comprehensive.setLastMonthGenerateRate(BigDecimal.valueOf(comprehensive.getMonthGenerate() / comprehensive.getLastMonthGenerate() * 100).setScale(2, RoundingMode.HALF_UP).doubleValue()); + }else{ + comprehensive.setLastMonthGenerateRate(0.0); + } + // 本月等效小时 + if(comprehensive.getMonthGenerate() > 0){ + comprehensive.setMonthEquivalent(BigDecimal.valueOf(comprehensive.getMonthGenerate() / installedCapacity).setScale(2, RoundingMode.HALF_UP).doubleValue()); + }else{ + comprehensive.setMonthEquivalent(0.0); + } + // 去年同月等效小时 + if(comprehensive.getLastMonthGenerate() > 0){ + comprehensive.setLastMonthEquivalent(BigDecimal.valueOf(comprehensive.getLastMonthGenerate() / installedCapacity).setScale(2, RoundingMode.HALF_UP).doubleValue()); + }else{ + comprehensive.setLastMonthEquivalent(0.0); + } + comprehensive.setYearGenerate(threes.stream().filter(o->o.getStrMonth().contains(currentYear)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); + comprehensive.setLastYearGenerate(threes.stream().filter(o->o.getStrMonth().contains(lastYear)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); + if(comprehensive.getYearGenerate() > 0 && comprehensive.getLastYearGenerate() > 0){ + comprehensive.setLastYearGenerateRate(BigDecimal.valueOf(comprehensive.getYearGenerate() / comprehensive.getLastYearGenerate() * 100).setScale(2, RoundingMode.HALF_UP).doubleValue()); + } + if(CollectionUtil.isEmpty(electrics)){ + // 本年等效小时 + comprehensive.setYearEquivalent(comprehensive.getMonthEquivalent()); + // 去年同期等效小时 + comprehensive.setLastYearEquivalent(comprehensive.getLastMonthEquivalent()); + }else{ + // 累计等效小时 + comprehensive.setYearEquivalent(electrics.stream().mapToDouble(ComprehensiveElectricVo::getMonthEquivalent).sum() + comprehensive.getMonthEquivalent()); + comprehensive.setLastYearEquivalent(electrics.stream().mapToDouble(ComprehensiveElectricVo::getLastMonthEquivalent).sum() + comprehensive.getLastMonthEquivalent()); + } + }else{ + comprehensive.setMonthGenerate(0.0); + comprehensive.setLastMonthGenerate(0.0); + comprehensive.setYearGenerate(0.0); + comprehensive.setLastYearGenerate(0.0); + comprehensive.setLastMonthGenerateRate(0.0); + comprehensive.setLastYearGenerateRate(0.0); + comprehensive.setMonthEquivalent(0.0); + comprehensive.setLastMonthEquivalent(0.0); + comprehensive.setYearEquivalent(0.0); + comprehensive.setLastYearEquivalent(0.0); + } + // 降雨 : fixme 模拟降雨 + comprehensive.setMonthRain(BigDecimal.valueOf(random.nextDouble() * 10 * 8).setScale(2, RoundingMode.HALF_UP).doubleValue()); + comprehensive.setLastMonthRain(BigDecimal.valueOf(random.nextDouble() * 10 * 8).setScale(2, RoundingMode.HALF_UP).doubleValue()); + if(CollectionUtil.isEmpty(electrics)){ + comprehensive.setYearRain(comprehensive.getMonthRain()); + comprehensive.setLastYearRain(comprehensive.getLastMonthRain()); + }else{ + // 累计降雨 + comprehensive.setYearRain(electrics.stream().mapToDouble(ComprehensiveElectricVo::getMonthRain).sum() + comprehensive.getMonthRain()); + comprehensive.setLastYearRain(electrics.stream().mapToDouble(ComprehensiveElectricVo::getLastMonthRain).sum() + comprehensive.getLastMonthRain()); + } + electrics.add(comprehensive); calendar.add(Calendar.MONTH,1); current = calendar.getTime(); } - - return null; + return electrics; } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.java index e804cd3..ce1d4a6 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.java @@ -1,15 +1,15 @@ package com.hnac.hzims.business.interruption.mapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.hnac.hzims.business.interruption.entity.InterruptionEntity; import com.hnac.hzims.business.interruption.vo.InterruptionStationVo; +import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; import java.util.List; /** * @author ysj */ -public interface InterruptionMapper extends BaseMapper { +public interface InterruptionMapper extends UserDataScopeBaseMapper { List interruptionStations(); }