فهرست منبع

首页查询优化

zouxuan 2 سال پیش
والد
کامیت
97df60005a

+ 4 - 4
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/IndexBaseMonthDataDao.java

@@ -369,13 +369,13 @@ public interface IndexBaseMonthDataDao extends BaseDAO<Long, IndexBaseMonthData>
     List<IndexBaseMonthData> getTotalAmountDataWithTimelyDetails(@Param("startDate") String startDate,
                                                                  @Param("endDate") String endDate,
                                                                  @Param("organIds") List<Integer> organIds,
-                                                                 @Param("orderType") String orderType,
-                                                                 @Param("notOrderType") List<String> notOrderType,@Param("tenantId") Integer tenantId);
+                                                                 @Param("orderTypeList") List<String> orderTypeList,
+                                                                 @Param("tenantId") Integer tenantId);
     List<IndexBaseMonthData> getOrganTotalAmountDataWithTimelyDetails(@Param("startDate") String startDate,
                                                                  @Param("endDate") String endDate,
                                                                  @Param("organIds") List<Integer> organIds,
-                                                                 @Param("orderType") String orderType,
-                                                                 @Param("notOrderType") List<String> notOrderType,@Param("tenantId") Integer tenantId);
+                                                                 @Param("orderTypeList") List<String> orderTypeList,
+                                                                 @Param("tenantId") Integer tenantId);
 
     List<IndexBaseMonthData> getVipAmountDataWithTimelyDetails(@Param("startDate") String startDate,
                                                                  @Param("endDate") String endDate,

+ 35 - 36
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.google.common.collect.Lists;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
@@ -120,7 +121,7 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 		}
 
 		String startDate1 = startDate.toString() + " 00:00:00";
-		String endDate1 = endDate.toString() + " 23:59:59";;
+		String endDate1 = endDate + " 23:59:59";
 		List<Integer> arrayList = null;
 		if(!CollectionUtils.isEmpty(organIds)){
 			arrayList = new ArrayList<>(organIds);
@@ -386,43 +387,53 @@ 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){
+		List<String> orderTypeList = new ArrayList<>();
+		orderTypeList.add("RENEW");orderTypeList.add("PRACTICE_GROUP_BUY");orderTypeList.add("PRACTICE_GROUP_RENEW");
+		orderTypeList.add("APPLY");orderTypeList.add("ADD_STUDENT");
 		CompletableFuture future1 = this.async(() -> {
-			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)));
+			List<IndexBaseMonthData> details = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList, orderTypeList, tenantId);
+			if(!CollectionUtils.isEmpty(details)){
+				Map<String, List<IndexBaseMonthData>> collect = details.stream().collect(Collectors.groupingBy(e -> e.getOrderType()));
+				indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_RENEW_AMOUNT,collect.getOrDefault("RENEW", Lists.newArrayList())));
+				indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_PRACTICE_AMOUNT,collect.getOrDefault("PRACTICE_GROUP", Lists.newArrayList())));
+				indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_APPLY_AMOUNT,collect.getOrDefault("APPLY", Lists.newArrayList())));
+			}
 		});
-		CompletableFuture future2 = this.async(() -> {
-			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)));
+		CompletableFuture future2 = this.async(()->{
+			List<IndexBaseMonthData> details = indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,orderTypeList,tenantId);
+			if(!CollectionUtils.isEmpty(details)){
+				Map<String, List<IndexBaseMonthData>> collect = details.stream().collect(Collectors.groupingBy(e -> e.getOrderType()));
+				typeDateMap.put(RENEW_AMOUNT,collect.getOrDefault("RENEW", Lists.newArrayList()));
+				typeDateMap.put(APPLY_AMOUNT,collect.getOrDefault("PRACTICE_GROUP", Lists.newArrayList()));
+				typeDateMap.put(PRACTICE_AMOUNT,collect.getOrDefault("APPLY", Lists.newArrayList()));
+			}
 		});
 		CompletableFuture future3 = this.async(() -> {
-			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)));
+			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_VIP_AMOUNT,indexBaseMonthDataDao.getOrganVipAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId)));
 		});
 		CompletableFuture future4 = this.async(() -> {
-			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)));
+			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_OTHER_AMOUNT,indexBaseMonthDataDao.getOrganOtherAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId)));
 		});
