Bläddra i källkod

根据姓名搜索学生信息

ywx
雍文秀 6 månader sedan
förälder
incheckning
e329754e6e

+ 36
- 0
src/main/java/com/xhkjedu/controller/EPaperVerifyController.java Visa fil

@@ -0,0 +1,36 @@
1
+package com.xhkjedu.controller;
2
+
3
+import com.xhkjedu.model.EClassStudent;
4
+import com.xhkjedu.service.EPaperVerifyService;
5
+import com.xhkjedu.utils.N_Utils;
6
+import com.xhkjedu.vo.ResultVo;
7
+import org.springframework.web.bind.annotation.PostMapping;
8
+import org.springframework.web.bind.annotation.RequestBody;
9
+
10
+import javax.annotation.Resource;
11
+import java.util.List;
12
+import java.util.Map;
13
+
14
+/**
15
+ * @author ywx
16
+ * @classname EPaperCorrectVerifyController
17
+ * @description 考卷校验
18
+ * @date 2024/6/8 14:36
19
+ **/
20
+public class EPaperVerifyController {
21
+    @Resource
22
+    private EPaperVerifyService ePaperVerifyService;
23
+
24
+    //根据姓名搜索学生信息
25
+    @PostMapping("/search_stu")
26
+    public ResultVo listStudentByExamno(@RequestBody EClassStudent student) {
27
+        Integer examid = student.getExamid();
28
+        String studentname = student.getStudentname();
29
+        N_Utils.validation(new Object[]{examid, "考试id", 1, studentname, "姓名", 2});
30
+        List<Map> list = ePaperVerifyService.listStudentByStudentname(examid, studentname);
31
+        return new ResultVo(0, "获取成功", list);
32
+    }
33
+
34
+
35
+
36
+}

+ 68
- 0
src/main/java/com/xhkjedu/exception/ErrorAdivceController.java Visa fil

@@ -0,0 +1,68 @@
1
+package com.xhkjedu.exception;
2
+import com.alibaba.fastjson2.JSON;
3
+import com.xhkjedu.utils.N_Utils;
4
+import com.xhkjedu.vo.ResultVo;
5
+import lombok.extern.slf4j.Slf4j;
6
+import org.springframework.dao.DataIntegrityViolationException;
7
+import org.springframework.web.bind.annotation.ControllerAdvice;
8
+import org.springframework.web.bind.annotation.ExceptionHandler;
9
+import org.springframework.web.bind.annotation.ResponseBody;
10
+
11
+import javax.servlet.http.HttpServletRequest;
12
+
13
+/**
14
+ * @创建人 :zj
15
+ * @创建时间 2019/11/7
16
+ * @修改人和其它信息
17
+ * @描述 :项目异常处理类:
18
+ * 项目中所有controller层抛出的异常信息都会被拦截。
19
+ * 方便我们查看异常原因,减少开发中大量的try catch。
20
+ * 拦截异常后,打印异常信息,返回前端约定参数对象。
21
+ */
22
+@Slf4j
23
+@ResponseBody
24
+@ControllerAdvice
25
+public class ErrorAdivceController {
26
+    @ExceptionHandler(MissingParametersException.class)
27
+    public ResultVo missingParametersException(MissingParametersException ex) {
28
+        log.error("参数异常:   -------> " + ex.getMessage());
29
+        return new ResultVo(1, ex.getMessage());
30
+    }
31
+
32
+    @ExceptionHandler(DataIntegrityViolationException.class)
33
+    public ResultVo DataIntegrityViolationException(DataIntegrityViolationException ex){
34
+        log.error("数据库异常:   -------> " + ex.getMessage());
35
+        String msg = ex.getMessage();
36
+        if (N_Utils.isNotEmpty(msg) && msg.indexOf("SQLIntegrityConstraintViolationException") != -1){
37
+            return new ResultVo(1,"存在关联信息");
38
+        }
39
+        return new ResultVo(1,"数据库处理异常");
40
+    }
41
+
42
+    @ExceptionHandler(Exception.class)
43
+    public ResultVo exceptionHandler(Exception ex) {
44
+        log.error("程序运行异常:   -------> " + ex.getMessage());
45
+        String msg = ex.getMessage();
46
+        if (N_Utils.isNotEmpty(msg) && msg.indexOf("JSON parse error") != -1){
47
+            return new ResultVo(1,"json格式不对");
48
+        } else if (N_Utils.isNotEmpty(msg) && msg.indexOf("Maximum upload size exceeded") != -1) {
49
+            return new ResultVo(1, "文件过大");
50
+        }
51
+        return new ResultVo(1, "程序处理异常");
52
+    }
53
+
54
+    @ExceptionHandler(NullPointerException.class)
55
+    public ResultVo nullPointerException(NullPointerException ex) {
56
+        StackTraceElement element = ex.getStackTrace()[0];
57
+        log.error("参数为空异常:   -------> " + JSON.toJSONString(element));
58
+        return new ResultVo(1, "参数为空异常");
59
+    }
60
+
61
+    @ExceptionHandler(value = IllegalArgumentException.class)
62
+    public ResultVo illegalArgumentExceptionHandler(HttpServletRequest request,IllegalArgumentException ex) {
63
+        log.error("请求参数错误 URL : {},Exception : {}", request.getRequestURL(),ex.getMessage());
64
+        return new ResultVo(1, "请求参数错误");
65
+    }
66
+
67
+
68
+}

