Browse Source

增加首页课程数据统计查询

hgw 3 years ago
parent
commit
d2e5540546

+ 14 - 1
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/HomeController.java

@@ -3,6 +3,7 @@ package com.yonge.cooleshow.admin.controller;
 import com.yonge.cooleshow.biz.dal.dto.req.TotalReq;
 import com.yonge.cooleshow.biz.dal.service.HomeService;
 import com.yonge.cooleshow.biz.dal.service.MusicSheetService;
+import com.yonge.cooleshow.biz.dal.vo.CourseHomeVo;
 import com.yonge.cooleshow.biz.dal.vo.HomeMusicSheetVo;
 import com.yonge.cooleshow.biz.dal.vo.res.HomeTotalStudent;
 import com.yonge.cooleshow.biz.dal.vo.res.HomeTotalTeacher;
@@ -15,6 +16,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/home")
@@ -47,11 +49,22 @@ public class HomeController extends BaseController {
         return homeService.totalStudent(totalReq);
     }
 
-
     @ApiOperation(value = "首页曲目点播数据")
     @PostMapping("/musicSheet")
     public HttpResponseResult<HomeMusicSheetVo> musicSheet() {
         return succeed(musicSheetService.getMusicSheetHome());
     }
 
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "year", dataType = "Integer", value = "年"),
+            @ApiImplicitParam(name = "month", dataType = "Integer", value = "月"),
+            @ApiImplicitParam(name = "type", dataType = "String", value = "类型  PRACTICE陪练课  LIVE直播课"),
+    })
+    @ApiOperation(value = "获取首页课程数据")
+    @PostMapping("/courseHome")
+    @PreAuthorize("@pcs.hasPermissions('home/courseHome')")
+    public HttpResponseResult<CourseHomeVo> queryCourseHomeData(@RequestBody Map<String,Object> param) {
+        return succeed(homeService.queryCourseHomeData(param));
+    }
+
 }

+ 12 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/CourseScheduleDao.java

@@ -185,5 +185,17 @@ public interface CourseScheduleDao extends BaseMapper<CourseSchedule> {
 
     //根据id统计评价
     Integer countReplies(Long studentId);
+
+    /**
+     * 按年查询首页课程数据
+     * @param param
+     */
+    List<CourseHomeVo.CourseHomeInfoVo> queryCourseHomeOfYear(@Param("param") Map<String, Object> param);
+
+    /**
+     * 按月查询首页课程数据
+     * @param param
+     */
+    List<CourseHomeVo.CourseHomeInfoVo> queryCourseHomeOfMonth(@Param("param") Map<String, Object> param);
 }
 

+ 7 - 4
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/enums/CourseScheduleEnum.java

@@ -2,6 +2,7 @@ package com.yonge.cooleshow.biz.dal.enums;
 
 import com.baomidou.mybatisplus.annotation.EnumValue;
 import com.yonge.toolset.base.enums.BaseEnum;
+import com.yonge.toolset.base.exception.BizException;
 
 import java.util.Arrays;
 import java.util.List;
