Compare commits

..

12 Commits

Author SHA1 Message Date
670788339
d3e84feb48 日志 2025-03-29 12:58:43 +08:00
670788339
d4964ca7f1 日志 2025-03-29 12:22:11 +08:00
670788339
efdfa6f00c study-video-time 最后修改时间调整 2025-03-29 10:51:08 +08:00
670788339
500fb090fb 在线课-外部讲师报错 添加讲师类型 2025-03-19 13:17:06 +08:00
670788339
ee95435d01 在线课-外部讲师报错 添加供应商 2025-03-19 13:08:54 +08:00
670788339
76f0d1933a 在线课-外部讲师报错 2025-03-19 11:56:48 +08:00
670788339
58d6f49006 考试提交调用加catch 2025-03-13 10:03:21 +08:00
670788339
c8ffdd561f 考试提交调用course项目同步 2025-03-10 16:03:10 +08:00
670788339
98611edcaa 考试提交调用course项目同步 2025-03-10 16:02:19 +08:00
670788339
8aea21bde7 参数转换 2025-03-10 14:32:21 +08:00
670788339
a79f6b43b2 日志 2025-03-10 14:22:03 +08:00
670788339
81ea19f0f3 study-video-time redis优化 2025-03-03 17:49:49 +08:00
10 changed files with 333 additions and 108 deletions

View File

@@ -8,9 +8,11 @@ import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.boe.feign.api.courseweb.entity.ExamTestDto;
import com.boe.feign.api.courseweb.entity.ProjectStudyDto;
import com.boe.feign.api.courseweb.remote.ExternalRemoteClient;
import com.boe.feign.api.courseweb.remote.OffCourseRemoteClient;
import com.boe.feign.api.courseweb.remote.ProjectAdminRemoteClient;
import com.boe.feign.api.courseweb.remote.ProjectRemoteClient;
import com.boe.feign.api.courseweb.reps.ExamStudyRecordParam;
import com.boe.feign.api.infrastructure.entity.CommonSearchVo;
import com.boe.feign.api.infrastructure.entity.Dict;
import com.boe.feign.api.infrastructure.remote.DictRemoteClient;
@@ -73,6 +75,8 @@ public class ThirdApi {
@Resource
private ProjectRemoteClient projectRemoteClient;
@Resource
ExternalRemoteClient externalRemoteClient;
@Resource
private DictRemoteClient dictRemoteClient;
@@ -262,11 +266,19 @@ public class ThirdApi {
}
public List<StudyCourse> getStudyCourseList(String studyId, String courseId, String token) {
log.info(" 1 studyId = "+ studyId + " ,courseId = " + courseId );
if ( studyId == null || courseId == null ){
log.error(" 在线课学习记录 参数不能为空 ");
return new ArrayList<>();
}
StudyCourseVo studyCourseVo = new StudyCourseVo();
studyCourseVo.setStudyId(studyId);
studyCourseVo.setCourseId(courseId);
ProjectStudyDto projectStudyDto = new ProjectStudyDto();
BeanUtil.copyProperties(studyCourseVo, studyCourseVo);
// BeanUtil.copyProperties(studyCourseVo, studyCourseVo);
projectStudyDto.setStudyId(Long.parseLong(studyId));
projectStudyDto.setCourseId(Long.parseLong(courseId));
log.info(" 12 在线课学习记录 studyId = "+ projectStudyDto.getStudyId() + " ,courseId = " + projectStudyDto.getCourseId() );
projectRemoteClient.updateStudyStatus(projectStudyDto);
return new ArrayList<>();
}
@@ -382,4 +394,8 @@ public class ThirdApi {
.body()).orElseThrow(() -> new RuntimeException("token校验失败"));
log.info("updateOrSaveCourse = " + resp);
}
public void syncExamStudyRecord(ExamStudyRecordParam param) {
externalRemoteClient.syncExamStudyRecord(param);
}
}

View File

