瀏覽代碼

首页查询优化

zouxuan 2 年之前
父節點
當前提交
105e7bf851
共有 1 個文件被更改,包括 73 次插入59 次删除
  1. 73 59
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/IndexBaseMonthDataServiceImpl.java

+ 73 - 59
mec-biz/src/main/java/com/ym/mec/biz/service/impl/IndexBaseMonthDataServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ym.mec.biz.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.extension.api.R;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
@@ -19,6 +20,7 @@ import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.formula.functions.T;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -32,6 +34,7 @@ import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.function.Consumer;
 import java.util.stream.Collectors;
 
 import static com.ym.mec.biz.dal.enums.IndexDataType.*;
@@ -161,64 +164,8 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 		//按分部汇总
 		if((CollectionUtils.isEmpty(dataTypes) || dataTypes.contains(ORGAN_FINANCE_BALANCE_AMOUNT.getCode()) ||
 				dataTypes.contains(ORGAN_FINANCE_AMOUNT.getCode())) && organIds != null){
-			CompletableFuture<List<IndexBaseDto>> future = CompletableFuture.supplyAsync(() -> {
-				System.out.println("start search 经营报表细化1");
-				List<IndexBaseDto> indexBaseDtoList = new ArrayList<>();
-				List<IndexBaseMonthData> renewAmount = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"RENEW",null,tenantId);
-				indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_RENEW_AMOUNT,renewAmount));
-				List<IndexBaseMonthData> vipAmount = indexBaseMonthDataDao.getOrganVipAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId);
-				indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_VIP_AMOUNT,vipAmount));
-				List<IndexBaseMonthData> practiceAmount = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"PRACTICE_GROUP_BUY,PRACTICE_GROUP_RENEW",null,tenantId);
-				indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_PRACTICE_AMOUNT,practiceAmount));
-				List<IndexBaseMonthData> otherAmount = indexBaseMonthDataDao.getOrganOtherAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId);
-				indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_OTHER_AMOUNT,otherAmount));
-				System.out.println("end search 经营报表细化1");
-				return indexBaseDtoList;
-			},exportExecutorService);
-			CompletableFuture<List<IndexBaseDto>> future2 = CompletableFuture.supplyAsync(() -> {
-				System.out.println("start search 经营报表细化2");
-				List<IndexBaseDto> indexBaseDtoList = new ArrayList<>();
-				indexBaseDtoList.add(this.getIndexBaseDto(IndexDataType.ORGAN_FINANCE_BALANCE_AMOUNT,indexBaseMonthDataDao.getOrganFinanceBalanceDataWithTimely(startDate1, endDate1, arrayList,tenantId)));
-				indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_FINANCE_AMOUNT,indexBaseMonthDataDao.getOrganFinanceActualDataWithTimely(startDate1, endDate1, arrayList,tenantId)));
-				List<IndexBaseMonthData> totalAmountDataWithTimely = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimely(startDate1, endDate1, arrayList,tenantId);
-				indexBaseDtoList.add(this.getIndexBaseDto(IndexDataType.ORGAN_TOTAL_AMOUNT,totalAmountDataWithTimely));
-				//经营报表细化
-				List<IndexBaseMonthData> applyAmount = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"APPLY,ADD_STUDENT",null,tenantId);
-				indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_APPLY_AMOUNT,applyAmount));
-				System.out.println("end search 经营报表细化2");
-				return indexBaseDtoList;
-			},exportExecutorService);
-			CompletableFuture<Map<IndexDataType, List<IndexBaseMonthData>>> future3 = CompletableFuture.supplyAsync(()->{
-				System.out.println("start search 经营报表细化3");
-				Map<IndexDataType, List<IndexBaseMonthData>> typeDateMap1 = new HashMap<>(4);
-				typeDateMap1.put(IndexDataType.FINANCE_BALANCE_AMOUNT,indexBaseMonthDataDao.getFinanceBalanceDataWithTimely(startDate1, endDate1, arrayList,tenantId));
-				typeDateMap1.put(FINANCE_AMOUNT,indexBaseMonthDataDao.getFinanceActualDataWithTimely(startDate1, endDate1, arrayList,tenantId));
-				List<IndexBaseMonthData> totalAmountDataWithTimely = indexBaseMonthDataDao.getTotalAmountDataWithTimely(startDate1, endDate1, arrayList,tenantId);
-				typeDateMap1.put(IndexDataType.TOTAL_AMOUNT,totalAmountDataWithTimely);
-				//经营报表细化
-				List<IndexBaseMonthData> applyAmount = indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"APPLY,ADD_STUDENT",null,tenantId);
-				typeDateMap1.put(APPLY_AMOUNT,applyAmount);
-				System.out.println("end search 经营报表细化3");
-				return typeDateMap1;
-			},exportExecutorService);
-			CompletableFuture<Map<IndexDataType, List<IndexBaseMonthData>>> future4 = CompletableFuture.supplyAsync(()->{
-				System.out.println("start search 经营报表细化4");
-				Map<IndexDataType, List<IndexBaseMonthData>> typeDateMap1 = new HashMap<>(4);
-				List<IndexBaseMonthData> renewAmount = indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"RENEW",null,tenantId);
-				typeDateMap1.put(RENEW_AMOUNT,renewAmount);
-				List<IndexBaseMonthData> vipAmount = indexBaseMonthDataDao.getVipAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId);
-				typeDateMap1.put(VIP_AMOUNT,vipAmount);
-				List<IndexBaseMonthData> practiceAmount = indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"PRACTICE_GROUP_BUY,PRACTICE_GROUP_RENEW",null,tenantId);
-				typeDateMap1.put(PRACTICE_AMOUNT,practiceAmount);
-				List<IndexBaseMonthData> otherAmount = indexBaseMonthDataDao.getOtherAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId);
-				typeDateMap1.put(OTHER_AMOUNT,otherAmount);
-				System.out.println("end search 经营报表细化4");
-				return typeDateMap1;
-			},exportExecutorService);
-			result.addAll(future.join());
-			result.addAll(future2.join());
-			typeDateMap.putAll(future3.join());
-			typeDateMap.putAll(future4.join());
+			//经营数据查询
+			this.syncOperation(startDate1,endDate1,arrayList,tenantId,result,typeDateMap);
 		}
 
 		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(MUSIC_GROUP_COURSE.getCode())||dataTypes.contains(VIP_GROUP_COURSE.getCode())
