Przeglądaj źródła

feat:首页数据

Joburgess 4 lat temu
rodzic
commit
7a8fb24d4d

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

@@ -1,9 +1,61 @@
 package com.ym.mec.biz.dal.dao;
 
 import com.ym.mec.biz.dal.entity.IndexBaseMonthData;
+import com.ym.mec.biz.dal.enums.IndexDataType;
 import com.ym.mec.common.dal.BaseDAO;
+import org.apache.ibatis.annotations.Param;
+import org.apache.poi.ss.formula.functions.Index;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
 
 public interface IndexBaseMonthDataDao extends BaseDAO<Long, IndexBaseMonthData> {
 
-	
+    int batchInsert(@Param("datas") List<IndexBaseMonthData> datas);
+
+    int batchInsertWithDataType(@Param("datas") List<IndexBaseMonthData> datas,
+                                @Param("dataType")IndexDataType dataType);
+
+    int deleteWithMonthAndType(@Param("months") Collection months,
+                               @Param("dataType")IndexDataType dataType);
+
+    /**
+     * @describe 获取首页统计数据
+     * @author Joburgess
+     * @date 2021/1/8 0008
+     * @param organIds:
+     * @param dataTypes:
+     * @param startMonth:
+     * @param endMonth:
+     * @return java.util.List<com.ym.mec.biz.dal.entity.IndexBaseMonthData>
+     */
+	List<IndexBaseMonthData> getIndexBaseData(@Param("organIds") Set<Integer> organIds,
+                                              @Param("dataTypes") Set<String> dataTypes,
+                                              @Param("startMonth") String startMonth,
+                                              @Param("endMonth") String endMonth);
+
+    /**
+     * @describe 统计系统中指定时间段的学员注册数据
+     * @author Joburgess
+     * @date 2021/1/7 0007
+     * @param startMonth:
+     * @param endMonth:
+     * @return java.util.List<com.ym.mec.biz.dal.dto.IndexBaseMonthDto>
+     */
+    List<IndexBaseMonthData> getStudentSignUpData(@Param("startMonth") String startMonth,
+                                                  @Param("endMonth") String endMonth);
+
+    /**
+     * @describe 统计作业布置数据
+     * @author Joburgess
+     * @date 2021/1/7 0007
+     * @param startMonth:
+     * @param endMonth:
+     * @return java.util.List<com.ym.mec.biz.dal.dto.IndexBaseMonthDto>
+     */
+    List<IndexBaseMonthData> getHomeworkDate(@Param("startMonth") String startMonth,
+                                             @Param("endMonth") String endMonth,
+                                             @Param("type") String type);
+
 }

+ 0 - 42
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/IndexDao.java

@@ -1,42 +0,0 @@
-package com.ym.mec.biz.dal.dao;
-
-import com.ym.mec.biz.dal.entity.IndexBaseMonthData;
-import org.apache.ibatis.annotations.Param;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * @Author Joburgess
- * @Date 2021/1/7 0007
- **/
-public interface IndexDao {
-
-    /**
-     * @describe 统计系统中指定时间段的学员注册数据
-     * @author Joburgess
-     * @date 2021/1/7 0007
-     * @param organIds:
-     * @param startMonth:
-     * @param endMonth:
-     * @return java.util.List<com.ym.mec.biz.dal.dto.IndexBaseMonthDto>
-     */
-    List<IndexBaseMonthData> getStudentSignUpData(@Param("organIds") Set<Integer> organIds,
-                                                  @Param("startMonth") String startMonth,
-                                                  @Param("endMonth") String endMonth);
-
-    /**
-     * @describe 统计作业布置数据
-     * @author Joburgess
-     * @date 2021/1/7 0007
-     * @param organIds:
-     * @param startMonth:
-     * @param endMonth:
-     * @return java.util.List<com.ym.mec.biz.dal.dto.IndexBaseMonthDto>
-     */
-    List<IndexBaseMonthData> getHomeworkDate(@Param("organIds") Set<Integer> organIds,
-                                                  @Param("startMonth") String startMonth,
-                                                  @Param("endMonth") String endMonth,
-                                                  @Param("type") String type);
-
-}

