From dc326b3a42ee0c416e7c7e07f81cf0e4391352e2 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期二, 29 十月 2024 12:14:51 +0800
Subject: [PATCH] 交卷后不能作答
---
src/main/java/com/ycl/jxkg/service/impl/EducationResourceServiceImpl.java | 48 +++++++++++++++++++++++++++++-------------------
1 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/src/main/java/com/ycl/jxkg/service/impl/EducationResourceServiceImpl.java b/src/main/java/com/ycl/jxkg/service/impl/EducationResourceServiceImpl.java
index d18955c..5e0059d 100644
--- a/src/main/java/com/ycl/jxkg/service/impl/EducationResourceServiceImpl.java
+++ b/src/main/java/com/ycl/jxkg/service/impl/EducationResourceServiceImpl.java
@@ -5,6 +5,7 @@
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ycl.jxkg.base.Result;
+import com.ycl.jxkg.constants.CaffeineConstant;
import com.ycl.jxkg.context.WebContext;
import com.ycl.jxkg.domain.entity.EducationResource;
import com.ycl.jxkg.domain.entity.Subject;
@@ -18,13 +19,11 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
/**
* @author锛歠lq
@@ -35,12 +34,16 @@
@Slf4j
public class EducationResourceServiceImpl implements EducationResourceService {
+
private final EducationResourceMapper mapper;
private final SubjectMapper subjectMapper;
private final WebContext webContext;
private final ClassesUserMapper classesUserMapper;
@Autowired
private Cache<String, Object> caffeineCache;
+ @Value("${spring.config.url}")
+ private String url;
+
@Override
public Result add(EducationResourceVO form) {
EducationResource educationResource = new EducationResource();
@@ -86,6 +89,7 @@
page.getList().stream().forEach(item -> {
item.setContentUrl(JSON.parseObject(item.getContentUrlString(), EducationResourceVO.UploadFile.class));
item.setAttachment(JSON.parseArray(item.getAttachmentString(), EducationResourceVO.UploadFile.class));
+ item.setVisitUrl(url + "/api/files/" + item.getContentUrl().getUrl());
});
return Result.ok(page.getList()).put("total", page.getTotal());
}
@@ -105,6 +109,7 @@
page.getList().stream().forEach(item -> {
item.setContentUrl(JSON.parseObject(item.getContentUrlString(), EducationResourceVO.UploadFile.class));
item.setAttachment(JSON.parseArray(item.getAttachmentString(), EducationResourceVO.UploadFile.class));
+ item.setVisitUrl(url + "/api/files/" + item.getContentUrl().getUrl());
});
return Result.ok(page.getList()).put("total", page.getTotal());
}
@@ -114,27 +119,32 @@
List<Subject> subjects = subjectMapper.allSubject();
return Result.ok(subjects);
}
+
//璁板綍瑙嗛鏃堕暱
@Override
public Result recordTime(Integer userId) {
- if (userId ==null){
+ if (userId == null) {
throw new RuntimeException("鐢ㄦ埛id涓虹┖");
}
- StudyRecord studyRecord = (StudyRecord) caffeineCache.getIfPresent("STUDENT_"+userId);
- if (studyRecord != null) {
- //瀛樺湪缂撳瓨
- Date lastTime = studyRecord.getLastTime();
- Date now = new Date();
- studyRecord.setStudyTime(studyRecord.getStudyTime()+(now.getTime()-lastTime.getTime())/1000);
- studyRecord.setLastTime(now);
- }else {
- //涓嶅瓨鍦ㄧ紦瀛�
- studyRecord = new StudyRecord();
- studyRecord.setStudentId(userId);
- studyRecord.setStudyTime(0L);
- studyRecord.setLastTime(new Date());
+ Map<String, StudyRecord> studyMap = (Map<String, StudyRecord>) caffeineCache.getIfPresent(CaffeineConstant.STUDY_RECORD);
+ if (!CollectionUtils.isEmpty(studyMap)) {
+ StudyRecord studyRecord = studyMap.get(userId + "");
+ if (studyRecord != null) {
+ //瀛樺湪缂撳瓨
+ Date lastTime = studyRecord.getLastTime();
+ Date now = new Date();
+ studyRecord.setStudyTime(studyRecord.getStudyTime() + (now.getTime() - lastTime.getTime()) / 1000);
+ studyRecord.setLastTime(now);
+ } else {
+ //涓嶅瓨鍦ㄧ紦瀛�
+ studyRecord = new StudyRecord();
+ studyRecord.setStudentId(userId);
+ studyRecord.setStudyTime(0L);
+ studyRecord.setLastTime(new Date());
+ }
+ studyMap.put(userId + "", studyRecord);
+ caffeineCache.put(CaffeineConstant.STUDY_RECORD, studyMap);
}
- caffeineCache.put("STUDENT_" + userId, studyRecord);
return Result.ok();
}
}
--
Gitblit v1.8.0