From 4f8d2f2fc480935425663ed8c5a45e1b97097da8 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Tue, 26 Sep 2023 18:28:46 +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 --- .../operation/fill/impl/GenerateServiceImpl.java | 51 +++++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/GenerateServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/GenerateServiceImpl.java index 6f5ee6f..2ea51cc 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/GenerateServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/GenerateServiceImpl.java @@ -15,6 +15,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; @@ -94,19 +95,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; + } }