+ 22 - 2
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/IndexBaseDto.java

@@ -1,6 +1,7 @@
 package com.ym.mec.biz.dal.dto;
 
 import com.ym.mec.biz.dal.entity.IndexBaseMonthData;
+import com.ym.mec.biz.dal.enums.IndexDataType;
 import com.ym.mec.common.constant.CommonConstants;
 import org.springframework.util.CollectionUtils;
 
@@ -13,6 +14,8 @@ import java.util.List;
  */
 public class IndexBaseDto {
 
+    private IndexDataType dataType;
+
     private String title;
 
     private BigDecimal percent;
@@ -26,12 +29,25 @@ public class IndexBaseDto {
         this.title = title;
     }
 
+    public IndexBaseDto(IndexDataType dataType, String title) {
+        this.dataType = dataType;
+        this.title = title;
+    }
+
     public IndexBaseDto(String title, BigDecimal percent, List<IndexBaseMonthData> indexMonthData) {
         this.title = title;
         this.percent = percent;
         this.indexMonthData = indexMonthData;
     }
 
+    public IndexDataType getDataType() {
+        return dataType;
+    }
+
+    public void setDataType(IndexDataType dataType) {
+        this.dataType = dataType;
+    }
+
     public String getTitle() {
         return title;
     }
@@ -56,8 +72,12 @@ public class IndexBaseDto {
         this.indexMonthData = indexMonthData;
         if(!CollectionUtils.isEmpty(indexMonthData)){
             BigDecimal total = indexMonthData.stream().map(IndexBaseMonthData::getTotalNum).reduce(BigDecimal.ZERO, BigDecimal::add);
-            BigDecimal activateNum = indexMonthData.stream().map(IndexBaseMonthData::getActivateNum).reduce(BigDecimal.ZERO, BigDecimal::add);
-            this.percent = activateNum.divide(total, CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN);
+            if(IndexDataType.ACTIVATION_RATE.equals(dataType)){
+                BigDecimal activateNum = indexMonthData.stream().map(IndexBaseMonthData::getActivateNum).reduce(BigDecimal.ZERO, BigDecimal::add);
+                this.percent = activateNum.divide(total, CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN);
+            }else{
+                this.percent = total;
+            }
         }
     }
 }

+ 11 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/IndexBaseMonthData.java

@@ -1,6 +1,6 @@
 package com.ym.mec.biz.dal.entity;
 
-import org.apache.commons.lang3.builder.ToStringBuilder;
+import com.ym.mec.biz.dal.enums.IndexDataType;
 
 import java.math.BigDecimal;
 import java.util.Date;