-
-		CompletableFuture future5 = this.async(()->{
-			typeDateMap.put(IndexDataType.FINANCE_BALANCE_AMOUNT,indexBaseMonthDataDao.getFinanceBalanceDataWithTimely(startDate1, endDate1, arrayList,tenantId));
-			typeDateMap.put(FINANCE_AMOUNT,indexBaseMonthDataDao.getFinanceActualDataWithTimely(startDate1, endDate1, arrayList,tenantId));
+		CompletableFuture future5 = this.async(() -> {
+			typeDateMap.put(VIP_AMOUNT,indexBaseMonthDataDao.getVipAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId));
 		});
-		CompletableFuture future6 = this.async(()->{
-			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);
+		CompletableFuture future6 = this.async(() -> {
+			typeDateMap.put(OTHER_AMOUNT,indexBaseMonthDataDao.getOtherAmountDataWithTimelyDetails(startDate1, endDate1, arrayList,tenantId));
 		});
 		CompletableFuture future7 = this.async(()->{
-			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));
+			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)));
 		});
 		CompletableFuture future8 = this.async(()->{
-			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));
+			typeDateMap.put(IndexDataType.FINANCE_BALANCE_AMOUNT,indexBaseMonthDataDao.getFinanceBalanceDataWithTimely(startDate1, endDate1, arrayList,tenantId));
+			indexBaseDtoList.add(this.getIndexBaseDto(IndexDataType.ORGAN_TOTAL_AMOUNT,indexBaseMonthDataDao.getOrganTotalAmountDataWithTimely(startDate1, endDate1, arrayList,tenantId)));
+		});
+		CompletableFuture future9 = this.async(()->{
+			typeDateMap.put(FINANCE_AMOUNT,indexBaseMonthDataDao.getFinanceActualDataWithTimely(startDate1, endDate1, arrayList,tenantId));
+			typeDateMap.put(IndexDataType.TOTAL_AMOUNT,indexBaseMonthDataDao.getTotalAmountDataWithTimely(startDate1, endDate1, arrayList,tenantId));
 		});
 		future1.join();future2.join();future3.join();future4.join();
-		future5.join();future6.join();future7.join();future8.join();
+		future5.join();future6.join();future7.join();future8.join();future9.join();
 	}
 
 	@Override
@@ -502,7 +513,6 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.PART_TIME_NUM)) {
 			saveData(indexBaseMonthDataDao.getTeacherData(dayStr, JobNatureEnum.PART_TIME, null,tenantId), dayStr, IndexDataType.PART_TIME_NUM, tenantId);
 		}
-//		saveData(indexBaseMonthDataDao.getTeacherData(dayStr, null, true), dayStr, IndexDataType.DIMISSION_NUM);
 
 		//剩余课时
 		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.SURPLUS_COURSE_NUM)) {
@@ -532,17 +542,6 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 			saveData(indexBaseMonthDataDao.getGroupSurplusCourseData(dayStr, GroupType.PRACTICE, CourseStatusEnum.OVER,tenantId), dayStr, IndexDataType.OVER_PRACTICE_COURSE_NUM, tenantId);
 		}
 
