1.解决了热点榜死锁问题,优化了查询热点榜的sql,updateValueByKey重开一个事务
2.首页统计总时长增加过滤条件(过滤掉不满足条件的时间信息) 3.完善了登录后日志信息中没有名字情况(默认登录操作无法利用Shiro框架去获取当前的用户。解决方法,通过解析接收的参数去添加当前用户名)
This commit is contained in:
parent
c61c371dc6
commit
9bf5c6972b
@ -50,3 +50,8 @@ alter table live_scene_count
|
||||
-- 增加报道统计点赞数
|
||||
alter table aijinan.live_report
|
||||
add column live_count int default '0' COMMENT '统计点赞数';
|
||||
|
||||
|
||||
1 autoLiveTask AutoLiveTask 0/30 * * * * ? 0 This is a test job 2025-02-08 10:55:23
|
||||
2 likeSyncTask syncLikesToDatabase 0/15 * * * * ? 0 自动将redis的点赞数存储在数据库中
|
||||
3 likeSyncTask syncReportLikesToDatabase 0/15 * * * * ? 0 自动将redis的点赞数存储在数据库中 2025-02-20 11:07:00
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.platform.common.aspect;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.platform.common.annotation.SysLog;
|
||||
import com.platform.common.utils.HttpContextUtils;
|
||||
import com.platform.common.utils.IPUtils;
|
||||
@ -8,6 +10,7 @@ import com.platform.modules.live.constants.SceneConstants;
|
||||
import com.platform.modules.sys.entity.SysLogEntity;
|
||||
import com.platform.modules.sys.entity.SysUserEntity;
|
||||
import com.platform.modules.sys.service.SysLogService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
@ -34,10 +37,10 @@ import java.util.Date;
|
||||
public class SysLogAspect {
|
||||
@Autowired
|
||||
private SysLogService sysLogService;
|
||||
|
||||
|
||||
@Pointcut("@annotation(com.platform.common.annotation.SysLog)")
|
||||
public void logPointCut() {
|
||||
|
||||
public void logPointCut() {
|
||||
|
||||
}
|
||||
|
||||
@Around("logPointCut()")
|
||||
@ -47,10 +50,10 @@ public class SysLogAspect {
|
||||
Object result = point.proceed();
|
||||
//执行时长(毫秒)
|
||||
long time = System.currentTimeMillis() - beginTime;
|
||||
|
||||
|
||||
//保存日志
|
||||
saveSysLog(point, time);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -59,7 +62,7 @@ public class SysLogAspect {
|
||||
Method method = signature.getMethod();
|
||||
|
||||
SysLogEntity sysLog = new SysLogEntity();
|
||||
|
||||
|
||||
SysLog syslog = method.getAnnotation(SysLog.class);
|
||||
if(syslog != null){
|
||||
//注解上的描述
|
||||
@ -86,7 +89,18 @@ public class SysLogAspect {
|
||||
sysLog.setIp(IPUtils.getIpAddr(request));
|
||||
//用户名
|
||||
String username = SecurityUtils.getSubject().getPrincipal()==null ? null : ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
|
||||
if(className=="com.platform.modules.qk.controller.CloudClipsController" || className.equals("com.platform.modules.qk.controller.CloudClipsController")){
|
||||
if("com.platform.modules.sys.controller.SysLoginController".equals(className) && "login".equals(methodName)){
|
||||
|
||||
// 创建 JsonParser 实例
|
||||
JsonParser parser = new JsonParser();
|
||||
|
||||
// 将 JSON 字符串解析为 JsonObject
|
||||
JsonObject jsonObject = parser.parse(sysLog.getParams()).getAsJsonObject();
|
||||
|
||||
// 获取 username 的值
|
||||
username = jsonObject.get("username").getAsString();
|
||||
}
|
||||
if(className=="com.platform.modules.qk.controller.CloudClipsController" || className.equals("com.platform.modules.qk.controller.CloudClipsController")){
|
||||
username = "趣看";
|
||||
}else if("com.platform.modules.live.controller.LiveNotifyController".equals(className)){
|
||||
username = "阿里云";
|
||||
|
||||
@ -10,14 +10,14 @@ import org.quartz.*;
|
||||
*/
|
||||
public class ScheduleUtils {
|
||||
private final static String JOB_NAME = "TASK_";
|
||||
|
||||
|
||||
/**
|
||||
* 获取触发器key
|
||||
*/
|
||||
public static TriggerKey getTriggerKey(Long jobId) {
|
||||
return TriggerKey.triggerKey(JOB_NAME + jobId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取jobKey
|
||||
*/
|
||||
@ -49,13 +49,16 @@ public class ScheduleUtils {
|
||||
.withMisfireHandlingInstructionDoNothing();
|
||||
|
||||
//按新的cronExpression表达式构建一个新的trigger
|
||||
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(scheduleJob.getJobId())).withSchedule(scheduleBuilder).build();
|
||||
CronTrigger trigger = TriggerBuilder.newTrigger()
|
||||
.withIdentity(getTriggerKey(scheduleJob.getJobId()))
|
||||
.withSchedule(scheduleBuilder)
|
||||
.build();
|
||||
|
||||
//放入参数,运行时的方法可以获取
|
||||
jobDetail.getJobDataMap().put(ScheduleJobEntity.JOB_PARAM_KEY, scheduleJob);
|
||||
|
||||
scheduler.scheduleJob(jobDetail, trigger);
|
||||
|
||||
|
||||
//暂停任务
|
||||
if(scheduleJob.getStatus() == Constant.ScheduleStatus.PAUSE.getValue()){
|
||||
pauseJob(scheduler, scheduleJob.getJobId());
|
||||
@ -64,7 +67,7 @@ public class ScheduleUtils {
|
||||
throw new RRException("创建定时任务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新定时任务
|
||||
*/
|
||||
@ -77,20 +80,20 @@ public class ScheduleUtils {
|
||||
.withMisfireHandlingInstructionDoNothing();
|
||||
|
||||
CronTrigger trigger = getCronTrigger(scheduler, scheduleJob.getJobId());
|
||||
|
||||
|
||||
//按新的cronExpression表达式重新构建trigger
|
||||
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
|
||||
|
||||
|
||||
//参数
|
||||
trigger.getJobDataMap().put(ScheduleJobEntity.JOB_PARAM_KEY, scheduleJob);
|
||||
|
||||
|
||||
scheduler.rescheduleJob(triggerKey, trigger);
|
||||
|
||||
|
||||
//暂停任务
|
||||
if(scheduleJob.getStatus() == Constant.ScheduleStatus.PAUSE.getValue()){
|
||||
pauseJob(scheduler, scheduleJob.getJobId());
|
||||
}
|
||||
|
||||
|
||||
} catch (SchedulerException e) {
|
||||
throw new RRException("更新定时任务失败", e);
|
||||
}
|
||||
@ -104,7 +107,7 @@ public class ScheduleUtils {
|
||||
//参数
|
||||
JobDataMap dataMap = new JobDataMap();
|
||||
dataMap.put(ScheduleJobEntity.JOB_PARAM_KEY, scheduleJob);
|
||||
|
||||
|
||||
scheduler.triggerJob(getJobKey(scheduleJob.getJobId()), dataMap);
|
||||
} catch (SchedulerException e) {
|
||||
throw new RRException("立即执行定时任务失败", e);
|
||||
|
||||
@ -67,4 +67,12 @@ public interface LiveSceneDao extends BaseMapper<LiveSceneEntity> {
|
||||
|
||||
@Select("select id,title,title_image,live_state from live_scene where scene_state = 2 by live_start desc limit 20;")
|
||||
List<LiveSceneDTO> getMoreScenes();
|
||||
|
||||
@Update("<script>" +
|
||||
"UPDATE live_scene SET hot_spot = 1 WHERE id IN " +
|
||||
"<foreach item='id' collection='ids' open='(' separator=',' close=')'>" +
|
||||
"#{id}" +
|
||||
"</foreach>" +
|
||||
"</script>")
|
||||
void batchUpdateHotSpot(@Param("ids") List<Long> ids);
|
||||
}
|
||||
|
||||
@ -2420,6 +2420,7 @@ public class LiveSceneServiceImpl extends ServiceImpl<LiveSceneDao, LiveSceneEnt
|
||||
@Override
|
||||
public void cycleDelete(Integer[] ids){
|
||||
this.baseMapper.deleteBatchIds(Arrays.asList(ids));
|
||||
|
||||
}
|
||||
|
||||
private void saveSceneChannels(LiveSceneEntity liveScene, List<Integer> channelsId) {
|
||||
@ -2844,7 +2845,6 @@ public class LiveSceneServiceImpl extends ServiceImpl<LiveSceneDao, LiveSceneEnt
|
||||
createSceneIndex(entity, null, null, entity.getLiveState(), null, null);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> countBySceneState() {
|
||||
ArrayList<Long> result = new ArrayList<>();
|
||||
@ -2859,19 +2859,27 @@ public class LiveSceneServiceImpl extends ServiceImpl<LiveSceneDao, LiveSceneEnt
|
||||
result.add(count);
|
||||
//2.统计总时间(所有现场流的推流结束时间-推流开始时间之和)
|
||||
List<LiveSceneLiveInfoEntity> liveInfoEntities = liveSceneLiveInfoService.selectList(null);
|
||||
long sum = liveInfoEntities.stream().mapToLong(entity -> {
|
||||
Instant pushStart = entity.getPushStart().toInstant();
|
||||
Instant pushEnd = entity.getPushEnd().toInstant();
|
||||
return Duration.between(pushStart,pushEnd).toHours();
|
||||
}).sum();
|
||||
if(liveInfoEntities != null) {
|
||||
long sum = liveInfoEntities.stream()
|
||||
.filter(entity -> entity.getPushStart() != null && entity.getPushEnd() != null)
|
||||
.mapToLong(entity -> {
|
||||
Instant pushStart = entity.getPushStart().toInstant();
|
||||
Instant pushEnd = entity.getPushEnd().toInstant();
|
||||
return Duration.between(pushStart, pushEnd).toHours();
|
||||
}).sum();
|
||||
|
||||
result.add(sum);
|
||||
result.add(sum);
|
||||
}else {
|
||||
result.add(0L);
|
||||
}
|
||||
|
||||
//3.统计总观看人数
|
||||
EntityWrapper<LiveSceneCountEntity> countWrapper = new EntityWrapper<>();
|
||||
countWrapper.eq("scene_state", SceneConstants.SCENE_PROD);
|
||||
List<LiveSceneCountEntity> countEntities = liveSceneCountService.selectList(countWrapper);
|
||||
long sumViews = countEntities.stream().mapToLong(LiveSceneCountEntity::getViewsShow).sum();
|
||||
long sumViews = countEntities.stream()
|
||||
.filter(entity -> entity.getViewsShow() != null)
|
||||
.mapToLong(LiveSceneCountEntity::getViewsShow)
|
||||
.sum();
|
||||
result.add(sumViews);
|
||||
return result;
|
||||
}
|
||||
@ -2907,9 +2915,13 @@ public class LiveSceneServiceImpl extends ServiceImpl<LiveSceneDao, LiveSceneEnt
|
||||
sysConfigService.updateValueByKey("HOT_LIST_DISPLAY_COUNT", String.valueOf(count));
|
||||
List<SceneDTO> sceneDTOS = liveSceneDao.hotList(count);
|
||||
liveSceneDao.resetHotSpot();
|
||||
sceneDTOS.forEach(sceneDTO -> {
|
||||
liveSceneDao.updateHotSpot(sceneDTO.getId());
|
||||
});
|
||||
// sceneDTOS.forEach(sceneDTO -> {
|
||||
// liveSceneDao.updateHotSpot(sceneDTO.getId());
|
||||
// });
|
||||
|
||||
// 改为批量更新热点
|
||||
List<Long> ids = sceneDTOS.stream().map(SceneDTO::getId).collect(Collectors.toList());
|
||||
liveSceneDao.batchUpdateHotSpot(ids);
|
||||
return sceneDTOS;
|
||||
}
|
||||
|
||||
|
||||
@ -8,11 +8,9 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -14,6 +14,7 @@ import com.platform.modules.sys.service.SysConfigService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -37,7 +38,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigDao, SysConfigEnt
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void save(SysConfigEntity config) {
|
||||
this.insert(config);
|
||||
@ -52,7 +53,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigDao, SysConfigEnt
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
|
||||
public void updateValueByKey(String key, String value) {
|
||||
baseMapper.updateValueByKey(key, value);
|
||||
sysConfigRedis.delete(key);
|
||||
@ -79,7 +80,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigDao, SysConfigEnt
|
||||
|
||||
return config == null ? null : config.getValue();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T> T getConfigObject(String key, Class<T> clazz) {
|
||||
String value = getValue(key);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user