Kaynağa Gözat

feat:首页改造

Joburgess 4 yıl önce
ebeveyn
işleme
dd5e0e663d

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

@@ -85,7 +85,11 @@ public interface IndexBaseMonthDataDao extends BaseDAO<Long, IndexBaseMonthData>
     List<IndexBaseMonthData> getMusicGroupStudentFromPreData(@Param("month") String month,
                                                              @Param("paymentStatus") PaymentStatusEnum paymentStatus);
 
-    List<IndexBaseMonthData> getStudentConversionData(@Param("month") String month);
+    List<Integer> getMusicGroupStudentIdFromPre(@Param("month") String month,
+                                                @Param("paymentStatus") PaymentStatusEnum paymentStatus);
+
+    List<IndexBaseMonthData> getStudentConversionData(@Param("month") String month,
+                                                      @Param("studentIds") List<Integer> studentIds);
 
     List<IndexBaseMonthData> getOtherStudentData(@Param("month") String month);
 

+ 91 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/IndexBaseMonthDataServiceImpl.java

@@ -6,6 +6,7 @@ import com.ym.mec.biz.dal.entity.Organization;
 import com.ym.mec.biz.dal.enums.GroupType;
 import com.ym.mec.biz.dal.enums.IndexDataType;
 import com.ym.mec.biz.dal.enums.JobNatureEnum;
+import com.ym.mec.biz.dal.enums.PaymentStatusEnum;
 import com.ym.mec.common.constant.CommonConstants;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
@@ -19,6 +20,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
+import javax.xml.crypto.Data;
 import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
@@ -111,7 +113,7 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 			indexBaseData.setIndexMonthData(typeDateMapEntry.getValue(), currentMonth);
 			result.add(indexBaseData);
 		}
-
+		countStudentConvertData(result, currentMonth);
 		return result;
 	}
 
@@ -161,7 +163,15 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 		//学员变动
 		saveData(indexBaseMonthDataDao.getMusicStudentData(month, "ALL"), month, IndexDataType.NEWLY_STUDENT_NUM);
 		saveData(indexBaseMonthDataDao.getMusicStudentData(month, "QUIT"), month, IndexDataType.QUIT_MUSIC_GROUP_STUDENT_NUM);
-		saveData(indexBaseMonthDataDao.getStudentConversionData(month), month, IndexDataType.STUDENT_CONVERSION);
+		saveData(indexBaseMonthDataDao.getMusicGroupPreRegistrationStudentData(month), month, IndexDataType.STUDENT_CONVERSION_PRE_STUDENT_NUM);
+		saveData(indexBaseMonthDataDao.getMusicGroupStudentFromPreData(month, null), month, IndexDataType.STUDENT_CONVERSION_STUDENT_NUM);
+		saveData(indexBaseMonthDataDao.getMusicGroupStudentFromPreData(month, PaymentStatusEnum.YES), month, IndexDataType.STUDENT_CONVERSION_PAYMENT_STUDENT_NUM);
+		List<Integer> studentIds = indexBaseMonthDataDao.getMusicGroupStudentIdFromPre(month, PaymentStatusEnum.YES);
+		List<IndexBaseMonthData> convertStudentNum = new ArrayList<>();
+		if(!CollectionUtils.isEmpty(studentIds)){
+			convertStudentNum = indexBaseMonthDataDao.getStudentConversionData(month, studentIds);
+		}
+		saveData(convertStudentNum, month, IndexDataType.STUDENT_CONVERSION_VIP_PRACTICE_STUDENT_NUM);
 
 		//课程数据
 		saveData(indexBaseMonthDataDao.getGroupCourseData(month, GroupType.MUSIC), month, IndexDataType.MUSIC_GROUP_COURSE);
@@ -171,6 +181,85 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 		return result;
 	}
 