@@ -28,6 +28,8 @@ public class IndexBaseMonthData {
 	/** 最终结果 */
 	private BigDecimal percent;
 
+	private IndexDataType dataType;
+
 	private Date createTime;
 
 	private Date updateTime;
@@ -80,6 +82,14 @@ public class IndexBaseMonthData {
 		this.percent = percent;
 	}
 
+	public IndexDataType getDataType() {
+		return dataType;
+	}
+
+	public void setDataType(IndexDataType dataType) {
+		this.dataType = dataType;
+	}
+
 	public Date getCreateTime() {
 		return createTime;
 	}

+ 59 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/IndexDataType.java

@@ -0,0 +1,59 @@
+package com.ym.mec.biz.dal.enums;
+
+import com.ym.mec.common.enums.BaseEnum;
+
+/**
+ * @Author Joburgess
+ * @Date 2021/1/8 0008
+ **/
+public enum IndexDataType implements BaseEnum<String, IndexDataType> {
+    SCHOOL("SCHOOL","合作单位"),
+    MUSIC_GROUP_NUM("MUSIC_GROUP_NUM","乐团数量"),
+    MUSIC_GROUP_STUDENT("MUSIC_GROUP_STUDENT","乐团学员"),
+    OTHER_STUDENT("OTHER_STUDENT","其他学员"),
+    ACTIVATION_RATE("ACTIVATION_RATE","激活率"),
+    HOMEWORK_CREATE_RATE("HOMEWORK_CREATE_RATE","作业布置率"),
+    HOMEWORK_SUBMIT_RATE("HOMEWORK_SUBMIT_RATE","作业提交率"),
+    HOMEWORK_COMMENT_RATE("HOMEWORK_COMMENT_RATE","作业点评率"),
+    SHOULD_INCOME_MONEY("SHOULD_INCOME_MONEY","应收金额"),
+    ANTICIPATED_INCOME_MONEY("ANTICIPATED_INCOME_MONEY","预收金额"),
+    SHOULD_EXPEND_MONEY("SHOULD_EXPEND_MONEY","预付金额"),
+    ANTICIPATED_EXPEND_MONEY("ANTICIPATED_EXPEND_MONEY","应付金额"),
+    REVENUE_MONEY("REVENUE_MONEY","营收金额"),
+    TEACHER_NUM("TEACHER_NUM","老师总数"),
+    FULL_TIME_NUM("FULL_TIME_NUM","全职人数"),
+    PART_TIME_NUM("PART_TIME_NUM","兼职人数"),
+    DIMISSION_NUM("DIMISSION_NUM","离职人数"),
+    NEWLY_STUDENT_NUM("NEWLY_STUDENT_NUM","新增学员"),
+    QUIT_MUSIC_GROUP_STUDENT_NUM("QUIT_MUSIC_GROUP_STUDENT_NUM","退团学员"),
+    STUDENT_CONVERSION("STUDENT_CONVERSION","学员转化"),
+    MUSIC_GROUP_COURSE("MUSIC_GROUP_COURSE","乐团课"),
+    VIP_GROUP_COURSE("VIP_GROUP_COURSE","VIP课"),
+    PRACTICE_GROUP_COURSE("PRACTICE_GROUP_COURSE","网管课");
+
+    private String code;
+
+    private String msg;
+
+    IndexDataType(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+    @Override
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+}

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

@@ -1,9 +1,17 @@
 package com.ym.mec.biz.service;
 
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.ym.mec.biz.dal.dto.IndexBaseDto;
 import com.ym.mec.biz.dal.entity.IndexBaseMonthData;
 import com.ym.mec.common.service.BaseService;
 
 public interface IndexBaseMonthDataService extends BaseService<Long, IndexBaseMonthData> {
 
+    List<IndexBaseDto> getIndexBaseData(String dataType, String organIds, String startMonth, String endMonth);
+
+    Map<String, List<IndexBaseDto>> indexBaseDataTask(String startMonth, String endMonth);
+
 }

+ 0 - 17
mec-biz/src/main/java/com/ym/mec/biz/service/IndexService.java

@@ -1,17 +0,0 @@
-package com.ym.mec.biz.service;
-
-import com.ym.mec.biz.dal.dto.IndexBaseDto;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @Author Joburgess
- * @Date 2021/1/7 0007
- **/
-public interface IndexService {
-
-    Map<String, List<IndexBaseDto>> getIndexBaseData(Set<String> dataType, String organIds, String startMonth, String endMonth);
-
-}

+ 97 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/IndexBaseMonthDataServiceImpl.java

@@ -1,12 +1,21 @@
 package com.ym.mec.biz.service.impl;
 
+import com.ym.mec.biz.dal.dto.IndexBaseDto;
+import com.ym.mec.biz.dal.enums.IndexDataType;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.util.date.DateUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 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.util.CollectionUtils;
+
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBaseMonthData> implements IndexBaseMonthDataService {
@@ -18,5 +27,92 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 	public BaseDAO<Long, IndexBaseMonthData> getDAO() {
 		return indexBaseMonthDataDao;
 	}
-	
+
+	@Override
+	public List<IndexBaseDto> getIndexBaseData(String dataTypesStr, String organIdsStr, String startMonth, String endMonth) {
+		List<IndexBaseDto> result = new ArrayList<>();
+
+		if(StringUtils.isBlank(startMonth)){
+			LocalDateTime nowDateTime = LocalDateTime.now();
+			startMonth = nowDateTime.getYear() + "-01";
+			endMonth = null;
+		}
+		Set<Integer> organIds = null;
+		if(StringUtils.isNotBlank(organIdsStr)){
+			organIds = Arrays.stream(organIdsStr.split(",")).map(Integer::new).collect(Collectors.toSet());
+		}
+		Set<String> dataTypes = null;
+		if(StringUtils.isNotBlank(dataTypesStr)){
+			dataTypes = Arrays.stream(dataTypesStr.split(",")).collect(Collectors.toSet());
+		}
+
+
+		List<IndexBaseMonthData> indexBaseDatas = indexBaseMonthDataDao.getIndexBaseData(organIds, dataTypes, startMonth, endMonth);
+		if(CollectionUtils.isEmpty(indexBaseDatas)){
+			return result;
+		}
+
+		Map<IndexDataType, List<IndexBaseMonthData>> typeDateMap = indexBaseDatas.stream().collect(Collectors.groupingBy(IndexBaseMonthData::getDataType));
+		for (Map.Entry<IndexDataType, List<IndexBaseMonthData>> typeDateMapEntry : typeDateMap.entrySet()) {
+			IndexBaseDto indexBaseData = new IndexBaseDto(typeDateMapEntry.getKey(),typeDateMapEntry.getKey().getMsg());
+			indexBaseData.setIndexMonthData(typeDateMapEntry.getValue());
+			result.add(indexBaseData);
+		}
+
+		return result;
+	}
+
+	@Override
+	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;
+		}
+
+		countUserSignUpDate(startMonth, endMonth);
+
+		countHomeworkDate(startMonth, endMonth);
+
+		return result;
+	}
+
+	private void countUserSignUpDate(String startMonth, String endMonth){
+		List<IndexBaseMonthData> dataList = indexBaseMonthDataDao.getStudentSignUpData(startMonth, endMonth);
+		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.ACTIVATION_RATE);
+		indexBaseMonthDataDao.batchInsertWithDataType(dataList, IndexDataType.ACTIVATION_RATE);
+	}
+
+	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);
+
+		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);
+
+
+		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);
+	}
 }

