Browse Source

Merge remote-tracking branch 'origin/master'

zouxuan 4 years ago
parent
commit
b072b12c3c

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

@@ -59,7 +59,7 @@ public interface IndexBaseMonthDataDao extends BaseDAO<Long, IndexBaseMonthData>
      * @date 2021/1/11 0011
      * @return java.util.List<com.ym.mec.biz.dal.entity.IndexBaseMonthData>
      */
-    List<IndexBaseMonthData> getSchoolData();
+    List<IndexBaseMonthData> getSchoolData(@Param("month") String month);
 
     /**
      * @describe 统计乐团数据

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/IndexBaseMonthDataService.java

@@ -11,6 +11,6 @@ public interface IndexBaseMonthDataService extends BaseService<Long, IndexBaseMo
 
     List<IndexBaseDto> getIndexBaseData(String dataType, String organIds, String startMonth, String endMonth);
 
-    Map<String, List<IndexBaseDto>> indexBaseDataTask(String startMonth, String endMonth);
+    Map<String, List<IndexBaseDto>> indexBaseDataTask(String month);
 
 }

+ 47 - 26
mec-biz/src/main/java/com/ym/mec/biz/service/impl/IndexBaseMonthDataServiceImpl.java

@@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
+import java.text.DateFormat;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
@@ -50,8 +51,9 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 	public List<IndexBaseDto> getIndexBaseData(String dataTypesStr, String organIdsStr, String startMonth, String endMonth) {
 		List<IndexBaseDto> result = new ArrayList<>();
 
+		LocalDate nowDateTime = LocalDate.now();
+		nowDateTime.withDayOfMonth(1);
 		if(StringUtils.isBlank(startMonth)){
-			LocalDateTime nowDateTime = LocalDateTime.now();
 			startMonth = nowDateTime.getYear() + "-01";
 			endMonth = null;
 		}
@@ -69,8 +71,27 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 			return result;
 		}
 
+		LocalDate startMonthDate = LocalDate.parse(startMonth + "-01", DateUtil.dateFormatter);
+
 		Map<IndexDataType, List<IndexBaseMonthData>> typeDateMap = indexBaseDatas.stream().collect(Collectors.groupingBy(IndexBaseMonthData::getDataType));
 		for (Map.Entry<IndexDataType, List<IndexBaseMonthData>> typeDateMapEntry : typeDateMap.entrySet()) {
+			Set<String> hasMonths = typeDateMapEntry.getValue().stream().map(d -> DateUtil.dateToString(d.getMonth(), "yyyy-MM-dd")).collect(Collectors.toSet());
+			LocalDate currentMonthDate = startMonthDate;
+			while (currentMonthDate.compareTo(nowDateTime)<=0){
+				if(hasMonths.contains(currentMonthDate.toString())){
+					currentMonthDate = currentMonthDate.plusMonths(1);
+					continue;
+				}
+				IndexBaseMonthData indexBaseMonthData = new IndexBaseMonthData();
+				indexBaseMonthData.setMonth(Date.from(currentMonthDate.atStartOfDay(DateUtil.zoneId).toInstant()));
+				indexBaseMonthData.setTotalNum(BigDecimal.ONE);
+				indexBaseMonthData.setActivateNum(BigDecimal.ZERO);
+				indexBaseMonthData.setPercent(BigDecimal.ZERO);
+				indexBaseMonthData.setDataType(typeDateMapEntry.getKey());
+				typeDateMapEntry.getValue().add(indexBaseMonthData);
+				currentMonthDate = currentMonthDate.plusMonths(1);
+			}
+			typeDateMapEntry.getValue().sort(Comparator.comparing(IndexBaseMonthData::getMonth));
 			if(IndexDataType.ACTIVATION_RATE.equals(typeDateMapEntry.getKey())||IndexDataType.HOMEWORK_CREATE_RATE.equals(typeDateMapEntry.getKey())
 					||IndexDataType.HOMEWORK_SUBMIT_RATE.equals(typeDateMapEntry.getKey())||IndexDataType.HOMEWORK_SUBMIT_RATE.equals(typeDateMapEntry.getKey())
 					||IndexDataType.STUDENT_CONVERSION.equals(typeDateMapEntry.getKey())){
@@ -88,7 +109,7 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
-	public Map<String, List<IndexBaseDto>> indexBaseDataTask(String startMonth, String endMonth) {
+	public Map<String, List<IndexBaseDto>> indexBaseDataTask(String month) {
 		Map<String, List<IndexBaseDto>> result = new HashMap<>();
 
 		DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM");
@@ -100,42 +121,42 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 			this.organIds.get().addAll(allOrgans.stream().map(Organization::getId).collect(Collectors.toSet()));
 		}
 
-		startMonth = df.format(nowDate);
+		month = df.format(nowDate);
 
 		//运营数据
-		saveData(indexBaseMonthDataDao.getSchoolData(), startMonth, IndexDataType.SCHOOL);
-		saveData(indexBaseMonthDataDao.getMusicData(), startMonth, IndexDataType.MUSIC_GROUP_NUM);
-		saveData(indexBaseMonthDataDao.getMusicStudentData(null), startMonth, IndexDataType.MUSIC_GROUP_STUDENT);
-		saveData(indexBaseMonthDataDao.getOtherStudentData(), startMonth, IndexDataType.OTHER_STUDENT);
+		saveData(indexBaseMonthDataDao.getSchoolData(month), month, IndexDataType.SCHOOL);
+		saveData(indexBaseMonthDataDao.getMusicData(), month, IndexDataType.MUSIC_GROUP_NUM);
+		saveData(indexBaseMonthDataDao.getMusicStudentData(null), month, IndexDataType.MUSIC_GROUP_STUDENT);
+		saveData(indexBaseMonthDataDao.getOtherStudentData(), month, IndexDataType.OTHER_STUDENT);
 
 		//业务数据
-		saveData(indexBaseMonthDataDao.getStudentSignUpData(), startMonth, IndexDataType.ACTIVATION_RATE);
-		saveData(indexBaseMonthDataDao.getHomeworkData(null), startMonth, IndexDataType.HOMEWORK_CREATE_RATE);
-		saveData(indexBaseMonthDataDao.getHomeworkData("submit"), startMonth, IndexDataType.HOMEWORK_SUBMIT_RATE);
-		saveData(indexBaseMonthDataDao.getHomeworkData("comment"), startMonth, IndexDataType.HOMEWORK_COMMENT_RATE);
+		saveData(indexBaseMonthDataDao.getStudentSignUpData(), month, IndexDataType.ACTIVATION_RATE);
+		saveData(indexBaseMonthDataDao.getHomeworkData(null), month, IndexDataType.HOMEWORK_CREATE_RATE);
+		saveData(indexBaseMonthDataDao.getHomeworkData("submit"), month, IndexDataType.HOMEWORK_SUBMIT_RATE);
+		saveData(indexBaseMonthDataDao.getHomeworkData("comment"), month, IndexDataType.HOMEWORK_COMMENT_RATE);
 
 		//经营数据
-		saveData(null, startMonth, IndexDataType.SHOULD_INCOME_MONEY);
-		saveData(null, startMonth, IndexDataType.ANTICIPATED_INCOME_MONEY);
-		saveData(null, startMonth, IndexDataType.SHOULD_EXPEND_MONEY);
-		saveData(null, startMonth, IndexDataType.ANTICIPATED_EXPEND_MONEY);
-		saveData(null, startMonth, IndexDataType.REVENUE_MONEY);
+		saveData(null, month, IndexDataType.SHOULD_INCOME_MONEY);
+		saveData(null, month, IndexDataType.ANTICIPATED_INCOME_MONEY);
+		saveData(null, month, IndexDataType.SHOULD_EXPEND_MONEY);
+		saveData(null, month, IndexDataType.ANTICIPATED_EXPEND_MONEY);
+		saveData(null, month, IndexDataType.REVENUE_MONEY);
 
 		//人事数据
-		saveData(indexBaseMonthDataDao.getTeacherData(null, null), startMonth, IndexDataType.TEACHER_NUM);
-		saveData(indexBaseMonthDataDao.getTeacherData(JobNatureEnum.FULL_TIME, null), startMonth, IndexDataType.FULL_TIME_NUM);
-		saveData(indexBaseMonthDataDao.getTeacherData(JobNatureEnum.PART_TIME, null), startMonth, IndexDataType.PART_TIME_NUM);
-		saveData(indexBaseMonthDataDao.getTeacherData(null, true), startMonth, IndexDataType.DIMISSION_NUM);
+		saveData(indexBaseMonthDataDao.getTeacherData(null, null), month, IndexDataType.TEACHER_NUM);
+		saveData(indexBaseMonthDataDao.getTeacherData(JobNatureEnum.FULL_TIME, null), month, IndexDataType.FULL_TIME_NUM);
+		saveData(indexBaseMonthDataDao.getTeacherData(JobNatureEnum.PART_TIME, null), month, IndexDataType.PART_TIME_NUM);
+		saveData(indexBaseMonthDataDao.getTeacherData(null, true), month, IndexDataType.DIMISSION_NUM);
 
 		//学员变动
-		saveData(indexBaseMonthDataDao.getMusicStudentData("ALL"), startMonth, IndexDataType.NEWLY_STUDENT_NUM);
-		saveData(indexBaseMonthDataDao.getMusicStudentData("QUIT"), startMonth, IndexDataType.QUIT_MUSIC_GROUP_STUDENT_NUM);
-		saveData(indexBaseMonthDataDao.getStudentConversionData(), startMonth, IndexDataType.STUDENT_CONVERSION);
+		saveData(indexBaseMonthDataDao.getMusicStudentData("ALL"), month, IndexDataType.NEWLY_STUDENT_NUM);
+		saveData(indexBaseMonthDataDao.getMusicStudentData("QUIT"), month, IndexDataType.QUIT_MUSIC_GROUP_STUDENT_NUM);
+		saveData(indexBaseMonthDataDao.getStudentConversionData(), month, IndexDataType.STUDENT_CONVERSION);
 
 		//课程数据
-		saveData(indexBaseMonthDataDao.getGroupCourseData(GroupType.MUSIC), startMonth, IndexDataType.MUSIC_GROUP_COURSE);
-		saveData(indexBaseMonthDataDao.getGroupCourseData(GroupType.VIP), startMonth, IndexDataType.VIP_GROUP_COURSE);
-		saveData(indexBaseMonthDataDao.getGroupCourseData(GroupType.PRACTICE), startMonth, IndexDataType.PRACTICE_GROUP_COURSE);
+		saveData(indexBaseMonthDataDao.getGroupCourseData(GroupType.MUSIC), month, IndexDataType.MUSIC_GROUP_COURSE);
+		saveData(indexBaseMonthDataDao.getGroupCourseData(GroupType.VIP), month, IndexDataType.VIP_GROUP_COURSE);
+		saveData(indexBaseMonthDataDao.getGroupCourseData(GroupType.PRACTICE), month, IndexDataType.PRACTICE_GROUP_COURSE);
 
 		return result;
 	}

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

@@ -188,7 +188,7 @@
 	<select id="getSchoolData" resultMap="IndexBaseMonthData">
 		SELECT
 			organ_id_,
-			CONCAT(DATE_FORMAT(NOW(), '%Y-%m'), '-01') month_,
+			CONCAT(#{month}, '-01') month_,
 			COUNT( id_ ) total_num_,
 			COUNT( id_ ) activate_num_,
 			COUNT( id_ ) percent_
@@ -197,6 +197,7 @@
 		WHERE
 			del_flag_ = 0
 		  	AND organ_id_ IS NOT NULL
+			AND DATE_FORMAT(create_time_, '%Y-%m') = #{month}
 		GROUP BY
 			organ_id_
 		ORDER BY

+ 2 - 2
mec-web/src/main/java/com/ym/mec/web/controller/TaskController.java

@@ -321,7 +321,7 @@ public class TaskController extends BaseController {
 	}
 
 	@GetMapping("/countIndexBaseData")
-	public void countIndexBaseData(String startMonth, String endMonth){
-		indexBaseMonthDataService.indexBaseDataTask(startMonth, endMonth);
+	public void countIndexBaseData(String startMonth){
+		indexBaseMonthDataService.indexBaseDataTask(startMonth);
 	}
 }