@@ -39,7 +40,7 @@ public enum CourseScheduleEnum implements BaseEnum<String,CourseScheduleEnum> {
     public static CourseScheduleEnum existCourseType(String code, String errMsg) {
         CourseScheduleEnum[] values = {PRACTICE, LIVE};
         existCourse(values, code, errMsg);
-        //陪练课-校验学生时间是否交集
+        //返回枚举对象
         if (code.equals(CourseScheduleEnum.PRACTICE.getCode())) {
             return CourseScheduleEnum.PRACTICE;
         } else {
@@ -59,10 +60,12 @@ public enum CourseScheduleEnum implements BaseEnum<String,CourseScheduleEnum> {
     }
 
     private static void existCourse(CourseScheduleEnum[] values, String code, String errMsg) {
-        List<String> collect = Arrays.stream(values).map(CourseScheduleEnum::getCode).collect(Collectors.toList());
-        boolean typeFlag = collect.contains(code);
+        List<String> collect = Arrays.stream(values)
+                .map(CourseScheduleEnum::getCode)
+                .collect(Collectors.toList());
+        boolean typeFlag = collect.contains(code.toUpperCase());
         if (!typeFlag) {
-            throw new RuntimeException(errMsg);
+            throw new BizException(errMsg);
         }
     }
 

+ 15 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/HomeService.java

@@ -1,11 +1,14 @@
 package com.yonge.cooleshow.biz.dal.service;
 
 import com.yonge.cooleshow.biz.dal.dto.req.TotalReq;
+import com.yonge.cooleshow.biz.dal.vo.CourseHomeVo;
 import com.yonge.cooleshow.biz.dal.vo.res.HomeTotalStudent;
 import com.yonge.cooleshow.biz.dal.vo.res.HomeTotalTeacher;
 import com.yonge.cooleshow.biz.dal.vo.res.HomeUserToDoNum;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 
+import java.util.Map;
+
 /**
  * @Author: liweifan
  * @Data: 2022/3/30 18:07
@@ -35,4 +38,16 @@ public interface HomeService {
      * @return: com.yonge.cooleshow.common.entity.HttpResponseResult<com.yonge.cooleshow.biz.dal.vo.res.HomeTotalTeacher>
      */
     HttpResponseResult<HomeTotalStudent> totalStudent(TotalReq totalReq);
+
+    /**
+     * 获取首页课程数据
+     * <p>未完成  未开始&进行中
+     * <p>已完成  已完成课程
+     *
+     * @param param 传入参数
+     *              <p> - year 年
+     *              <p> - month 月
+     *              <p> - type 类型  PRACTICE陪练课  LIVE直播课
+     */
+    CourseHomeVo queryCourseHomeData(Map<String, Object> param);
 }

+ 95 - 5
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/HomeServiceImpl.java

@@ -1,23 +1,29 @@
 package com.yonge.cooleshow.biz.dal.service.impl;
 
+import com.yonge.cooleshow.biz.dal.dao.CourseScheduleDao;
 import com.yonge.cooleshow.biz.dal.dao.HomeDao;
 import com.yonge.cooleshow.biz.dal.dto.req.TotalReq;
-import com.yonge.cooleshow.biz.dal.enums.PeriodEnum;
+import com.yonge.cooleshow.biz.dal.enums.CourseScheduleEnum;
+import com.yonge.cooleshow.biz.dal.service.CourseScheduleService;
 import com.yonge.cooleshow.biz.dal.service.HomeService;
+import com.yonge.cooleshow.biz.dal.support.WrapperUtil;
+import com.yonge.cooleshow.biz.dal.vo.CourseHomeVo;
 import com.yonge.cooleshow.biz.dal.vo.res.HomeTotalStudent;
 import com.yonge.cooleshow.biz.dal.vo.res.HomeTotalTeacher;
 import com.yonge.cooleshow.biz.dal.vo.res.HomeUserToDoNum;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
-import com.yonge.toolset.base.exception.BizException;
-import io.swagger.annotations.ApiModelProperty;
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
 import java.time.temporal.TemporalAdjusters;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * @Author: liweifan
@@ -27,6 +33,8 @@ import java.util.List;
 public class HomeServiceImpl implements HomeService {
     @Autowired
     private HomeDao baserMapper;
+    @Autowired
+    private CourseScheduleService courseScheduleService;
 
     @Override
     public HomeUserToDoNum getUserToDoNum() {
@@ -106,4 +114,86 @@ public class HomeServiceImpl implements HomeService {
         total.setInfoList(totalList);
         return HttpResponseResult.succeed(total);
     }
+
+    /**
+     * 获取首页课程数据
+     * <p>未完成  未开始&进行中
+     * <p>已完成  已完成课程
+     *
+     * @param param 传入参数
+     *              <p> - year 年
+     *              <p> - month 月
+     *              <p> - type 类型  PRACTICE陪练课  LIVE直播课
+     */
+    public CourseHomeVo queryCourseHomeData(Map<String, Object> param) {
+        CourseScheduleEnum.existCourseType(WrapperUtil.toStr(param, "type"), "课程类型参数错误");
+        Integer year = WrapperUtil.toInt(param, "year", "年份不能为空!");
+        Integer monthParam = WrapperUtil.toInt(param, "month");
+        //按月查询true  年查询false
+        boolean isYear = monthParam == 0;
+        int month = isYear ? 1 : monthParam;
+
+        LocalDate firstDate;
+        LocalDate endDate;
+        CourseHomeVo result = new CourseHomeVo();
+        CourseScheduleDao courseScheduleServiceDao = courseScheduleService.getDao();
+        firstDate = LocalDate.of(year, month, 1);
+        //获取开始时间
+        if (isYear) {
+            //查询当年最后一天
+            endDate = firstDate.with(TemporalAdjusters.lastDayOfYear());
+        } else {
+            //查询当月最后一天
+            endDate = firstDate.with(TemporalAdjusters.lastDayOfMonth());
+        }
+        param.put("startDate", firstDate);
+        param.put("endDate", endDate);
+
+        //查询数据
+        List<CourseHomeVo.CourseHomeInfoVo> courseYearInfoList;
+        if (isYear) {
+            courseYearInfoList = courseScheduleServiceDao.queryCourseHomeOfYear(param);
+        } else {
+            courseYearInfoList = courseScheduleServiceDao.queryCourseHomeOfMonth(param);
+        }
+        if (CollectionUtils.isEmpty(courseYearInfoList)) {
+            courseYearInfoList = new ArrayList<>();
+        }
+        Map<String, CourseHomeVo.CourseHomeInfoVo> collect = courseYearInfoList.stream()
+                .collect(Collectors.toMap(CourseHomeVo.CourseHomeInfoVo::getDate, Function.identity(), (key1, key2) -> key2));
+        //补全数据
+        while (firstDate.isBefore(endDate)) {
+            CourseHomeVo.CourseHomeInfoVo infoVo = collect.get(firstDate.toString());
+            if (Objects.isNull(infoVo)) {
+                infoVo = new CourseHomeVo.CourseHomeInfoVo();
+                if (isYear) {
+                    infoVo.setDate(firstDate.toString().substring(0, 7));
+                } else {
+                    infoVo.setDate(firstDate.toString());
+                }
+                infoVo.setDoneCount(0);
+                infoVo.setUndoneCount(0);
+                courseYearInfoList.add(infoVo);
+            } else {
+                if (isYear) {
+                    infoVo.setDate(firstDate.toString().substring(0, 7));
+                }
+            }
+            if (isYear) {
+                firstDate = firstDate.plusMonths(1L);
+            } else {
+                firstDate = firstDate.plusDays(1L);
+            }
+        }
+        result.setCourseHomeInfoList(courseYearInfoList);
+        //计算总数方法
+        Function<Function<CourseHomeVo.CourseHomeInfoVo, Integer>, Integer> reduceFunc = (c) -> result.getCourseHomeInfoList().stream()
+                .map(c)
+                .reduce(0, Integer::sum);
+        result.setTotalDoneCount(reduceFunc.apply(CourseHomeVo.CourseHomeInfoVo::getDoneCount));
+        result.setTotalUndoneCount(reduceFunc.apply(CourseHomeVo.CourseHomeInfoVo::getUndoneCount));
+        result.setTotalCount(result.getTotalDoneCount() + result.getTotalUndoneCount());
+        return result;
+    }
+
 }

+ 15 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/SysUserContractRecordServiceImpl.java

@@ -3,7 +3,9 @@ package com.yonge.cooleshow.biz.dal.service.impl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yonge.cooleshow.biz.dal.dao.SysUserContractRecordDao;
 import com.yonge.cooleshow.biz.dal.entity.SysUserContractRecord;
+import com.yonge.cooleshow.biz.dal.service.ContractTemplateService;
 import com.yonge.cooleshow.biz.dal.service.SysUserContractRecordService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import org.slf4j.Logger;
@@ -20,10 +22,23 @@ public class SysUserContractRecordServiceImpl extends ServiceImpl<SysUserContrac
 
     private final static Logger log = LoggerFactory.getLogger(SysUserContractRecordServiceImpl.class);
 
+    @Autowired
+    private ContractTemplateService contractTemplateService;
+
     @Override
     public SysUserContractRecordDao getDao() {
         return this.baseMapper;
     }
 
+    /**
+     * 校验当前用户签署的协议是否是最新版本
+     */
+    public void checkContractRecord(Long userId,String type) {
+        //根据人员id及协议类型查询最新协议记录
+        //查询对应类型的最新的协议
+        //对比当前类型及人员id的协议版本
+        //如果不是最新版本,则返回false
+    }
+
 }
 

+ 85 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/CourseHomeVo.java

@@ -0,0 +1,85 @@
+package com.yonge.cooleshow.biz.dal.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.util.List;
+
+@ApiModel(description = "首页课程信息")
+public class CourseHomeVo {
+
+    @ApiModelProperty(value = "未完成课程总数")
+    private Integer totalUndoneCount;
+    @ApiModelProperty(value = "已完成课程总数")
+    private Integer totalDoneCount;
+    @ApiModelProperty(value = "总课程数")
+    private Integer totalCount;
+    @ApiModelProperty(value = "数据明细")
+    private List<CourseHomeInfoVo> courseHomeInfoList;
+
+    @ApiModel(description = "首页课程明细")
+    public static class CourseHomeInfoVo {
+        @ApiModelProperty(value = "日期-按年查询返回年月 按月查询返回年月日")
+        private String date;
+        @ApiModelProperty(value = "未完成课程数")
+        private Integer undoneCount;
+        @ApiModelProperty(value = "已完成课程数")
+        private Integer doneCount;
+
+        public String getDate() {
+            return date;
+        }
+
+        public void setDate(String date) {
+            this.date = date;
+        }
+
+        public Integer getUndoneCount() {
+            return undoneCount;
+        }
+
+        public void setUndoneCount(Integer undoneCount) {
+            this.undoneCount = undoneCount;
+        }
+
+        public Integer getDoneCount() {
+            return doneCount;
+        }
+
+        public void setDoneCount(Integer doneCount) {
+            this.doneCount = doneCount;
+        }
+    }
+
+    public Integer getTotalUndoneCount() {
+        return totalUndoneCount;
+    }
+
+    public void setTotalUndoneCount(Integer totalUndoneCount) {
+        this.totalUndoneCount = totalUndoneCount;
+    }
+
+    public Integer getTotalDoneCount() {
+        return totalDoneCount;
+    }
+
+    public void setTotalDoneCount(Integer totalDoneCount) {
+        this.totalDoneCount = totalDoneCount;
+    }
+
+    public Integer getTotalCount() {
+        return totalCount;
+    }
+
+    public void setTotalCount(Integer totalCount) {
+        this.totalCount = totalCount;
+    }
+
+    public List<CourseHomeInfoVo> getCourseHomeInfoList() {
+        return courseHomeInfoList;
+    }
+
+    public void setCourseHomeInfoList(List<CourseHomeInfoVo> courseHomeInfoList) {
+        this.courseHomeInfoList = courseHomeInfoList;
+    }
+}

+ 32 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -655,4 +655,36 @@
         FROM course_schedule_replied
         WHERE student_id_=#{studentId}
     </select>
+
+
+    <select id="queryCourseHomeOfYear" parameterType="map"
+            resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeVo$CourseHomeInfoVo">
+        select `date`,
+               sum(a.not_start_count) as undoneCount,
+               sum(a.complete_count)  as doneCount
+        from (select date_format(class_date_, '%Y-%m-01')                                      as `date`,
+                     ifnull(case when status_ in ('NOT_START', 'ING') then count(1) end, 0) as not_start_count,
+                     ifnull(case when status_ = 'COMPLETE' then count(1) end, 0)            as complete_count
+              from course_schedule
+              where type_ = #{param.type}
+                and status_ in ('NOT_START', 'ING', 'COMPLETE')
+        <![CDATA[ AND class_date_ >= #{param.startDate} ]]>
+        <![CDATA[ AND class_date_ <= #{param.endDate} ]]>
+        group by class_date_) as a
+        group by date
+    </select>
+
+    <select id="queryCourseHomeOfMonth" parameterType="map"
+            resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeVo$CourseHomeInfoVo">
+        select class_date_                                                            as `date`,
+               ifnull(case when status_ in ('NOT_START', 'ING') then count(1) end, 0) as undoneCount,
+               ifnull(case when status_ = 'COMPLETE' then count(1) end, 0)            as doneCount
+        from course_schedule
+        where type_ = #{param.type}
+          and status_ in ('NOT_START', 'ING', 'COMPLETE')
+        <![CDATA[ AND class_date_ >= #{param.startDate} ]]>
+        <![CDATA[ AND class_date_ <= #{param.endDate} ]]>
+        group by class_date_
+    </select>
+
 </mapper>