+ 0 - 109
mec-biz/src/main/java/com/ym/mec/biz/service/impl/IndexServiceImpl.java

@@ -1,109 +0,0 @@
-package com.ym.mec.biz.service.impl;
-
-import com.ym.mec.biz.dal.dao.IndexDao;
-import com.ym.mec.biz.dal.dto.IndexBaseDto;
-import com.ym.mec.biz.service.IndexService;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.time.LocalDateTime;
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * @Author Joburgess
- * @Date 2021/1/7 0007
- */
-@Service
-public class IndexServiceImpl implements IndexService {
-    
-    @Autowired
-    private IndexDao indexDao;
-
-    @Override
-    public Map<String, List<IndexBaseDto>> getIndexBaseData(Set<String> dataTypes, String organIdsStr, 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;
-        }
-        Set<Integer> organIds = null;
-        if(StringUtils.isNotBlank(organIdsStr)){
-            organIds = Arrays.stream(organIdsStr.split(",")).map(Integer::new).collect(Collectors.toSet());
-        }
-
-        if(dataTypes.contains("ALL") || dataTypes.contains("OPERATION_DATA")){
-            //运营数据
-            List<IndexBaseDto> operationData = new LinkedList<>();
-            operationData.add(new IndexBaseDto("合作单位"));
-            operationData.add(new IndexBaseDto("乐团数量"));
-            operationData.add(new IndexBaseDto("乐团学员"));
-            operationData.add(new IndexBaseDto("其他学员"));
-            result.put("OPERATION_DATA", operationData);
-        }
-
-        if(dataTypes.contains("ALL") || dataTypes.contains("BUSINESS_DATA")){
-            //业务数据
-            List<IndexBaseDto> businessData = new LinkedList<>();
-            businessData.add(getUserSignUpDate(new IndexBaseDto("激活率"), organIds, startMonth, endMonth));
-            businessData.add(getHomeworkDate(new IndexBaseDto("作业布置率"), organIds, startMonth, endMonth, "assign"));
-            businessData.add(getHomeworkDate(new IndexBaseDto("作业提交率"), organIds, startMonth, endMonth, "submit"));
-            businessData.add(getHomeworkDate(new IndexBaseDto("作业点评率"), organIds, startMonth, endMonth, "comment"));
-            result.put("BUSINESS_DATA", businessData);
-        }
-
-        if(dataTypes.contains("ALL") || dataTypes.contains("FINANCE_DATA")){
-            //财务数据
-            List<IndexBaseDto> financeData = new LinkedList<>();
-            financeData.add(new IndexBaseDto("应收金额"));
-            financeData.add(new IndexBaseDto("预收金额"));
-            financeData.add(new IndexBaseDto("预付金额"));
-            financeData.add(new IndexBaseDto("应付金额"));
-            financeData.add(new IndexBaseDto("营收金额"));
-            result.put("FINANCE_DATA", financeData);
-        }
-
-        if(dataTypes.contains("ALL") || dataTypes.contains("PERSONNEL_DATA")){
-            //人事数据
-            List<IndexBaseDto> personnelData = new LinkedList<>();
-            personnelData.add(new IndexBaseDto("老师总数"));
-            personnelData.add(new IndexBaseDto("全职人数"));
-            personnelData.add(new IndexBaseDto("兼职人数"));
-            personnelData.add(new IndexBaseDto("离职人数"));
-            result.put("PERSONNEL_DATA", personnelData);
-        }
-
-        if(dataTypes.contains("ALL") || dataTypes.contains("STUDENT_VARIATION")){
-            //学员变动
-            List<IndexBaseDto> studentVariation = new LinkedList<>();
-            studentVariation.add(new IndexBaseDto("新增学员"));
-            studentVariation.add(new IndexBaseDto("退团学员"));
-            studentVariation.add(new IndexBaseDto("学员转化"));
-            result.put("STUDENT_VARIATION", studentVariation);
-        }
-
-        if(dataTypes.contains("ALL") || dataTypes.contains("COURSE_DATA")){
-            //本月课程
-            List<IndexBaseDto> courseData = new LinkedList<>();
-            courseData.add(new IndexBaseDto("乐团课"));
-            courseData.add(new IndexBaseDto("VIP课"));
-            courseData.add(new IndexBaseDto("网管课"));
-            result.put("COURSE_DATA", courseData);
-        }
-
-        return result;
-    }
-
-    private IndexBaseDto getUserSignUpDate(IndexBaseDto indexBaseData, Set<Integer> organIds, String startMonth, String endMonth){
-        indexBaseData.setIndexMonthData(indexDao.getStudentSignUpData(organIds, startMonth, endMonth));
-        return indexBaseData;
-    }
-
-    private IndexBaseDto getHomeworkDate(IndexBaseDto indexBaseData, Set<Integer> organIds, String startMonth, String endMonth, String type){
-        indexBaseData.setIndexMonthData(indexDao.getHomeworkDate(organIds, startMonth, endMonth, type));
-        return indexBaseData;
-    }
-}

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