@@ -327,9 +327,7 @@ public class CoursePortalApi extends ApiBaseController{
teacherCourseDto.setSysCreateBy(ct.getSysCreateBy());
teacherCourseDto.setSysCreateTime(ct.getSysCreateTime());
teacherCourseDto.setId(ct.getId());
if(user!=null){
teacherCourseDto.setUserNo(user.getUserNo());
}
teacherCourseDto.setUserNo(user.getUserNo());
teacherCourseDtos.add(teacherCourseDto);
}else if (redisTemplate.opsForValue().get(ct.getTeacherId())==null){
List<String> list=new ArrayList<>();
@@ -347,9 +345,7 @@ public class CoursePortalApi extends ApiBaseController{
teacherCourseDto.setSysCreateBy(ct.getSysCreateBy());
teacherCourseDto.setSysCreateTime(ct.getSysCreateTime());
teacherCourseDto.setId(ct.getId());
if(user!=null){
teacherCourseDto.setUserNo(user.getUserNo());
}
teacherCourseDto.setUserNo(user.getUserNo());
teacherCourseDtos.add(teacherCourseDto);
}
}

View File

@@ -49,4 +49,12 @@ public class CourseTeacher extends IdBaseEntity {
@Transient
private String code;
/**供应商*/
@Transient
private String supplier;
/**讲师类型 1 内部讲师 2外部讲师*/
@Transient
private Integer teacherType;
}

View File

