diff --git a/servers/boe-server-all/pom.xml b/servers/boe-server-all/pom.xml index ba338021..ff7cf2ac 100644 --- a/servers/boe-server-all/pom.xml +++ b/servers/boe-server-all/pom.xml @@ -236,7 +236,14 @@ spring-retry 1.3.1 - + + + com.xuxueli + xxl-job-core + 2.3.0 + + + diff --git a/servers/boe-server-all/src/main/java/com/xboe/XxlJobConfig.java b/servers/boe-server-all/src/main/java/com/xboe/XxlJobConfig.java new file mode 100644 index 00000000..929a5a72 --- /dev/null +++ b/servers/boe-server-all/src/main/java/com/xboe/XxlJobConfig.java @@ -0,0 +1,40 @@ +package com.xboe; + +import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class XxlJobConfig { + + @Value("${xxl.job.admin.addresses}") + private String adminAddresses; + @Value("${xxl.job.executor.appname}") + private String appName; + @Value("${xxl.job.executor.ip}") + private String ip; + @Value("${xxl.job.executor.port}") + private int port; + @Value("${xxl.job.accessToken}") + private String accessToken; + @Value("${xxl.job.executor.logpath}") + private String logPath; + @Value("${xxl.job.executor.logretentiondays}") + private int logRetentionDays; + + @Bean + public XxlJobSpringExecutor xxlJobExecutor() { + // 创建 XxlJobSpringExecutor 执行器 + XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); + xxlJobSpringExecutor.setAdminAddresses(adminAddresses); + xxlJobSpringExecutor.setAppname(appName); + xxlJobSpringExecutor.setIp(ip); + xxlJobSpringExecutor.setPort(port); + xxlJobSpringExecutor.setAccessToken(accessToken); + xxlJobSpringExecutor.setLogPath(logPath); + xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays); + // 返回 + return xxlJobSpringExecutor; + } +} \ No newline at end of file diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/api/CaseScheduledTasks.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/api/CaseScheduledTasks.java index 49212347..4cb651b4 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/api/CaseScheduledTasks.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/api/CaseScheduledTasks.java @@ -1,6 +1,7 @@ package com.xboe.module.boecase.api; import com.xboe.module.boecase.service.ICasesService; +import com.xxl.job.core.handler.annotation.XxlJob; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -16,6 +17,7 @@ public class CaseScheduledTasks { * 每月的第一天的1:00执行 */ // @Scheduled(cron = "0 0 1 1 * ?") + @XxlJob("refreshViewsRankOfMajor") public void refreshViewsRankOfMajor() { casesService.refreshViewsRankOfMajor(); } @@ -23,7 +25,8 @@ public class CaseScheduledTasks { /** * 季初第一天两点执行,cron表达式设置为每个季度的第一个月的第一天的特定时间。每个季度的第一个月是1月、4月、7月和10月: */ - @Scheduled(cron = "0 0 2 1 1,4,7,10 ?") +// @Scheduled(cron = "0 0 2 1 1,4,7,10 ?") + @XxlJob("refreshLastQuarterStatistics") public void refreshLastQuarterStatistics() { casesService.refreshLastQuarterStatistics(); } diff --git a/servers/boe-server-all/src/main/java/com/xboe/school/study/api/StudyCourseApi.java b/servers/boe-server-all/src/main/java/com/xboe/school/study/api/StudyCourseApi.java index 26d8e404..8663e426 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/school/study/api/StudyCourseApi.java +++ b/servers/boe-server-all/src/main/java/com/xboe/school/study/api/StudyCourseApi.java @@ -177,7 +177,7 @@ public class StudyCourseApi extends ApiBaseController{ if (!Objects.isNull(studyCourse)){ pass = true; } - if (Objects.isNull(studyCourse) && !courseCrowdList.isEmpty()) { + if (Objects.isNull(studyCourse) && !courseCrowdList.isEmpty() && !StringUtils.isEmpty(audiences)) { List audienceList = Arrays.asList(audiences.split(",")); // 此用户所在受众组 log.error("---------------参数------------ audienceList = " + audienceList); for (CourseCrowd c : courseCrowdList) { diff --git a/servers/boe-server-all/src/main/java/com/xboe/school/study/dao/StudyCourseDao.java b/servers/boe-server-all/src/main/java/com/xboe/school/study/dao/StudyCourseDao.java index 462f9c26..845eb56e 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/school/study/dao/StudyCourseDao.java +++ b/servers/boe-server-all/src/main/java/com/xboe/school/study/dao/StudyCourseDao.java @@ -2,10 +2,14 @@ package com.xboe.school.study.dao; import java.time.LocalDateTime; import java.util.List; +import java.util.concurrent.TimeUnit; import com.xboe.api.ThirdApi; +import com.xboe.constants.CacheName; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Repository; import com.xboe.core.orm.BaseDao; @@ -26,6 +30,9 @@ public class StudyCourseDao extends BaseDao { @Autowired StudyCourseItemDao scItemDao; + @Autowired + StringRedisTemplate redisTemplate; + @Resource private ThirdApi thirdApi; @@ -36,6 +43,11 @@ public class StudyCourseDao extends BaseDao { * @param total */ public void finishCheck(String studyId,String courseId,Integer total,String token){ + + if(StringUtils.isNotEmpty(redisTemplate.opsForValue().get(studyId + "_" + courseId + "_" + total))){ + return ; + } + log.info("------1.完成情况检查---------------studyId = " + studyId + " , courseId = " + courseId + " , total = " + total ); LocalDateTime now=LocalDateTime.now(); //已完成的内容 @@ -50,7 +62,9 @@ public class StudyCourseDao extends BaseDao { } log.info("------3.完成情况检查---------------studyId = " + studyId + " , courseId = " + courseId + " , total = " + total ); //以下注意,float类型,是否等于100对应 - float percent=n*100/total; + float percent=n*100/total; + + if(n>=total) { //自主报名的课程,代表学习完成 super.updateMultiFieldById(studyId, @@ -58,11 +72,13 @@ public class StudyCourseDao extends BaseDao { UpdateBuilder.create("lastTime",now), UpdateBuilder.create("finishTime",now), UpdateBuilder.create("status",StudyCourse.STATUS_FINISH)); + redisTemplate.opsForValue().set(studyId + "_" + courseId + "_" + total, "100", 24, TimeUnit.HOURS); }else { super.updateMultiFieldById(studyId, UpdateBuilder.create("progress",percent), UpdateBuilder.create("lastTime",LocalDateTime.now()), UpdateBuilder.create("status",StudyCourse.STATUS_STUDYING)); +// redisTemplate.opsForValue().set(studyId, String.valueOf(percent), 10, TimeUnit.SECONDS); } List allUserList = thirdApi.getStudyCourseList(studyId ,courseId, token); diff --git a/servers/boe-server-all/src/main/resources/application-pro.properties b/servers/boe-server-all/src/main/resources/application-pro.properties index 21371d27..65da10ba 100644 --- a/servers/boe-server-all/src/main/resources/application-pro.properties +++ b/servers/boe-server-all/src/main/resources/application-pro.properties @@ -74,3 +74,12 @@ xboe.email.url=https://u.boe.com/api/b1/email/send xboe.email.from=boeu_learning@boe.com.cn xboe.email.user= xboe.email.security= + +xxl.job.admin.addresses=http://u.boe.com/jobAdmin +xxl.job.accessToken=65ddc683-22f5-83b4-de3a-3c97a0a29af0 +xxl.job.executor.appname=java-servers-job-api +xxl.job.executor.port=9995 +xxl.job.executor.address= +xxl.job.executor.ip= +xxl.job.executor.logpath=/var/log/xxl-job/dw/ +xxl.job.executor.logretentiondays=30 \ No newline at end of file diff --git a/servers/boe-server-all/src/main/resources/application-test.properties b/servers/boe-server-all/src/main/resources/application-test.properties index 74d42897..e86c1314 100644 --- a/servers/boe-server-all/src/main/resources/application-test.properties +++ b/servers/boe-server-all/src/main/resources/application-test.properties @@ -80,4 +80,13 @@ xboe.email.from=boeu_learning@boe.com.cn xboe.email.user= xboe.email.security= -boe.domain=https://u-pre.boe.com \ No newline at end of file +boe.domain=https://u-pre.boe.com + +xxl.job.admin.addresses=http://u-pre.boe.com/jobAdmin +xxl.job.accessToken=65ddc683-22f5-83b4-de3a-3c97a0a29af0 +xxl.job.executor.appname=java-servers-job-api +xxl.job.executor.port=9995 +xxl.job.executor.address= +xxl.job.executor.ip= +xxl.job.executor.logpath=/var/log/xxl-job/dw/ +xxl.job.executor.logretentiondays=30 \ No newline at end of file