Browse Source

日期格式校验

tags/正式3.7.0
雍文秀 2 years ago
parent
commit
2d719cf805

+ 16
- 0
scommons/src/main/java/com/xhkjedu/utils/DatesUtil.java View File

@@ -178,4 +178,20 @@ public class DatesUtil {
178 178
         return gtime;
179 179
     }
180 180
 
181
+    /**
182
+     * 日期不合法
183
+     *
184
+     * @return boolean
185
+     * @Param [date]
186
+     * @Author ywx
187
+     * @Date 2023/1/3 9:17
188
+     **/
189
+    public static boolean dateNan(String date) {
190
+        if (date != null && date.contains("NaN")) {
191
+            return true;
192
+        } else {
193
+            return false;
194
+        }
195
+    }
196
+
181 197
 }

+ 5
- 4
sexam/src/main/java/com/xhkjedu/sexam/controller/exam/EBaseController.java View File

@@ -16,6 +16,7 @@ import com.xhkjedu.sexam.vo.exam.EBaseVo;
16 16
 import com.xhkjedu.sexam.vo.exam.ExamVo;
17 17
 import com.xhkjedu.sexam.vo.paper.EPaperVo;
18 18
 import com.xhkjedu.sexam.vo.system.UserVo;
19
+import com.xhkjedu.utils.DatesUtil;
19 20
 import com.xhkjedu.utils.N_Utils;
20 21
 import com.xhkjedu.utils.PageUtil;
21 22
 import com.xhkjedu.vo.PageResult;
