From 64a9db5db3caff4291d5cda42518d3f822f360a7 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Tue, 26 Sep 2023 15:18:33 +0800 Subject: [PATCH] =?UTF-8?q?#=E6=B0=B4=E7=94=B5=E7=AB=99bug=E8=A7=A3?= =?UTF-8?q?=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fill/service/impl/GenerateServiceImpl.java | 53 ++++++++++++++++------ .../main/service/impl/HomeServiceImpl.java | 7 ++- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java index f4c92cf..0a53e2b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java @@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.operational.fill.entity.GenerateEntity; -import com.hnac.hzims.operational.fill.entity.UseEntity; import com.hnac.hzims.operational.fill.mapper.GenerateMapper; import com.hnac.hzims.operational.fill.service.GenerateService; import com.hnac.hzims.operational.fill.vo.GenerateVo; @@ -13,7 +12,6 @@ import com.hnac.hzims.operational.fill.vo.QueryVo; import com.hnac.hzims.operational.fill.wrapper.GenerateWrapper; import com.hnac.hzims.operational.main.vo.GenerationPowerVo; import com.hnac.hzims.operational.main.vo.PowerMonthVo; -import com.hnac.hzims.operational.main.vo.UsrPowerVo; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; @@ -29,6 +27,7 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Calendar; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -154,19 +153,45 @@ public class GenerateServiceImpl extends BaseServiceImpl(); } + List mons = this.mons(2,12,false); + List format = records.stream().peek(record-> record.setFillDate(DateUtil.format(DateUtil.parse(record.getFillDate(),"yyyy-MM"),"yyyy-MM") + "-01")).collect(Collectors.toList()); // 返回结果 - return records.stream().peek( - record-> record.setFillDate(DateUtil.format(DateUtil.parse(record.getFillDate(),"yyyy-MM"),"yyyy-MM") + "-01") - ).collect(Collectors.toMap(GenerateEntity::getFillDate,GenerateEntity::getGenerate,Double::sum)). - entrySet().stream().map(entry->{ - PowerMonthVo mon = new PowerMonthVo(); - mon.setStrMonth(entry.getKey()); - if(Math.abs(entry.getValue()) <= 0){ - mon.setPower(0f); - }else{ - mon.setPower(Float.parseFloat(entry.getValue().toString())); - } - return mon; + return mons.stream().map(mon->{ + PowerMonthVo powerMonth = new PowerMonthVo(); + powerMonth.setStrMonth(mon); + powerMonth.setPower((float) format.stream().filter(o->o.getFillDate().equals(mon)).mapToDouble(GenerateEntity::getGenerate).sum()); + return powerMonth; }).collect(Collectors.toList()); } + + + /** + * 获取近年月份集合 + * @param year + * @return + */ + public List mons(int year, int endMoth, boolean nextMon) { + List list = new ArrayList<>(); + // 开始日期 + Calendar endCal = Calendar.getInstance(); + endCal.setTime(new Date()); + endCal.add(Calendar.MONTH, -endCal.get(Calendar.MONTH) + endMoth); + endCal.add(Calendar.DATE, -endCal.get(Calendar.DATE) + 1); + + // 结束日期 + Calendar startCal = Calendar.getInstance(); + startCal.setTime(new Date()); + startCal.set(Calendar.YEAR, startCal.get(Calendar.YEAR) - year); + startCal.add(Calendar.MONTH, -startCal.get(Calendar.MONTH)); + startCal.add(Calendar.DATE, -startCal.get(Calendar.DATE) + 1); + // 获取日期之间的月份 + while (endCal.after(startCal)) { + list.add(DateUtil.format(startCal.getTime(),DateUtil.PATTERN_DATE)); + startCal.add(Calendar.MONTH, 1); + } + if(nextMon){ + list.add(DateUtil.format(endCal.getTime(),DateUtil.PATTERN_DATE)); + } + return list; + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomeServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomeServiceImpl.java index f047a22..b6e7d7a 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomeServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomeServiceImpl.java @@ -153,7 +153,12 @@ public class HomeServiceImpl implements HomeService { if(HomePageConstant.CHARGE.equals(type) && "2".equals(serve)){ TargetVo target = (TargetVo) redisTemplate.opsForValue().get(charge); if(ObjectUtil.isNotEmpty(target)){ - count.setCount(Long.valueOf(Optional.ofNullable(target.getCharge()).orElse(0))); + TargetVo charge = this.chargeTarget(); + if(ObjectUtil.isNotEmpty(charge)){ + count.setCount(Long.valueOf(charge.getCharge())); + }else{ + count.setCount(92L); + } } }else if(HomePageConstant.WATER_CONSERVANCY.equals(type) && "2".equals(serve)){ count.setCount(stations.stream().filter(station->serve.equals(station.getServeType()) && HomePageConstant.waterList.contains(station.getType())).count());