소스 검색

返回一对多数据的时候, 按类型分组

王苗苗 7 달 전
부모
커밋
5919c50acb

+ 3 - 0
slibra-system/src/main/java/com/slibra/business/domain/TXinyiCarbonMajor.java

@@ -4,6 +4,7 @@ import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
+import java.util.Map;
 
 import com.slibra.business.res.ChartBasic;
 import lombok.AllArgsConstructor;
@@ -476,6 +477,8 @@ public class TXinyiCarbonMajor extends BaseEntity
     //额外的关联多条数据的集合
     private List<TXinyiCarbonExtra> extraList;
 
+    private Map<Integer, List<TXinyiCarbonExtra>> extraMap;
+
 
 
 

+ 6 - 1
slibra-system/src/main/java/com/slibra/business/service/impl/TXinyiCarbonMajorServiceImpl.java

@@ -3,6 +3,7 @@ package com.slibra.business.service.impl;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.*;
+import java.util.stream.Collectors;
 
 import com.alibaba.fastjson2.JSON;
 import com.slibra.business.domain.TXinyiCarbonExtra;
@@ -739,7 +740,8 @@ public class TXinyiCarbonMajorServiceImpl implements ITXinyiCarbonMajorService
         }
         tXinyiCarbonMajor.setRecent7Datas(recent7PflDatas);
         //关联的多条数据
-        tXinyiCarbonMajor.setExtraList(this.xinyiCarbonExtraMapper.selectTXinyiCarbonExtraList(TXinyiCarbonExtra.builder().majorId(tXinyiCarbonMajor.getId()).build()));
+//        tXinyiCarbonMajor.setExtraList();
+        tXinyiCarbonMajor.setExtraMap(this.xinyiCarbonExtraMapper.selectTXinyiCarbonExtraList(TXinyiCarbonExtra.builder().majorId(tXinyiCarbonMajor.getId()).build()).stream().collect(Collectors.groupingBy(TXinyiCarbonExtra::getType)));
     }
 
     public static void main(String[] args) {
@@ -757,5 +759,8 @@ public class TXinyiCarbonMajorServiceImpl implements ITXinyiCarbonMajorService
         System.out.println(reduce);
         System.out.println(reduce.isPresent());
         System.out.println(reduce.get());
+        list = new ArrayList<>();
+        Map<Integer, List<TXinyiCarbonExtra>> collect = list.stream().collect(Collectors.groupingBy(TXinyiCarbonExtra::getType));
+        System.out.println(collect);
     }
 }