@@ -58,8 +59,8 @@ public class EBaseController {
58 59
     public ResultVo add(@RequestBody EBase eBase) {
59 60
         if (N_Utils.isListEmpty(eBase.getClassids())) return new ResultVo(1, "考试班级不能为空");
60 61
         if (N_Utils.isListEmpty(eBase.getSubjects())) return new ResultVo(1, "考试科目不能为空");
61
-        if ("NaN-aN-aN".equals(eBase.getExamdate())) {
62
-            return new ResultVo(1,"日期格式不正确");
62
+        if (DatesUtil.dateNan(eBase.getExamdate())) {
63
+            return new ResultVo(1, "日期格式不正确");
63 64
         }
64 65
         return eBaseService.save(eBase);
65 66
     }
@@ -84,8 +85,8 @@ public class EBaseController {
84 85
         EBaseVo vo = eBaseService.getExamStateAndMode(examid);
85 86
         if (2 <= vo.getExamstate()) return new ResultVo(1, "考试已结束禁止操作");
86 87
 
87
-        if (JSON.toJSONString(subjects).contains("NaN-aN-aN")) {
88
-            return new ResultVo(1,"日期格式不正确");
88
+        if (DatesUtil.dateNan(JSON.toJSONString(subjects))) {
89
+            return new ResultVo(1, "日期格式不正确");
89 90
         }
90 91
         if (vo.getExammode() == 1) {//线上的考试必须有时间
91 92
             for (ESubject es : subjects) {

+ 3
- 2
slive/src/main/java/com/xhkjedu/slive/controller/liveplay/CourseController.java View File

@@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo;
5 5
 import com.xhkjedu.slive.model.liveplay.LCourse;
6 6
 import com.xhkjedu.slive.service.liveplay.CourseService;
7 7
 import com.xhkjedu.slive.vo.liveplay.*;
8
+import com.xhkjedu.utils.DatesUtil;
8 9
 import com.xhkjedu.utils.N_Utils;
9 10
 import com.xhkjedu.utils.PageUtil;
10 11
 import com.xhkjedu.vo.PageResult;
@@ -33,8 +34,8 @@ public class CourseController {
33 34
     @PostMapping("/add")
34 35
     public ResultVo add(@RequestBody LCourse course) {
35 36
         N_Utils.validation(new Object[]{course.getSubjectid(),"科目id",2});
36
-        if ("NaN-aN-aN".equals(course.getBegindate()) || "NaN-aN-aN".equals(course.getEnddate())) {
37
-            return new ResultVo(1,"日期格式不正确");
37
+        if (DatesUtil.dateNan(course.getBegindate()) || DatesUtil.dateNan(course.getEnddate())) {
38
+            return new ResultVo(1, "日期格式不正确");
38 39
         }
39 40
         return courseService.save(course);
40 41
     }

+ 7
- 5
slive/src/main/java/com/xhkjedu/slive/controller/liveplay/CourseSectionController.java View File

@@ -11,6 +11,7 @@ import com.xhkjedu.slive.vo.liveplay.CSVStudentVo;
11 11
 import com.xhkjedu.slive.vo.liveplay.CourseParams;
12 12
 import com.xhkjedu.slive.vo.liveplay.CourseSectionVo;
13 13
 import com.xhkjedu.slive.vo.liveplay.CourseVo;
14
+import com.xhkjedu.utils.DatesUtil;
14 15
 import com.xhkjedu.utils.N_Utils;
15 16
 import com.xhkjedu.utils.PageUtil;
16 17
 import com.xhkjedu.vo.PageResult;
@@ -39,7 +40,7 @@ public class CourseSectionController {
39 40
     @PostMapping("/add")
40 41
     public ResultVo add(@RequestBody LCourseSection section) {
41 42
         N_Utils.validation(new Object[]{section.getCourseid(),"课程id",1,section.getTeacherid(),"教师id",1});
42
-        if ("NaN-aN-aN".equals(section.getSectiondate())) return new ResultVo(1,"日期格式不正确");
43
+        if (DatesUtil.dateNan(section.getSectiondate())) return new ResultVo(1, "日期格式不正确");
43 44
         return courseSectionService.save(section);
44 45
     }
45 46
 
@@ -58,7 +59,7 @@ public class CourseSectionController {
58 59
     @PostMapping("/update")
59 60
     public ResultVo update(@RequestBody LCourseSection section) {
60 61
         N_Utils.validation(new Object[]{section.getSectionid(),"课节id",1,section.getCreateid(),"用户id",1});
61
-        if ("NaN-aN-aN".equals(section.getSectiondate())) return new ResultVo(1,"日期格式不正确");
62
+        if (DatesUtil.dateNan(section.getSectiondate())) return new ResultVo(1, "日期格式不正确");
62 63
         return courseSectionService.update(section);
63 64
     }
64 65
 
@@ -384,9 +385,10 @@ public class CourseSectionController {
384 385
 
385 386
     @PostMapping("/myupdate")
386 387
     public ResultVo myUpdate(@RequestBody LCourseSection section) {
387
-        N_Utils.validation(new Object[]{section.getSectionid(),"课节id",1,section.getCreateid(),"用户id",1
388
-        ,section.getSectionname(),"课节名称",2,section.getPlanbegintime(),"计划开始时间",2,section.getPlanendtime(),"计划结束时间",2});
389
-        if ("NaN-aN-aN".equals(section.getSectiondate())) return new ResultVo(1,"日期格式不正确");
388
+        N_Utils.validation(new Object[]{section.getSectionid(), "课节id", 1, section.getCreateid(), "用户id", 1
389
+                , section.getSectionname(), "课节名称", 2, section.getPlanbegintime(), "计划开始时间", 2, section.getPlanendtime(),
390
+                "计划结束时间", 2});
391
+        if (DatesUtil.dateNan(section.getSectiondate())) return new ResultVo(1, " 日期格式不正确 ");
390 392
         return courseSectionService.myUpdate(section);
391 393
     }
392 394
 

+ 2
- 1
slive/src/main/java/com/xhkjedu/slive/controller/liveplay/CsController.java View File

@@ -6,6 +6,7 @@ import com.xhkjedu.slive.model.liveplay.LCourse;
6 6
 import com.xhkjedu.slive.service.liveplay.CsService;
7 7
 import com.xhkjedu.slive.vo.liveplay.CourseParams;
8 8
 import com.xhkjedu.slive.vo.liveplay.CourseVo;
9
+import com.xhkjedu.utils.DatesUtil;
9 10
 import com.xhkjedu.utils.N_Utils;
10 11
 import com.xhkjedu.utils.PageUtil;
11 12
 import com.xhkjedu.vo.PageResult;
@@ -34,7 +35,7 @@ public class CsController {
34 35
     @PostMapping("/add")
35 36
     public ResultVo add(@RequestBody LCourse course) {
36 37
         N_Utils.validation(new Object[]{course.getSubjectid(), "科目id", 2});
37
-        if ("NaN-aN-aN".equals(course.getBegindate()) || "NaN-aN-aN".equals(course.getEnddate())) {
38
+        if (DatesUtil.dateNan(course.getBegindate()) || DatesUtil.dateNan(course.getEnddate())) {
38 39
             return new ResultVo(1, "日期格式不正确");
39 40
         }
40 41
         return csService.save(course);

+ 3
- 5
slive/src/main/java/com/xhkjedu/slive/controller/xz/XzController.java View File

@@ -4,9 +4,8 @@ import com.github.pagehelper.PageHelper;
4 4
 import com.github.pagehelper.PageInfo;
5 5
 import com.xhkjedu.slive.model.xz.LXz;
6 6
 import com.xhkjedu.slive.service.xz.XzService;
7
-import com.xhkjedu.slive.utils.PoiUtils;
8 7
 import com.xhkjedu.slive.vo.xz.XzDateKjTeaVo;
9
-import com.xhkjedu.slive.vo.xz.XzDateVo;
8
+import com.xhkjedu.utils.DatesUtil;
10 9
 import com.xhkjedu.utils.N_Utils;
11 10
 import com.xhkjedu.utils.PageUtil;
12 11
 import com.xhkjedu.vo.PageResult;
@@ -18,7 +17,6 @@ import org.springframework.web.bind.annotation.RestController;
18 17
 import org.springframework.web.multipart.MultipartFile;
19 18
 
20 19
 import javax.annotation.Resource;
21
-import java.util.LinkedHashMap;
22 20
 import java.util.List;
23 21
 import java.util.Map;
24 22
 
@@ -62,8 +60,8 @@ public class XzController {
62 60
     public ResultVo save(@RequestBody LXz xz){
63 61
         N_Utils.validation(new Object[]{xz.getXzname(),"名称",2,xz.getGradeid(),"年级",1,xz.getDaynum(),"课节数量",1,
64 62
         xz.getBegindate(),"开始日期",2,xz.getEnddate(),"结束日期",2,xz.getSchoolid(),"学校id",1});
65
-        if ("NaN-aN-aN".equals(xz.getBegindate()) || "NaN-aN-aN".equals(xz.getEnddate())) {
66
-            return new ResultVo(1,"日期格式不正确");
63
+        if (DatesUtil.dateNan(xz.getBegindate()) || DatesUtil.dateNan(xz.getEnddate())) {
64
+            return new ResultVo(1, "日期格式不正确");
67 65
         }
68 66
         return xzService.saveXz(xz);
69 67
     }

+ 3
- 2
suser/src/main/java/com/xhkjedu/suser/service/gradeclass/ClassStudentService.java View File

@@ -16,6 +16,7 @@ import com.xhkjedu.suser.utils.UserUtil;
16 16
 import com.xhkjedu.suser.vo.gradeclass.ClassStudentVo;
17 17
 import com.xhkjedu.suser.vo.gradeclass.ClassVo;
18 18
 import com.xhkjedu.suser.vo.gradeclass.ImportStudentVo;
19
+import com.xhkjedu.utils.DatesUtil;
19 20
 import com.xhkjedu.utils.N_Utils;
20 21
 import com.xhkjedu.vo.ResultVo;
21 22
 import lombok.extern.slf4j.Slf4j;
@@ -395,7 +396,7 @@ public class ClassStudentService {
395 396
             }
396 397
         }
397 398
         user.setBindphoned(bindphoned);
398
-        if ("NaN-aN-aN".equals(user.getUsertime())) {//有效期异常值置空
399
+        if (DatesUtil.dateNan(user.getUsertime())) {//有效期异常值置空
399 400
             user.setUsertime(null);
400 401
         }
401 402
         user.setBindsecret(0);
@@ -483,7 +484,7 @@ public class ClassStudentService {
483 484
             bindphoned = 1;
484 485
         }
485 486
         user.setBindphoned(bindphoned);
486
-        if ("NaN-aN-aN".equals(user.getUsertime())) {//有效期异常值置空
487
+        if (DatesUtil.dateNan(user.getUsertime())) {//有效期异常值置空
487 488
             user.setUsertime(null);
488 489
         }
489 490
         user.setCreatetime(N_Utils.getSecondTimestamp());

+ 2
- 2
suser/src/main/java/com/xhkjedu/suser/service/system/UserService.java View File

@@ -417,7 +417,7 @@ public class UserService extends JedisUtil {
417 417
             }
418 418
         }
419 419
         user.setBindphoned(bindphoned);
420
-        if ("NaN-aN-aN".equals(user.getUsertime())) {//有效期异常值置空
420
+        if (DatesUtil.dateNan(user.getUsertime())) {//有效期异常值置空
421 421
             user.setUsertime(null);
422 422
         }
423 423
         user.setBindsecret(0);
@@ -459,7 +459,7 @@ public class UserService extends JedisUtil {
459 459
             bindphoned = 1;
460 460
         }
461 461
         user.setBindphoned(bindphoned);
462
-        if ("NaN-aN-aN".equals(user.getUsertime())) {//有效期异常值置空
462
+        if (DatesUtil.dateNan(user.getUsertime())) {//有效期异常值置空
463 463
             user.setUsertime(null);
464 464
         }
465 465
         user.setCreatetime(N_Utils.getSecondTimestamp());

Loading…
Cancel
Save