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
         return gtime;
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
 import com.xhkjedu.sexam.vo.exam.ExamVo;
16
 import com.xhkjedu.sexam.vo.exam.ExamVo;
17
 import com.xhkjedu.sexam.vo.paper.EPaperVo;
17
 import com.xhkjedu.sexam.vo.paper.EPaperVo;
18
 import com.xhkjedu.sexam.vo.system.UserVo;
18
 import com.xhkjedu.sexam.vo.system.UserVo;
19
+import com.xhkjedu.utils.DatesUtil;
19
 import com.xhkjedu.utils.N_Utils;
20
 import com.xhkjedu.utils.N_Utils;
20
 import com.xhkjedu.utils.PageUtil;
21
 import com.xhkjedu.utils.PageUtil;
21
 import com.xhkjedu.vo.PageResult;
22
 import com.xhkjedu.vo.PageResult;
58
     public ResultVo add(@RequestBody EBase eBase) {
59
     public ResultVo add(@RequestBody EBase eBase) {
59
         if (N_Utils.isListEmpty(eBase.getClassids())) return new ResultVo(1, "考试班级不能为空");
60
         if (N_Utils.isListEmpty(eBase.getClassids())) return new ResultVo(1, "考试班级不能为空");
60
         if (N_Utils.isListEmpty(eBase.getSubjects())) return new ResultVo(1, "考试科目不能为空");
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
         return eBaseService.save(eBase);
65
         return eBaseService.save(eBase);
65
     }
66
     }
84
         EBaseVo vo = eBaseService.getExamStateAndMode(examid);
85
         EBaseVo vo = eBaseService.getExamStateAndMode(examid);
85
         if (2 <= vo.getExamstate()) return new ResultVo(1, "考试已结束禁止操作");
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
         if (vo.getExammode() == 1) {//线上的考试必须有时间
91
         if (vo.getExammode() == 1) {//线上的考试必须有时间
91
             for (ESubject es : subjects) {
92
             for (ESubject es : subjects) {

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

5
 import com.xhkjedu.slive.model.liveplay.LCourse;
5
 import com.xhkjedu.slive.model.liveplay.LCourse;
6
 import com.xhkjedu.slive.service.liveplay.CourseService;
6
 import com.xhkjedu.slive.service.liveplay.CourseService;
7
 import com.xhkjedu.slive.vo.liveplay.*;
7
 import com.xhkjedu.slive.vo.liveplay.*;
8
+import com.xhkjedu.utils.DatesUtil;
8
 import com.xhkjedu.utils.N_Utils;
9
 import com.xhkjedu.utils.N_Utils;
9
 import com.xhkjedu.utils.PageUtil;
10
 import com.xhkjedu.utils.PageUtil;
10
 import com.xhkjedu.vo.PageResult;
11
 import com.xhkjedu.vo.PageResult;
33
     @PostMapping("/add")
34
     @PostMapping("/add")
34
     public ResultVo add(@RequestBody LCourse course) {
35
     public ResultVo add(@RequestBody LCourse course) {
35
         N_Utils.validation(new Object[]{course.getSubjectid(),"科目id",2});
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
         return courseService.save(course);
40
         return courseService.save(course);
40
     }
41
     }

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

11
 import com.xhkjedu.slive.vo.liveplay.CourseParams;
11
 import com.xhkjedu.slive.vo.liveplay.CourseParams;
12
 import com.xhkjedu.slive.vo.liveplay.CourseSectionVo;
12
 import com.xhkjedu.slive.vo.liveplay.CourseSectionVo;
13
 import com.xhkjedu.slive.vo.liveplay.CourseVo;
13
 import com.xhkjedu.slive.vo.liveplay.CourseVo;
14
+import com.xhkjedu.utils.DatesUtil;
14
 import com.xhkjedu.utils.N_Utils;
15
 import com.xhkjedu.utils.N_Utils;
15
 import com.xhkjedu.utils.PageUtil;
16
 import com.xhkjedu.utils.PageUtil;
16
 import com.xhkjedu.vo.PageResult;
17
 import com.xhkjedu.vo.PageResult;
39
     @PostMapping("/add")
40
     @PostMapping("/add")
40
     public ResultVo add(@RequestBody LCourseSection section) {
41
     public ResultVo add(@RequestBody LCourseSection section) {
41
         N_Utils.validation(new Object[]{section.getCourseid(),"课程id",1,section.getTeacherid(),"教师id",1});
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
         return courseSectionService.save(section);
44
         return courseSectionService.save(section);
44
     }
45
     }
45
 
46
 
58
     @PostMapping("/update")
59
     @PostMapping("/update")
59
     public ResultVo update(@RequestBody LCourseSection section) {
60
     public ResultVo update(@RequestBody LCourseSection section) {
60
         N_Utils.validation(new Object[]{section.getSectionid(),"课节id",1,section.getCreateid(),"用户id",1});
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
         return courseSectionService.update(section);
63
         return courseSectionService.update(section);
63
     }
64
     }
64
 
65
 
384
 
385
 
385
     @PostMapping("/myupdate")
386
     @PostMapping("/myupdate")
386
     public ResultVo myUpdate(@RequestBody LCourseSection section) {
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
         return courseSectionService.myUpdate(section);
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
 import com.xhkjedu.slive.service.liveplay.CsService;
6
 import com.xhkjedu.slive.service.liveplay.CsService;
7
 import com.xhkjedu.slive.vo.liveplay.CourseParams;
7
 import com.xhkjedu.slive.vo.liveplay.CourseParams;
8
 import com.xhkjedu.slive.vo.liveplay.CourseVo;
8
 import com.xhkjedu.slive.vo.liveplay.CourseVo;
9
+import com.xhkjedu.utils.DatesUtil;
9
 import com.xhkjedu.utils.N_Utils;
10
 import com.xhkjedu.utils.N_Utils;
10
 import com.xhkjedu.utils.PageUtil;
11
 import com.xhkjedu.utils.PageUtil;
11
 import com.xhkjedu.vo.PageResult;
12
 import com.xhkjedu.vo.PageResult;
34
     @PostMapping("/add")
35
     @PostMapping("/add")
35
     public ResultVo add(@RequestBody LCourse course) {
36
     public ResultVo add(@RequestBody LCourse course) {
36
         N_Utils.validation(new Object[]{course.getSubjectid(), "科目id", 2});
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
             return new ResultVo(1, "日期格式不正确");
39
             return new ResultVo(1, "日期格式不正确");
39
         }
40
         }
40
         return csService.save(course);
41
         return csService.save(course);

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

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

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

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

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

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

Loading…
Cancel
Save