@@ -8,6 +8,8 @@ import java.util.Map;
import javax.annotation.Resource;
import com.boe.feign.api.courseweb.reps.ExamStudyRecordParam;
import com.xboe.api.ThirdApi;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -37,7 +39,10 @@ public class AloneExamServiceImpl implements IAloneExamService{
@Resource
AloneExamDao aeDao;
@Resource
private ThirdApi thirdApi;
@Override
@Transactional
public void save(AloneExamAnswer aea){
@@ -101,7 +106,18 @@ public class AloneExamServiceImpl implements IAloneExamService{
// //这种情况汶是不存在的
// }
}
}
try {
ExamStudyRecordParam param = new ExamStudyRecordParam();
param.setTestId(aea.getTestId());
param.setAid(aea.getAid());
thirdApi.syncExamStudyRecord(param);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
@Transactional

View File

@@ -204,6 +204,8 @@ public class StudyCourseApi extends ApiBaseController{
Teacher t = teacherService.get(ct.getTeacherId());
if(t!=null) {
ct.setRemark(t.getDescription());
ct.setSupplier(t.getSupplier());
ct.setTeacherType(t.getTeacherType());
}
if(redisTemplate.opsForValue().get(ct.getTeacherId())==null){
List<String>list=new ArrayList<>();
@@ -212,11 +214,11 @@ public class StudyCourseApi extends ApiBaseController{
redisTemplate.opsForValue().set(teacherVo.get(0).getTeacherId(), teacherVo.get(0).getStatus());
//设置过期时间为1天
redisTemplate.expire(teacherVo.get(0).getTeacherId(), 24 * 60 * 60, TimeUnit.SECONDS);
if (Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1")){
if (Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1") && t.getTeacherType() == 1 ){
ct.setTeacherName("BOE教师");
}
}
if (Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1")){
if (Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1") && t.getTeacherType() == 1 ){
ct.setTeacherName("BOE教师");
}
}
@@ -343,6 +345,8 @@ public class StudyCourseApi extends ApiBaseController{
}
//追加学习时长
studyService.appendStudyDuration(sci.getStudyId(),item.getId(),sci.getContentId(),sci.getDuration());
log.info(" 1 在线课学习记录 sci.getStudyId() = "+ sci.getStudyId() + " , sci.getCourseId() = " + sci.getCourseId() );
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(sci.getStudyId() ,sci.getCourseId(), token);
log.info("在线课学习记录"+allUserList);
return success(item.getId());

View File

@@ -0,0 +1,108 @@
package com.xboe.school.study.api;
import com.xboe.school.study.service.IStudyService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
* @author by lyc
* @date 2025/3/3
*/
@Component
@Slf4j
@RequiredArgsConstructor
public class StudyCourseTask {
private final IStudyService studyService;
private final StringRedisTemplate redisTemplate;
/**
* 定时任务
* 获取redis 中学习结束的数据更新入库
* */
@XxlJob("saveStudyCourseItemLastTime")
public void saveStudyCourseItemLastTime() {
log.info("------定时任务-获取redis 中学习结束的数据更新入库------" );
// 1. 定义匹配模式匹配所有目标key
final String KEY_PATTERN = "studyContentId:*:last_active";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
// 2. 使用SCAN安全遍历避免阻塞
ScanOptions options = ScanOptions.scanOptions()
.match(KEY_PATTERN)
.count(100) // 分页大小
.build();
try (RedisConnection connection = Objects.requireNonNull(redisTemplate.getConnectionFactory()).getConnection()) {
Cursor<byte[]> cursor = connection.scan(options);
// 3. 遍历处理符合条件的key
while (cursor.hasNext()) {
String redisKey = new String(cursor.next());
log.info("------定时任务-获取redis 中学习结束的数据更新入库------redisKey = " + redisKey );
// 4. 获取剩余TTL
Long ttl = redisTemplate.getExpire(redisKey, TimeUnit.SECONDS);
log.info("------定时任务-获取redis 中学习结束的数据更新入库------ttl = " + ttl );
// 5. 过滤条件:剩余时间 >= 29天23小时30分钟转换为秒
// 总需时间 = (30天 - 30分钟) = 29天23小时30分钟 = 2590200秒
// 5分钟 300秒 || 2592000 - 300 = 2591700
if (ttl <= 2590200) {
try {
// 6. 提取studyContentId
String[] parts = redisKey.split(":");
if (parts.length < 2) continue;
String studyContentId = parts[1];
// 7. 获取存储的时间点(示例逻辑)
String redisValue = redisTemplate.opsForValue().get(redisKey);
if (redisValue == null) continue;
String[] partValues = redisValue.split("&");
int lastStudyTime = Integer.parseInt(partValues[0]);
LocalDateTime timestamp = null;
if (partValues.length >= 2){
timestamp = LocalDateTime.parse(partValues[1], formatter);
}
log.info("-定时任务-获取redis 中学习结束的数据更新入库---studyContentId = " + studyContentId + ",lastStudyTime = " + lastStudyTime + ", timestamp = " + timestamp);
// 8. 更新数据库(调用已有服务方法)
studyService.updateStudyCourseItemLastTime(studyContentId, lastStudyTime, timestamp);
// 9. 删除Redis键原子操作
redisTemplate.delete(redisKey);
log.info("处理成功 key: {}, lastStudyTime: {}", redisKey, lastStudyTime);
} catch (Exception e) {
log.error("处理失败 key: {}", redisKey, e);
}
}
}
cursor.close();
} catch (Exception e) {
log.error("定时任务执行异常", e);
}
/* // 新增日志逻辑
if (ttl <= 172800) {
studyService.saveCourseExpireLog(
studyContentId,
lastStudyTime,
redisKey,
ttl,
"system_job"
);
}*/
}
}

View File

@@ -1,5 +1,6 @@
package com.xboe.school.study.service;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@@ -99,4 +100,5 @@ public interface IStudyService {
List<StudyCourseItem> getList(String courseId, String contentId, String name, Integer status);
void updateStudyCourseItemLastTime(String studyContentId, int lastStudyTime, LocalDateTime timestamp);
}

View File

@@ -1,5 +1,6 @@
package com.xboe.school.study.service.impl;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@@ -15,6 +16,7 @@ import com.xboe.school.study.entity.StudyCourse;
import com.xboe.system.user.entity.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import com.xboe.common.OrderCondition;
@@ -51,7 +53,10 @@ public class StudyServiceImpl implements IStudyService{
@Autowired
UserDao userDao;
@Autowired
StringRedisTemplate redisTemplate;
@Override
public StudyCourseItem checkHas(String studyId,String contentId) {
List<StudyCourseItem> items = scItemDao.findList(FieldFilters.eq("studyId", studyId),FieldFilters.eq("contentId", contentId));
@@ -324,8 +329,26 @@ public class StudyServiceImpl implements IStudyService{
// 更新 前端传输已学习时长
@Override
@Transactional
public void updateLastTime(String studyContentId, int lastStudyTime,String aid) {
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
String value = lastStudyTime + "&" + now.format(formatter); // 使用ISO8601时间格式
log.info("-study-video-time-----value = " + value);
// 20250303 优化 多次更新改一次更新
// 更新Redis中的最后活跃时间带30秒过期
redisTemplate.opsForValue().set(
"studyContentId:" + studyContentId + ":last_active",
value,
Duration.ofSeconds(2592000)
);
log.info("-study-video-time-redis保存---value = " + value);
// Duration.ofDays(30) 也就是 2592000秒
}
@Override
@Transactional
public void updateStudyCourseItemLastTime(String studyContentId, int lastStudyTime,LocalDateTime timestamp) {
log.info("-study-video-time-定时---studyContentId = " + studyContentId + ",lastStudyTime = " + lastStudyTime + ", timestamp = " + timestamp);
// 更新最后的学习时间点
LocalDateTime now=LocalDateTime.now();
UpdateBuilder update=UpdateBuilder.from(StudyCourseItem.class);
@@ -333,9 +356,9 @@ public class StudyServiceImpl implements IStudyService{
//只记录时间长的时候的处理
update.addFilter(FieldFilters.lt("lastStudyTime", lastStudyTime));
update.addUpdateField("lastStudyTime", lastStudyTime);
update.addUpdateField("lastTime", now);
update.addUpdateField("lastTime", timestamp==null ? now : timestamp);
scItemDao.update(update.builder());
//增加用户的学习时长,在api中调用
log.info("-study-video-time-mysql保存---studyContentId = " + studyContentId);
}
@Override

View File

@@ -1,102 +1,159 @@
boe:
domain: http://192.168.0.253
spring:
# application.yml
servlet:
multipart:
max-file-size: 1000MB
max-request-size: 1000MB
web:
resources:
static-locations: file:E:/Projects/BOE/java/static
cloud:
nacos:
discovery:
server-addr: 192.168.0.253:8848
config:
server-addr: 192.168.0.253:8848
max-file-size: 500MB
max-request-size: 500MB
redis:
database: 1
host: 192.168.0.253
host: 192.168.0.101
password: boe@123
port: 6379
lettuce:
pool:
max-active: 8
min-idle: 0
max-idle: 30
max-wait: 10000ms
shutdown-timeout: 100ms
jpa:
database: MYSQL
properties:
hibernate:
naming_strategy: org.hibernate.cfg.EJB3NamingStrategy
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
current_session_context_class: org.springframework.orm.hibernate5.SpringSessionContext
show-sql: true
hibernate:
ddl-auto: none
ddl-auto: update
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.0.253:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.0.101:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
username: root
password: boe#1234A
type: com.zaxxer.hikari.HikariDataSource
hikari:
auto-commit: true
minimum-idle: 5
idle-timeout: 60000
connection-timeout: 30000
max-lifetime: 1800000
maximum-pool-size: 20
logging:
level:
org:
hibernate:
SQL: ERROR
config: classpath:log/logback-@profileActive@.xml
web:
resources:
static-locations: file:E:/Projects/BOE/10/static
server:
port: 9090
servlet:
multipart:
max-file-size: 500MB
max-request-size: 500MB
session:
timeout: 30m
encoding:
charset: UTF-8
enabled: true
force: true
tomcat:
uri-encoding: UTF-8
servlet:
multipart:
maxFileSize: 1024MB
maxRequestSize: 1024MB
mvc:
static-path-pattern: /cdn/**
#logging.level.org.hibernate.SQL=DEBUG
#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
#logging.config=classpath:log/logback-@profileActive@.xml
# logging:
# config: classpath:log/logback-${spring.profiles.active}.xml
# level:
# org:
# hibernate:
# SQL: DEBUG
# type:
# descriptor:
# sql:
# BasicBinder: TRACE
xcaching:
specs:
favorites:
timeout: 10s
praises:
timeout: 10s
shares:
timeout: 10s
xboe:
api:
cross_filter: true
local:
dev: true
upload:
file:
temp_path: /tmp
temp_path: D:/Projects/BOE/10/static/temp
save_path: /home/www/elearning/upload
http_path: http://192.168.0.253/upload
http_path: http://127.0.0.1/upload
externalinterface:
url:
system: http://127.0.0.1:9091
system: http://localhost:9091
old:
base:
url: http://192.168.0.253
url: http://192.168.0.101
server:
userbasic:
url: http://192.168.0.101/userbasic
stat:
base:
url: http://127.0.0.1:9080
server:
userbasic:
url: http://192.168.0.253/userbasic
elasticsearch:
server:
ip: 192.168.0.253
ip: 192.168.0.101
port: 9200
user:
password:
email:
url: http://192.168.0.253/api/b1/email/send
url: http://192.168.0.101/api/b1/email/send
from: boeu_learning@boe.com.cn
user:
security:
jasypt:
encryptor:
algorithm: PBEWithMD5AndDES
iv-generator-classname: org.jasypt.iv.NoIvGenerator
xxl:
job:
accessToken: 65ddc683-22f5-83b4-de3a-3c97a0a29af0
admin:
addresses: http://192.168.0.253/jobAdmin
executor:
appname: java-servers-job-api
port: 9995
address:
ip:
logpath: /var/log/xxl-job/dw/
logretentiondays: 30
aop-log-record:
#是否开启日志记录
enabled: true
#不进行拦截的包或者类
excludeClassNames:
activemq:
broker-url: tcp://192.168.0.253:61616
user: admin
password: admin
elasticsearch:
host: 192.168.0.253
port: 9200
jasypt:
encryptor:
algorithm: PBEWithMD5AndDES
iv-generator-classname: org.jasypt.iv.NoIvGenerator
boe:
domain: http://127.0.0.1
ok:
http:
connect-timeout: 30
read-timeout: 30
write-timeout: 30
max-idle-connections: 200
keep-alive-duration: 300
orgTree:
orgTreeList: ${boe.domain}/userbasic/org/list
orgChildTreeList: ${boe.domain}/userbasic/org/childOrgs
userBasic:
searchUserList: ${boe.domain}/userbasic/user/list
getUserBasicInfo: ${boe.domain}/userbasic/user/getUserBasicInfo
getTeacherIds: ${boe.domain}/userbasic/user/getTeacherInfo
audience:
usersByAudienceList: ${boe.domain}/userbasic/audience/memberList
getOrgUsers: ${boe.domain}/userbasic/user/getOrgUsers
statApi:
userdynamicList: ${boe.domain}/statApi/xboe/m/stat/userdynamic/list
infrasApi:
dict: ${boe.domain}/infrasApi/dict/list
manageApi:
stu:
offcourse: ${boe.domain}/manageApi/stu/offcourse/getOffCourseId
editExam: ${boe.domain}/manageApi/admin/project/editExam
getStudyStatus: ${boe.domain}/manageApi/stu/project/completeStatus
coursesuilt:
getStudyStatus: ${boe.domain}/manageApi/stu/project/completeStatus

View File

@@ -1,13 +1,13 @@
# application-pro.yml
# application-dev.yml
spring:
redis:
database: 1
host: 192.168.0.253
password: boe@123
database: 2
port: 6379
host: 192.168.0.101
password: boe@123
jpa:
hibernate:
ddl-auto: update
ddl-auto: none
open-in-view: false
properties:
hibernate:
@@ -16,46 +16,41 @@ spring:
driverClassName: com.mysql.jdbc.Driver
db1:
driverClassName: com.mysql.jdbc.Driver
jdbc-url: jdbc:mysql://192.168.0.253:3306/boe_basic?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
jdbc-url: jdbc:mysql://192.168.0.101:3306/boe_basic?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
username: root
password: boe#1234A
db2:
driverClassName: com.mysql.jdbc.Driver
jdbc-url: jdbc:mysql://192.168.0.253:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
jdbc-url: jdbc:mysql://192.168.0.101:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
username: root
password: boe#1234A
web:
resources:
static-locations: file:E:/Projects/BOE/java/static
web:
resources:
static-locations: file:E:/Projects/BOE/java/static
logging:
level:
org:
hibernate:
SQL: ERROR
# type:
# descriptor:
# sql:
# BasicBinder: TRACE
SQL: DEBUG
type:
descriptor:
sql:
BasicBinder: TRACE
config: classpath:log/logback-dev.xml
xboe:
api:
cross_filter: true
upload:
file:
temp_path: /tmp
save_path: /home/www/elearning/upload
http_path: http://192.168.0.253/upload
temp_path: E:/Projects/BOE/java/static/temp
save_path: E:/Projects/BOE/java/static/upload
http_path: http://localhost:9090/upload
inner:
data:
sync:
baseurl: http://127.0.0.1:9090
baseurl: http://localhost:9090
jasypt:
encryptor:
algorithm: PBEWithMD5AndDES
iv-generator-classname: org.jasypt.iv.NoIvGenerator
iv-generator-classname: org.jasypt.iv.NoIvGenerator