Commit 8c4743b8fcfba83023072f74034fde870c3e3d1c
1 parent
623099fe
Exists in
master
大华设备对接艺校考勤
Showing
4 changed files
with
148 additions
and
0 deletions
Show diff stats
cloud/dahua/src/main/java/com/example/dahua/bean/yx/Result.java
0 → 100644
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +package com.example.dahua.bean.yx; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 统一API响应结果封装 | |
| 5 | + */ | |
| 6 | +public class Result<T> { | |
| 7 | + private int code; | |
| 8 | + private String message; | |
| 9 | + private T data; | |
| 10 | + | |
| 11 | + public Result<T> setCode(ResultCode resultCode) { | |
| 12 | + this.code = resultCode.code(); | |
| 13 | + return this; | |
| 14 | + } | |
| 15 | + | |
| 16 | + public int getCode() { | |
| 17 | + return code; | |
| 18 | + } | |
| 19 | + | |
| 20 | + public String getMessage() { | |
| 21 | + return message; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public Result<T> setMessage(String message) { | |
| 25 | + this.message = message; | |
| 26 | + return this; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public T getData() { | |
| 30 | + return data; | |
| 31 | + } | |
| 32 | + | |
| 33 | + Result<T> setData(T data) { | |
| 34 | + this.data = data; | |
| 35 | + return this; | |
| 36 | + } | |
| 37 | +} | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/bean/yx/ResultCode.java
0 → 100644
| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | +package com.example.dahua.bean.yx; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 响应码枚举,参考HTTP状态码的语义 | |
| 5 | + */ | |
| 6 | +public enum ResultCode { | |
| 7 | + | |
| 8 | + // 成功 | |
| 9 | + SUCCESS(200), | |
| 10 | + // 失败 | |
| 11 | + FAIL(400), | |
| 12 | + // 未认证(签名错误) | |
| 13 | + UNAUTHORIZED(401), | |
| 14 | + // 接口不存在 | |
| 15 | + NOT_FOUND(404), | |
| 16 | + // 服务器内部错误 | |
| 17 | + INTERNAL_SERVER_ERROR(500); | |
| 18 | + | |
| 19 | + private final int code; | |
| 20 | + | |
| 21 | + ResultCode(int code){ | |
| 22 | + this.code = code; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public int code() { | |
| 26 | + return code; | |
| 27 | + } | |
| 28 | +} | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/bean/yx/ResultGenerator.java
0 → 100644
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +package com.example.dahua.bean.yx; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 响应结果生成工具 | |
| 5 | + */ | |
| 6 | +public class ResultGenerator { | |
| 7 | + private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS"; | |
| 8 | + | |
| 9 | + private ResultGenerator() {} | |
| 10 | + | |
| 11 | + public static Result<String> genSuccessResult() { | |
| 12 | + return new Result<String>() | |
| 13 | + .setCode(ResultCode.SUCCESS) | |
| 14 | + .setMessage(DEFAULT_SUCCESS_MESSAGE); | |
| 15 | + } | |
| 16 | + | |
| 17 | + public static <T> Result<T> genSuccessResult(T data) { | |
| 18 | + return new Result<T>() | |
| 19 | + .setCode(ResultCode.SUCCESS) | |
| 20 | + .setMessage(DEFAULT_SUCCESS_MESSAGE) | |
| 21 | + .setData(data); | |
| 22 | + } | |
| 23 | + public static Result genFailResult(String message) { | |
| 24 | + return new Result() | |
| 25 | + .setCode(ResultCode.FAIL) | |
| 26 | + .setMessage(message); | |
| 27 | + } | |
| 28 | + | |
| 29 | +} | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/bean/yx/StudentInfo.java
0 → 100644
| ... | ... | @@ -0,0 +1,54 @@ |
| 1 | +package com.example.dahua.bean.yx; | |
| 2 | + | |
| 3 | +import java.util.List; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Create with IntelliJ IDEA | |
| 7 | + * | |
| 8 | + * @author xuquan | |
| 9 | + * @date 2022/2/10 15:36 | |
| 10 | + * @Description: 艺校学生信息返回 | |
| 11 | + */ | |
| 12 | +public class StudentInfo { | |
| 13 | + | |
| 14 | + private int total; | |
| 15 | + private List<Student> studentList; | |
| 16 | + | |
| 17 | + public int getTotal() { | |
| 18 | + return total; | |
| 19 | + } | |
| 20 | + | |
| 21 | + public void setTotal(int total) { | |
| 22 | + this.total = total; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public List<Student> getStudentList() { | |
| 26 | + return studentList; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public void setStudentList(List<Student> studentList) { | |
| 30 | + this.studentList = studentList; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public static class Student{ | |
| 34 | + | |
| 35 | + private String userName; | |
| 36 | + private String studentCode; | |
| 37 | + | |
| 38 | + public String getUserName() { | |
| 39 | + return userName; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void setUserName(String userName) { | |
| 43 | + this.userName = userName; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public String getStudentCode() { | |
| 47 | + return studentCode; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void setStudentCode(String studentCode) { | |
| 51 | + this.studentCode = studentCode; | |
| 52 | + } | |
| 53 | + } | |
| 54 | +} | ... | ... |