diff --git a/pom.xml b/pom.xml
index 802b602..2d3b361 100644
--- a/pom.xml
+++ b/pom.xml
@@ -128,6 +128,12 @@
org.springframework.boot
spring-boot-starter-data-redis
+
+
+ cn.hutool
+ hutool-all
+ 5.3.8
+
diff --git a/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java
index 42eff09..a87d5c1 100644
--- a/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java
+++ b/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java
@@ -1,5 +1,6 @@
package com.msdw.tms.service.impl;
+import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -409,37 +410,32 @@ public class QuestionsServiceImpl extends ServiceImpl ops = stringRedisTemplate.opsForValue();
-
String key = REMAINING_TINE_KEY + userId;
-
String startTime = ops.get(key);
- int remainingTime = duration;
+ // 剩余时间,单位:秒
+ int remainingTime = duration * 60;
if (StringUtils.isEmpty(startTime)) {
//如果没有,表示是开始测评,向redis中插入一条数据,key是前缀加用户id,value是当前时间,过期时间是测评时长加十秒
- ops.set(key, getSecondTimestamp(new Date()) + "", duration * 60 + 10, TimeUnit.SECONDS);
-
+ ops.set(key, String.valueOf(System.currentTimeMillis()), duration * 60 + 10, TimeUnit.SECONDS);
} else {
- int difference = getSecondTimestamp(new Date()) - Integer.valueOf(startTime);
- remainingTime = duration - difference;
+ // 当前时间与开始时间得时间差,单位:毫秒
+ long difference = System.currentTimeMillis() - Long.parseLong(startTime);
+ remainingTime = (duration * 60) - (new Long(difference).intValue() / 1000);
if (remainingTime < 0) {
ExceptionCast.cast(CommonCode.EVALUATION_TIME_INVALID);
}
}
- evaluation.setRemainingDuration(formatDateTime(remainingTime));
-
+ evaluation.setRemainingDuration(DateUtil.secondToTime(remainingTime));
//搜集随机抽取的试题
Set set = new HashSet<>();
-
//根据测评规则的类型不同
Integer evaluationType = evaluationRules.getEvaluationType();
if (evaluationType.equals(Constant.RulesType.RANDOM.getType())) {//随机
@@ -455,7 +451,6 @@ public class QuestionsServiceImpl extends ServiceImpl 0) {
- if (hours < 10) {
- DateTimes = "0" + hours + ":" + minutes;
- } else {
- DateTimes = hours + ":" + minutes;
- }
- } else {
- DateTimes = "00:" + minutes;
- }
-
- return DateTimes;
- }
-
@Override
public void exportQuestion(HttpServletResponse response) throws Exception {
// 请求包装类
diff --git a/src/test/java/com/msdw/tms/TmsApplicationTests.java b/src/test/java/com/msdw/tms/TmsApplicationTests.java
index 717bf72..f91b814 100644
--- a/src/test/java/com/msdw/tms/TmsApplicationTests.java
+++ b/src/test/java/com/msdw/tms/TmsApplicationTests.java
@@ -1,5 +1,6 @@
package com.msdw.tms;
+import cn.hutool.core.date.DateUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -98,6 +99,57 @@ class TmsApplicationTests {
return k;
}
+ @Test
+ void t1() {
+ long mss = 150 * 60;
+ String ss = formatDateTime3(mss);
+ System.out.println(ss);
+ }
+
+ private String formatDateTime3(long mss) {
+ String DateTimes = "";
+ long hours = (mss % (60 * 60 * 24)) / (60 * 60);
+ long minutes = (mss % (60 * 60)) / 60;
+ long seconds = mss % 60;
+ if (hours > 0) {
+ if (hours < 10) {
+ DateTimes += "0" + hours;
+ } else {
+ DateTimes += hours + "";
+ }
+ }
+ if (minutes > 0) {
+ if (minutes < 10) {
+ DateTimes += "0" + minutes;
+ } else {
+ DateTimes += minutes;
+ }
+ }
+ if (seconds > 0) {
+ if (seconds < 10) {
+ DateTimes += "0" + seconds;
+ } else {
+ DateTimes += seconds;
+ }
+ }
+// if (hours < 10) {
+// DateTimes += "0" + hours + ":";
+// } else {
+// DateTimes += hours + "" + ":";
+// }
+// if (minutes < 10) {
+// DateTimes += "0" + minutes + ":";
+// } else {
+// DateTimes += minutes + ":";
+// }
+// if (seconds < 10) {
+// DateTimes += "0" + seconds;
+// } else {
+// DateTimes += seconds;
+// }
+ return DateTimes;
+ }
+
private String formatDateTime(long mss) {
String DateTimes = null;
long days = mss / (60 * 60 * 24);
@@ -215,4 +267,15 @@ class TmsApplicationTests {
ops.set("aaa", "sss", 30, TimeUnit.SECONDS);
}
+
+ @Test
+ void t6() throws ParseException {
+
+ int se = 130*60;
+
+ String s = DateUtil.secondToTime(se);
+
+ System.out.println(s);
+ }
+
}