From bd196736b617c398a900f39fbd05049c6908f5e7 Mon Sep 17 00:00:00 2001 From: DengMin <16679070171@qq.com> Date: Wed, 22 Dec 2021 15:44:55 +0800 Subject: [PATCH] 新增定时器,代码优化 --- src/main/java/com/subsidy/controller/AdministerController.java | 14 +++++++------- src/main/java/com/subsidy/controller/CourseDictController.java | 4 ++-- src/main/java/com/subsidy/jobs/Scheduler.java | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/subsidy/mapper/OprAdmDictMapper.java | 3 +++ src/main/java/com/subsidy/mapper/OprMemDictMapper.java | 5 +++++ src/main/java/com/subsidy/mapper/VodPlayHistoryMapper.java | 7 +++++++ src/main/java/com/subsidy/util/DateFormatUtil.java | 8 ++++++++ src/main/java/com/subsidy/vo/course/QueryCoursesVO.java | 29 ++++++++++++++++++++++++++++- src/main/java/com/subsidy/vo/vod/GetVodPlayHistoryVO.java | 22 ++++++++++++++++++++++ src/main/resources/mapper/OprAdmDictMapper.xml | 13 +++++++++++++ src/main/resources/mapper/OprMemDictMapper.xml | 14 ++++++++++++++ src/main/resources/mapper/VodPlayHistoryMapper.xml | 19 +++++++++++++++++++ 12 files changed, 236 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/subsidy/jobs/Scheduler.java create mode 100644 src/main/java/com/subsidy/vo/vod/GetVodPlayHistoryVO.java diff --git a/src/main/java/com/subsidy/controller/AdministerController.java b/src/main/java/com/subsidy/controller/AdministerController.java index 9dd8824..ce1c124 100644 --- a/src/main/java/com/subsidy/controller/AdministerController.java +++ b/src/main/java/com/subsidy/controller/AdministerController.java @@ -69,47 +69,47 @@ public class AdministerController { } @PostMapping("/administers") - @ApiOperation("** 查询所有运营者 { userName pageNum pageSize }") + @ApiOperation("查询所有运营者 { userName pageNum pageSize }") @LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE}) public ResponseVO operators(@RequestBody OperatorsDTO operatorsDTO){ return ResponseData.generateCreatedResponse(0,administerService.operators(operatorsDTO)); } @PostMapping("addAdminister") - @ApiOperation("** 添加运营者 id userName 名称 accountName 账号 ") + @ApiOperation("添加运营者 id userName 名称 accountName 账号 ") public ResponseVO addAdminister(@RequestBody AdministerDO administerDO){ return ResponseData.generateCreatedResponse(0,administerService.addAdminister(administerDO)); } @PostMapping("deleteAdminister") - @ApiOperation("** 添加运营者 id ") + @ApiOperation("添加运营者 id ") public ResponseVO deleteAdminister(@RequestBody AdministerDO administerDO){ return ResponseData.generateCreatedResponse(0,administerService.deleteAdminister(administerDO)); } @PostMapping("updateAdminister") - @ApiOperation("** 编辑运营者 id userName 名称 accountName 账号 password") + @ApiOperation("编辑运营者 id userName 名称 accountName 账号 password") public ResponseVO updateAdminister(@RequestBody AdministerDO administerDO){ return ResponseData.generateCreatedResponse(0,administerService.updateAdminister(administerDO)); } @PostMapping("classSummary") - @ApiOperation("** 课程汇总 id 班级id ") + @ApiOperation("课程汇总 id 班级id ") @LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE}) public ResponseVO classSummary(@RequestBody ClassDetailDTO classDetailDTO){ return ResponseData.generateCreatedResponse(0,administerService.classSummary(classDetailDTO)); } @PostMapping("classDetail") - @ApiOperation("** 班级管理--班级成员 id 班级id userName") + @ApiOperation("班级管理--班级成员 id 班级id userName") @LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE}) public ResponseVO classDetail(@RequestBody ClassDetailDTO classDetailDTO){ return ResponseData.generateCreatedResponse(0,administerService.classDetail(classDetailDTO)); } @PostMapping("exportClassDetail") - @ApiOperation("** 班级管理--班级成员--导出 id 班级id userName") + @ApiOperation("班级管理--班级成员--导出 id 班级id userName") @LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE}) public void exportClassDetail(@RequestBody ClassDetailDTO classDetailDTO)throws Exception{ classDetailDTO.setFlag(true); diff --git a/src/main/java/com/subsidy/controller/CourseDictController.java b/src/main/java/com/subsidy/controller/CourseDictController.java index a3ded81..d3ca18e 100644 --- a/src/main/java/com/subsidy/controller/CourseDictController.java +++ b/src/main/java/com/subsidy/controller/CourseDictController.java @@ -45,7 +45,7 @@ public class CourseDictController { } @PostMapping("queryCourses") - @ApiOperation("** 平台运营者--查询课程 pageSize pageNum administerId companyId courseName categoryId courseType courseSource") + @ApiOperation("平台运营者--查询课程 pageSize pageNum administerId companyId courseName categoryId courseType courseSource") //@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE}) public ResponseVO queryCourses(@RequestBody QueryCoursesDTO queryCoursesDTO){ return ResponseData.generateCreatedResponse(0,courseDictService.queryCourses(queryCoursesDTO)); @@ -59,7 +59,7 @@ public class CourseDictController { } @PostMapping("queryCompanyCourse") - @ApiOperation("企业内容管理-- { ** companyId 所选企业id}") + @ApiOperation("企业内容管理-- { companyId 所选企业id}") public ResponseVO queryCompanyCourse(@RequestBody QueryCoursesDTO queryCoursesDTO){ return ResponseData.generateCreatedResponse(0,courseDictService.queryCompanyCourse(queryCoursesDTO)); } diff --git a/src/main/java/com/subsidy/jobs/Scheduler.java b/src/main/java/com/subsidy/jobs/Scheduler.java new file mode 100644 index 0000000..bc15b92 --- /dev/null +++ b/src/main/java/com/subsidy/jobs/Scheduler.java @@ -0,0 +1,108 @@ +package com.subsidy.jobs; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.subsidy.mapper.OprAdmDictMapper; +import com.subsidy.mapper.OprMemDictMapper; +import com.subsidy.mapper.VodPlayHistoryMapper; +import com.subsidy.model.OprAdmDictDO; +import com.subsidy.model.OprMemDictDO; +import com.subsidy.model.VodPlayHistoryDO; +import com.subsidy.util.DateFormatUtil; +import com.subsidy.util.RedisUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Set; + +/** + *

+ * 定时器 + *

+ * + * @author DengMin + * @since 2021/12/21 + */ + +@Component +public class Scheduler { + + @Autowired + private OprAdmDictMapper oprAdmDictMapper; + + @Autowired + private OprMemDictMapper oprMemDictMapper; + + @Autowired + private VodPlayHistoryMapper vodPlayHistoryMapper; + + @Autowired + private RedisUtil redisUtil; + + /** + 删除十天前登录记录(管理端) + */ + @Scheduled(cron = "0 42 18 * * ?") + public void delOprAdmRecord() { + List list = oprAdmDictMapper.getRecordByDate(); + if(list != null) { + for (OprAdmDictDO oprAdmDictDO : list) { + oprAdmDictMapper.deleteById(oprAdmDictDO.getId()); + } + } + } + + /** + * 删除十天前登录记录(学员) + */ + @Scheduled(cron = "0 42 18 * * ?") + public void delOprMemRecord() { + List list = oprMemDictMapper.getRecordByDate(); + if(list != null) { + for (OprMemDictDO oprMemDictDO : list) { + oprMemDictMapper.deleteById(oprMemDictDO.getId()); + } + } + } + + /** + * 用户数据审计记录添加(学员) + */ + @Scheduled(cron = "0 39 18 * * ?") + public void getOprMemRecord() { + Set set = redisUtil.keys("*memberLogin*"); + if(set != null) { + for (String str : set) { + int result = (Integer) redisUtil.get(str); + OprMemDictDO oprMemDictDO = new OprMemDictDO(); + String [] opr = str.split("_"); + LocalDateTime createDate = DateFormatUtil.secondToLocalDateTime(Long.valueOf(opr[3])); + oprMemDictDO.setResult(result); + oprMemDictDO.setOprType("登录"); + oprMemDictDO.setUserId(Long.valueOf(opr[2])); + oprMemDictDO.setCreateDate(createDate); + oprMemDictMapper.insert(oprMemDictDO); + redisUtil.del(str); + } + } + } + + /** + * 视频播放记录缩量 + */ + @Scheduled(cron = "0 35 18 * * ?") + @Transactional(rollbackFor = Exception.class) + public void condenseVodPlayHistory() { + List list = vodPlayHistoryMapper.getVodPlayHistory(); + List vodPlayHistoryList = vodPlayHistoryMapper.selectList(new QueryWrapper()); + for (VodPlayHistoryDO vodPlayHistoryDO : vodPlayHistoryList) { + vodPlayHistoryMapper.deleteById(vodPlayHistoryDO.getId()); + } + + for (VodPlayHistoryDO vodPlayHistoryDO : list) { + vodPlayHistoryMapper.insert(vodPlayHistoryDO); + } + } +} diff --git a/src/main/java/com/subsidy/mapper/OprAdmDictMapper.java b/src/main/java/com/subsidy/mapper/OprAdmDictMapper.java index 774ba82..d52761c 100644 --- a/src/main/java/com/subsidy/mapper/OprAdmDictMapper.java +++ b/src/main/java/com/subsidy/mapper/OprAdmDictMapper.java @@ -30,4 +30,7 @@ public interface OprAdmDictMapper extends BaseMapper { List getLoginInfo(Long userId); + List getRecordByDate(); + + void deleteById(Long id); } diff --git a/src/main/java/com/subsidy/mapper/OprMemDictMapper.java b/src/main/java/com/subsidy/mapper/OprMemDictMapper.java index 0719384..d9abf46 100644 --- a/src/main/java/com/subsidy/mapper/OprMemDictMapper.java +++ b/src/main/java/com/subsidy/mapper/OprMemDictMapper.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.subsidy.vo.opr.GetHistoryVO; import org.springframework.stereotype.Repository; +import java.util.List; + /** *

* 审计表 Mapper 接口 @@ -19,4 +21,7 @@ public interface OprMemDictMapper extends BaseMapper { IPage getHistory(IPage page,String userName,String startDate,String endDate); + List getRecordByDate(); + + void deleteById(Long id); } diff --git a/src/main/java/com/subsidy/mapper/VodPlayHistoryMapper.java b/src/main/java/com/subsidy/mapper/VodPlayHistoryMapper.java index fb63813..8300758 100644 --- a/src/main/java/com/subsidy/mapper/VodPlayHistoryMapper.java +++ b/src/main/java/com/subsidy/mapper/VodPlayHistoryMapper.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.subsidy.model.VodPlayHistoryDO; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.subsidy.vo.vod.GetMemberStudyInfoVO; +import com.subsidy.vo.vod.GetVodPlayHistoryVO; import com.subsidy.vo.vod.StudyHistoryVO; import org.springframework.stereotype.Repository; @@ -30,4 +31,10 @@ public interface VodPlayHistoryMapper extends BaseMapper { */ List getMemberStudyInfo(Long classId,List memberIds,String startDate,String endDate); + /** + * 缩量记录 + */ + List getVodPlayHistory(); + + void deleteById(Long id); } diff --git a/src/main/java/com/subsidy/util/DateFormatUtil.java b/src/main/java/com/subsidy/util/DateFormatUtil.java index 5e9bc25..65b9687 100644 --- a/src/main/java/com/subsidy/util/DateFormatUtil.java +++ b/src/main/java/com/subsidy/util/DateFormatUtil.java @@ -3,6 +3,7 @@ package com.subsidy.util; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.Date; @@ -85,4 +86,11 @@ public class DateFormatUtil { ZonedDateTime zdt = dateTime.atZone(zoneId); return Date.from(zdt.toInstant()); } + + public static LocalDateTime secondToLocalDateTime(Long second) { + if(second != null) { + return LocalDateTime.ofEpochSecond(second, 0, ZoneOffset.ofHours(8)); + } + return LocalDateTime.now(); + } } diff --git a/src/main/java/com/subsidy/vo/course/QueryCoursesVO.java b/src/main/java/com/subsidy/vo/course/QueryCoursesVO.java index ba7ead4..fa3c8d0 100644 --- a/src/main/java/com/subsidy/vo/course/QueryCoursesVO.java +++ b/src/main/java/com/subsidy/vo/course/QueryCoursesVO.java @@ -4,8 +4,35 @@ import com.subsidy.model.CourseDictDO; import lombok.Data; @Data -public class QueryCoursesVO extends CourseDictDO { +public class QueryCoursesVO { private String name; + private Long id; + + /** + * + */ + private Long companyId; + + /** + * 课程名称 + */ + private String courseName; + + /** + * 类目id + */ + private Long categoryId; + + /** + * 课程类型 + */ + private String courseType; + + /** + * 课程来源 + */ + private String courseSource; + } diff --git a/src/main/java/com/subsidy/vo/vod/GetVodPlayHistoryVO.java b/src/main/java/com/subsidy/vo/vod/GetVodPlayHistoryVO.java new file mode 100644 index 0000000..c70fd71 --- /dev/null +++ b/src/main/java/com/subsidy/vo/vod/GetVodPlayHistoryVO.java @@ -0,0 +1,22 @@ +package com.subsidy.vo.vod; + +import lombok.Data; + +@Data +public class GetVodPlayHistoryVO { + + /** + * 观看时长 + */ + private Integer playLength; + + /** + * 播放视频位置 + */ + private Integer playRecord; + + /** + * 聚合 + */ + private Integer playCount; +} diff --git a/src/main/resources/mapper/OprAdmDictMapper.xml b/src/main/resources/mapper/OprAdmDictMapper.xml index 2c8ab78..aeccd0c 100644 --- a/src/main/resources/mapper/OprAdmDictMapper.xml +++ b/src/main/resources/mapper/OprAdmDictMapper.xml @@ -20,6 +20,10 @@ id, user_id, opr_type + + delete from opr_adm_dict + where id = #{id} + + + diff --git a/src/main/resources/mapper/OprMemDictMapper.xml b/src/main/resources/mapper/OprMemDictMapper.xml index 209e10d..1366a59 100644 --- a/src/main/resources/mapper/OprMemDictMapper.xml +++ b/src/main/resources/mapper/OprMemDictMapper.xml @@ -20,6 +20,11 @@ id, user_id, opr_type + + delete from opr_mem_dict + where id = #{id} + + + + diff --git a/src/main/resources/mapper/VodPlayHistoryMapper.xml b/src/main/resources/mapper/VodPlayHistoryMapper.xml index 6ad4a30..14a22d8 100644 --- a/src/main/resources/mapper/VodPlayHistoryMapper.xml +++ b/src/main/resources/mapper/VodPlayHistoryMapper.xml @@ -22,6 +22,10 @@ delete_date, id, class_id, vod_id, member_id, play_length, play_record + + delete from vod_play_history + where id = #{id} + + + -- libgit2 0.25.0