-		//经营数据
-
-//		List<IndexBaseMonthData> financePayData = indexBaseMonthDataDao.getFinancePayData(dayStr);
-//		List<IndexBaseMonthData> financeBalanceData = indexBaseMonthDataDao.getFinanceBalanceData(dayStr);
-//		List<IndexBaseMonthData> financeActualData = indexBaseMonthDataDao.getFinanceActualData(dayStr);
-//
-//		saveData(financePayData,dayStr,IndexDataType.FINANCE_PAY);
-//		saveData(financeBalanceData,dayStr,IndexDataType.FINANCE_BALANCE_AMOUNT);
-//		saveData(financeActualData,dayStr,IndexDataType.FINANCE_AMOUNT);
-//		saveData(totalAmountData,dayStr,IndexDataType.TOTAL_AMOUNT);
-
 		//业务数据
 		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.HOMEWORK_CREATE_RATE)) {
 			saveData(indexBaseMonthDataDao.getHomeworkData(dayStr, null,tenantId), monday.toString(), IndexDataType.HOMEWORK_CREATE_RATE, tenantId);

+ 17 - 29
mec-biz/src/main/resources/config/mybatis/IndexBaseMonthDataMapper.xml

@@ -1496,49 +1496,37 @@
 			   SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
 		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) activate_num_,
 			   SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
-		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) percent_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
+		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) percent_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_,
+		CASE WHEN spo.type_ IN ('RENEW') THEN 'RENEW' WHEN spo.type_ IN ('PRACTICE_GROUP_BUY', 'PRACTICE_GROUP_RENEW') THEN 'PRACTICE_GROUP' ELSE 'APPLY' END AS order_type_
 		FROM student_payment_order spo
 		WHERE spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
-		<if test="orderType != null">
-			AND FIND_IN_SET(spo.type_,#{orderType})
-		</if>
-		<if test="notOrderType != null">
-			AND spo.type_ NOT IN
-			<foreach collection="notOrderType" open="(" close=")" item="item" separator=",">
-				#{item}
-			</foreach>
-		</if>
+		AND spo.type_ IN
+		<foreach collection="orderTypeList" open="(" close=")" item="orderType" separator=",">
+			#{orderType}
+		</foreach>
 		<if test="organIds!=null and organIds.size()>0">
 			AND spo.organ_id_ IN
 			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
 				#{organId}
 			</foreach>
 		</if>
-		GROUP BY DATE_FORMAT(spo.pay_time_,'%Y-%m-%d')
+		GROUP BY DATE_FORMAT(spo.pay_time_,'%Y-%m-%d'),order_type_
 	</select>
 
 	<select id="getOrganTotalAmountDataWithTimelyDetails" resultMap="IndexBaseMonthData">
 		SELECT SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
 		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) percent_,
-		    			   o.id_ organ_id_,o.name_ organ_name_
+		    			   o.id_ organ_id_,o.name_ organ_name_,
+		CASE WHEN spo.type_ IN ('RENEW') THEN 'RENEW'
+		WHEN spo.type_ IN ('PRACTICE_GROUP_BUY', 'PRACTICE_GROUP_RENEW') THEN 'PRACTICE_GROUP'
+		ELSE 'APPLY' END AS order_type_
 		FROM organization o
-		LEFT JOIN student_payment_order spo ON o.id_ = spo.organ_id_ AND o.tenant_id_ = spo.tenant_id_
+		LEFT JOIN student_payment_order spo ON o.id_ = spo.organ_id_
 		AND spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate}
-		<if test="orderType != null">
-			AND FIND_IN_SET(spo.type_,#{orderType})
-		</if>
-		<if test="notOrderType != null">
-			AND spo.type_ NOT IN
-			<foreach collection="notOrderType" open="(" close=")" item="item" separator=",">
-				#{item}
-			</foreach>
-		</if>
-		<if test="organIds!=null and organIds.size()>0">
-			AND spo.organ_id_ IN
-			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
-				#{organId}
-			</foreach>
-		</if>
+		AND spo.type_ IN
+		<foreach collection="orderTypeList" open="(" close=")" item="orderType" separator=",">
+			#{orderType}
+		</foreach>
 		WHERE o.tenant_id_ = #{tenantId}
 		<if test="organIds!=null and organIds.size()>0">
 			AND o.id_ IN
@@ -1546,7 +1534,7 @@
 				#{organId}
 			</foreach>
 		</if>
-		GROUP BY o.id_ ORDER BY percent_ DESC
+		GROUP BY o.id_,order_type_ ORDER BY percent_ DESC
 	</select>
 
 	<select id="getVipAmountDataWithTimelyDetails" resultMap="IndexBaseMonthData">