+	private void countStudentConvertData(List<IndexBaseDto> result, Date currentMonth){
+		List<IndexBaseMonthData> convertData = new ArrayList<>();
+
+		Map<IndexDataType, IndexBaseDto> typeDataMap = result.stream().collect(Collectors.toMap(IndexBaseDto::getDataType, i -> i, (i1, i2) -> i1));
+		List<IndexBaseMonthData> preStudentNum = typeDataMap.get(IndexDataType.STUDENT_CONVERSION_PRE_STUDENT_NUM).getIndexMonthData();
+
+		IndexBaseMonthData preStudentNumData = new IndexBaseMonthData();
+		preStudentNumData.setMonth(currentMonth);
+		preStudentNumData.setDataType(IndexDataType.STUDENT_CONVERSION_PRE_STUDENT_NUM);
+		preStudentNumData.setTotalNum(preStudentNum.stream().map(IndexBaseMonthData::getTotalNum).reduce(BigDecimal.ZERO, BigDecimal::add));
+		preStudentNumData.setActivateNum(preStudentNum.stream().map(IndexBaseMonthData::getActivateNum).reduce(BigDecimal.ZERO, BigDecimal::add));
+
+		List<IndexBaseMonthData> studentNum = typeDataMap.get(IndexDataType.STUDENT_CONVERSION_STUDENT_NUM).getIndexMonthData();
+
+		IndexBaseMonthData studentNumData = new IndexBaseMonthData();
+		studentNumData.setMonth(currentMonth);
+		studentNumData.setDataType(IndexDataType.STUDENT_CONVERSION_STUDENT_NUM);
+		studentNumData.setTotalNum(studentNum.stream().map(IndexBaseMonthData::getTotalNum).reduce(BigDecimal.ZERO, BigDecimal::add));
+		studentNumData.setActivateNum(studentNum.stream().map(IndexBaseMonthData::getActivateNum).reduce(BigDecimal.ZERO, BigDecimal::add));
+
+		List<IndexBaseMonthData> paymentStudentNum = typeDataMap.get(IndexDataType.STUDENT_CONVERSION_PAYMENT_STUDENT_NUM).getIndexMonthData();
+
+		IndexBaseMonthData paymentStudentNumData = new IndexBaseMonthData();
+		paymentStudentNumData.setMonth(currentMonth);
+		paymentStudentNumData.setDataType(IndexDataType.STUDENT_CONVERSION_PAYMENT_STUDENT_NUM);
+		paymentStudentNumData.setTotalNum(paymentStudentNum.stream().map(IndexBaseMonthData::getTotalNum).reduce(BigDecimal.ZERO, BigDecimal::add));
+		paymentStudentNumData.setActivateNum(paymentStudentNum.stream().map(IndexBaseMonthData::getActivateNum).reduce(BigDecimal.ZERO, BigDecimal::add));
+
+		List<IndexBaseMonthData> convertStudentNum = typeDataMap.get(IndexDataType.STUDENT_CONVERSION_VIP_PRACTICE_STUDENT_NUM).getIndexMonthData();
+
+		IndexBaseMonthData convertStudentNumData = new IndexBaseMonthData();
+		convertStudentNumData.setMonth(currentMonth);
+		convertStudentNumData.setDataType(IndexDataType.STUDENT_CONVERSION_VIP_PRACTICE_STUDENT_NUM);
+		convertStudentNumData.setTotalNum(convertStudentNum.stream().map(IndexBaseMonthData::getTotalNum).reduce(BigDecimal.ZERO, BigDecimal::add));
+		convertStudentNumData.setActivateNum(convertStudentNum.stream().map(IndexBaseMonthData::getActivateNum).reduce(BigDecimal.ZERO, BigDecimal::add));
+
+		if(preStudentNumData.getActivateNum().compareTo(BigDecimal.ZERO)==0){
+			studentNumData.setPercent(BigDecimal.ZERO);
+			paymentStudentNumData.setPercent(BigDecimal.ZERO);
+			convertStudentNumData.setPercent(BigDecimal.ZERO);
+		}else{
+			studentNumData.setPercent(studentNumData.getActivateNum().divide(preStudentNumData.getActivateNum()).multiply(new BigDecimal(100)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN));
+			if(studentNumData.getActivateNum().compareTo(BigDecimal.ZERO)==0){
+				paymentStudentNumData.setPercent(BigDecimal.ZERO);
+				convertStudentNumData.setPercent(BigDecimal.ZERO);
+			}else{
+				paymentStudentNumData.setPercent(paymentStudentNumData.getActivateNum().divide(studentNumData.getActivateNum()).multiply(new BigDecimal(100)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN));
+				if(paymentStudentNumData.getActivateNum().compareTo(BigDecimal.ZERO)==0){
+					convertStudentNumData.setPercent(BigDecimal.ZERO);
+				}else{
+					convertStudentNumData.setPercent(convertStudentNumData.getActivateNum().divide(paymentStudentNumData.getActivateNum()).multiply(new BigDecimal(100)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN));
+				}
+			}
+		}
+
+		convertData.add(preStudentNumData);
+		convertData.add(studentNumData);
+		convertData.add(paymentStudentNumData);
+		convertData.add(convertStudentNumData);
+		IndexBaseDto indexBaseData = new IndexBaseDto(IndexDataType.STUDENT_CONVERSION, IndexDataType.STUDENT_CONVERSION.getMsg());
+		indexBaseData.setIndexMonthData(convertData, currentMonth);
+		result.add(indexBaseData);
+	}
+
+	private void fillEmptyOrganData(List<IndexBaseMonthData> dataList, String startMonth){
+		startMonth = startMonth+"-01";
+		Date date = DateUtil.stringToDate(startMonth, "yyyy-MM-dd");
+		if(Objects.isNull(dataList)){
+			dataList = new ArrayList<>();
+		}
+		Set<Integer> hasOrganIds = dataList.stream().map(IndexBaseMonthData::getOrganId).collect(Collectors.toSet());
+		for (Integer organId : this.organIds.get()) {
+			if(hasOrganIds.contains(organId)){
+				continue;
+			}
+			dataList.add(new IndexBaseMonthData(date, organId));
+		}
+	}
+
 	/**
 	 * @describe 处理并保存每月数据
 	 * @author Joburgess

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

@@ -336,27 +336,27 @@
 
 	<select id="getStudentConversionData" resultMap="IndexBaseMonthData">
 		SELECT
-			mg.organ_id_,
-			CONCAT( #{month}, '-01' ) month_,
-			COUNT( DISTINCT sr.user_id_ ) total_num_,
-			COUNT( DISTINCT IF((cssp.group_type_='PRACTICE' AND pg.type_='CHARGE') OR cssp.group_type_='VIP', cssp.user_id_, NULL) ) activate_num_,
-			TRUNCATE(COUNT( DISTINCT IF((cssp.group_type_='PRACTICE' AND pg.type_='CHARGE') OR cssp.group_type_='VIP', cssp.user_id_, NULL) )/COUNT( DISTINCT sr.user_id_ )*100, 2) percent_
+			cs.organ_id_,
+			CONCAT( '2020-01', '-01' ) month_,
+			COUNT( DISTINCT m.user_id_ ) total_num_,
+			COUNT( DISTINCT m.user_id_ ) activate_num_,
+			COUNT( DISTINCT m.user_id_ ) percent_
 		FROM
-			student_registration sr
-			LEFT JOIN student_pre_registration spr ON sr.user_id_ = spr.user_id_ AND sr.music_group_id_ = spr.music_group_id_
-			LEFT JOIN music_group mg ON spr.music_group_id_ = mg.id_
-			LEFT JOIN course_schedule_student_payment cssp ON sr.user_id_=cssp.user_id_
-			LEFT JOIN practice_group pg ON cssp.music_group_id_=pg.id_
+			course_schedule_student_payment m
+				LEFT JOIN course_schedule cs ON m.course_schedule_id_=cs.id_
 		WHERE
-			mg.del_flag_ = 0
-			AND mg.organ_id_ IS NOT NULL
-			<if test="month!=null and month!=''">
-				AND DATE_FORMAT(sr.create_time_, '%Y-%m') &lt;= #{month}
-			</if>
+			(cs.del_flag_ IS NULL OR cs.del_flag_=0)
+			AND cs.organ_id_ IS NOT NULL
+			AND (cs.new_course_id_ IS NULL OR cs.new_course_id_=cs.id_)
+			AND m.group_type_ IN ('VIP', 'PRACTICE')
+			AND m.user_id_ IN
+			<foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
+				#{studentId}
+			</foreach>
 		GROUP BY
-			mg.organ_id_
+			cs.organ_id_
 		ORDER BY
-			mg.organ_id_;
+			cs.organ_id_;
 	</select>
 
 	<select id="getMusicGroupPreRegistrationStudentData" resultMap="IndexBaseMonthData">
@@ -404,4 +404,22 @@
 		ORDER BY
 			mg.organ_id_;
 	</select>
+
+	<select id="getMusicGroupStudentIdFromPre" resultType="int">
+		SELECT
+			sr.user_id_
+		FROM
+			student_registration sr
+			LEFT JOIN student_pre_registration spr ON sr.user_id_ = spr.user_id_ AND sr.music_group_id_ = spr.music_group_id_
+			LEFT JOIN music_group mg ON spr.music_group_id_ = mg.id_
+		WHERE
+			mg.del_flag_ = 0
+			AND mg.organ_id_ IS NOT NULL
+			AND mg.status_ = 'PROGRESS'
+			<if test="paymentStatus!=null">
+				AND sr.music_group_status_ = 'NORMAL'
+				AND sr.payment_status_ = #{paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+			</if>
+			AND DATE_FORMAT( sr.create_time_, '%Y-%m' ) &lt;= #{month}
+	</select>
 </mapper>

+ 2 - 2
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentStudentCourseDetailMapper.xml

@@ -80,7 +80,7 @@
             <if test="courseType != null">
                 course_type_ = #{courseType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
             </if>
-                update_time_ = #{updateTime}
+                update_time_ = NOW()
         </set>
         WHERE id_ = #{id}
     </update>
@@ -108,7 +108,7 @@
                 <if test="paymentCourseDetail.courseType != null">
                     course_type_ = #{paymentCourseDetail.courseType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
                 </if>
-                update_time_ = #{paymentCourseDetail.updateTime}
+                update_time_ = NOW()
             </set>
             WHERE id_ = #{paymentCourseDetail.id}
         </foreach>