@@ -384,10 +331,77 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 			}
 			result.add(indexBaseData);
 		}
-
 		return result;
 	}
 
+	//异步处理经营数据查询
+	public void syncOperation(String startDate1,String endDate1,List<Integer> arrayList,Integer tenantId,List<IndexBaseDto> indexBaseDtoList,Map<IndexDataType, List<IndexBaseMonthData>> typeDateMap){
+		CompletableFuture future1 = CompletableFuture.supplyAsync(() -> {
+//			List<IndexBaseDto> indexBaseDtoList = new ArrayList<>();
+			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_RENEW_AMOUNT,indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"RENEW",null,tenantId)));
+			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_VIP_AMOUNT,indexBaseMonthDataDao.getOrganVipAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId)));
+//			return indexBaseDtoList;
+			return true;
+		},exportExecutorService);
+		CompletableFuture future2 = CompletableFuture.supplyAsync(() -> {
+//			List<IndexBaseDto> indexBaseDtoList = new ArrayList<>();
+			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_PRACTICE_AMOUNT,indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"PRACTICE_GROUP_BUY,PRACTICE_GROUP_RENEW",null,tenantId)));
+			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_OTHER_AMOUNT,indexBaseMonthDataDao.getOrganOtherAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId)));
+//			return indexBaseDtoList;
+			return true;
+		},exportExecutorService);
+		CompletableFuture future3 = CompletableFuture.supplyAsync(() -> {
+//			List<IndexBaseDto> indexBaseDtoList = new ArrayList<>();
+			indexBaseDtoList.add(this.getIndexBaseDto(IndexDataType.ORGAN_TOTAL_AMOUNT,indexBaseMonthDataDao.getOrganTotalAmountDataWithTimely(startDate1, endDate1, arrayList,tenantId)));
+			//经营报表细化
+			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_APPLY_AMOUNT,indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"APPLY,ADD_STUDENT",null,tenantId)));
+//			return indexBaseDtoList;
+			return true;
+		},exportExecutorService);
+		CompletableFuture future4 = CompletableFuture.supplyAsync(() -> {
+//			List<IndexBaseDto> indexBaseDtoList = new ArrayList<>();
+			indexBaseDtoList.add(this.getIndexBaseDto(IndexDataType.ORGAN_FINANCE_BALANCE_AMOUNT,indexBaseMonthDataDao.getOrganFinanceBalanceDataWithTimely(startDate1, endDate1, arrayList,tenantId)));
+			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_FINANCE_AMOUNT,indexBaseMonthDataDao.getOrganFinanceActualDataWithTimely(startDate1, endDate1, arrayList,tenantId)));
+//			return indexBaseDtoList;
+			return true;
+		},exportExecutorService);
+
+		CompletableFuture future5 = CompletableFuture.supplyAsync(()->{
+//			Map<IndexDataType, List<IndexBaseMonthData>> typeDateMap = new HashMap<>(2);
+			typeDateMap.put(IndexDataType.FINANCE_BALANCE_AMOUNT,indexBaseMonthDataDao.getFinanceBalanceDataWithTimely(startDate1, endDate1, arrayList,tenantId));
+			typeDateMap.put(FINANCE_AMOUNT,indexBaseMonthDataDao.getFinanceActualDataWithTimely(startDate1, endDate1, arrayList,tenantId));
+			return true;
+		},exportExecutorService);
+		CompletableFuture future6 = CompletableFuture.supplyAsync(()->{
+//			Map<IndexDataType, List<IndexBaseMonthData>> typeDateMap = new HashMap<>(2);
+			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);
+			return true;
+		},exportExecutorService);
+		CompletableFuture future7 = CompletableFuture.supplyAsync(()->{
+//			Map<IndexDataType, List<IndexBaseMonthData>> typeDateMap = new HashMap<>(2);
+			List<IndexBaseMonthData> totalAmountDataWithTimely = indexBaseMonthDataDao.getTotalAmountDataWithTimely(startDate1, endDate1, arrayList,tenantId);
+			typeDateMap.put(IndexDataType.TOTAL_AMOUNT,totalAmountDataWithTimely);
+			//经营报表细化
+			List<IndexBaseMonthData> applyAmount = indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"APPLY,ADD_STUDENT",null,tenantId);
+			typeDateMap.put(APPLY_AMOUNT,applyAmount);
+			return true;
+		},exportExecutorService);
+		CompletableFuture future8 = CompletableFuture.supplyAsync(()->{
+//			Map<IndexDataType, List<IndexBaseMonthData>> typeDateMap = new HashMap<>(2);
+			List<IndexBaseMonthData> practiceAmount = indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,"PRACTICE_GROUP_BUY,PRACTICE_GROUP_RENEW",null,tenantId);
+			typeDateMap.put(PRACTICE_AMOUNT,practiceAmount);
+			List<IndexBaseMonthData> otherAmount = indexBaseMonthDataDao.getOtherAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId);
+			typeDateMap.put(OTHER_AMOUNT,otherAmount);
+			return true;
+		},exportExecutorService);
+		future1.join();future2.join();future3.join();future4.join();
+		future5.join();future6.join();future7.join();future8.join();
+	}
+
+
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void indexBaseDataTask(Integer tenantId, String dayStr, Set<IndexDataType> dataTypes) {