Commit 942bd075 authored by liwei's avatar liwei

新增了刷新话题动态数的定时任务

parent 11b26e11
......@@ -36,5 +36,12 @@ public interface OpmTopicRepository extends CyBaseMapper<OpmTopic> {
//权重验重
OpmTopic checkWeight(@Param("weight")Integer weight);
//查询所有话题
List<OpmTopic> selectAllTopic();
//查询某个话题下的动态数
Integer selectArticleCountByTopicId(Integer businessId);
int updateArticleCountById(@Param("entity") OpmTopic topic);
}
......@@ -4,9 +4,13 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.rcisoft.business.opmArticle.dao.OpmArticleRepository;
import org.rcisoft.business.opmArticle.entity.OpmArticle;
import org.rcisoft.business.opmTopic.dao.OpmTopicRepository;
import org.rcisoft.business.opmTopic.entity.OpmTopic;
import org.rcisoft.business.opmTopic.service.OpmTopicService;
import org.rcisoft.business.sysScheduledTaskLog.entity.SysScheduledTaskLog;
import org.rcisoft.business.sysScheduledTaskLog.service.SysScheduledTaskLogService;
import org.rcisoft.core.exception.CyServiceException;
import org.rcisoft.core.model.CyPageInfo;
import org.rcisoft.core.model.CyPersistModel;
......@@ -17,6 +21,7 @@ import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
......@@ -28,8 +33,10 @@ import java.util.List;
@Slf4j
public class OpmTopicServiceImpl extends ServiceImpl<OpmTopicRepository, OpmTopic> implements OpmTopicService {
@Autowired
private OpmArticleRepository opmArticleRepository;
@Autowired
private SysScheduledTaskLogService sysScheduledTaskLogServiceImpl;
/**
* 保存 话题
......@@ -164,4 +171,33 @@ public class OpmTopicServiceImpl extends ServiceImpl<OpmTopicRepository, OpmTopi
return new CyPersistModel(line);
}
/**
* 定时更新话题表的动态数
*/
public void opmTopicSchedule() {
try {
//查询所有话题
List<OpmTopic> allTopicList = baseMapper.selectAllTopic();
allTopicList.forEach(topic -> {
Integer articleCount = baseMapper.selectArticleCountByTopicId(topic.getBusinessId());
topic.setArticleCount(articleCount);
baseMapper.updateArticleCountById(topic);
});
SysScheduledTaskLog sysScheduledTaskLog = new SysScheduledTaskLog();
sysScheduledTaskLog.setTaskName("定时更新话题表动态数定时任务");
sysScheduledTaskLog.setTaskState("成功");
sysScheduledTaskLog.setTaskTime("每2小时执行一次");
sysScheduledTaskLog.setCreateDate(new Date());
sysScheduledTaskLogServiceImpl.persist(sysScheduledTaskLog);
} catch (Exception e) {
SysScheduledTaskLog sysScheduledTaskLog = new SysScheduledTaskLog();
sysScheduledTaskLog.setTaskName("定时更新话题表动态数定时任务");
sysScheduledTaskLog.setTaskState("失败");
sysScheduledTaskLog.setTaskTime("每2小时执行一次");
sysScheduledTaskLog.setCreateDate(new Date());
sysScheduledTaskLogServiceImpl.persist(sysScheduledTaskLog);
}
}
}
......@@ -11,6 +11,7 @@ import org.rcisoft.business.memInfo.service.impl.MemInfoServiceImpl;
import org.rcisoft.business.memLeaveMessage.service.impl.MemLeaveMessageServiceImpl;
import org.rcisoft.business.memTraffic.service.MemTrafficService;
import org.rcisoft.business.memTraffic.service.impl.MemTrafficServiceImpl;
import org.rcisoft.business.opmTopic.service.impl.OpmTopicServiceImpl;
import org.rcisoft.core.service.CyRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
......@@ -36,6 +37,8 @@ public class ScheduleTasks {
private MemLeaveMessageServiceImpl memLeaveMessageService;
@Autowired
private MemTrafficServiceImpl memTrafficService;
@Autowired
private OpmTopicServiceImpl opmTopicServiceImpl;
/**
* 每俩小时 执行一次点赞数据定时任务 将点赞数据同步到点赞表表中
......@@ -103,5 +106,13 @@ public class ScheduleTasks {
memTrafficService.memTrafficSchedule();
}
/**
* 定时更新话题表 刷新话题表的动态数
* 每俩小时执行一次
*/
@Scheduled(cron = "0 0 */2 * * ?")
public void opmTopicSchedule() {
opmTopicServiceImpl.opmTopicSchedule();
}
}
......@@ -142,4 +142,24 @@
and del_flag = '0'
and weight = #{weight}
</select>
<select id="selectAllTopic" resultType="org.rcisoft.business.opmTopic.entity.OpmTopic">
select *
from opm_topic
where 1=1
and del_flag = '0'
</select>
<select id="selectArticleCountByTopicId" resultType="java.lang.Integer">
select COUNT(*)
from opm_article
where 1=1
and del_flag = '0'
and flag = '1'
and exam_status = '1'
and topic_id = #{topicId}
</select>
<update id="updateArticleCountById">
update opm_topic
set article_count = #{entity.articleCount}
where business_id = #{entity.businessId}
</update>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment