Przeglądaj źródła

Merge branch 'Joburgess'

Joburgess 4 lat temu
rodzic
commit
cdbc9f218e

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

@@ -0,0 +1,42 @@
+package com.ym.mec.biz.dal.dao;
+
+import com.ym.mec.biz.dal.dto.IndexBaseMonthDto;
+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<IndexBaseMonthDto> 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<IndexBaseMonthDto> getHomeworkDate(@Param("organIds") Set<Integer> organIds,
+                                                  @Param("startMonth") String startMonth,
+                                                  @Param("endMonth") String endMonth,
+                                                  @Param("type") String type);
+
+}

+ 62 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/IndexBaseDto.java

@@ -0,0 +1,62 @@
+package com.ym.mec.biz.dal.dto;
+
+import com.ym.mec.common.constant.CommonConstants;
+import org.springframework.util.CollectionUtils;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * @Author Joburgess
+ * @Date 2021/1/7 0007
+ */
+public class IndexBaseDto {
+
+    private String title;
+
+    private BigDecimal percent;
+
+    private List<IndexBaseMonthDto> indexMonthData;
+
+    public IndexBaseDto() {
+    }
+
+    public IndexBaseDto(String title) {
+        this.title = title;
+    }
+
+    public IndexBaseDto(String title, BigDecimal percent, List<IndexBaseMonthDto> indexMonthData) {
+        this.title = title;
+        this.percent = percent;
+        this.indexMonthData = indexMonthData;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public BigDecimal getPercent() {
+        return percent;
+    }
+
+    public void setPercent(BigDecimal percent) {
+        this.percent = percent;
+    }
+
+    public List<IndexBaseMonthDto> getIndexMonthData() {
+        return indexMonthData;
+    }
+
+    public void setIndexMonthData(List<IndexBaseMonthDto> indexMonthData) {
+        this.indexMonthData = indexMonthData;
+        if(!CollectionUtils.isEmpty(indexMonthData)){
+            BigDecimal total = indexMonthData.stream().map(IndexBaseMonthDto::getTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
+            BigDecimal activateNum = indexMonthData.stream().map(IndexBaseMonthDto::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);
+        }
+    }
+}

+ 55 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/IndexBaseMonthDto.java

@@ -0,0 +1,55 @@
+package com.ym.mec.biz.dal.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import java.math.BigDecimal;
+
+/**
+ * @Author Joburgess
+ * @Date 2021/1/7 0007
+ */
+public class IndexBaseMonthDto {
+
+    private String title;
+
+    //总数
+    private BigDecimal total;
+
+    //有效数量
+    private BigDecimal activateNum;
+
+    //最终结果
+    private BigDecimal percent;
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public BigDecimal getTotal() {
+        return total;
+    }
+
+    public void setTotal(BigDecimal total) {
+        this.total = total;
+    }
+
+    public BigDecimal getActivateNum() {
+        return activateNum;
+    }
+
+    public void setActivateNum(BigDecimal activateNum) {
+        this.activateNum = activateNum;
+    }
+
+    public BigDecimal getPercent() {
+        return percent;
+    }
+
+    public void setPercent(BigDecimal percent) {
+        this.percent = percent;
+    }
+}

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

@@ -0,0 +1,17 @@
+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);
+
+}

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

@@ -0,0 +1,113 @@
+package com.ym.mec.biz.service.impl;
+
+import com.sun.org.apache.xerces.internal.xs.StringList;
+import com.ym.mec.biz.dal.dao.IndexDao;
+import com.ym.mec.biz.dal.dto.IndexBaseDto;
+import com.ym.mec.biz.dal.dto.IndexBaseMonthDto;
+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 org.springframework.util.CollectionUtils;
+
+import java.math.BigDecimal;
+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;
+    }
+}

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

@@ -0,0 +1,77 @@
+<?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.dto.IndexBaseMonthDto">
+        SELECT
+            DATE_FORMAT( create_time_, '%Y-%m' ) title,
+            COUNT( id_ ) total,
+            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
+            title
+        ORDER BY
+            title;
+    </select>
+
+    <select id="getHomeworkDate" resultType="com.ym.mec.biz.dal.dto.IndexBaseMonthDto">
+        SELECT
+            DATE_FORMAT(sees.monday_, '%Y-%m') title,
+            <choose>
+                <when test="type == 'submit'">
+                    SUM(sees.expect_exercises_num_) total,
+                    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_) total,
+                    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_) total,
+                    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 title
+        ORDER BY title
+    </select>
+
+</mapper>

+ 36 - 0
mec-web/src/main/java/com/ym/mec/web/controller/IndexController.java

@@ -2,10 +2,16 @@ 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.common.entity.HttpResponseResult;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -44,6 +50,9 @@ public class IndexController extends BaseController {
 
 	@Autowired
 	private EmployeeDao employeeDao;
+
+	@Autowired
+	private EmployeeService employeeService;
 	
 	@Autowired
 	private SysUserCashAccountDetailDao sysUserCashAccountDetailDao;
@@ -51,6 +60,9 @@ public class IndexController extends BaseController {
 	@Autowired
 	private StudentPaymentOrderDao studentPaymentOrderDao;
 
+	@Autowired
+	private IndexService indexService;
+
 	@ApiOperation(value = "获取首页数据")
 	@GetMapping("/index")
 	public Object index() {
@@ -103,4 +115,28 @@ public class IndexController extends BaseController {
 		return succeed(model);
 	}
 
+	@GetMapping("/newIndex")
+	public HttpResponseResult newIndex(String dataTypes, String organIds, String startMonth, String endMonth){
+		SysUser sysUser = sysUserFeignService.queryUserInfo();
+		if (sysUser == null) {
+			return failed("用户信息获取失败");
+		}
+		if (!sysUser.getIsSuperAdmin()) {
+			Employee employee = employeeService.get(sysUser.getId());
+			if (StringUtils.isBlank(organIds)) {
+				organIds = employee.getOrganIdList();
+			}else if(StringUtils.isEmpty(employee.getOrganIdList())){
+				return failed("用户所在分部异常");
+			}else {
+				List<String> list = Arrays.asList(employee.getOrganIdList().split(","));
+				if(!list.containsAll(Arrays.asList(organIds.split(",")))){
+					return failed("非法请求");
+				}
+			}
+		}
+		if(StringUtils.isBlank(dataTypes)){
+			dataTypes = "ALL";
+		}
+		return succeed(indexService.getIndexBaseData(Arrays.stream(dataTypes.split(",")).collect(Collectors.toSet()), organIds, startMonth, endMonth));
+	}
 }