Commit bd196736 by 邓敏

新增定时器,代码优化

1 parent a91e9ad7
......@@ -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);
......
......@@ -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));
}
......
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;
/**
* <p>
* 定时器
* </p>
*
* @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<OprAdmDictDO> list = oprAdmDictMapper.getRecordByDate();
if(list != null) {
for (OprAdmDictDO oprAdmDictDO : list) {
oprAdmDictMapper.deleteById(oprAdmDictDO.getId());
}
}
}
/**
* 删除十天前登录记录(学员)
*/
@Scheduled(cron = "0 42 18 * * ?")
public void delOprMemRecord() {
List<OprMemDictDO> list = oprMemDictMapper.getRecordByDate();
if(list != null) {
for (OprMemDictDO oprMemDictDO : list) {
oprMemDictMapper.deleteById(oprMemDictDO.getId());
}
}
}
/**
* 用户数据审计记录添加(学员)
*/
@Scheduled(cron = "0 39 18 * * ?")
public void getOprMemRecord() {
Set<String> 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<VodPlayHistoryDO> list = vodPlayHistoryMapper.getVodPlayHistory();
List<VodPlayHistoryDO> vodPlayHistoryList = vodPlayHistoryMapper.selectList(new QueryWrapper<VodPlayHistoryDO>());
for (VodPlayHistoryDO vodPlayHistoryDO : vodPlayHistoryList) {
vodPlayHistoryMapper.deleteById(vodPlayHistoryDO.getId());
}
for (VodPlayHistoryDO vodPlayHistoryDO : list) {
vodPlayHistoryMapper.insert(vodPlayHistoryDO);
}
}
}
......@@ -30,4 +30,7 @@ public interface OprAdmDictMapper extends BaseMapper<OprAdmDictDO> {
List<OprAdmDictDO> getLoginInfo(Long userId);
List<OprAdmDictDO> getRecordByDate();
void deleteById(Long id);
}
......@@ -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;
/**
* <p>
* 审计表 Mapper 接口
......@@ -19,4 +21,7 @@ public interface OprMemDictMapper extends BaseMapper<OprMemDictDO> {
IPage<GetHistoryVO> getHistory(IPage page,String userName,String startDate,String endDate);
List<OprMemDictDO> getRecordByDate();
void deleteById(Long id);
}
......@@ -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<VodPlayHistoryDO> {
*/
List<GetMemberStudyInfoVO> getMemberStudyInfo(Long classId,List<Long> memberIds,String startDate,String endDate);
/**
* 缩量记录
*/
List<VodPlayHistoryDO> getVodPlayHistory();
void deleteById(Long id);
}
......@@ -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();
}
}
......@@ -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;
}
package com.subsidy.vo.vod;
import lombok.Data;
@Data
public class GetVodPlayHistoryVO {
/**
* 观看时长
*/
private Integer playLength;
/**
* 播放视频位置
*/
private Integer playRecord;
/**
* 聚合
*/
private Integer playCount;
}
......@@ -20,6 +20,10 @@
id, user_id, opr_type
</sql>
<delete id="deleteById">
delete from opr_adm_dict
where id = #{id}
</delete>
<select id="getHistory" resultType="com.subsidy.vo.opr.GetHistoryVO">
SELECT
......@@ -64,4 +68,13 @@
LIMIT 5)t2
</select>
<select id="getRecordByDate" resultType="com.subsidy.model.OprAdmDictDO">
SELECT
*
FROM
opr_adm_dict
WHERE
create_date &lt; (NOW() - INTERVAL 10 DAY)
</select>
</mapper>
......@@ -20,6 +20,11 @@
id, user_id, opr_type
</sql>
<delete id="deleteById">
delete from opr_mem_dict
where id = #{id}
</delete>
<select id="getHistory" resultType="com.subsidy.vo.opr.GetHistoryVO">
SELECT
t.id,
......@@ -44,4 +49,13 @@
ORDER BY
t.create_date DESC
</select>
<select id="getRecordByDate" resultType="com.subsidy.model.OprMemDictDO">
SELECT
*
FROM
opr_mem_dict
WHERE
create_date &lt; (NOW() - INTERVAL 10 DAY)
</select>
</mapper>
......@@ -22,6 +22,10 @@
delete_date,
id, class_id, vod_id, member_id, play_length, play_record
</sql>
<delete id="deleteById">
delete from vod_play_history
where id = #{id}
</delete>
<select id="studyHistory" parameterType="long" resultType="com.subsidy.vo.vod.StudyHistoryVO">
SELECT
......@@ -83,4 +87,19 @@
DATE_FORMAT( t.create_date, '%Y-%m-%d' )
</select>
<select id="getVodPlayHistory" resultType="com.subsidy.model.VodPlayHistoryDO">
SELECT
a.member_id,
a.class_id,
a.vod_id,
a.play_length,
a.play_count,
b.play_record
FROM
( SELECT sum( play_length ) as play_length, sum( play_count ) as play_count, member_id, class_id, vod_id FROM vod_play_history GROUP BY member_id, class_id, vod_id ) a
LEFT JOIN ( SELECT max( create_date ), play_record, member_id, class_id, vod_id FROM vod_play_history GROUP BY member_id, class_id, vod_id ) b ON a.member_id = b.member_id
AND a.class_id = b.class_id
AND a.vod_id = b.vod_id
</select>
</mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!