+ 10
- 0
src/main/java/com/xhkjedu/exception/MissingParametersException.java Visa fil

@@ -0,0 +1,10 @@
1
+package com.xhkjedu.exception;
2
+
3
+public class MissingParametersException extends RuntimeException{
4
+    public MissingParametersException() {
5
+    }
6
+
7
+    public MissingParametersException(String message) {
8
+        super(message);
9
+    }
10
+}

+ 19
- 0
src/main/java/com/xhkjedu/exception/ServiceException.java Visa fil

@@ -0,0 +1,19 @@
1
+package com.xhkjedu.exception;
2
+
3
+/**
4
+ * @Description:业务处理异常
5
+ * @Author: WN
6
+ * @Date: 2023/11/15 17:50:40
7
+ **/
8
+public class ServiceException extends RuntimeException {
9
+    public ServiceException() {
10
+    }
11
+
12
+    public ServiceException(String message) {
13
+        super(message);
14
+    }
15
+
16
+    public ServiceException(String message, Throwable cause) {
17
+        super(message, cause);
18
+    }
19
+}

+ 17
- 0
src/main/java/com/xhkjedu/mapper/EPaperVerifyMapper.java Visa fil

@@ -0,0 +1,17 @@
1
+package com.xhkjedu.mapper;
2
+
3
+import org.apache.ibatis.annotations.Param;
4
+
5
+import java.util.List;
6
+import java.util.Map;
7
+
8
+/**
9
+ * @author ywx
10
+ * @classname EPaperVerifyMapper
11
+ * @description todo
12
+ * @date 2024/6/8 14:44
13
+ **/
14
+public interface EPaperVerifyMapper {
15
+    //根据姓名搜索学生信息
16
+    List<Map> listStudentByStudentname(@Param("examid") Integer examid,@Param("studentname") String studentname);
17
+}

+ 26
- 0
src/main/java/com/xhkjedu/model/BaseBean.java Visa fil

@@ -0,0 +1,26 @@
1
+package com.xhkjedu.model;
2
+
3
+import lombok.Data;
4
+
5
+import javax.persistence.Transient;
6
+
7
+/**
8
+ * @author lgq
9
+ * @date 2019/11/8 9:29
10
+ * @description: 添加时返回主键绑定id
11
+ */
12
+@Data
13
+public class BaseBean {
14
+    //添加时返回主键
15
+    @Transient
16
+    private Integer id;
17
+    //创建人姓名
18
+    @Transient
19
+    private String createname;
20
+    //分页显示页码
21
+    @Transient
22
+    private Integer page;
23
+    //分页显示条数
24
+    @Transient
25
+    private Integer pageSize;
26
+}

+ 38
- 0
src/main/java/com/xhkjedu/model/EClassStudent.java Visa fil

@@ -0,0 +1,38 @@
1
+package com.xhkjedu.model;
2
+
3
+import com.xhkjedu.model.BaseBean;
4
+import lombok.Data;
5
+
6
+import javax.persistence.Id;
7
+import javax.persistence.Table;
8
+import javax.persistence.Transient;
9
+
10
+@Table(name = "e_class_student")
11
+@Data
12
+public class EClassStudent extends BaseBean {
13
+    @Id
14
+    //考试关联学生表
15
+    private Integer ecsid;
16
+
17
+    //考试id
18
+    private Integer examid;
19
+
20
+    //班级id
21
+    private Integer classid;
22
+
23
+    //学生id
24
+    private Integer studentid;
25
+
26
+    //学生pdf报告
27
+    private String reportstu;
28
+
29
+    @Transient
30
+    //学生姓名
31
+    private String studentname;
32
+
33
+    @Transient
34
+    private String examno;//考号
35
+
36
+    @Transient
37
+    private Integer schoolid;//学校id
38
+}

+ 25
- 0
src/main/java/com/xhkjedu/service/EPaperVerifyService.java Visa fil

