package com.ym.mec.biz.service.impl;

import com.alibaba.fastjson.JSON;
import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dao.*;
import com.ym.mec.biz.dal.dto.*;
import com.ym.mec.biz.dal.entity.*;
import com.ym.mec.biz.dal.enums.*;
import com.ym.mec.biz.dal.page.IndexDataQueryInfo;
import com.ym.mec.biz.dal.page.OrganCloudStudyStudentDataQueryInfo;
import com.ym.mec.biz.service.*;
import com.ym.mec.common.constant.CommonConstants;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.exception.BizException;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.common.service.impl.BaseServiceImpl;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

import static com.ym.mec.biz.dal.enums.IndexDataType.*;
import static com.ym.mec.biz.dal.enums.SysUserRoleEnum.EDUCATION;

@Service
public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBaseMonthData> implements IndexBaseMonthDataService {

	@Autowired
	private IndexBaseMonthDataDao indexBaseMonthDataDao;
	@Autowired
	private OrganizationService organizationService;
	@Autowired
	private MusicGroupDao musicGroupDao;
	@Autowired
	private SysConfigDao sysConfigDao;
	@Autowired
	private SysTenantConfigService sysTenantConfigService;
	@Autowired
	private MusicGroupPaymentCalenderDao musicGroupPaymentCalenderDao;
	@Autowired
	private SysUserFeignService sysUserFeignService;
	@Autowired
	private StudentExtracurricularExercisesSituationDao studentExtracurricularExercisesSituationDao;
	@Autowired
	private ClassGroupDao classGroupDao;
	@Autowired
	private StudentRegistrationDao studentRegistrationDao;
	@Autowired
	private MusicGroupPerformanceDao musicGroupPerformanceDao;
	@Autowired
	private StudentDao studentDao;
	@Autowired
	private SysEmployeePositionService employeePositionService;

	private static ThreadLocal<Set<Integer>> organIds = new ThreadLocal<Set<Integer>>(){
		@Override
		protected Set<Integer> initialValue() {
			return new HashSet<>();
		}
	};

	@Override
	public BaseDAO<Long, IndexBaseMonthData> getDAO() {
		return indexBaseMonthDataDao;
	}

	public IndexBaseDto getIndexBaseDto(IndexDataType indexDataType,List<IndexBaseMonthData> indexBaseMonthData) {
		BigDecimal reduce = indexBaseMonthData.stream().map(e -> e.getPercent()).reduce(BigDecimal.ZERO, BigDecimal::add);
		indexBaseMonthData.stream().forEach(e -> {
			e.setDataType(indexDataType);
			e.setTitle(indexDataType.getMsg());
		});
		return new IndexBaseDto(indexDataType,reduce,indexBaseMonthData);
	}

	@Override
	public List<IndexBaseDto> getIndexBaseData(IndexDataQueryInfo queryInfo) {
		List<IndexBaseDto> result = new ArrayList<>();

		LocalDate nowDate = LocalDate.now();

		LocalDate startDate = nowDate.plusDays(-30);
		if(Objects.nonNull(queryInfo.getStartDate())){
			startDate = LocalDateTime.ofInstant(queryInfo.getStartDate().toInstant(), DateUtil.zoneId).toLocalDate();
		}

		LocalDate endDate = nowDate.plusDays(-1);
		if(Objects.nonNull(queryInfo.getEndDate())){
			endDate = LocalDateTime.ofInstant(queryInfo.getEndDate().toInstant(), DateUtil.zoneId).toLocalDate();
		}
		Date currentMonth = Date.from(endDate.atStartOfDay(DateUtil.zoneId).toInstant());

		Set<Integer> organIds = null;
		if(StringUtils.isNotBlank(queryInfo.getOrganId())){
			organIds = Arrays.stream(queryInfo.getOrganId().split(",")).map(Integer::new).collect(Collectors.toSet());
		}
		if("MEMBER_STUDENT_NUM,CLOUD_STUDY_LIVELY_STUDENT_NUM,CLOUD_STUDY_DAY_USE_STUDENT_NUM,CLOUD_STUDY_NEW_STUDENT_NUM".equals(queryInfo.getDataTypes())){
			organIds = organIds.stream().filter(id -> !OrganizationService.EXCLUDE_ORGAN_IDS.contains(id)).collect(Collectors.toSet());
		}
		Set<String> dataTypes = new HashSet<>();
		if(StringUtils.isNotBlank(queryInfo.getDataTypes())){
			dataTypes = Arrays.stream(queryInfo.getDataTypes().split(",")).collect(Collectors.toSet());
		}

		List<IndexBaseMonthData> indexBaseDatas = indexBaseMonthDataDao.getIndexBaseData(organIds, dataTypes, startDate.toString(), endDate.toString(),queryInfo.getTenantId());
		if(Objects.isNull(indexBaseDatas)){
			indexBaseDatas = new ArrayList<>();
		}

		Map<Date, Map<IndexDataType, Map<String, Integer>>> vipCategoryCourseListMap = new HashMap<>();
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains("VIP_GROUP_COURSE")||dataTypes.contains("VIP_GROUP_ONLINE_COURSE")||dataTypes.contains("VIP_GROUP_OFFLINE_COURSE")){
			Set<String> vipDataTypes = new HashSet<>();
			vipDataTypes.add("VIP_GROUP_COURSE");
			vipDataTypes.add("VIP_GROUP_ONLINE_COURSE");
			vipDataTypes.add("VIP_GROUP_OFFLINE_COURSE");
			List<IndexBaseMonthData> indexBaseDataList = indexBaseMonthDataDao.getVipCourseDataList(organIds, vipDataTypes, startDate.toString(), endDate.toString(),queryInfo.getTenantId());
			if(!CollectionUtils.isEmpty(indexBaseDataList)){
				for (IndexBaseMonthData indexBaseMonthData : indexBaseDataList) {
					if(StringUtils.isBlank(indexBaseMonthData.getExtendInfo())){
						continue;
					}
					if(!vipCategoryCourseListMap.containsKey(indexBaseMonthData.getMonth())){
						vipCategoryCourseListMap.put(indexBaseMonthData.getMonth(), new HashMap<>());
					}
					if(!vipCategoryCourseListMap.get(indexBaseMonthData.getMonth()).containsKey(indexBaseMonthData.getDataType())){
						vipCategoryCourseListMap.get(indexBaseMonthData.getMonth()).put(indexBaseMonthData.getDataType(), new HashMap<>());
					}
					Map<String, Integer> map = JSON.parseObject(indexBaseMonthData.getExtendInfo(), Map.class);
					for (Map.Entry<String, Integer> o : map.entrySet()) {
						if(!vipCategoryCourseListMap.get(indexBaseMonthData.getMonth()).get(indexBaseMonthData.getDataType()).containsKey(o.getKey())){
							vipCategoryCourseListMap.get(indexBaseMonthData.getMonth()).get(indexBaseMonthData.getDataType()).put(o.getKey(), 0);
						}
						vipCategoryCourseListMap.get(indexBaseMonthData.getMonth()).get(indexBaseMonthData.getDataType()).put(o.getKey(), vipCategoryCourseListMap.get(indexBaseMonthData.getMonth()).get(indexBaseMonthData.getDataType()).get(o.getKey())+o.getValue());
					}
				}
			}
		}

		Map<IndexDataType, List<IndexBaseMonthData>> typeDateMap = indexBaseDatas.stream().filter(d->Objects.nonNull(d.getDataType())).collect(Collectors.groupingBy(IndexBaseMonthData::getDataType));

		//按天汇总
		if((CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(FINANCE_PAY.getCode())||dataTypes.contains(FINANCE_BALANCE_AMOUNT.getCode())||dataTypes.contains(FINANCE_AMOUNT.getCode())) && organIds != null){
			List<IndexBaseMonthData> financePayDataWithTimely = indexBaseMonthDataDao.getFinancePayDataWithTimely(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),queryInfo.getTenantId());
			typeDateMap.put(IndexDataType.FINANCE_PAY,financePayDataWithTimely);
			typeDateMap.put(IndexDataType.FINANCE_BALANCE_AMOUNT,indexBaseMonthDataDao.getFinanceBalanceDataWithTimely(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),queryInfo.getTenantId()));
			typeDateMap.put(FINANCE_AMOUNT,indexBaseMonthDataDao.getFinanceActualDataWithTimely(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),queryInfo.getTenantId()));
			List<IndexBaseMonthData> totalAmountDataWithTimely = indexBaseMonthDataDao.getTotalAmountDataWithTimely(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),queryInfo.getTenantId());
			typeDateMap.put(IndexDataType.TOTAL_AMOUNT,totalAmountDataWithTimely);
			//经营报表细化
			List<IndexBaseMonthData> applyAmount = indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),"APPLY,ADD_STUDENT",null,queryInfo.getTenantId());
			typeDateMap.put(APPLY_AMOUNT,applyAmount);
			List<IndexBaseMonthData> renewAmount = indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),"RENEW",null,queryInfo.getTenantId());
			typeDateMap.put(RENEW_AMOUNT,renewAmount);
			List<IndexBaseMonthData> vipAmount = indexBaseMonthDataDao.getVipAmountDataWithTimelyDetails(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),queryInfo.getTenantId());
			typeDateMap.put(VIP_AMOUNT,vipAmount);
			List<IndexBaseMonthData> practiceAmount = indexBaseMonthDataDao.getTotalAmountDataWithTimelyDetails(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),"PRACTICE_GROUP_BUY,PRACTICE_GROUP_RENEW",null,queryInfo.getTenantId());
			typeDateMap.put(PRACTICE_AMOUNT,practiceAmount);
			List<IndexBaseMonthData> otherAmount = indexBaseMonthDataDao.getOtherAmountDataWithTimelyDetails(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),queryInfo.getTenantId());
			typeDateMap.put(OTHER_AMOUNT,otherAmount);
		}
		//按分部汇总
		List<IndexBaseDto> indexBaseDtoList = new ArrayList<>();
		if((CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(ORGAN_FINANCE_PAY.getCode())||dataTypes.contains(ORGAN_FINANCE_BALANCE_AMOUNT.getCode())||
				dataTypes.contains(ORGAN_FINANCE_AMOUNT.getCode())) && organIds != null){
			List<IndexBaseMonthData> financePayDataWithTimely = indexBaseMonthDataDao.getOrganFinancePayDataWithTimely(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),queryInfo.getTenantId());
			indexBaseDtoList.add(this.getIndexBaseDto(IndexDataType.ORGAN_FINANCE_PAY,financePayDataWithTimely));

			indexBaseDtoList.add(this.getIndexBaseDto(IndexDataType.ORGAN_FINANCE_BALANCE_AMOUNT,indexBaseMonthDataDao.getOrganFinanceBalanceDataWithTimely(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),queryInfo.getTenantId())));
			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_FINANCE_AMOUNT,indexBaseMonthDataDao.getOrganFinanceActualDataWithTimely(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),queryInfo.getTenantId())));
			List<IndexBaseMonthData> totalAmountDataWithTimely = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimely(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),queryInfo.getTenantId());
			indexBaseDtoList.add(this.getIndexBaseDto(IndexDataType.ORGAN_TOTAL_AMOUNT,totalAmountDataWithTimely));
			//经营报表细化
			List<IndexBaseMonthData> applyAmount = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),"APPLY,ADD_STUDENT",null,queryInfo.getTenantId());
			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_APPLY_AMOUNT,applyAmount));
			List<IndexBaseMonthData> renewAmount = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),"RENEW",null,queryInfo.getTenantId());
			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_RENEW_AMOUNT,renewAmount));
			List<IndexBaseMonthData> vipAmount = indexBaseMonthDataDao.getOrganVipAmountDataWithTimelyDetails(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),queryInfo.getTenantId());
			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_VIP_AMOUNT,vipAmount));
			List<IndexBaseMonthData> practiceAmount = indexBaseMonthDataDao.getOrganTotalAmountDataWithTimelyDetails(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),"PRACTICE_GROUP_BUY,PRACTICE_GROUP_RENEW",null,queryInfo.getTenantId());
			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_PRACTICE_AMOUNT,practiceAmount));
			List<IndexBaseMonthData> otherAmount = indexBaseMonthDataDao.getOrganOtherAmountDataWithTimelyDetails(startDate.toString(), endDate.toString(), new ArrayList<>(organIds),queryInfo.getTenantId());
			indexBaseDtoList.add(this.getIndexBaseDto(ORGAN_OTHER_AMOUNT,otherAmount));
		}

		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(MUSIC_GROUP_COURSE.getCode())||dataTypes.contains(VIP_GROUP_COURSE.getCode())
				||dataTypes.contains(VIP_GROUP_ONLINE_COURSE.getCode())||dataTypes.contains(VIP_GROUP_OFFLINE_COURSE.getCode())
				||dataTypes.contains(PRACTICE_GROUP_COURSE.getCode())){
			if((CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.MUSIC_GROUP_COURSE.getCode())) && organIds != null) {
				List<IndexBaseMonthData> musicCourseData = indexBaseMonthDataDao.getGroupCourseDataWithGroup(null, startDate.toString(), endDate.toString(), GroupType.MUSIC, null, null, new ArrayList<>(organIds),queryInfo.getTenantId());
				typeDateMap.put(MUSIC_GROUP_COURSE,musicCourseData);
			}

			if((CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.VIP_GROUP_COURSE.getCode())) && organIds != null) {
				List<IndexBaseMonthData> vipCourseData = indexBaseMonthDataDao.getGroupCourseDataWithGroup(null, startDate.toString(), endDate.toString(), GroupType.VIP, null, null, new ArrayList<>(organIds),queryInfo.getTenantId());
				List<OrganVipGroupCategoryCourseNumDto> vipGroupCategoryCourseData = indexBaseMonthDataDao.getVipGroupCategoryCourseData(null, startDate.toString(), endDate.toString(), GroupType.VIP, null, null, new ArrayList<>(organIds),queryInfo.getTenantId());
				Map<Integer, Map<String, Integer>> organCategoryCourseMap = new HashMap<>();
				if (!CollectionUtils.isEmpty(vipGroupCategoryCourseData)) {
					organCategoryCourseMap = vipGroupCategoryCourseData.stream().collect(Collectors.groupingBy(OrganVipGroupCategoryCourseNumDto::getOrganId, Collectors.toMap(OrganVipGroupCategoryCourseNumDto::getCategoryName, o -> o.getCourseNum())));
				}
				for (IndexBaseMonthData vipCourseDatum : vipCourseData) {
					if (organCategoryCourseMap.containsKey(vipCourseDatum.getOrganId())) {
						vipCourseDatum.setExtendInfo(JSON.toJSONString(organCategoryCourseMap.get(vipCourseDatum.getOrganId())));
					}
				}
				typeDateMap.put(VIP_GROUP_COURSE,vipCourseData);
			}

			if((CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.VIP_GROUP_ONLINE_COURSE.getCode())) && organIds != null) {
				List<IndexBaseMonthData> vipOnlineCourseData = indexBaseMonthDataDao.getGroupCourseDataWithGroup(null, startDate.toString(), endDate.toString(), GroupType.VIP, null, TeachModeEnum.ONLINE, new ArrayList<>(organIds),queryInfo.getTenantId());
				List<OrganVipGroupCategoryCourseNumDto> vipGroupOnlineCategoryCourseData = indexBaseMonthDataDao.getVipGroupCategoryCourseData(null, startDate.toString(), endDate.toString(), GroupType.VIP, null, TeachModeEnum.ONLINE, new ArrayList<>(organIds),queryInfo.getTenantId());
				Map<Integer, Map<String, Integer>> organOnlineCategoryCourseMap = new HashMap<>();
				if (!CollectionUtils.isEmpty(vipGroupOnlineCategoryCourseData)) {
					organOnlineCategoryCourseMap = vipGroupOnlineCategoryCourseData.stream().collect(Collectors.groupingBy(OrganVipGroupCategoryCourseNumDto::getOrganId, Collectors.toMap(OrganVipGroupCategoryCourseNumDto::getCategoryName, o -> o.getCourseNum())));
				}
				for (IndexBaseMonthData vipCourseDatum : vipOnlineCourseData) {
					if (organOnlineCategoryCourseMap.containsKey(vipCourseDatum.getOrganId())) {
						vipCourseDatum.setExtendInfo(JSON.toJSONString(organOnlineCategoryCourseMap.get(vipCourseDatum.getOrganId())));
					}
				}
				typeDateMap.put(VIP_GROUP_ONLINE_COURSE,vipOnlineCourseData);
			}

			if((CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.VIP_GROUP_OFFLINE_COURSE.getCode())) && organIds != null) {
				List<IndexBaseMonthData> vipOfflineCourseData = indexBaseMonthDataDao.getGroupCourseDataWithGroup(null, startDate.toString(), endDate.toString(), GroupType.VIP, null, TeachModeEnum.OFFLINE, new ArrayList<>(organIds),queryInfo.getTenantId());
				List<OrganVipGroupCategoryCourseNumDto> vipGroupOfflineCategoryCourseData = indexBaseMonthDataDao.getVipGroupCategoryCourseData(null, startDate.toString(), endDate.toString(), GroupType.VIP, null, TeachModeEnum.OFFLINE, new ArrayList<>(organIds),queryInfo.getTenantId());
				Map<Integer, Map<String, Integer>> organOfflineCategoryCourseMap = new HashMap<>();
				if (!CollectionUtils.isEmpty(vipGroupOfflineCategoryCourseData)) {
					organOfflineCategoryCourseMap = vipGroupOfflineCategoryCourseData.stream().collect(Collectors.groupingBy(OrganVipGroupCategoryCourseNumDto::getOrganId, Collectors.toMap(OrganVipGroupCategoryCourseNumDto::getCategoryName, o -> o.getCourseNum())));
				}
				for (IndexBaseMonthData vipCourseDatum : vipOfflineCourseData) {
					if (organOfflineCategoryCourseMap.containsKey(vipCourseDatum.getOrganId())) {
						vipCourseDatum.setExtendInfo(JSON.toJSONString(organOfflineCategoryCourseMap.get(vipCourseDatum.getOrganId())));
					}
				}
				typeDateMap.put(VIP_GROUP_OFFLINE_COURSE,vipOfflineCourseData);
			}

			if((CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.PRACTICE_GROUP_COURSE.getCode())) && organIds != null) {
				List<IndexBaseMonthData> practiceCourses = indexBaseMonthDataDao.getGroupCourseDataWithGroup(null, startDate.toString(), endDate.toString(), GroupType.PRACTICE, null, null, new ArrayList<>(organIds),queryInfo.getTenantId());
				typeDateMap.put(PRACTICE_GROUP_COURSE,practiceCourses);
			}
		}

		for (IndexDataType dataType : IndexDataType.values()) {
			if(typeDateMap.containsKey(dataType)||(!CollectionUtils.isEmpty(dataTypes)&&!dataTypes.contains(dataType.getCode()))){
				continue;
			}
			if(dataType.equals(ORGAN_FINANCE_AMOUNT)){
				continue;
			}

			IndexBaseMonthData indexBaseMonthData = new IndexBaseMonthData();
			indexBaseMonthData.setMonth(Date.from(endDate.atStartOfDay(DateUtil.zoneId).toInstant()));
			if(IndexDataType.HOMEWORK_CREATE_RATE.equals(dataType)
					||IndexDataType.HOMEWORK_SUBMIT_RATE.equals(dataType)
					||IndexDataType.HOMEWORK_COMMENT_RATE.equals(dataType)){
				indexBaseMonthData.setMonth(Date.from(endDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue()).atStartOfDay(DateUtil.zoneId).toInstant()));
			}
			indexBaseMonthData.setTotalNum(BigDecimal.ZERO);
			indexBaseMonthData.setActivateNum(BigDecimal.ZERO);
			indexBaseMonthData.setPercent(BigDecimal.ZERO);
			indexBaseMonthData.setDataType(dataType);
			typeDateMap.put(dataType, new ArrayList<>(Arrays.asList(indexBaseMonthData)));
		}


		for (Map.Entry<IndexDataType, List<IndexBaseMonthData>> typeDateMapEntry : typeDateMap.entrySet()) {
			List<IndexBaseMonthData> value = typeDateMapEntry.getValue();
			Set<String> hasMonths = value.stream().filter(e->e.getMonth() != null).map(d -> DateUtil.dateToString(d.getMonth(), "yyyy-MM-dd")).collect(Collectors.toSet());
			LocalDate currentMonthDate = startDate;
			while (currentMonthDate.compareTo(endDate)<=0){
				if((IndexDataType.HOMEWORK_CREATE_RATE.equals(typeDateMapEntry.getKey())
					||IndexDataType.HOMEWORK_SUBMIT_RATE.equals(typeDateMapEntry.getKey())
					||IndexDataType.HOMEWORK_COMMENT_RATE.equals(typeDateMapEntry.getKey()))
					&&currentMonthDate.getDayOfWeek()!=DayOfWeek.MONDAY){
					currentMonthDate = currentMonthDate.plusDays(1);
					continue;
				}
				if(hasMonths.contains(currentMonthDate.toString())){
					currentMonthDate = currentMonthDate.plusDays(1);
					continue;
				}
				IndexBaseMonthData indexBaseMonthData = new IndexBaseMonthData();
				indexBaseMonthData.setMonth(Date.from(currentMonthDate.atStartOfDay(DateUtil.zoneId).toInstant()));
				indexBaseMonthData.setTotalNum(BigDecimal.ZERO);
				indexBaseMonthData.setActivateNum(BigDecimal.ZERO);
				indexBaseMonthData.setPercent(BigDecimal.ZERO);
				indexBaseMonthData.setDataType(typeDateMapEntry.getKey());
				value.add(indexBaseMonthData);
				currentMonthDate = currentMonthDate.plusDays(1);
			}
			value.sort(Comparator.comparing(IndexBaseMonthData::getMonth));
			if(typeDateMapEntry.getKey().getPercent()){
				for (IndexBaseMonthData indexBaseMonthData : value) {
					if(indexBaseMonthData.getTotalNum().compareTo(BigDecimal.ZERO)==0){
						indexBaseMonthData.setPercent(BigDecimal.ZERO);
						continue;
					}
					indexBaseMonthData.setPercent(indexBaseMonthData.getActivateNum().divide(indexBaseMonthData.getTotalNum(), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN));
				}
			}
			IndexBaseDto indexBaseData = new IndexBaseDto(typeDateMapEntry.getKey(),typeDateMapEntry.getKey().getMsg());
			indexBaseData.setIndexMonthData(value, currentMonth);
			if(OTHER_AMOUNT.equals(typeDateMapEntry.getKey())){
				List<IndexBaseMonthData> otherAmountDetails = new ArrayList<>();
				if(value != null && value.size() > 0){
					Map<String, List<IndexBaseMonthData>> collect = value.stream().filter(c->StringUtils.isNotEmpty(c.getOrderType())).collect(Collectors.groupingBy(e -> e.getOrderType()));
					collect.keySet().forEach(e->{
						IndexBaseMonthData data = new IndexBaseMonthData();
						data.setOrderType(e);
						BigDecimal reduce = collect.get(e).stream().map(IndexBaseMonthData::getPercent).reduce(BigDecimal.ZERO, BigDecimal::add);
						data.setPercent(reduce);data.setActivateNum(reduce);data.setTotalNum(reduce);
						otherAmountDetails.add(data);
					});
				}
				indexBaseData.setIndexMonthDataDetail(otherAmountDetails);
			}
			if(FINANCE_PAY.equals(typeDateMapEntry.getKey()) || FINANCE_AMOUNT.equals(typeDateMapEntry.getKey()) ||
				FINANCE_BALANCE_AMOUNT.equals(typeDateMapEntry.getKey()) ||
					TOTAL_AMOUNT.equals(typeDateMapEntry.getKey()) ||
					APPLY_AMOUNT.equals(typeDateMapEntry.getKey()) ||
					RENEW_AMOUNT.equals(typeDateMapEntry.getKey()) ||
					VIP_AMOUNT.equals(typeDateMapEntry.getKey()) ||
					PRACTICE_AMOUNT.equals(typeDateMapEntry.getKey()) ||
					OTHER_AMOUNT.equals(typeDateMapEntry.getKey())){
				indexBaseData.setPercent(value.stream().map(IndexBaseMonthData::getPercent).reduce(BigDecimal.ZERO, BigDecimal::add));
			}
			if(IndexDataType.VIP_GROUP_COURSE.equals(typeDateMapEntry.getKey()) || VIP_GROUP_ONLINE_COURSE.equals(typeDateMapEntry.getKey()) ||
					IndexDataType.VIP_GROUP_OFFLINE_COURSE.equals(typeDateMapEntry.getKey())){
				for (IndexBaseMonthData indexBaseMonthData : indexBaseData.getIndexMonthData()) {
					if(vipCategoryCourseListMap.containsKey(indexBaseMonthData.getMonth())&&vipCategoryCourseListMap.get(indexBaseMonthData.getMonth()).containsKey(indexBaseData.getDataType())){
						TreeMap<String, Integer> extendSortMap = new TreeMap<>(vipCategoryCourseListMap.get(indexBaseMonthData.getMonth()).get(indexBaseData.getDataType()));
						indexBaseMonthData.setExtendInfo(JSON.toJSONString(extendSortMap));
					}
				}
			}
			if(QUIT_MUSIC_GROUP_STUDENT_NUM.equals(typeDateMapEntry.getKey())){
				//查询时间段内学员成功退团申请的数量
				Integer quitNum = musicGroupDao.countQuitNum(queryInfo);
				indexBaseData.setIndexMonthData(new ArrayList<>(),null);
				indexBaseData.setIndexMonthDataDetail(new ArrayList<>());
				indexBaseData.setDataType(QUIT_MUSIC_GROUP_STUDENT_NUM);
				indexBaseData.setPercent(new BigDecimal(quitNum));
				indexBaseData.setTitle(QUIT_MUSIC_GROUP_STUDENT_NUM.getMsg());
			}
			result.add(indexBaseData);
		}
		result.addAll(indexBaseDtoList);
		return result;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void indexBaseDataTask(Integer tenantId, String dayStr, Set<IndexDataType> dataTypes) {
		LocalDate nowDate = LocalDate.now();
		
		List<Organization> allOrgans = organizationService.findAllOrgans(tenantId);
		this.organIds.get().clear();
		this.organIds.get().addAll(allOrgans.stream().map(Organization::getId).collect(Collectors.toSet()));

		if(StringUtils.isBlank(dayStr)){
			dayStr = nowDate.plusDays(-1).toString();
		}

		LocalDate day = LocalDate.parse(dayStr, DateUtil.dateFormatter);
		LocalDate monday = day.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue());

		//学员数据
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.STUDENT_REGISTRATION_NUM)){
			saveData(indexBaseMonthDataDao.getStudentRegistrationData(dayStr,tenantId), dayStr, IndexDataType.STUDENT_REGISTRATION_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.CHARGE_STUDENT_CHANGE_RATE)) {
			saveData(indexBaseMonthDataDao.getChargeStudentChangeData(dayStr,tenantId), dayStr, IndexDataType.CHARGE_STUDENT_CHANGE_RATE, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.ACTIVATION_RATE)) {
			saveData(indexBaseMonthDataDao.getStudentSignUpData(dayStr, nowDate.plusMonths(-6).toString(),tenantId), dayStr, IndexDataType.ACTIVATION_RATE, tenantId);
		}

		//运营数据
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.SCHOOL)) {
			saveData(indexBaseMonthDataDao.getSchoolData(dayStr,tenantId), dayStr, IndexDataType.SCHOOL, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.PROGRESS_MUSIC_GROUP_NUM)) {
			saveData(indexBaseMonthDataDao.getMusicData(dayStr,tenantId), dayStr, IndexDataType.PROGRESS_MUSIC_GROUP_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(TRANSACTION_TEACHER_NUM)) {
			Map<String, List<SimpleUserDto>> organPosition = employeePositionService.findOrganPosition(null, tenantId);
			List<SimpleUserDto> transactionTeachers = organPosition.get(SysUserRoleEnum.JOIN_TEACHER.name());
			Map<Integer, Integer> organTeacherNumMap = new HashMap<>();
			if (transactionTeachers != null) {
				for (SimpleUserDto transactionTeacher : transactionTeachers) {
					Set<Integer> organIds = Arrays.stream(transactionTeacher.getOrganIds().split(","))
												  .map(s -> Integer.valueOf(s))
												  .collect(Collectors.toSet());
					for (Integer organId : organIds) {
						if (organTeacherNumMap.containsKey(organId)) {
							organTeacherNumMap.put(organId, organTeacherNumMap.get(organId) + 1);
						} else {
							organTeacherNumMap.put(organId, 1);
						}
					}
				}
			}
			List<IndexBaseMonthData> datas = new ArrayList<>();
			Date month = DateUtil.stringToDate(dayStr, "yyyy-MM-dd");
			for (Map.Entry<Integer, Integer> organTeacherNumMapEntry : organTeacherNumMap.entrySet()) {
				IndexBaseMonthData data = new IndexBaseMonthData();
				data.setOrganId(organTeacherNumMapEntry.getKey());
				data.setMonth(month);
				BigDecimal num = new BigDecimal(organTeacherNumMapEntry.getValue());
				data.setTotalNum(num);
				data.setActivateNum(num);
				data.setPercent(num);
				datas.add(data);
			}
			saveData(datas, dayStr, IndexDataType.TRANSACTION_TEACHER_NUM, tenantId);
		}

		//人事数据
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.TEACHER_NUM)) {
			saveData(indexBaseMonthDataDao.getTeacherData(dayStr, null, null,tenantId), dayStr, IndexDataType.TEACHER_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.FULL_TIME_NUM)) {
			saveData(indexBaseMonthDataDao.getTeacherData(dayStr, JobNatureEnum.FULL_TIME, null,tenantId), dayStr, IndexDataType.FULL_TIME_NUM, tenantId);
		}
		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)) {
			saveData(indexBaseMonthDataDao.getGroupCourseData(dayStr, null, CourseStatusEnum.NOT_START,tenantId), dayStr, IndexDataType.SURPLUS_COURSE_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.SURPLUS_MUSIC_COURSE_NUM)) {
			saveData(indexBaseMonthDataDao.getGroupCourseData(dayStr, GroupType.MUSIC, CourseStatusEnum.NOT_START,tenantId), dayStr, IndexDataType.SURPLUS_MUSIC_COURSE_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.SURPLUS_VIP_COURSE_NUM)) {
			saveData(indexBaseMonthDataDao.getGroupCourseData(dayStr, GroupType.VIP, CourseStatusEnum.NOT_START,tenantId), dayStr, IndexDataType.SURPLUS_VIP_COURSE_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.SURPLUS_PRACTICE_COURSE_NUM)) {
			saveData(indexBaseMonthDataDao.getGroupCourseData(dayStr, GroupType.PRACTICE, CourseStatusEnum.NOT_START,tenantId), dayStr, IndexDataType.SURPLUS_PRACTICE_COURSE_NUM, tenantId);
		}

		//已消耗课时
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.OVER_COURSE_NUM)) {
			saveData(indexBaseMonthDataDao.getGroupSurplusCourseData(dayStr, null, CourseStatusEnum.OVER,tenantId), dayStr, IndexDataType.OVER_COURSE_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.OVER_MUSIC_COURSE_NUM)) {
			saveData(indexBaseMonthDataDao.getGroupSurplusCourseData(dayStr, GroupType.MUSIC, CourseStatusEnum.OVER,tenantId), dayStr, IndexDataType.OVER_MUSIC_COURSE_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.OVER_VIP_COURSE_NUM)) {
			saveData(indexBaseMonthDataDao.getGroupSurplusCourseData(dayStr, GroupType.VIP, CourseStatusEnum.OVER,tenantId), dayStr, IndexDataType.OVER_VIP_COURSE_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.OVER_PRACTICE_COURSE_NUM)) {
			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);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.HOMEWORK_SUBMIT_RATE)) {
			saveData(indexBaseMonthDataDao.getHomeworkData(dayStr, "submit",tenantId), monday.toString(), IndexDataType.HOMEWORK_SUBMIT_RATE, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.HOMEWORK_COMMENT_RATE)) {
			saveData(indexBaseMonthDataDao.getHomeworkData(dayStr, "comment",tenantId), monday.toString(), IndexDataType.HOMEWORK_COMMENT_RATE, tenantId);
		}

		//课程数据
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.MUSIC_GROUP_COURSE)) {
			saveData(indexBaseMonthDataDao.getGroupCourseDataWithGroup(dayStr, null, null, GroupType.MUSIC, null, null, null,tenantId), dayStr, IndexDataType.MUSIC_GROUP_COURSE, tenantId);
		}

		//小课数据统计
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(STUDENT_VIP_ORDER_NUM)) {
			saveData(indexBaseMonthDataDao.getStudentVipOrderNum(dayStr,tenantId), dayStr, IndexDataType.STUDENT_VIP_ORDER_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(STUDENT_THEORY_ORDER_NUM)) {
			saveData(indexBaseMonthDataDao.getStudentTheoryOrderNum(dayStr,tenantId), dayStr, IndexDataType.STUDENT_THEORY_ORDER_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(STUDENT_PRACTICE_ORDER_NUM)) {
			saveData(indexBaseMonthDataDao.getStudentPracticeOrderNum(dayStr,tenantId), dayStr, IndexDataType.STUDENT_PRACTICE_ORDER_NUM, tenantId);
		}

		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.VIP_GROUP_COURSE)) {
			List<IndexBaseMonthData> vipCourseData = indexBaseMonthDataDao.getGroupCourseDataWithGroup(dayStr, null, null, GroupType.VIP, null, null, null,tenantId);
			List<OrganVipGroupCategoryCourseNumDto> vipGroupCategoryCourseData = indexBaseMonthDataDao.getVipGroupCategoryCourseData(dayStr, null, null, GroupType.VIP, null, null, null,tenantId);
			Map<Integer, Map<String, Integer>> organCategoryCourseMap = new HashMap<>();
			if (!CollectionUtils.isEmpty(vipGroupCategoryCourseData)) {
				organCategoryCourseMap = vipGroupCategoryCourseData.stream().collect(Collectors.groupingBy(OrganVipGroupCategoryCourseNumDto::getOrganId, Collectors.toMap(OrganVipGroupCategoryCourseNumDto::getCategoryName, o -> o.getCourseNum())));
			}
			for (IndexBaseMonthData vipCourseDatum : vipCourseData) {
				if (organCategoryCourseMap.containsKey(vipCourseDatum.getOrganId())) {
					vipCourseDatum.setExtendInfo(JSON.toJSONString(organCategoryCourseMap.get(vipCourseDatum.getOrganId())));
				}
			}
			saveData(vipCourseData, dayStr, IndexDataType.VIP_GROUP_COURSE, tenantId);
		}

		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.VIP_GROUP_ONLINE_COURSE)) {
			List<IndexBaseMonthData> vipOnlineCourseData = indexBaseMonthDataDao.getGroupCourseDataWithGroup(dayStr, null, null, GroupType.VIP, null, TeachModeEnum.ONLINE, null,tenantId);
			List<OrganVipGroupCategoryCourseNumDto> vipGroupOnlineCategoryCourseData = indexBaseMonthDataDao.getVipGroupCategoryCourseData(dayStr, null, null, GroupType.VIP, null, TeachModeEnum.ONLINE, null,tenantId);
			Map<Integer, Map<String, Integer>> organOnlineCategoryCourseMap = new HashMap<>();
			if (!CollectionUtils.isEmpty(vipGroupOnlineCategoryCourseData)) {
				organOnlineCategoryCourseMap = vipGroupOnlineCategoryCourseData.stream().collect(Collectors.groupingBy(OrganVipGroupCategoryCourseNumDto::getOrganId, Collectors.toMap(OrganVipGroupCategoryCourseNumDto::getCategoryName, o -> o.getCourseNum())));
			}
			for (IndexBaseMonthData vipCourseDatum : vipOnlineCourseData) {
				if (organOnlineCategoryCourseMap.containsKey(vipCourseDatum.getOrganId())) {
					vipCourseDatum.setExtendInfo(JSON.toJSONString(organOnlineCategoryCourseMap.get(vipCourseDatum.getOrganId())));
				}
			}
			saveData(vipOnlineCourseData, dayStr, IndexDataType.VIP_GROUP_ONLINE_COURSE, tenantId);
		}

		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.VIP_GROUP_OFFLINE_COURSE)) {
			List<IndexBaseMonthData> vipOfflineCourseData = indexBaseMonthDataDao.getGroupCourseDataWithGroup(dayStr, null, null, GroupType.VIP, null, TeachModeEnum.OFFLINE, null,tenantId);
			List<OrganVipGroupCategoryCourseNumDto> vipGroupOfflineCategoryCourseData = indexBaseMonthDataDao.getVipGroupCategoryCourseData(dayStr, null, null, GroupType.VIP, null, TeachModeEnum.OFFLINE, null,tenantId);
			Map<Integer, Map<String, Integer>> organOfflineCategoryCourseMap = new HashMap<>();
			if (!CollectionUtils.isEmpty(vipGroupOfflineCategoryCourseData)) {
				organOfflineCategoryCourseMap = vipGroupOfflineCategoryCourseData.stream().collect(Collectors.groupingBy(OrganVipGroupCategoryCourseNumDto::getOrganId, Collectors.toMap(OrganVipGroupCategoryCourseNumDto::getCategoryName, o -> o.getCourseNum())));
			}
			for (IndexBaseMonthData vipCourseDatum : vipOfflineCourseData) {
				if (organOfflineCategoryCourseMap.containsKey(vipCourseDatum.getOrganId())) {
					vipCourseDatum.setExtendInfo(JSON.toJSONString(organOfflineCategoryCourseMap.get(vipCourseDatum.getOrganId())));
				}
			}
			saveData(vipOfflineCourseData, dayStr, IndexDataType.VIP_GROUP_OFFLINE_COURSE, tenantId);
		}

		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.PRACTICE_GROUP_COURSE)) {
			saveData(indexBaseMonthDataDao.getGroupCourseDataWithGroup(dayStr, null, null, GroupType.PRACTICE, null, null, null,tenantId), dayStr, IndexDataType.PRACTICE_GROUP_COURSE, tenantId);
		}

		//学员变动
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.ADD_STUDENT_REGISTRATION_NUM)) {
			saveData(indexBaseMonthDataDao.getAddStudentRegistrationData(dayStr,tenantId), dayStr, IndexDataType.ADD_STUDENT_REGISTRATION_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.MUSIC_GROUP_STUDENT)) {
			saveData(indexBaseMonthDataDao.getMusicStudentData(dayStr, null,tenantId), dayStr, IndexDataType.MUSIC_GROUP_STUDENT, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.NEWLY_STUDENT_NUM)) {
			saveData(null, nowDate.toString(), IndexDataType.NEWLY_STUDENT_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.QUIT_MUSIC_GROUP_STUDENT_NUM)) {
			saveData(null, nowDate.toString(), IndexDataType.QUIT_MUSIC_GROUP_STUDENT_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.VIP_PRACTICE_STUDENT_NUM)) {
			saveData(indexBaseMonthDataDao.getOtherStudentData(dayStr,tenantId), dayStr, IndexDataType.VIP_PRACTICE_STUDENT_NUM, tenantId);
		}
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.VIP_PRACTICE_ADD_STUDENT_NUM)) {
			saveData(indexBaseMonthDataDao.getVipPracticeAddStudentData(dayStr,tenantId), dayStr, IndexDataType.VIP_PRACTICE_ADD_STUDENT_NUM, tenantId);
		}

		//云教练相关
		//分部学员数量
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.ORGAN_TOTAL_STUDENT_NUM)) {
			saveData(indexBaseMonthDataDao.getOrgansStudentNumData(dayStr,tenantId), dayStr, IndexDataType.ORGAN_TOTAL_STUDENT_NUM, tenantId);
		}

		//会员数量
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.MEMBER_STUDENT_NUM)) {
			saveData(indexBaseMonthDataDao.getMemberStudentNumData(dayStr,tenantId), dayStr, IndexDataType.MEMBER_STUDENT_NUM, tenantId);
		}

		//新增会员数量
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.NEW_MEMBER_STUDENT_NUM)) {
			saveData(indexBaseMonthDataDao.getNewMemberStudentNumData(dayStr,tenantId), dayStr, IndexDataType.NEW_MEMBER_STUDENT_NUM, tenantId);
		}

		//试用会员数量
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.EXPERIENCE_MEMBER_STUDENT_NUM)) {
			saveData(indexBaseMonthDataDao.getExperienceMemberStudentNumData(dayStr,tenantId), dayStr, IndexDataType.EXPERIENCE_MEMBER_STUDENT_NUM, tenantId);
		}

		//云教练使用用户
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.CLOUD_STUDY_DAY_USE_STUDENT_NUM)) {
			saveData(indexBaseMonthDataDao.getCloudStudyDayUseStudentNumData(dayStr,tenantId), dayStr, IndexDataType.CLOUD_STUDY_DAY_USE_STUDENT_NUM, tenantId);
		}

		//活跃用户
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.CLOUD_STUDY_LIVELY_STUDENT_NUM)) {
			saveData(indexBaseMonthDataDao.getCloudStudyLivelyStudentNumData(dayStr,tenantId), dayStr, IndexDataType.CLOUD_STUDY_LIVELY_STUDENT_NUM, tenantId);
		}

		//云教练新增人数
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.CLOUD_STUDY_NEW_STUDENT_NUM)) {
			saveData(indexBaseMonthDataDao.getCloudStudyNewStudentNumData(dayStr,tenantId), dayStr, IndexDataType.CLOUD_STUDY_NEW_STUDENT_NUM, tenantId);
		}

		//云教练新用户人数
		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains(IndexDataType.CLOUD_NEW_STUDENT_NUM)) {
			List<Integer> studentIdList = studentRegistrationDao.findStudentIds(tenantId);
			if(!CollectionUtils.isEmpty(studentIdList)){
				saveData(studentDao.groupOrganId(null,studentIdList),LocalDate.now().toString(),IndexDataType.CLOUD_NEW_STUDENT_NUM, tenantId);
			}
		}
	}

	/**
	 * @describe 处理并保存每日数据
	 * @author Joburgess
	 * @date 2021/1/11 0011
	 * @return void
	 */
	private void saveData(List<IndexBaseMonthData> dataList, String dayStr, IndexDataType indexDataType, Integer tenantId){
		Date date = DateUtil.stringToDate(dayStr, "yyyy-MM-dd");
		if(Objects.isNull(dataList)){
			dataList = new ArrayList<>();
		}
		Set<Integer> hasOrganIds = dataList.stream().map(IndexBaseMonthData::getOrganId).collect(Collectors.toSet());

		boolean specialType = IndexDataType.NEWLY_STUDENT_NUM.equals(indexDataType)||IndexDataType.QUIT_MUSIC_GROUP_STUDENT_NUM.equals(indexDataType);
		Set<Integer> ignoreOrganIds = new HashSet<>();
		if(specialType){
			List<IndexBaseMonthData> indexBaseDatas = indexBaseMonthDataDao.getWithDayAndDataType(dayStr, indexDataType, tenantId);
			if(!CollectionUtils.isEmpty(indexBaseDatas)) {
				ignoreOrganIds = indexBaseDatas.stream().map(IndexBaseMonthData::getOrganId).collect(Collectors.toSet());
			}
		}

		for (Integer organId : this.organIds.get()) {
			if(hasOrganIds.contains(organId)){
				continue;
			}
			if(specialType&&ignoreOrganIds.contains(organId)){
				continue;
			}
			dataList.add(new IndexBaseMonthData(date, organId, tenantId));
		}
		if(!IndexDataType.NEWLY_STUDENT_NUM.equals(indexDataType) && !IndexDataType.QUIT_MUSIC_GROUP_STUDENT_NUM.equals(indexDataType)){
			indexBaseMonthDataDao.deleteWithMonthAndType(Arrays.asList(dayStr), indexDataType, tenantId);
		}
		if(!CollectionUtils.isEmpty(dataList)){
			indexBaseMonthDataDao.batchInsertWithDataType(dataList, indexDataType);
		}
	}

	@Override
	public Map<String, Object> getIndexErrData(String organIdsStr, IndexErrorType errorType) {
		//只筛选指定时间之后的数据
		String startTime = DateUtil.format(DateUtil.getFirstDayOfMonth(DateUtil.addMonths(new Date(), -2)),DateUtil.ISO_EXPANDED_DATE_FORMAT);

		Set<Integer> organIds = null;
		if(StringUtils.isNotBlank(organIdsStr)){
			organIds = Arrays.stream(organIdsStr.split(",")).map(Integer::new).collect(Collectors.toSet());
		}
		List<IndexErrInfoDto> all = new ArrayList<>();
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		//如果当前用户只有教务老师角色，那么只能看到他所管理的课程组的信息
		List<Long> classGroupIds = null;
		Integer educationUserId = null;
		Boolean onlyForRole = employeePositionService.onlyForRole(SysUserRoleEnum.EDUCATION,sysUser.getId(),sysUser.getIsSuperAdmin());
		if (onlyForRole) {
			//获取教务老师关联的班级列表
			classGroupIds = classGroupDao.queryGroupClassGroupIds(sysUser.getId());
			educationUserId = sysUser.getId();
		}
		Integer tenantId = TenantContextHolder.getTenantId();
		if(IndexErrorType.MUSIC_PATROL.equals(errorType)){
			IndexErrInfoDto<IndexErrInfoDto> one = new IndexErrInfoDto<>();
			one.setErrorType(IndexErrorType.MUSIC_PATROL);
			one.setDesc(IndexErrorType.MUSIC_PATROL.getMsg());
			List<IndexErrInfoDto> oneChild = new ArrayList<>();

			//基础技能班学员数量异常
			oneChild.add(new IndexErrInfoDto(IndexErrorType.HIGH_CLASS_STUDENT_LESS_THAN_THREE, IndexErrorType.HIGH_CLASS_STUDENT_LESS_THAN_THREE.getMsg(), indexBaseMonthDataDao.countLessThenThreeClassGroupNum(organIds,educationUserId,tenantId), null));

			//乐团巡查事项异常
			int errInspection = indexBaseMonthDataDao.queryErrInspection(organIds,startTime,tenantId);
			oneChild.add(new IndexErrInfoDto(IndexErrorType.MUSIC_PATROL_ITEM, IndexErrorType.MUSIC_PATROL_ITEM.getMsg(),errInspection, null));

			//未加入任何班级学员
			IndexErrInfoDto noClassMusicGroupStudentInfo = indexBaseMonthDataDao.getNoClassMusicGroupStudentInfo(organIds,educationUserId,tenantId);
			noClassMusicGroupStudentInfo.setDesc(IndexErrorType.NO_CLASS_MUSIC_GROUP_STUDENT_INFO.getMsg());
			oneChild.add(noClassMusicGroupStudentInfo);

			one.setNum(oneChild.stream().mapToInt(IndexErrInfoDto::getNum).sum());
			one.setResult(oneChild);
			all.add(one);
		}

		if(IndexErrorType.STUDENT_INFO.equals(errorType)){

			IndexErrInfoDto<IndexErrInfoDto> two = new IndexErrInfoDto<>();
			two.setErrorType(IndexErrorType.STUDENT_INFO);
			two.setDesc(IndexErrorType.STUDENT_INFO.getMsg());
			List<IndexErrInfoDto> twoChild = new ArrayList<>();
			//学员请假异常提醒(只提醒本月的异常)
			int studentErrorLeave = 0;
			String studentErrorLeaveNum = sysTenantConfigService.getTenantConfigValue(SysConfigService.STUDENT_ERROR_LEAVE_NUM, tenantId);
			if(StringUtils.isNotEmpty(studentErrorLeaveNum)){
				String format1 = DateUtil.format(new Date(), DateUtil.ISO_YEAR_MONTH_FORMAT);
				studentErrorLeave = indexBaseMonthDataDao.countStudentErrorLeave(organIds, format1, classGroupIds,Integer.parseInt(studentErrorLeaveNum),tenantId);
			}

			twoChild.add(new IndexErrInfoDto(IndexErrorType.STUDENT_ERROR_LEAVE, IndexErrorType.STUDENT_ERROR_LEAVE.getMsg(),studentErrorLeave , null));

			//未缴费学员数
			twoChild.add(new IndexErrInfoDto(IndexErrorType.STUDENT_ARREARAGE, IndexErrorType.STUDENT_ARREARAGE.getMsg(), indexBaseMonthDataDao.countNoPaymentStudentNum(organIds,educationUserId,0,tenantId), Arrays.asList(educationUserId)));

			//申请退团学员数
			List<Long> quitGroupNum = indexBaseMonthDataDao.queryApplyForQuitGroupNum(organIds,educationUserId,tenantId);
			twoChild.add(new IndexErrInfoDto(IndexErrorType.STUDENT_APPLY_FOR_QUIT_MUSIC_GROUP, IndexErrorType.STUDENT_APPLY_FOR_QUIT_MUSIC_GROUP.getMsg(), quitGroupNum.size(),  quitGroupNum));

			//学员已排课时长未消耗完
			Map<String, Object> params = new HashMap<>();
			params.put("organId", organIdsStr);
			params.put("tenantId", tenantId);
			twoChild.add(new IndexErrInfoDto(IndexErrorType.HAS_FREE_COURSE_TIMES, IndexErrorType.HAS_FREE_COURSE_TIMES.getMsg(), musicGroupDao.countHasFreeCourseTimes(params), null));

			//乐团学员会员到期首页提醒
//			List<StudentRegistration> studentRegistrations = studentRegistrationDao.queryMemberEndAutoQuitMusic(null,educationUserId,organIdsStr);
//			IndexErrInfoDto noClassMusicGroupStudentInfo = new IndexErrInfoDto();
//			Set<String> musicGroupIds = studentRegistrations.stream().map(e -> e.getMusicGroupId()).collect(Collectors.toSet());
//			Set<Integer> userIds = studentRegistrations.stream().map(e -> e.getUserId()).collect(Collectors.toSet());
//			noClassMusicGroupStudentInfo.setErrorType(IndexErrorType.NO_MEMBER_STUDENT_INFO);
//			noClassMusicGroupStudentInfo.setNum(musicGroupIds.size());
//			noClassMusicGroupStudentInfo.setNum2(userIds.size());
//			noClassMusicGroupStudentInfo.setDesc(IndexErrorType.NO_MEMBER_STUDENT_INFO.getMsg());
//			twoChild.add(noClassMusicGroupStudentInfo);
			two.setNum(twoChild.stream().mapToInt(IndexErrInfoDto::getNum).sum());
			two.setResult(twoChild);
			all.add(two);
		}

		if(IndexErrorType.TEACHER_INFO.equals(errorType)){
			IndexErrInfoDto<IndexErrInfoDto> three = new IndexErrInfoDto<>();
			three.setErrorType(IndexErrorType.TEACHER_INFO);
			three.setDesc(IndexErrorType.TEACHER_INFO.getMsg());
			List<IndexErrInfoDto> threeChild = new ArrayList<>();

			Integer userId = null;
			if (onlyForRole) {
				userId = sysUser.getId();
			}

			//乐团巡查任务未计划
			int inspectionItem = indexBaseMonthDataDao.queryInspectionItem(organIdsStr,startTime,userId,tenantId);
			threeChild.add(new IndexErrInfoDto(IndexErrorType.INSPECTION_ITEM, IndexErrorType.INSPECTION_ITEM.getMsg(),inspectionItem, null));

			//乐团巡查任务未提交
			int inspectionItemPlan = indexBaseMonthDataDao.queryInspectionItemPlan(organIdsStr,startTime,tenantId);
			threeChild.add(new IndexErrInfoDto(IndexErrorType.INSPECTION_ITEM_PLAN, IndexErrorType.INSPECTION_ITEM_PLAN.getMsg(),inspectionItemPlan, null));

			//回访任务未完成
			int studentVisit = indexBaseMonthDataDao.queryStudentVisit(organIdsStr,startTime,userId,tenantId);
			threeChild.add(new IndexErrInfoDto(IndexErrorType.STUDENT_VISIT, IndexErrorType.STUDENT_VISIT.getMsg(),studentVisit, null));

			three.setNum(threeChild.stream().mapToInt(IndexErrInfoDto::getNum).sum());
			three.setResult(threeChild);
			all.add(three);
		}

		if(IndexErrorType.ATTENDANCE_SERVE.equals(errorType)){
			IndexErrInfoDto<IndexErrInfoDto> four = new IndexErrInfoDto<>();
			four.setErrorType(IndexErrorType.ATTENDANCE_SERVE);
			four.setDesc(IndexErrorType.ATTENDANCE_SERVE.getMsg());
			List<IndexErrInfoDto> fourChild = new ArrayList<>();

			//课程考勤异常
			int attendanceError = 0;
			int noAttendance = 0;
			//课程时间安排异常
			int courseTimeError = 0;
			if(classGroupIds == null || classGroupIds.size() > 0){
				attendanceError = indexBaseMonthDataDao.getAttendanceError(organIds,startTime,classGroupIds,tenantId);
				noAttendance = indexBaseMonthDataDao.getNoAttendance(organIds,startTime,classGroupIds,tenantId);
				String courseStartTimeError = sysTenantConfigService.getTenantConfigValue(SysConfigService.COURSE_START_TIME_ERROR, tenantId);
				String courseEndTimeError = sysTenantConfigService.getTenantConfigValue(SysConfigService.COURSE_END_TIME_ERROR, tenantId);
				if(StringUtils.isNotEmpty(courseStartTimeError) && StringUtils.isNotEmpty(courseEndTimeError)){
					courseTimeError = indexBaseMonthDataDao.getCourseTimeError(organIds,classGroupIds,courseStartTimeError,courseEndTimeError,tenantId);
				}
			}
			fourChild.add(new IndexErrInfoDto(IndexErrorType.COURSE_TIME_ERROR, IndexErrorType.COURSE_TIME_ERROR.getMsg(), courseTimeError, null));

			fourChild.add(new IndexErrInfoDto(IndexErrorType.TEACHER_EXCEPTION_ATTENDANCE, IndexErrorType.TEACHER_EXCEPTION_ATTENDANCE.getMsg(), attendanceError, null));

			//课程异常
			fourChild.add(new IndexErrInfoDto(IndexErrorType.TEACHER_NOT_A_CLASS, IndexErrorType.TEACHER_NOT_A_CLASS.getMsg(), noAttendance, null));

			//只适用大雅
			if(tenantId == 1){
				//服务指标异常
				Map<String, Object> params = new HashMap<>();
				LocalDate nowDate = LocalDateTime.now(DateUtil.zoneId).toLocalDate();
				LocalDate monDayDate = nowDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue()).plusDays(-7);
				LocalDate sunDayDate = nowDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.SUNDAY.getValue()).plusDays(-7);
				params.put("organIds", organIds);
				params.put("monday",monDayDate.toString());
				params.put("sunday",sunDayDate.toString());
				params.put("jobNature", JobNatureEnum.FULL_TIME);
				params.put("unDone",1);
				params.put("reminded",0);
				params.put("tenantId",tenantId);
				int serveErrTeacherNum = studentExtracurricularExercisesSituationDao.countTeacherServeInfo(params);
				fourChild.add(new IndexErrInfoDto(IndexErrorType.TEACHER_SERVE_ERROR, IndexErrorType.TEACHER_SERVE_ERROR.getMsg(), serveErrTeacherNum, null));
			}
			four.setNum(fourChild.stream().mapToInt(IndexErrInfoDto::getNum).sum());
			four.setResult(fourChild);
			all.add(four);
		}

		Map<String, Object> result = new HashMap<>(2);
		result.put("totalNum", all.stream().mapToInt(IndexErrInfoDto::getNum).sum());
		result.put("data", all);
		return result;
	}

	@Override
	public List<IndexErrorDataExportDto> exportIndexErrData(String organIdsStr, IndexErrorType errorType) {
		List<IndexErrorDataExportDto> results = new ArrayList<>();

		//只筛选指定时间之后的数据
		String startTime = DateUtil.format(DateUtil.getFirstDayOfMonth(DateUtil.addMonths(new Date(), -2)),DateUtil.ISO_EXPANDED_DATE_FORMAT);

		Set<Integer> organIds = null;
		if(StringUtils.isNotBlank(organIdsStr)){
			organIds = Arrays.stream(organIdsStr.split(",")).map(Integer::new).collect(Collectors.toSet());
		}
		Date date = new Date();

		SysUser sysUser = sysUserFeignService.queryUserInfo();
		Boolean onlyForRole = employeePositionService.onlyForRole(EDUCATION, sysUser.getId(), sysUser.getIsSuperAdmin());
		//如果当前用户只有教务老师角色，那么只能看到他所管理的课程组的信息
		List<Long> classGroupIds = null;
		Integer educationUserId = null;
		if (onlyForRole) {
			//获取教务老师关联的班级列表
			classGroupIds = classGroupDao.queryGroupClassGroupIds(sysUser.getId());
			educationUserId = sysUser.getId();
		}

		//基础技能班学员数量异常
		Map<Integer, Integer> highClassStudentLessThanThreeMap = new HashMap<>();
		//乐团巡查事项异常
		Map<Integer, Integer> musicPatrolItemMap = new HashMap<>();
		//未加入任何班级学员
		Map<Integer, Integer> organNoClassMusicGroupStudentNumMap = new HashMap<>();
		//未缴费学员数
		Map<Integer, Integer> studentNotPaymentMap = new HashMap<>();
		//申请退团学员数
		Map<Integer, Integer> studentApplyForQuitMusicGroupMap = new HashMap<>();
		//预计课酬较低
		Map<Integer, Integer> teacherExpectSalaryBeLowMap = new HashMap<>();
		//课程时间安排异常
		Map<Integer, Integer> courseTimeErrorMap = new HashMap<>();
		//乐团巡查任务未计划
		Map<Integer, Integer> inspectionItemMap = new HashMap<>();
		//乐团巡查任务未提交
		Map<Integer, Integer> inspectionItemPlanMap = new HashMap<>();
		//回访任务未完成
		Map<Integer, Integer> studentVisitMap = new HashMap<>();
		//课程考勤异常
		Map<Integer, Integer> teacherExceptionAttendanceMap = new HashMap<>();
		//课程异常
		Map<Integer, Integer> teacherNotAClassMap = new HashMap<>();
		//服务指标异常
		Map<Integer, Integer> teacherServeErrorMap = new HashMap<>();
		//学员请假异常
		Map<Integer, Integer> studentErrorLeaveMap = new HashMap<>();
		//会员过期学员数
		Map<Integer, Integer> noMemberStudentMap = new HashMap<>();
		
		Integer tenantId = TenantContextHolder.getTenantId();

		if(IndexErrorType.MUSIC_PATROL.equals(errorType)||Objects.isNull(errorType)){
			//基础技能班学员数量异常
			List<Map<Integer, Integer>> highClassStudentLessThanThreeMapList = indexBaseMonthDataDao.countLessThenThreeClassOrganGroupNum(organIds, educationUserId, tenantId);
			highClassStudentLessThanThreeMap = MapUtil.mapListToMap(highClassStudentLessThanThreeMapList, Integer.class, Integer.class);

			//乐团巡查事项异常
			List<Map<Integer, Integer>> musicPatrolItemMapList = indexBaseMonthDataDao.queryOrganErrInspection(organIds, startTime, tenantId);
			musicPatrolItemMap = MapUtil.mapListToMap(musicPatrolItemMapList, Integer.class, Integer.class);

			//未加入任何班级学员
			List<Map<Integer, Integer>> organNoClassMusicGroupStudentNumMapList = indexBaseMonthDataDao.getOrganNoClassMusicGroupStudentNum(organIds, educationUserId, tenantId);
			organNoClassMusicGroupStudentNumMap = MapUtil.mapListToMap(organNoClassMusicGroupStudentNumMapList, Integer.class, Integer.class);
		}

		if(IndexErrorType.STUDENT_INFO.equals(errorType)||Objects.isNull(errorType)){
			//学员异常请假数
			List<Map<Integer, Integer>> studentErrorLeaveMapList = indexBaseMonthDataDao.countOrganStudentErrorLeave(organIds, classGroupIds, tenantId);
			studentErrorLeaveMap = MapUtil.mapListToMap(studentErrorLeaveMapList, Integer.class, Integer.class);

			//未缴费学员数
			List<Map<Integer, Integer>> studentNotPaymentMapList = indexBaseMonthDataDao.countOrganNoPaymentStudentNum(organIds, educationUserId, tenantId);
			studentNotPaymentMap = MapUtil.mapListToMap(studentNotPaymentMapList, Integer.class, Integer.class);

			//申请退团学员数
			List<Map<Integer, Integer>> studentApplyForQuitMusicGroupMapList = indexBaseMonthDataDao.queryOrganApplyForQuitGroupNum(organIds, educationUserId, tenantId);
			studentApplyForQuitMusicGroupMap = MapUtil.mapListToMap(studentApplyForQuitMusicGroupMapList, Integer.class, Integer.class);

			//会员过期学员数
			List<Map<Integer, Integer>> memberEndAutoQuitMusicMapList = studentRegistrationDao.queryOrganMemberEndAutoQuitMusic(null, educationUserId,organIds);
			noMemberStudentMap = MapUtil.mapListToMap(memberEndAutoQuitMusicMapList, Integer.class, Integer.class);
		}

		if(IndexErrorType.TEACHER_INFO.equals(errorType)||Objects.isNull(errorType)){
			String monthStr = DateUtil.format(date, DateUtil.ISO_YEAR_MONTH_FORMAT);

			//全职未离职老师
			//预计课酬较低
			List<Map<Integer, Integer>> teacherExpectSalaryBeLowMapList = indexBaseMonthDataDao.queryOrganLowTeacherSalary(organIdsStr, monthStr, tenantId);
			teacherExpectSalaryBeLowMap = MapUtil.mapListToMap(teacherExpectSalaryBeLowMapList, Integer.class, Integer.class);

			//课程时间安排异常
			if(classGroupIds == null || classGroupIds.size() > 0){
				List<Map<Integer, Integer>> courseTimeErrorMapList = indexBaseMonthDataDao.getOrganCourseTimeError(organIds, classGroupIds, tenantId);
				courseTimeErrorMap = MapUtil.mapListToMap(courseTimeErrorMapList, Integer.class, Integer.class);
			}

			//乐团巡查任务未计划
			List<Map<Integer, Integer>> inspectionItemMapList = indexBaseMonthDataDao.queryOrganInspectionItem(organIdsStr, startTime, null, tenantId);
			inspectionItemMap = MapUtil.mapListToMap(inspectionItemMapList, Integer.class, Integer.class);

			//乐团巡查任务未提交
			List<Map<Integer, Integer>> inspectionItemPlanMapList = indexBaseMonthDataDao.queryOrganInspectionItemPlan(organIdsStr, startTime, tenantId);
			inspectionItemPlanMap = MapUtil.mapListToMap(inspectionItemPlanMapList, Integer.class, Integer.class);

			//回访任务未完成
			List<Map<Integer, Integer>> studentVisitMapList = indexBaseMonthDataDao.queryOrganStudentVisit(organIdsStr, startTime, null, tenantId);
			studentVisitMap = MapUtil.mapListToMap(studentVisitMapList, Integer.class, Integer.class);
		}

		if(IndexErrorType.ATTENDANCE_SERVE.equals(errorType)||Objects.isNull(errorType)){
			if(classGroupIds == null || classGroupIds.size() > 0){
				//课程考勤异常
				List<Map<Integer, Integer>> teacherExceptionAttendanceMapList = indexBaseMonthDataDao.getOrganAttendanceError(organIds, startTime, classGroupIds, tenantId);
				teacherExceptionAttendanceMap = MapUtil.mapListToMap(teacherExceptionAttendanceMapList, Integer.class, Integer.class);

				//课程异常
				List<Map<Integer, Integer>> teacherNotAClassMapList = indexBaseMonthDataDao.getOrganNoAttendance(organIds, startTime, classGroupIds, tenantId);
				teacherNotAClassMap = MapUtil.mapListToMap(teacherNotAClassMapList, Integer.class, Integer.class);
			}

			//服务指标异常
			Map<String, Object> params = new HashMap<>();
			LocalDate nowDate = LocalDateTime.now(DateUtil.zoneId).toLocalDate();
			LocalDate monDayDate = nowDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue()).plusDays(-7);
			LocalDate sunDayDate = nowDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.SUNDAY.getValue()).plusDays(-7);
			params.put("organIds", organIds);
			params.put("monday",monDayDate.toString());
			params.put("sunday",sunDayDate.toString());
			params.put("jobNature", JobNatureEnum.FULL_TIME);
			params.put("unDone",1);
			params.put("reminded",0);
			params.put("tenantId",TenantContextHolder.getTenantId());
			List<Map<Integer, Integer>> teacherServeErrorMapList = indexBaseMonthDataDao.countOrganTeacherServeInfo(params);
			teacherServeErrorMap = MapUtil.mapListToMap(teacherServeErrorMapList, Integer.class, Integer.class);
		}

		List<Organization> organs = organizationService.findOrgans(new ArrayList<>(organIds),tenantId);

		IndexErrorDataExportDto totalData = new IndexErrorDataExportDto();
		totalData.setOrganName("总计");
		for (Organization organ : organs) {
			IndexErrorDataExportDto indexErrorData = new IndexErrorDataExportDto();
			indexErrorData.setOrganId(organ.getId());
			indexErrorData.setOrganName(organ.getName());

			int total = 0;
			//基础技能班学员数量异常
			if(highClassStudentLessThanThreeMap.containsKey(organ.getId())){
				indexErrorData.setHighClassStudentLessThanThreeNum(highClassStudentLessThanThreeMap.get(organ.getId()));
			}
			total += indexErrorData.getHighClassStudentLessThanThreeNum();
			totalData.setHighClassStudentLessThanThreeNum(totalData.getHighClassStudentLessThanThreeNum() + indexErrorData.getHighClassStudentLessThanThreeNum());
			//乐团巡查事项异常
			if(musicPatrolItemMap.containsKey(organ.getId())){
				indexErrorData.setMusicPatrolItem(musicPatrolItemMap.get(organ.getId()));
			}
			total += indexErrorData.getMusicPatrolItem();
			totalData.setMusicPatrolItem(totalData.getMusicPatrolItem() + indexErrorData.getMusicPatrolItem());
			//未加入任何班级学员
			if(organNoClassMusicGroupStudentNumMap.containsKey(organ.getId())){
				indexErrorData.setNoClassMusicGroupStudentInfo(organNoClassMusicGroupStudentNumMap.get(organ.getId()));
			}
			total += indexErrorData.getNoClassMusicGroupStudentInfo();
			totalData.setNoClassMusicGroupStudentInfo(totalData.getNoClassMusicGroupStudentInfo() + indexErrorData.getNoClassMusicGroupStudentInfo());
			//学员请假异常数
			if(studentErrorLeaveMap.containsKey(organ.getId())){
				indexErrorData.setStudentErrorLeave(studentErrorLeaveMap.get(organ.getId()));
			}
			total += indexErrorData.getStudentErrorLeave();
			totalData.setStudentErrorLeave(totalData.getStudentErrorLeave() + indexErrorData.getStudentErrorLeave());
			//未缴费学员数
			if(studentNotPaymentMap.containsKey(organ.getId())){
				indexErrorData.setStudentNotPayment(studentNotPaymentMap.get(organ.getId()));
			}
			total += indexErrorData.getStudentNotPayment();
			totalData.setStudentNotPayment(totalData.getStudentNotPayment() + indexErrorData.getStudentNotPayment());
			//申请退团学员数
			if(studentApplyForQuitMusicGroupMap.containsKey(organ.getId())){
				indexErrorData.setStudentApplyForQuitMusicGroup(studentApplyForQuitMusicGroupMap.get(organ.getId()));
			}
			total += indexErrorData.getStudentApplyForQuitMusicGroup();
			totalData.setStudentApplyForQuitMusicGroup(totalData.getStudentApplyForQuitMusicGroup() + indexErrorData.getStudentApplyForQuitMusicGroup());
			//会员已过期数量
			if(noMemberStudentMap.containsKey(organ.getId())){
				indexErrorData.setNoMemberStudentNum(noMemberStudentMap.get(organ.getId()));
			}
			total += indexErrorData.getNoMemberStudentNum();
			totalData.setNoMemberStudentNum(totalData.getNoMemberStudentNum() + indexErrorData.getNoMemberStudentNum());
			//预计课酬较低
			if(teacherExpectSalaryBeLowMap.containsKey(organ.getId())){
				indexErrorData.setTeacherExpectSalaryBeLow(teacherExpectSalaryBeLowMap.get(organ.getId()));
			}
			total += indexErrorData.getTeacherExpectSalaryBeLow();
			totalData.setTeacherExpectSalaryBeLow(totalData.getTeacherExpectSalaryBeLow() + indexErrorData.getTeacherExpectSalaryBeLow());
			//课程时间安排异常
			if(courseTimeErrorMap.containsKey(organ.getId())){
				indexErrorData.setCourseTimeError(courseTimeErrorMap.get(organ.getId()));
			}
			total += indexErrorData.getCourseTimeError();
			totalData.setCourseTimeError(totalData.getCourseTimeError() + indexErrorData.getCourseTimeError());
			//乐团巡查任务未计划
			if(inspectionItemMap.containsKey(organ.getId())){
				indexErrorData.setInspectionItem(inspectionItemMap.get(organ.getId()));
			}
			total += indexErrorData.getInspectionItem();
			totalData.setInspectionItem(totalData.getInspectionItem() + indexErrorData.getInspectionItem());
			//乐团巡查任务未提交
			if(inspectionItemPlanMap.containsKey(organ.getId())){
				indexErrorData.setInspectionItemPlan(inspectionItemPlanMap.get(organ.getId()));
			}
			total += indexErrorData.getInspectionItemPlan();
			totalData.setInspectionItemPlan(totalData.getInspectionItemPlan() + indexErrorData.getInspectionItemPlan());
			//回访任务未完成
			if(studentVisitMap.containsKey(organ.getId())){
				indexErrorData.setStudentVisit(studentVisitMap.get(organ.getId()));
			}
			total += indexErrorData.getStudentVisit();
			totalData.setStudentVisit(totalData.getStudentVisit() + indexErrorData.getStudentVisit());
			//课程考勤异常
			if(teacherExceptionAttendanceMap.containsKey(organ.getId())){
				indexErrorData.setTeacherExceptionAttendance(teacherExceptionAttendanceMap.get(organ.getId()));
			}
			total += indexErrorData.getTeacherExceptionAttendance();
			totalData.setTeacherExceptionAttendance(totalData.getTeacherExceptionAttendance() + indexErrorData.getTeacherExceptionAttendance());
			//课程异常
			if(teacherNotAClassMap.containsKey(organ.getId())){
				indexErrorData.setTeacherNotAClass(teacherNotAClassMap.get(organ.getId()));
			}
			total += indexErrorData.getTeacherNotAClass();
			totalData.setTeacherNotAClass(totalData.getTeacherNotAClass() + indexErrorData.getTeacherNotAClass());
			//服务指标异常
			if(teacherServeErrorMap.containsKey(organ.getId())){
				indexErrorData.setTeacherServeError(teacherServeErrorMap.get(organ.getId()));
			}
			total += indexErrorData.getTeacherServeError();
			totalData.setTeacherServeError(totalData.getTeacherServeError() + indexErrorData.getTeacherServeError());
			indexErrorData.setTotal(total);
			totalData.setTotal(totalData.getTotal() + indexErrorData.getTotal());
			results.add(indexErrorData);
		}
		results.add(totalData);

		return results;
	}

	@Override
	public List<IndexErrInfoDto> getRemindMatterData(String organIds) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (sysUser == null) {
			throw new BizException("用户信息获取失败");
		}
		Integer tenantId = TenantContextHolder.getTenantId();

		Set<Integer> organIdSet = null;
		if(StringUtils.isNotBlank(organIds)){
			organIdSet = Arrays.stream(organIds.split(",")).map(Integer::new).collect(Collectors.toSet());
		}
		//当前用户是否是分部经理
		Boolean onlyForRole = employeePositionService.onlyForRole(SysUserRoleEnum.EDUCATION,sysUser.getId(),sysUser.getIsSuperAdmin());
		Integer educationUserId = null;
		if (onlyForRole) {
			//获取教务老师关联的班级列表
			educationUserId = sysUser.getId();
		}
		Date date = new Date();

		List<IndexErrInfoDto> result = new ArrayList<>();

		//未缴费学员数
		result.add(new IndexErrInfoDto(IndexErrorType.STUDENT_NOT_PAYMENT, IndexErrorType.STUDENT_NOT_PAYMENT.getMsg(), indexBaseMonthDataDao.countNoPaymentStudentNum(organIdSet,educationUserId, 1, tenantId), Arrays.asList(educationUserId)));

		String monthStr = DateUtil.format(date, DateUtil.ISO_YEAR_MONTH_FORMAT);
		//全职未离职老师
		//预计课酬较低
		int lowTeacherSalary = indexBaseMonthDataDao.queryLowTeacherSalary(organIds,monthStr, tenantId);
		result.add(new IndexErrInfoDto(IndexErrorType.TEACHER_EXPECT_SALARY_BE_LOW, IndexErrorType.TEACHER_EXPECT_SALARY_BE_LOW.getMsg(),lowTeacherSalary, null));

		//乐团展演计划提醒
		List<MusicGroupPerformance> musicGroupPerformances = musicGroupPerformanceDao.findNoStart(educationUserId,organIds);
		IndexErrInfoDto infoDto1 = new IndexErrInfoDto();
		infoDto1.setErrorType(IndexErrorType.MUSIC_GROUP_PERFORMANCE);
		infoDto1.setNum(musicGroupPerformances.stream().map(e -> e.getMusicGroupId()).collect(Collectors.toSet()).size());
		infoDto1.setNum2(musicGroupPerformances.stream().map(e -> e.getId()).collect(Collectors.toSet()).size());
		infoDto1.setDesc(IndexErrorType.MUSIC_GROUP_PERFORMANCE.getMsg());
		result.add(infoDto1);

		//乐团剩余时长未排课
		List<String> musicGroupIds = musicGroupDao.queryHasSubCourseTimes(organIds,tenantId);
		result.add(new IndexErrInfoDto(IndexErrorType.MUSIC_GROUP_HAS_COURSE_TIMES, IndexErrorType.MUSIC_GROUP_HAS_COURSE_TIMES.getMsg(),musicGroupIds.size(), null));
		return result;
	}

	@Override
	public Map<String,Boolean> hasIndexErrData(String organIdsStr) {
		Integer tenantId = TenantContextHolder.getTenantId();
		String startTime = DateUtil.format(DateUtil.getFirstDayOfMonth(DateUtil.addMonths(new Date(), -2)),DateUtil.ISO_EXPANDED_DATE_FORMAT);

		Map<String,Boolean> resultMap = new HashMap<>();
		Set<Integer> organIds = null;
		if(StringUtils.isNotBlank(organIdsStr)){
			organIds = Arrays.stream(organIdsStr.split(",")).map(Integer::new).collect(Collectors.toSet());
		}
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		Boolean onlyForRole = employeePositionService.onlyForRole(SysUserRoleEnum.EDUCATION,sysUser.getId(),sysUser.getIsSuperAdmin());
		//如果当前用户只有教务老师角色，那么只能看到他所管理的课程组的信息
		List<Long> classGroupIds = null;
		Integer educationUserId = null;
		if (onlyForRole) {
			//获取教务老师关联的班级列表
			classGroupIds = classGroupDao.queryGroupClassGroupIds(sysUser.getId());
			educationUserId = sysUser.getId();
		}
		Date date = new Date();
		boolean flag1 = false;
		int countLessThenThreeClassGroupNum = indexBaseMonthDataDao.countLessThenThreeClassGroupNum(organIds,educationUserId, tenantId);
		if(countLessThenThreeClassGroupNum > 0){
			flag1 = true;
		}
		if(!flag1){
			int errInspection = indexBaseMonthDataDao.queryErrInspection(organIds,startTime, tenantId);
			if(errInspection > 0){
				flag1 = true;
			}
		}
		if(!flag1){
			IndexErrInfoDto noClassMusicGroupStudentInfo = indexBaseMonthDataDao.getNoClassMusicGroupStudentInfo(organIds,educationUserId, tenantId);
			if(Objects.nonNull(noClassMusicGroupStudentInfo) && noClassMusicGroupStudentInfo.getNum() > 0){
				flag1 = true;
			}
		}
		resultMap.put("musicPatrol",flag1);
		boolean flag2 = false;
		if(!flag2){
			//学员请假异常提醒(获取前两个月的)
			int studentErrorLeave = 0;
			String studentErrorLeaveNum = sysTenantConfigService.getTenantConfigValue(SysConfigService.STUDENT_ERROR_LEAVE_NUM, tenantId);
			if(StringUtils.isNotEmpty(studentErrorLeaveNum)){
				String format1 = DateUtil.format(new Date(), DateUtil.ISO_YEAR_MONTH_FORMAT);
				studentErrorLeave = indexBaseMonthDataDao.countStudentErrorLeave(organIds, format1, classGroupIds,Integer.parseInt(studentErrorLeaveNum), tenantId);
			}
			if(studentErrorLeave > 0){
				flag2 = true;
			}
		}
		if(!flag2){
			List<Long> quitGroupNum = indexBaseMonthDataDao.queryApplyForQuitGroupNum(organIds,educationUserId, tenantId);
			if(quitGroupNum.size() > 0){
				flag2 = true;
			}
		}

		if(!flag2){
			int countNoPaymentStudentNum = indexBaseMonthDataDao.countNoPaymentStudentNum(organIds,educationUserId, 0, tenantId);
			if(countNoPaymentStudentNum > 0){
				flag2 = true;
			}
		}
		if(!flag2){
			String configValue = sysTenantConfigService.getTenantConfigValue(SysConfigService.PUSH_MEMBER_RENEW_QUIT,tenantId);
			if (StringUtils.isEmpty(configValue)) {
				configValue = "15";
			}
			List<StudentRegistration> studentRegistrations = studentRegistrationDao.queryMemberEndAutoQuitMusic(configValue,educationUserId,organIdsStr);
			if(studentRegistrations.size() > 0){
				flag2 = true;
			}
		}
		if(!flag2){
			Map<String, Object> params = new HashMap<String, Object>(2);
			params.put("organId",organIdsStr);
			params.put("tenantId",tenantId);
			Integer hasFreeCourseTimes = musicGroupDao.countHasFreeCourseTimes(params);
			if(hasFreeCourseTimes != null && hasFreeCourseTimes > 0){
				flag2 = true;
			}
		}
		resultMap.put("studentInfo",flag2);
		boolean flag3 = false;

		Integer userId = null;
		if (onlyForRole) {
			userId = sysUser.getId();
		}

		if(!flag3){
			int inspectionItem = indexBaseMonthDataDao.queryInspectionItem(organIdsStr,startTime,userId, tenantId);
			if(inspectionItem > 0){
				flag3 = true;
			}
		}
		if(!flag3){
			int inspectionItemPlan = indexBaseMonthDataDao.queryInspectionItemPlan(organIdsStr,startTime, tenantId);
			if(inspectionItemPlan > 0){
				flag3 = true;
			}
		}
		if(!flag3){
			int studentVisit = indexBaseMonthDataDao.queryStudentVisit(organIdsStr,startTime,userId, tenantId);
			if(studentVisit > 0){
				flag3 = true;
			}
		}
		resultMap.put("teacherInfo",flag3);

		boolean flag4 = false;
		if(!flag4){
			int courseTimeError = 0;
			if(classGroupIds == null || classGroupIds.size() > 0){
				String courseStartTimeError = sysTenantConfigService.getTenantConfigValue(SysConfigService.COURSE_START_TIME_ERROR, tenantId);
				String courseEndTimeError = sysTenantConfigService.getTenantConfigValue(SysConfigService.COURSE_END_TIME_ERROR, tenantId);
				if(StringUtils.isNotEmpty(courseStartTimeError) && StringUtils.isNotEmpty(courseEndTimeError)){
					courseTimeError = indexBaseMonthDataDao.getCourseTimeError(organIds,classGroupIds,courseStartTimeError,courseEndTimeError, tenantId);
				}
			}
			if(courseTimeError > 0){
				flag4 = true;
			}
		}
		if(!flag4){
			int attendanceError = 0;
			if(classGroupIds == null || classGroupIds.size() > 0){
				attendanceError = indexBaseMonthDataDao.getAttendanceError(organIds,startTime,classGroupIds, tenantId);
			}
			if(attendanceError > 0){
				flag4 = true;
			}
		}
		if(!flag4){
			int noAttendance = 0;
			if(classGroupIds == null || classGroupIds.size() > 0){
				noAttendance = indexBaseMonthDataDao.getNoAttendance(organIds,startTime,classGroupIds, tenantId);
			}
			if(noAttendance > 0){
				flag4 = true;
			}
		}
		//服务指标只用于大雅
		if(tenantId == 1 && !flag4){
			Map<String, Object> params = new HashMap<>();
			LocalDate nowDate = LocalDateTime.now(DateUtil.zoneId).toLocalDate();
			LocalDate monDayDate = nowDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue()).plusDays(-7);
			LocalDate sunDayDate = nowDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.SUNDAY.getValue()).plusDays(-7);
			params.put("organIds", organIds);
			params.put("monday",monDayDate.toString());
			params.put("sunday",sunDayDate.toString());
			params.put("jobNature", JobNatureEnum.FULL_TIME);
			params.put("unDone",1);
			params.put("reminded",0);
			int serveErrTeacherNum = studentExtracurricularExercisesSituationDao.countTeacherServeInfo(params);
			if(serveErrTeacherNum > 0){
				flag4 = true;
			}
		}
		resultMap.put("attendanceServe",flag4);

		boolean flag5 = false;
		if(!flag5){
			String monthStr = DateUtil.format(date, DateUtil.ISO_YEAR_MONTH_FORMAT);
			int lowTeacherSalary = indexBaseMonthDataDao.queryLowTeacherSalary(organIdsStr,monthStr, tenantId);
			if(lowTeacherSalary > 0){
				flag5 = true;
			}
		}
		if(!flag5){
			int countNoPaymentStudentNum = indexBaseMonthDataDao.countNoPaymentStudentNum(organIds,educationUserId, 1, tenantId);
			if(countNoPaymentStudentNum > 0){
				flag5 = true;
			}
		}
		if(!flag5){
			//获取关联的乐团列表
			List<String> musicGroupIds = musicGroupDao.queryIdsByEduIdAndOrganIds(educationUserId,organIdsStr,tenantId);
			if(musicGroupIds.size() > 0){
				String configValue1 = sysConfigDao.findConfigValue("push_create_payment_calender");
				date = new Date();
				String format = DateUtil.format(date, DateUtil.DEFAULT_PATTERN);
				List<Long> calenderIds = musicGroupPaymentCalenderDao.queryEndIds(configValue1, format,musicGroupIds);
				if(calenderIds.size() > 0){
					flag5 = true;
				}
			}
		}
		if(!flag5){
			if(!flag5){
				List<StudentRegistration> studentRegistrations = studentRegistrationDao.queryMemberEndAutoQuitMusic(null,educationUserId,organIdsStr);
				if(studentRegistrations.size() > 0){
					flag5 = true;
				}
			}
		}
		if(!flag5){
			if(!flag5){
				List<String> strings = musicGroupDao.queryHasSubCourseTimes(organIdsStr, tenantId);
				if(strings.size() > 0){
					flag5 = true;
				}
			}
		}
		resultMap.put("remindMatterData",flag5);

		return resultMap;
	}

	@Override
	public PageInfo<EduOrganStudentDataDto> organStudentOverView(List<Integer> organIds, OrganCloudStudyStudentDataQueryInfo queryInfo) {
		PageInfo<EduOrganStudentDataDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
		List<Organization> organs = organizationService.findOrgans(organIds, queryInfo.getTenantId());
		pageInfo.setTotal(organs.size());

		if(CollectionUtils.isEmpty(organs)){
			return pageInfo;
		}
		Set<String> dataTypes = new HashSet<String>(){{
			add(CLOUD_STUDY_LIVELY_STUDENT_NUM.getCode());add(MEMBER_STUDENT_NUM.getCode());add(NEW_MEMBER_STUDENT_NUM.getCode());
			add(ORGAN_TOTAL_STUDENT_NUM.getCode());add(CLOUD_STUDY_NEW_STUDENT_NUM.getCode());add(CLOUD_STUDY_DAY_USE_STUDENT_NUM.getCode());}};


		List<IndexBaseMonthData> indexBaseDatas = indexBaseMonthDataDao.getAllIndexBaseData(new HashSet<>(organIds), dataTypes, queryInfo.getDate(), queryInfo.getDate(), queryInfo.getTenantId());

		Map<Integer, Integer> organsStudentNumMap = indexBaseDatas.stream().filter(i->ORGAN_TOTAL_STUDENT_NUM.equals(i.getDataType())).collect(Collectors.toMap(IndexBaseMonthData::getOrganId, i->i.getActivateNum().intValue(), (i1, i2)->i1));

		Map<Integer, Integer> organsVipStudentNumMap = indexBaseDatas.stream().filter(i->MEMBER_STUDENT_NUM.equals(i.getDataType())).collect(Collectors.toMap(IndexBaseMonthData::getOrganId, i->i.getActivateNum().intValue(), (i1, i2)->i1));

//		Map<Integer, Integer> organsEVipStudentNumMap = indexBaseDatas.stream().filter(i->EXPERIENCE_MEMBER_STUDENT_NUM.equals(i.getDataType())).collect(Collectors.toMap(IndexBaseMonthData::getOrganId, i->i.getActivateNum().intValue(), (i1, i2)->i1));

		Map<Integer, Integer> organCloudStudyLivelyStudentNumMap =indexBaseDatas.stream().filter(i->CLOUD_STUDY_LIVELY_STUDENT_NUM.equals(i.getDataType())).collect(Collectors.toMap(IndexBaseMonthData::getOrganId, i->i.getActivateNum().intValue(), (i1, i2)->i1));

		Map<Integer, Integer> organsNewMemberStudentNumMap = indexBaseDatas.stream().filter(i->NEW_MEMBER_STUDENT_NUM.equals(i.getDataType())).collect(Collectors.toMap(IndexBaseMonthData::getOrganId, i->i.getActivateNum().intValue(), (i1, i2)->i1));

		Map<Integer, Integer> organsNewCloudStudyStudentNumMap = indexBaseDatas.stream().filter(i->CLOUD_STUDY_NEW_STUDENT_NUM.equals(i.getDataType())).collect(Collectors.toMap(IndexBaseMonthData::getOrganId, i->i.getActivateNum().intValue(), (i1, i2)->i1));

		Map<Integer, Integer> organsCloudStudyDayUseStudentNumMap = indexBaseDatas.stream().filter(i->CLOUD_STUDY_DAY_USE_STUDENT_NUM.equals(i.getDataType())).collect(Collectors.toMap(IndexBaseMonthData::getOrganId, i->i.getActivateNum().intValue(), (i1, i2)->i1));

		List<EduOrganStudentDataDto> result = new ArrayList<>();

		for (Organization organ : organs) {
			EduOrganStudentDataDto organStudentVipData = new EduOrganStudentDataDto();
			organStudentVipData.setOrganId(organ.getId());
			organStudentVipData.setOrganName(organ.getName());
			if(organsStudentNumMap.containsKey(organ.getId())){
				organStudentVipData.setTotalStudentNum(organsStudentNumMap.get(organ.getId()));
			}
			if(organsVipStudentNumMap.containsKey(organ.getId())){
				organStudentVipData.setVipStudentNum(organsVipStudentNumMap.get(organ.getId()));
			}
			if(organCloudStudyLivelyStudentNumMap.containsKey(organ.getId())){
				organStudentVipData.setCloudStudyLivelyStudentNum(organCloudStudyLivelyStudentNumMap.get(organ.getId()));
			}
			if(organsNewMemberStudentNumMap.containsKey(organ.getId())){
				organStudentVipData.setNewMemberStudentNum(organsNewMemberStudentNumMap.get(organ.getId()));
			}
			if(organsCloudStudyDayUseStudentNumMap.containsKey(organ.getId())){
				organStudentVipData.setCloudStudyUseStudentNum(organsCloudStudyDayUseStudentNumMap.get(organ.getId()));
			}
			if(organsNewCloudStudyStudentNumMap.containsKey(organ.getId())){
				organStudentVipData.setNewCloudStudyStudentNum(organsNewCloudStudyStudentNumMap.get(organ.getId()));
			}
			if(organStudentVipData.getCloudStudyLivelyStudentNum()>0&&organStudentVipData.getTotalStudentNum()>0){
				organStudentVipData.setCloudStudyLivelyStudentDuty(new BigDecimal(organStudentVipData.getCloudStudyLivelyStudentNum()).divide(new BigDecimal(organStudentVipData.getTotalStudentNum()), 4, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).floatValue());
			}
			if(organStudentVipData.getCloudStudyUseStudentNum()>0&&organStudentVipData.getTotalStudentNum()>0){
				organStudentVipData.setCloudStudyUseStudentDuty(new BigDecimal(organStudentVipData.getCloudStudyUseStudentNum()).divide(new BigDecimal(organStudentVipData.getTotalStudentNum()), 4, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).floatValue());
			}
			if(organStudentVipData.getVipStudentNum()>0&&organStudentVipData.getTotalStudentNum()>0){
				organStudentVipData.setVipStudentDuty(new BigDecimal(organStudentVipData.getVipStudentNum()).divide(new BigDecimal(organStudentVipData.getTotalStudentNum()), 4, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).floatValue());
			}
			result.add(organStudentVipData);
		}

		Comparator<EduOrganStudentDataDto> comparing = null;
		if(StringUtils.isNotBlank(queryInfo.getCloudStudyLivelyStudentNum())){
			if(Objects.isNull(comparing)){
				comparing = Comparator.comparing(EduOrganStudentDataDto::getCloudStudyLivelyStudentNum, "ASC".equals(queryInfo.getCloudStudyLivelyStudentNum())?Comparator.naturalOrder():Comparator.reverseOrder());
			}else{
				comparing.thenComparing(EduOrganStudentDataDto::getCloudStudyLivelyStudentNum, "ASC".equals(queryInfo.getCloudStudyLivelyStudentNum())?Comparator.naturalOrder():Comparator.reverseOrder());
			}
		}
		if(StringUtils.isNotBlank(queryInfo.getVipStudentNum())){
			if(Objects.isNull(comparing)){
				comparing = Comparator.comparing(EduOrganStudentDataDto::getVipStudentNum, "ASC".equals(queryInfo.getVipStudentNum())?Comparator.naturalOrder():Comparator.reverseOrder());
			}else{
				comparing.thenComparing(EduOrganStudentDataDto::getVipStudentNum, "ASC".equals(queryInfo.getVipStudentNum())?Comparator.naturalOrder():Comparator.reverseOrder());
			}
		}
		if(StringUtils.isNotBlank(queryInfo.geteVipStudentNum())){
			if(Objects.isNull(comparing)){
				comparing = Comparator.comparing(EduOrganStudentDataDto::geteVipStudentNum, "ASC".equals(queryInfo.geteVipStudentNum())?Comparator.naturalOrder():Comparator.reverseOrder());
			}else{
				comparing.thenComparing(EduOrganStudentDataDto::geteVipStudentNum, "ASC".equals(queryInfo.geteVipStudentNum())?Comparator.naturalOrder():Comparator.reverseOrder());
			}
		}
		if(StringUtils.isNotBlank(queryInfo.getNewMemberStudentNum())){
			if(Objects.isNull(comparing)){
				comparing = Comparator.comparing(EduOrganStudentDataDto::getNewMemberStudentNum, "ASC".equals(queryInfo.getNewMemberStudentNum())?Comparator.naturalOrder():Comparator.reverseOrder());
			}else{
				comparing.thenComparing(EduOrganStudentDataDto::getNewMemberStudentNum, "ASC".equals(queryInfo.getNewMemberStudentNum())?Comparator.naturalOrder():Comparator.reverseOrder());
			}
		}
		if(StringUtils.isNotBlank(queryInfo.getCloudStudyLivelyStudentDuty())){
			if(Objects.isNull(comparing)){
				comparing = Comparator.comparing(EduOrganStudentDataDto::getCloudStudyLivelyStudentDuty, "ASC".equals(queryInfo.getCloudStudyLivelyStudentDuty())?Comparator.naturalOrder():Comparator.reverseOrder());
			}else{
				comparing.thenComparing(EduOrganStudentDataDto::getCloudStudyLivelyStudentDuty, "ASC".equals(queryInfo.getCloudStudyLivelyStudentDuty())?Comparator.naturalOrder():Comparator.reverseOrder());
			}
		}
		if(StringUtils.isNotBlank(queryInfo.getCloudStudyUseStudentDuty())){
			if(Objects.isNull(comparing)){
				comparing = Comparator.comparing(EduOrganStudentDataDto::getCloudStudyUseStudentDuty, "ASC".equals(queryInfo.getCloudStudyUseStudentDuty())?Comparator.naturalOrder():Comparator.reverseOrder());
			}else{
				comparing.thenComparing(EduOrganStudentDataDto::getCloudStudyUseStudentDuty, "ASC".equals(queryInfo.getCloudStudyUseStudentDuty())?Comparator.naturalOrder():Comparator.reverseOrder());
			}
		}
		if(StringUtils.isNotBlank(queryInfo.getVipStudentDuty())){
			if(Objects.isNull(comparing)){
				comparing = Comparator.comparing(EduOrganStudentDataDto::getVipStudentDuty, "ASC".equals(queryInfo.getVipStudentDuty())?Comparator.naturalOrder():Comparator.reverseOrder());
			}else{
				comparing.thenComparing(EduOrganStudentDataDto::getVipStudentDuty, "ASC".equals(queryInfo.getVipStudentDuty())?Comparator.naturalOrder():Comparator.reverseOrder());
			}
		}

		if(Objects.isNull(comparing)){
			comparing = Comparator.comparing(EduOrganStudentDataDto::getOrganId);
		}

		result.sort(comparing);
		for (int i = 0; i < result.size(); i++) {
			result.get(i).setIndex(i+1);
		}
		result = result.stream().skip(pageInfo.getOffset()).limit(pageInfo.getLimit()).sorted(Comparator.comparing(EduOrganStudentDataDto::getIndex)).collect(Collectors.toList());
		pageInfo.setRows(result);
		return pageInfo;
	}
}
