From 967dee0ec73e696e745423fbd7d4998d6fa3627e Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期三, 10 七月 2024 15:43:25 +0800
Subject: [PATCH] 教学资源增加文件类型
---
src/main/resources/mapper/EducationResourceMapper.xml | 6 +++
src/main/java/com/ycl/jxkg/service/impl/EducationResourceServiceImpl.java | 47 ++++++++++++++---------
src/main/java/com/ycl/jxkg/controller/admin/UploadController.java | 3 +
src/main/resources/application-dev.yml | 3 +
src/main/resources/application-prod.yml | 2 +
src/main/java/com/ycl/jxkg/domain/vo/admin/education/EducationResourceVO.java | 1
6 files changed, 43 insertions(+), 19 deletions(-)
diff --git a/src/main/java/com/ycl/jxkg/controller/admin/UploadController.java b/src/main/java/com/ycl/jxkg/controller/admin/UploadController.java
index 6614268..d25c463 100644
--- a/src/main/java/com/ycl/jxkg/controller/admin/UploadController.java
+++ b/src/main/java/com/ycl/jxkg/controller/admin/UploadController.java
@@ -12,6 +12,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -41,6 +42,8 @@
private final UserService userService;
private final RuoYiConfig ruoYiConfig;
+
+
@Autowired
public UploadController(FileUpload fileUpload, SystemConfig systemConfig, UserService userService, RuoYiConfig ruoYiConfig) {
this.fileUpload = fileUpload;
diff --git a/src/main/java/com/ycl/jxkg/domain/vo/admin/education/EducationResourceVO.java b/src/main/java/com/ycl/jxkg/domain/vo/admin/education/EducationResourceVO.java
index 12ee9c9..2ed78dc 100644
--- a/src/main/java/com/ycl/jxkg/domain/vo/admin/education/EducationResourceVO.java
+++ b/src/main/java/com/ycl/jxkg/domain/vo/admin/education/EducationResourceVO.java
@@ -62,6 +62,7 @@
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
+ private String visitUrl;
@Data
public static class UploadFile {
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..c2c484b 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());
}
@@ -114,27 +118,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();
}
}
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
index 3967ffa..aa4e6d9 100644
--- a/src/main/resources/application-dev.yml
+++ b/src/main/resources/application-dev.yml
@@ -5,7 +5,10 @@
# 鏂囦欢璺緞 绀轰緥锛� Windows閰嶇疆D:/ruoyi/uploadPath锛孡inux閰嶇疆 /home/ruoyi/uploadPath锛�
url: D:/ycl/file
+
spring:
+ config:
+ url: http://localhost:8000
datasource:
url: jdbc:mysql://42.193.1.25:3306/xzs?useSSL=true&useUnicode=true&serverTimezone=GMT%2B8&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&allowMultiQueries=true
username: root
diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml
index 9d725da..2869bad 100644
--- a/src/main/resources/application-prod.yml
+++ b/src/main/resources/application-prod.yml
@@ -6,6 +6,8 @@
url: E:/ycl/file
spring:
+ config:
+ url: https://42.193.1.25:8000
datasource:
url: jdbc:mysql://42.193.1.25:3306/xzs?useSSL=true&useUnicode=true&serverTimezone=GMT%2B8&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&allowMultiQueries=true
username: root
diff --git a/src/main/resources/mapper/EducationResourceMapper.xml b/src/main/resources/mapper/EducationResourceMapper.xml
index cb750e2..4180bc8 100644
--- a/src/main/resources/mapper/EducationResourceMapper.xml
+++ b/src/main/resources/mapper/EducationResourceMapper.xml
@@ -32,6 +32,9 @@
<if test="query.classId != null">
AND ter.class_id = #{query.classId}
</if>
+ <if test="query.contentType != null and query.contentType != '' ">
+ AND ter.content_type = #{query.contentType}
+ </if>
</where>
ORDER BY
ter.create_time DESC
@@ -65,6 +68,9 @@
<if test="query.subjectId != null">
AND ter.subject_id = #{query.subjectId}
</if>
+ <if test="query.contentType != null and query.contentType != '' ">
+ AND ter.content_type = #{query.contentType}
+ </if>
</where>
ORDER BY
ter.create_time DESC
--
Gitblit v1.8.0