@@ -0,0 +1,25 @@
1
+package com.xhkjedu.service;
2
+
3
+import com.xhkjedu.mapper.EPaperVerifyMapper;
4
+import org.springframework.stereotype.Service;
5
+
6
+import javax.annotation.Resource;
7
+import java.util.List;
8
+import java.util.Map;
9
+
10
+/**
11
+ * @author ywx
12
+ * @classname EPaperCorrectVerifyService
13
+ * @description 考卷校验
14
+ * @date 2024/6/8 14:39
15
+ **/
16
+@Service
17
+public class EPaperVerifyService {
18
+    @Resource
19
+    private EPaperVerifyMapper ePaperVerifyMapper;
20
+
21
+    //根据姓名搜索学生信息
22
+    public List<Map> listStudentByStudentname(Integer examid, String studentname) {
23
+        return ePaperVerifyMapper.listStudentByStudentname(examid, studentname);
24
+    }
25
+}

+ 1224
- 0
src/main/java/com/xhkjedu/utils/N_Utils.java
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 41
- 0
src/main/java/com/xhkjedu/utils/SystemClock.java Visa fil

@@ -0,0 +1,41 @@
1
+package com.xhkjedu.utils;
2
+
3
+import java.util.concurrent.Executors;
4
+import java.util.concurrent.ScheduledExecutorService;
5
+import java.util.concurrent.TimeUnit;
6
+import java.util.concurrent.atomic.AtomicLong;
7
+
8
+/**
9
+ * @author ywx
10
+ * @classname SystemClock
11
+ * @description todo
12
+ * @date 2022/11/9 20:31
13
+ **/
14
+public class SystemClock {
15
+    private static final SystemClock MILLIS_CLOCK = new SystemClock(1);
16
+    private final long precision;
17
+    private final AtomicLong now;
18
+
19
+    private SystemClock(long precision) {
20
+        this.precision = precision;
21
+        now = new AtomicLong(System.currentTimeMillis());
22
+        scheduleClockUpdating();
23
+    }
24
+
25
+    public static SystemClock millisClock() {
26
+        return MILLIS_CLOCK;
27
+    }
28
+
29
+    private void scheduleClockUpdating() {
30
+        ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(runnable -> {
31
+            Thread thread = new Thread(runnable, "system.clock");
32
+            thread.setDaemon(true);
33
+            return thread;
34
+        });
35
+        scheduler.scheduleAtFixedRate(() -> now.set(System.currentTimeMillis()), precision, precision, TimeUnit.MILLISECONDS);
36
+    }
37
+
38
+    public long now() {
39
+        return now.get();
40
+    }
41
+}

+ 35
- 0
src/main/java/com/xhkjedu/vo/ResultVo.java Visa fil

@@ -0,0 +1,35 @@
1
+package com.xhkjedu.vo;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Data;
5
+import lombok.NoArgsConstructor;
6
+
7
+/**
8
+ * 返回值
9
+ *
10
+ * @author WN
11
+ * @Date 2018年3月28日 下午5:14:31
12
+ */
13
+@Data
14
+@AllArgsConstructor
15
+@NoArgsConstructor
16
+public class ResultVo {
17
+    private int code = 0;// 返回是否成功  0成功 1失败
18
+    private String msg = "";// 返回提示信息
19
+    private Object obj;// 返回对象或者对象列表
20
+
21
+    public ResultVo(int code, String msg) {
22
+        this.code = code;
23
+        this.msg = msg;
24
+    }
25
+
26
+    public ResultVo(Object obj, String msg) {
27
+        this.obj = obj;
28
+        this.msg = msg;
29
+    }
30
+
31
+    public ResultVo(int code, Object obj) {
32
+        this.code = code;
33
+        this.obj = obj;
34
+    }
35
+}

+ 12
- 0
src/main/resources/EPaperVerifyMapper.xml Visa fil

@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.xhkjedu.mapper.EPaperVerifyMapper">
4
+    <!--根据姓名搜索学生信息-->
5
+    <select id="listStudentByStudentname" resultType="java.util.Map">
6
+        select s.studentid,u.username studentname,u.examno,c.classid,c.classname,e.gradeid
7
+        from e_class_student s left join e_class c on s.examid=c.examid and c.classid=c.classid
8
+        LEFT JOIN t_user u on s.studentid=u.userid
9
+        left join e_base e on c.examid=e.examid
10
+        where s.examid=#{examid} and u.usertype=2 and u.username like concat('%', #{studentname}, '%') group by s.studentid
11
+    </select>
12
+</mapper>

Laddar…
Avbryt
Spara