From a7c16d2ae630408edacbb3c1200ac178e10b4ff8 Mon Sep 17 00:00:00 2001 From: zxc <954985706@qq.com> Date: Sun, 28 Jun 2020 13:47:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E6=A0=BC=E5=B0=8F=E7=BB=84,=E8=AF=9D?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/result/TopicSubAgencyResultDTO.java | 7 +++++ .../dto/result/TopicSubGridResultDTO.java | 7 +++++ .../service/group/impl/GroupServiceImpl.java | 5 +++- .../service/topic/impl/TopicServiceImpl.java | 30 +++++++++++++++---- .../main/resources/mapper/group/GroupDao.xml | 3 +- 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSubAgencyResultDTO.java b/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSubAgencyResultDTO.java index 87dd107010..3b599a64ff 100644 --- a/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSubAgencyResultDTO.java +++ b/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSubAgencyResultDTO.java @@ -1,5 +1,6 @@ package com.epmet.topic.dto.result; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import java.io.Serializable; @@ -32,4 +33,10 @@ public class TopicSubAgencyResultDTO implements Serializable { * 机关Id */ private String agencyId; + + /** + * 排序 + */ + @JsonIgnore + private Integer sort; } diff --git a/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSubGridResultDTO.java b/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSubGridResultDTO.java index 64cad1615c..d319e2c128 100644 --- a/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSubGridResultDTO.java +++ b/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSubGridResultDTO.java @@ -1,5 +1,6 @@ package com.epmet.topic.dto.result; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import java.io.Serializable; @@ -32,4 +33,10 @@ public class TopicSubGridResultDTO implements Serializable { * 网格Id */ private String gridId; + + /** + * 排序 + */ + @JsonIgnore + private Integer sort; } diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/group/impl/GroupServiceImpl.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/group/impl/GroupServiceImpl.java index 80a5624e3b..1c72f584fc 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/group/impl/GroupServiceImpl.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/group/impl/GroupServiceImpl.java @@ -15,7 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; /** * @Author zxc @@ -60,7 +62,8 @@ public class GroupServiceImpl implements GroupService { } }); }); - return result; + //倒序 + return result.stream().sorted(Comparator.comparing(GroupSubAgencyResultDTO::getValue).reversed()).collect(Collectors.toList()); } return new ArrayList<>(); } diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java index 0859bd2632..ad8d8e7eee 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java @@ -14,9 +14,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -94,6 +92,7 @@ public class TopicServiceImpl implements TopicService { public List topicSubGrid(TokenDto tokenDto) { String agencyId = this.getLoginUserDetails(tokenDto); List result = new ArrayList<>(); + List resultAll = new ArrayList<>(); List subGridIdList = topicDao.getSubGridIdList(agencyId); if (subGridIdList.size() != NumConstant.ZERO){ List gridAllTopicInfoLastDay = topicDao.getGridAllTopicInfoLastDay(); @@ -110,7 +109,17 @@ public class TopicServiceImpl implements TopicService { } }); }); - return result; + Map> collect = result.stream().collect(Collectors.groupingBy(TopicSubGridResultDTO::getGridId)); + Set>> entries = collect.entrySet(); + entries.forEach(entry -> { + List value = entry.getValue(); + Integer sort = value.stream().collect(Collectors.summingInt(TopicSubGridResultDTO::getValue)); + value.forEach(v -> { + v.setSort(sort); + resultAll.add(v); + }); + }); + return resultAll.stream().sorted(Comparator.comparing(TopicSubGridResultDTO::getSort).reversed()).collect(Collectors.toList()); } return new ArrayList<>(); } @@ -124,6 +133,7 @@ public class TopicServiceImpl implements TopicService { public List topicSubAgency(TokenDto tokenDto) { String agencyId = this.getLoginUserDetails(tokenDto); List result = new ArrayList<>(); + List resultAll = new ArrayList<>(); List subAgencyIdList = topicDao.getSubAgencyIdList(agencyId); //存在下级机关 if (subAgencyIdList.size() != NumConstant.ZERO){ @@ -142,7 +152,17 @@ public class TopicServiceImpl implements TopicService { } }); }); - return result; + Map> collect = result.stream().collect(Collectors.groupingBy(TopicSubAgencyResultDTO::getAgencyId)); + Set>> entries = collect.entrySet(); + entries.forEach(entry -> { + List value = entry.getValue(); + Integer sort = value.stream().collect(Collectors.summingInt(TopicSubAgencyResultDTO::getValue)); + value.forEach(v -> { + v.setSort(sort); + resultAll.add(v); + }); + }); + return resultAll.stream().sorted(Comparator.comparing(TopicSubAgencyResultDTO::getSort).reversed()).collect(Collectors.toList()); } //不存在 return new ArrayList<>(); diff --git a/epmet-module/data-report/data-report-server/src/main/resources/mapper/group/GroupDao.xml b/epmet-module/data-report/data-report-server/src/main/resources/mapper/group/GroupDao.xml index 6bee70e94b..47b42695ee 100644 --- a/epmet-module/data-report/data-report-server/src/main/resources/mapper/group/GroupDao.xml +++ b/epmet-module/data-report/data-report-server/src/main/resources/mapper/group/GroupDao.xml @@ -59,6 +59,7 @@ fggd.del_flag = '0' AND fggd.agency_id = #{agencyId} AND fggd.date_id = (SELECT MAX(date_id) FROM fact_group_grid_daily WHERE del_flag = '0') + ORDER BY value DESC @@ -89,7 +90,7 @@ del_flag = '0' AND agency_id = #{agencyId} ORDER BY - month_id DESC + month_id DESC, value DESC LIMIT 12