浏览代码

首页接口优化

zouxuan 2 年之前
父节点
当前提交
1c5d004714

+ 97 - 54
mec-biz/src/main/java/com/ym/mec/biz/service/impl/IndexBaseMonthDataServiceImpl.java

@@ -21,6 +21,7 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
+import com.ym.mec.util.web.EParallelStream;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -402,67 +403,109 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 	public void syncOperation(String startDate1,String endDate1,List<Integer> arrayList,Integer tenantId,List<IndexBaseDto> indexBaseDtoList,Map<IndexDataType, List<IndexBaseMonthData>> typeDateMap){
 //		System.out.println(System.currentTimeMillis());
 		List<Organization> organs = organizationService.findOrgans(arrayList, tenantId);
-		CompletableFuture future1 = this.async(() -> {
-//			long l = System.currentTimeMillis();
-			List<IndexBaseMonthData> renew = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList, "RENEW", null, tenantId);
-			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_RENEW_AMOUNT,renew,organs));
-			List<IndexBaseMonthData> details = indexBaseMonthDataDao.getOrganVipAmountDataWithTimelyDetails(startDate1, endDate1, arrayList, tenantId);
-			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_VIP_AMOUNT,details,organs));
-//			System.out.println("Thread.currentThread :" + Thread.currentThread() + "---" + (System.currentTimeMillis() - l));
-		});
-		CompletableFuture future2 = this.async(() -> {
-//			long l = System.currentTimeMillis();
-			List<IndexBaseMonthData> data = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList, "PRACTICE_GROUP_BUY,PRACTICE_GROUP_RENEW", null, tenantId);
-			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_PRACTICE_AMOUNT,data,organs));
-			List<IndexBaseMonthData> details = indexBaseMonthDataDao.getOrganOtherAmountDataWithTimelyDetails(startDate1, endDate1, arrayList, tenantId);
-			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_OTHER_AMOUNT,details,organs));
-//			System.out.println("Thread.currentThread :" + Thread.currentThread() + "---" + (System.currentTimeMillis() - l));
-		});
-		CompletableFuture future6 = this.async(()->{
-//			long l = System.currentTimeMillis();
-			List<IndexBaseMonthData> renewAmount = indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"RENEW",null,tenantId);
-			typeDateMap.put(RENEW_AMOUNT,renewAmount);
-			List<IndexBaseMonthData> vipAmount = indexBaseMonthDataDao.getVipAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId);
-			typeDateMap.put(VIP_AMOUNT,vipAmount);
-//			System.out.println("Thread.currentThread :" + Thread.currentThread() + "---" + (System.currentTimeMillis() - l));
-		});
-		CompletableFuture future8 = this.async(()->{
-//			long l = System.currentTimeMillis();
-			typeDateMap.put(PRACTICE_AMOUNT,indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"PRACTICE_GROUP_BUY,PRACTICE_GROUP_RENEW",null,tenantId));
-			typeDateMap.put(OTHER_AMOUNT,indexBaseMonthDataDao.getOtherAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId));
-//			System.out.println("Thread.currentThread :" + Thread.currentThread() + "---" + (System.currentTimeMillis() - l));
-		});
-		CompletableFuture future3 = this.async(() -> {
-//			long l = System.currentTimeMillis();
-			List<IndexBaseMonthData> details = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimely(startDate1, endDate1, arrayList, tenantId);
-			indexBaseDtoList.add(this.getIndexBaseDto(IndexDataType.ORGAN_TOTAL_AMOUNT,details,organs));
-			List<IndexBaseMonthData> apply = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList, "APPLY,ADD_STUDENT", null, tenantId);
-			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_APPLY_AMOUNT,apply,organs));
-//			System.out.println("Thread.currentThread :" + Thread.currentThread() + "---" + (System.currentTimeMillis() - l));
-		});
-		CompletableFuture future4 = this.async(() -> {
-//			long l = System.currentTimeMillis();
-			indexBaseDtoList.add(this.getIndexBaseDto(IndexDataType.ORGAN_FINANCE_BALANCE_AMOUNT,indexBaseMonthDataDao.getOrganFinanceBalanceDataWithTimely(startDate1, endDate1, arrayList,tenantId),organs));
-			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_FINANCE_AMOUNT,indexBaseMonthDataDao.getOrganFinanceActualDataWithTimely(startDate1, endDate1, arrayList,tenantId),organs));
-//			System.out.println("Thread.currentThread :" + Thread.currentThread() + "---" + (System.currentTimeMillis() - l));
+		EParallelStream.getParallelStream().forEach(data->{
+			switch (data) {
+				case P1:
+				{
+					List<IndexBaseMonthData> renew = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList, "RENEW", null, tenantId);
+					indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_RENEW_AMOUNT,renew,organs));
+				}
+					break;
+				case P2:
+				{
+					List<IndexBaseMonthData> details = indexBaseMonthDataDao.getOrganVipAmountDataWithTimelyDetails(startDate1, endDate1, arrayList, tenantId);
+					indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_VIP_AMOUNT,details,organs));
+				}
+					break;
+				case P3:
+				{
+					List<IndexBaseMonthData> details = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList, "PRACTICE_GROUP_BUY,PRACTICE_GROUP_RENEW", null, tenantId);
+					indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_PRACTICE_AMOUNT,details,organs));
+				}
+					break;
+				case P4:
+				{
+					List<IndexBaseMonthData> details = indexBaseMonthDataDao.getOrganOtherAmountDataWithTimelyDetails(startDate1, endDate1, arrayList, tenantId);
+					indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_OTHER_AMOUNT,details,organs));
+				}
+					break;
+				case P5:
+				{
+					List<IndexBaseMonthData> renewAmount = indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"RENEW",null,tenantId);
+					typeDateMap.put(RENEW_AMOUNT,renewAmount);
+				}
+					break;
+				case P6:
+				{
+					List<IndexBaseMonthData> vipAmount = indexBaseMonthDataDao.getVipAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId);
+					typeDateMap.put(VIP_AMOUNT,vipAmount);
+				}
+					break;
+				case P7:
+				{
+					typeDateMap.put(PRACTICE_AMOUNT,indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"PRACTICE_GROUP_BUY,PRACTICE_GROUP_RENEW",null,tenantId));
+				}
+				break;
+				case P8:
+				{
+					typeDateMap.put(OTHER_AMOUNT,indexBaseMonthDataDao.getOtherAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId));
+				}
+					break;
+				case P9:
+				{
+					List<IndexBaseMonthData> details = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimely(startDate1, endDate1, arrayList, tenantId);
+					indexBaseDtoList.add(this.getIndexBaseDto(IndexDataType.ORGAN_TOTAL_AMOUNT,details,organs));
+				}
+					break;
+				case P10:
+				{
+					List<IndexBaseMonthData> apply = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList, "APPLY,ADD_STUDENT", null, tenantId);
+					indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_APPLY_AMOUNT,apply,organs));
+				}
+					break;
+				case P11:
+				{
+					indexBaseDtoList.add(this.getIndexBaseDto(IndexDataType.ORGAN_FINANCE_BALANCE_AMOUNT,indexBaseMonthDataDao.getOrganFinanceBalanceDataWithTimely(startDate1, endDate1, arrayList,tenantId),organs));
+				}
+				break;
+				case P12:
+				{
+					indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_FINANCE_AMOUNT,indexBaseMonthDataDao.getOrganFinanceActualDataWithTimely(startDate1, endDate1, arrayList,tenantId),organs));
+				}
+					break;
+				case P13:
+                {
+					typeDateMap.put(IndexDataType.FINANCE_BALANCE_AMOUNT,indexBaseMonthDataDao.getFinanceBalanceDataWithTimely(startDate1, endDate1, arrayList,tenantId));
+				}
+				break;
+				case P14:
+				{
+					typeDateMap.put(FINANCE_AMOUNT,indexBaseMonthDataDao.getFinanceActualDataWithTimely(startDate1, endDate1, arrayList,tenantId));
+				}
+					break;
+				case P15:
+				{
+					typeDateMap.put(APPLY_AMOUNT,indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"APPLY,ADD_STUDENT",null,tenantId));
+				}
+					break;
+				case P16:
+				{
+					typeDateMap.put(IndexDataType.TOTAL_AMOUNT,indexBaseMonthDataDao.getTotalAmountDataWithTimely(startDate1, endDate1, arrayList,tenantId));
+				}
+					break;
+			}
 		});
 
