|
@@ -1,6 +1,8 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import com.ym.mec.biz.dal.dao.OrganizationDao;
|
|
|
import com.ym.mec.biz.dal.dto.IndexBaseDto;
|
|
|
+import com.ym.mec.biz.dal.entity.Organization;
|
|
|
import com.ym.mec.biz.dal.enums.IndexDataType;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
@@ -11,9 +13,12 @@ import com.ym.mec.biz.dal.entity.IndexBaseMonthData;
|
|
|
import com.ym.mec.biz.service.IndexBaseMonthDataService;
|
|
|
import com.ym.mec.biz.dal.dao.IndexBaseMonthDataDao;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -22,6 +27,15 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
|
|
|
|
|
|
@Autowired
|
|
|
private IndexBaseMonthDataDao indexBaseMonthDataDao;
|
|
|
+ @Autowired
|
|
|
+ private OrganizationDao organizationDao;
|
|
|
+
|
|
|
+ private static ThreadLocal<Set<Integer>> organIds = new ThreadLocal<Set<Integer>>(){
|
|
|
+ @Override
|
|
|
+ protected Set<Integer> initialValue() {
|
|
|
+ return new HashSet<>();
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, IndexBaseMonthData> getDAO() {
|
|
@@ -46,7 +60,6 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
|
|
|
dataTypes = Arrays.stream(dataTypesStr.split(",")).collect(Collectors.toSet());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
List<IndexBaseMonthData> indexBaseDatas = indexBaseMonthDataDao.getIndexBaseData(organIds, dataTypes, startMonth, endMonth);
|
|
|
if(CollectionUtils.isEmpty(indexBaseDatas)){
|
|
|
return result;
|
|
@@ -63,56 +76,98 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Map<String, List<IndexBaseDto>> indexBaseDataTask(String startMonth, String endMonth) {
|
|
|
Map<String, List<IndexBaseDto>> result = new HashMap<>();
|
|
|
|
|
|
- if(StringUtils.isBlank(startMonth)){
|
|
|
- LocalDateTime nowDateTime = LocalDateTime.now();
|
|
|
- startMonth = nowDateTime.getYear() + "-01";
|
|
|
- endMonth = null;
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM");
|
|
|
+ LocalDate nowDate = LocalDate.now();
|
|
|
+ LocalDate startDate = nowDate.withMonth(1).withDayOfMonth(1);
|
|
|
+ LocalDate endDate = nowDate.withDayOfMonth(1);
|
|
|
+ if(StringUtils.isNotBlank(startMonth)){
|
|
|
+ startDate = LocalDate.parse(startMonth+"-01", DateUtil.dateFormatter);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotBlank(endMonth)){
|
|
|
+ endDate = LocalDate.parse(endMonth+"-01", DateUtil.dateFormatter);
|
|
|
}
|
|
|
|
|
|
- countUserSignUpDate(startMonth, endMonth);
|
|
|
+ List<Organization> allOrgans = organizationDao.findAllOrgans();
|
|
|
+ Set<Integer> organIds = allOrgans.stream().map(Organization::getId).collect(Collectors.toSet());
|
|
|
+ this.organIds.get().clear();
|
|
|
+ this.organIds.get().addAll(organIds);
|
|
|
+
|
|
|
+ while (startDate.compareTo(endDate)<=0){
|
|
|
+ countUserSignUpData(df.format(startDate));
|
|
|
+ countHomeworkData(startMonth);
|
|
|
|
|
|
- countHomeworkDate(startMonth, endMonth);
|
|
|
+ startDate = startDate.plusMonths(1);
|
|
|
+ }
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- private void countUserSignUpDate(String startMonth, String endMonth){
|
|
|
- List<IndexBaseMonthData> dataList = indexBaseMonthDataDao.getStudentSignUpData(startMonth, endMonth);
|
|
|
- if(CollectionUtils.isEmpty(dataList)){
|
|
|
- return;
|
|
|
+ /**
|
|
|
+ * @describe 处理并保存每月数据
|
|
|
+ * @author Joburgess
|
|
|
+ * @date 2021/1/11 0011
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private void saveData(List<IndexBaseMonthData> dataList, String startMonth, IndexDataType indexDataType){
|
|
|
+ startMonth = startMonth+"-01";
|
|
|
+ Date date = DateUtil.stringToDate(startMonth, "yyyy-MM-dd");
|
|
|
+ if(Objects.isNull(dataList)){
|
|
|
+ dataList = new ArrayList<>();
|
|
|
}
|
|
|
- Set<String> months = dataList.stream().map(s -> DateUtil.dateToString(s.getMonth(), "yyyy-MM-dd")).collect(Collectors.toSet());
|
|
|
- indexBaseMonthDataDao.deleteWithMonthAndType(months, IndexDataType.ACTIVATION_RATE);
|
|
|
- indexBaseMonthDataDao.batchInsertWithDataType(dataList, IndexDataType.ACTIVATION_RATE);
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ indexBaseMonthDataDao.deleteWithMonthAndType(Arrays.asList(startMonth), indexDataType);
|
|
|
+ indexBaseMonthDataDao.batchInsertWithDataType(dataList, indexDataType);
|
|
|
}
|
|
|
|
|
|
- private void countHomeworkDate(String startMonth, String endMonth){
|
|
|
- List<IndexBaseMonthData> dataList = indexBaseMonthDataDao.getHomeworkDate(startMonth, endMonth, null);
|
|
|
- if(CollectionUtils.isEmpty(dataList)){
|
|
|
- return;
|
|
|
- }
|
|
|
- Set<String> months = dataList.stream().map(s -> DateUtil.dateToString(s.getMonth(), "yyyy-MM-dd")).collect(Collectors.toSet());
|
|
|
- indexBaseMonthDataDao.deleteWithMonthAndType(months, IndexDataType.HOMEWORK_CREATE_RATE);
|
|
|
- indexBaseMonthDataDao.batchInsertWithDataType(dataList, IndexDataType.HOMEWORK_CREATE_RATE);
|
|
|
+ /**
|
|
|
+ * @describe 激活率
|
|
|
+ * @author Joburgess
|
|
|
+ * @date 2021/1/11 0011
|
|
|
+ * @param startMonth:
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private void countUserSignUpData(String startMonth){
|
|
|
+ List<IndexBaseMonthData> dataList = indexBaseMonthDataDao.getStudentSignUpData(startMonth);
|
|
|
+ saveData(dataList, startMonth, IndexDataType.ACTIVATION_RATE);
|
|
|
+ }
|
|
|
|
|
|
- List<IndexBaseMonthData> dataList1 = indexBaseMonthDataDao.getHomeworkDate(startMonth, endMonth, "submit");
|
|
|
- if(CollectionUtils.isEmpty(dataList1)){
|
|
|
- return;
|
|
|
- }
|
|
|
- Set<String> months1 = dataList1.stream().map(s -> DateUtil.dateToString(s.getMonth(), "yyyy-MM-dd")).collect(Collectors.toSet());
|
|
|
- indexBaseMonthDataDao.deleteWithMonthAndType(months1, IndexDataType.HOMEWORK_SUBMIT_RATE);
|
|
|
- indexBaseMonthDataDao.batchInsertWithDataType(dataList1, IndexDataType.HOMEWORK_SUBMIT_RATE);
|
|
|
+ /**
|
|
|
+ * @describe 作业数据
|
|
|
+ * @author Joburgess
|
|
|
+ * @date 2021/1/11 0011
|
|
|
+ * @param startMonth:
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private void countHomeworkData(String startMonth){
|
|
|
+ List<IndexBaseMonthData> dataList = indexBaseMonthDataDao.getHomeworkDate(startMonth, null);
|
|
|
+ saveData(dataList, startMonth, IndexDataType.HOMEWORK_CREATE_RATE);
|
|
|
+
|
|
|
+ List<IndexBaseMonthData> dataList1 = indexBaseMonthDataDao.getHomeworkDate(startMonth, "submit");
|
|
|
+ saveData(dataList1, startMonth, IndexDataType.HOMEWORK_SUBMIT_RATE);
|
|
|
+
|
|
|
+ List<IndexBaseMonthData> dataList2 = indexBaseMonthDataDao.getHomeworkDate(startMonth, "comment");
|
|
|
+ saveData(dataList2, startMonth, IndexDataType.HOMEWORK_COMMENT_RATE);
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * @describe 统计合作单位数据
|
|
|
+ * @author Joburgess
|
|
|
+ * @date 2021/1/11 0011
|
|
|
+ * @param startMonth:
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private void countSchoolData(String startMonth){
|
|
|
|
|
|
- List<IndexBaseMonthData> dataList2 = indexBaseMonthDataDao.getHomeworkDate(startMonth, endMonth, "comment");
|
|
|
- if(CollectionUtils.isEmpty(dataList2)){
|
|
|
- return;
|
|
|
- }
|
|
|
- Set<String> months2 = dataList2.stream().map(s -> DateUtil.dateToString(s.getMonth(), "yyyy-MM-dd")).collect(Collectors.toSet());
|
|
|
- indexBaseMonthDataDao.deleteWithMonthAndType(months2, IndexDataType.HOMEWORK_COMMENT_RATE);
|
|
|
- indexBaseMonthDataDao.batchInsertWithDataType(dataList2, IndexDataType.HOMEWORK_COMMENT_RATE);
|
|
|
}
|
|
|
}
|