@@ -13,6 +13,7 @@
 		<result column="total_num_" property="totalNum" />
 		<result column="activate_num_" property="activateNum" />
 		<result column="percent_" property="percent" />
+		<result column="data_type_" property="dataType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
 		<result column="create_time_" property="createTime" />
 		<result column="update_time_" property="updateTime" />
 	</resultMap>
@@ -34,8 +35,26 @@
 		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL 
 		</selectKey>
 		-->
-		INSERT INTO index_base_month_data (id_,month_,organ_id_,total_num_,activate_num_,percent_,create_time_,update_time_)
-		VALUES(#{id},#{month},#{organId},#{totalNum},#{activateNum},#{percent},NOW(),NOW())
+		INSERT INTO index_base_month_data (month_,organ_id_,total_num_,activate_num_,percent_,data_type_,create_time_,update_time_)
+		VALUES(#{month},#{organId},#{totalNum},#{activateNum},#{percent},#{dataType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},NOW(),NOW())
+	</insert>
+
+	<insert id="batchInsertWithDataType" parameterType="com.ym.mec.biz.dal.entity.IndexBaseMonthData" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
+		INSERT INTO index_base_month_data (month_,organ_id_,total_num_,activate_num_,percent_,data_type_,create_time_,update_time_)
+		VALUES
+		<foreach collection="datas" item="data" separator=",">
+			(#{data.month},#{data.organId},#{data.totalNum},#{data.activateNum},#{data.percent},
+			#{dataType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},NOW(),NOW())
+		</foreach>
+	</insert>
+
+	<insert id="batchInsert" parameterType="com.ym.mec.biz.dal.entity.IndexBaseMonthData" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
+		INSERT INTO index_base_month_data (month_,organ_id_,total_num_,activate_num_,percent_,data_type_,create_time_,update_time_)
+		VALUES
+		<foreach collection="datas" item="data" separator=",">
+			(#{data.month},#{data.organId},#{data.totalNum},#{data.activateNum},#{data.percent},
+			#{data.dataType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},NOW(),NOW())
+		</foreach>
 	</insert>
 
 	<!-- 根据主键查询一条记录 -->
@@ -59,6 +78,9 @@
 		<if test="month != null">
 			month_ = #{month},
 		</if>
+		<if test="dataType != null">
+			data_type_ = #{dataType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+		</if>
 		update_time_ = NOW()
 	</set> WHERE id_ = #{id}
 	</update>
@@ -68,6 +90,17 @@
 		DELETE FROM index_base_month_data WHERE id_ = #{id}
 	</delete>
 
+	<delete id="deleteWithMonthAndType">
+		DELETE FROM index_base_month_data
+		WHERE DATE_FORMAT(month_, '%Y-%m-%d') IN
+		<foreach collection="months" item="month" open="(" close=")" separator=",">
+			#{month}
+		</foreach>
+		<if test="dataType!=null">
+			AND data_type_=#{dataType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+		</if>
+	</delete>
+
 	<!-- 分页查询 -->
 	<select id="queryPage" resultMap="IndexBaseMonthData" parameterType="map">
 		SELECT * FROM index_base_month_data ORDER BY id_ <include refid="global.limit"/>
@@ -77,4 +110,85 @@
 	<select id="queryCount" resultType="int">
 		SELECT COUNT(*) FROM index_base_month_data
 	</select>
+
+    <select id="getIndexBaseData" resultMap="IndexBaseMonthData">
+		SELECT *
+		FROM index_base_month_data
+		<where>
+			<if test="dataTypes!=null and dataTypes.size()>0">
+				AND data_type_ IN
+				<foreach collection="dataTypes" item="dataType" open="(" close=")" separator=",">
+					#{dataType}
+				</foreach>
+			</if>
+			<if test="organIds!=null and organIds.size()>0">
+				AND organ_id_ IN
+				<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
+					#{organId}
+				</foreach>
+			</if>
+			<if test="startMonth!=null and startMonth!=''">
+				AND DATE_FORMAT(month_, '%Y-%m')&gt;=#{startMonth}
+			</if>
+			<if test="endMonth!=null and endMonth!=''">
+				AND DATE_FORMAT(month_, '%Y-%m')&lt;=#{endMonth}
+			</if>
+		</where>
+	</select>
+
+	<select id="getStudentSignUpData" resultMap="IndexBaseMonthData">
+		SELECT
+			organ_id_,
+			CONCAT(DATE_FORMAT( create_time_, '%Y-%m' ), '-01') month_,
+			COUNT( id_ ) total_num_,
+			COUNT(CASE WHEN password_ IS NOT NULL THEN id_ ELSE NULL END) activate_num_,
+			TRUNCATE(COUNT(CASE WHEN password_ IS NOT NULL THEN id_ ELSE NULL END)/COUNT( id_ )*100, 2) percent_
+		FROM sys_user
+		WHERE
+			del_flag_=0
+			AND user_type_ LIKE '%STUDENT%'
+			<if test="startMonth!=null and startMonth!=''">
+				AND DATE_FORMAT(create_time_, '%Y-%m')&gt;=#{startMonth}
+			</if>
+			<if test="endMonth!=null and endMonth!=''">
+				AND DATE_FORMAT(create_time_, '%Y-%m')&lt;=#{endMonth}
+			</if>
+		GROUP BY organ_id_,month_
+		ORDER BY organ_id_,month_;
+	</select>
+
+	<select id="getHomeworkDate" resultMap="IndexBaseMonthData">
+		SELECT
+			su.organ_id_,
+			CONCAT(DATE_FORMAT(sees.monday_, '%Y-%m'), '-01') month_,
+			<choose>
+				<when test="type == 'submit'">
+					SUM(sees.expect_exercises_num_) total_num_,
+					SUM(sees.exercises_reply_num_) activate_num_,
+					TRUNCATE(SUM(sees.exercises_reply_num_)/SUM(sees.expect_exercises_num_)*100, 2) percent_
+				</when>
+				<when test="type == 'comment'">
+					SUM(sees.expect_exercises_num_) total_num_,
+					SUM(sees.exercises_reply_num_) activate_num_,
+					TRUNCATE(SUM(sees.exercises_reply_num_)/SUM(sees.expect_exercises_num_)*100, 2) percent_
+				</when>
+				<otherwise>
+					SUM(sees.expect_exercises_num_) total_num_,
+					SUM(sees.actual_exercises_num_) activate_num_,
+					TRUNCATE(SUM(sees.actual_exercises_num_)/SUM(sees.expect_exercises_num_)*100, 2) percent_
+				</otherwise>
+			</choose>
+		FROM student_extracurricular_exercises_situation_ sees
+		LEFT JOIN sys_user su ON sees.student_id_=su.id_
+		WHERE su.del_flag_=0
+			AND su.organ_id_ IS NOT NULL
+			<if test="startMonth!=null and startMonth!=''">
+				AND DATE_FORMAT(sees.monday_, '%Y-%m')&gt;=#{startMonth}
+			</if>
+			<if test="endMonth!=null and endMonth!=''">
+				AND DATE_FORMAT(sees.monday_, '%Y-%m')&lt;=#{endMonth}
+			</if>
+		GROUP BY su.organ_id_,month_
+		ORDER BY su.organ_id_,month_
+	</select>
 </mapper>

+ 0 - 75
mec-biz/src/main/resources/config/mybatis/IndexMapper.xml

@@ -1,75 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<!--
-这个文件是自动生成的。
-不要修改此文件。所有改动将在下次重新自动生成时丢失。
--->
-<mapper namespace="com.ym.mec.biz.dal.dao.IndexDao">
-
-    <select id="getStudentSignUpData" resultType="com.ym.mec.biz.dal.entity.IndexBaseMonthData">
-        SELECT
-            DATE_FORMAT( create_time_, '%Y-%m' ) month,
-            COUNT( id_ ) totalNum,
-            COUNT(CASE WHEN password_ IS NOT NULL THEN id_ ELSE NULL END) activateNum,
-            TRUNCATE(COUNT(CASE WHEN password_ IS NOT NULL THEN id_ ELSE NULL END)/COUNT( id_ )*100, 2) percent
-        FROM
-            sys_user
-        WHERE
-            del_flag_=0
-            AND user_type_ LIKE '%STUDENT%'
-            <if test="organIds!=null and organIds.size()>0">
-                AND organ_id_ IN
-                <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
-                    #{organIds}
-                </foreach>
-            </if>
-            <if test="startMonth!=null and startMonth!=''">
-                AND DATE_FORMAT(create_time_, '%Y-%m')&gt;=#{startMonth}
-            </if>
-            <if test="endMonth!=null and endMonth!=''">
-                AND DATE_FORMAT(create_time_, '%Y-%m')&lt;=#{endMonth}
-            </if>
-        GROUP BY month
-        ORDER BY month;
-    </select>
-
-    <select id="getHomeworkDate" resultType="com.ym.mec.biz.dal.entity.IndexBaseMonthData">
-        SELECT
-            DATE_FORMAT(sees.monday_, '%Y-%m') month,
-            <choose>
-                <when test="type == 'submit'">
-                    SUM(sees.expect_exercises_num_) totalNum,
-                    SUM(sees.exercises_reply_num_) activateNum,
-                    TRUNCATE(SUM(sees.exercises_reply_num_)/SUM(sees.expect_exercises_num_)*100, 2) percent
-                </when>
-                <when test="type == 'comment'">
-                    SUM(sees.expect_exercises_num_) totalNum,
-                    SUM(sees.exercises_reply_num_) activateNum,
-                    TRUNCATE(SUM(sees.exercises_reply_num_)/SUM(sees.expect_exercises_num_)*100, 2) percent
-                </when>
-                <otherwise>
-                    SUM(sees.expect_exercises_num_) totalNum,
-                    SUM(sees.actual_exercises_num_) activateNum,
-                    TRUNCATE(SUM(sees.actual_exercises_num_)/SUM(sees.expect_exercises_num_)*100, 2) percent
-                </otherwise>
-            </choose>
-        FROM student_extracurricular_exercises_situation_ sees
-                 LEFT JOIN sys_user su ON sees.student_id_=su.id_
-        WHERE su.del_flag_=0
-            <if test="organIds!=null and organIds.size()>0">
-                AND su.organ_id_ IN
-                <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
-                    #{organIds}
-                </foreach>
-            </if>
-            <if test="startMonth!=null and startMonth!=''">
-                AND DATE_FORMAT(sees.monday_, '%Y-%m')&gt;=#{startMonth}
-            </if>
-            <if test="endMonth!=null and endMonth!=''">
-                AND DATE_FORMAT(sees.monday_, '%Y-%m')&lt;=#{endMonth}
-            </if>
-        GROUP BY month
-        ORDER BY month
-    </select>
-
-</mapper>

+ 3 - 6
mec-web/src/main/java/com/ym/mec/web/controller/IndexController.java

@@ -3,7 +3,7 @@ package com.ym.mec.web.controller;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.entity.Employee;
 import com.ym.mec.biz.service.EmployeeService;
-import com.ym.mec.biz.service.IndexService;
+import com.ym.mec.biz.service.IndexBaseMonthDataService;
 import com.ym.mec.common.entity.HttpResponseResult;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -61,7 +61,7 @@ public class IndexController extends BaseController {
 	private StudentPaymentOrderDao studentPaymentOrderDao;
 
 	@Autowired
-	private IndexService indexService;
+	private IndexBaseMonthDataService indexService;
 
 	@ApiOperation(value = "获取首页数据")
 	@GetMapping("/index")
@@ -134,9 +134,6 @@ public class IndexController extends BaseController {
 				}
 			}
 		}
-		if(StringUtils.isBlank(dataTypes)){
-			dataTypes = "ALL";
-		}
-		return succeed(indexService.getIndexBaseData(Arrays.stream(dataTypes.split(",")).collect(Collectors.toSet()), organIds, startMonth, endMonth));
+		return succeed(indexService.getIndexBaseData(dataTypes , organIds, startMonth, endMonth));
 	}
 }

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

@@ -88,6 +88,8 @@ public class TaskController extends BaseController {
 	private CourseEventSource courseEventSource;
 	@Autowired
 	private RedisCache<String, Object> redisCache;
+	@Autowired
+	private IndexBaseMonthDataService indexBaseMonthDataService;
 
 	@GetMapping(value = "/autoAffirmReceiveTask")
 	// 自动确认收货
@@ -317,4 +319,9 @@ public class TaskController extends BaseController {
 	public void updateCourseActualPrice(){
 		courseEventSource.courseStatusChange(null);
 	}
+
+	@GetMapping("/countIndexBaseData")
+	public void countIndexBaseData(String startMonth, String endMonth){
+		indexBaseMonthDataService.indexBaseDataTask(startMonth, endMonth);
+	}
 }