-		CompletableFuture future5 = this.async(()->{
-//			long l = System.currentTimeMillis();
-			typeDateMap.put(IndexDataType.FINANCE_BALANCE_AMOUNT,indexBaseMonthDataDao.getFinanceBalanceDataWithTimely(startDate1, endDate1, arrayList,tenantId));
-			typeDateMap.put(FINANCE_AMOUNT,indexBaseMonthDataDao.getFinanceActualDataWithTimely(startDate1, endDate1, arrayList,tenantId));
-//			System.out.println("Thread.currentThread :" + Thread.currentThread() + "---" + (System.currentTimeMillis() - l));
-		});
-		CompletableFuture future7 = this.async(()->{
-//			long l = System.currentTimeMillis();
+/*		CompletableFuture future7 = this.async(()->{
+			long l = System.currentTimeMillis();
 			typeDateMap.put(IndexDataType.TOTAL_AMOUNT,indexBaseMonthDataDao.getTotalAmountDataWithTimely(startDate1, endDate1, arrayList,tenantId));
 			typeDateMap.put(APPLY_AMOUNT,indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"APPLY,ADD_STUDENT",null,tenantId));
-//			System.out.println("Thread.currentThread :" + Thread.currentThread() + "---" + (System.currentTimeMillis() - l));
+			System.out.println("Thread.currentThread :" + Thread.currentThread() + "---" + (System.currentTimeMillis() - l));
 		});
-//		System.out.println(System.currentTimeMillis());
+		System.out.println(System.currentTimeMillis());
 		CompletableFuture<Void> allFutures = CompletableFuture.allOf(future1, future2, future3, future4, future5, future6, future7, future8);
 		allFutures.join();
-//		System.out.println(System.currentTimeMillis());
+		System.out.println(System.currentTimeMillis());*/
 	}
 
 	@Override

+ 63 - 0
mec-util/src/main/java/com/ym/mec/util/web/EParallelStream.java

@@ -0,0 +1,63 @@
+package com.ym.mec.util.web;
+
+import com.google.common.collect.Lists;
+import lombok.Getter;
+
+import java.util.stream.Stream;
+
+/**
+ * Created by Eric.Shang on 2019-08-08.
+ */
+@Getter
+public enum EParallelStream {
+
+    P1(1, "P1"),
+    P2(2, "P2"),
+    P3(3, "P3"),
+    P4(4, "P4"),
+    P5(5, "P5"),
+    P6(6, "P6"),
+    P7(7, "P7"),
+    P8(8, "P8"),
+    P9(9, "P9"),
+    P10(10, "P10"),
+    P11(11, "P11"),
+    P12(12, "P12"),
+    P13(13, "P13"),
+    P14(14, "P14"),
+    P15(15, "P15"),
+    P16(16, "P16"),
+    ;
+
+    private final int value;
+    private final String name;
+
+    EParallelStream(int value, String name) {
+        this.value = value;
+        this.name = name;
+    }
+
+    /**
+     * 并发执行流程
+     * @param value 数据流
+     * @return EParallelStream
+     */
+    public static EParallelStream get(int value) {
+        EParallelStream[] values = EParallelStream.values();
+        for (EParallelStream item : values) {
+            if (item.getValue() == value) {
+                return item;
+            }
+        }
+        return P1;
+    }
+
+    /**
+     * 并发执行流程
+     * @return List<EParallelStream>
+     */
+    public static Stream<EParallelStream> getParallelStream() {
+
+        return Lists.newArrayList(EParallelStream.values()).parallelStream();
+    }
+}