From 59afc49a237951cf13729d62dc12f7f7b085eb93 Mon Sep 17 00:00:00 2001
From: lichuanyang <1176537920@qq.com>
Date: Mon, 23 Sep 2024 14:03:35 +0800
Subject: [PATCH] =?UTF-8?q?token=E7=9B=B8=E5=85=B3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../yudao-module-system-biz/pom.xml | 8 ++
.../outapi/JwtTokenAutoConfiguration.java | 16 ++++
.../admin/outapi/JwtTokenController.java | 28 +++++++
.../admin/outapi/JwtTokenInterceptor.java | 56 ++++++++++++++
.../service/outapi/JwtTokenService.java | 75 +++++++++++++++++++
...ot.autoconfigure.AutoConfiguration.imports | 1 +
.../PatientexamlistController.java | 6 ++
.../vo/PatientExamInfoAddReqVO.java | 59 +++++++++++++++
.../PatientexamlistService.java | 8 ++
.../PatientexamlistServiceImpl.java | 30 ++++++++
.../ultrasonic/ultrasonicController.java | 5 +-
.../src/main/resources/application.yaml | 4 +
12 files changed, 292 insertions(+), 4 deletions(-)
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/outapi/JwtTokenAutoConfiguration.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/outapi/JwtTokenController.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/outapi/JwtTokenInterceptor.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/outapi/JwtTokenService.java
create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
create mode 100644 yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/vo/PatientExamInfoAddReqVO.java
diff --git a/yudao-module-system/yudao-module-system-biz/pom.xml b/yudao-module-system/yudao-module-system-biz/pom.xml
index 664cc995d..096a3c03c 100644
--- a/yudao-module-system/yudao-module-system-biz/pom.xml
+++ b/yudao-module-system/yudao-module-system-biz/pom.xml
@@ -120,6 +120,14 @@
com.xingyuv
spring-boot-starter-captcha-plus
+
+
+
+ com.auth0
+ java-jwt
+ 4.4.0
+
+
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/outapi/JwtTokenAutoConfiguration.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/outapi/JwtTokenAutoConfiguration.java
new file mode 100644
index 000000000..5d3975934
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/outapi/JwtTokenAutoConfiguration.java
@@ -0,0 +1,16 @@
+package cn.iocoder.yudao.module.system.controller.admin.outapi;
+
+import cn.iocoder.yudao.framework.apilog.config.*;
+import cn.iocoder.yudao.framework.web.config.*;
+import org.springframework.boot.autoconfigure.*;
+import org.springframework.web.servlet.config.annotation.*;
+
+@AutoConfiguration(after = YudaoWebAutoConfiguration.class, before = YudaoApiLogAutoConfiguration.class)
+public class JwtTokenAutoConfiguration implements WebMvcConfigurer {
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(new JwtTokenInterceptor())
+ .addPathPatterns("/admin-api/ultrasoniccom/ultrasonic/InsImageInfo",
+ "/admin-api/tblist/patientexamlist/addPatientExamInfo");
+ }
+}
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/outapi/JwtTokenController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/outapi/JwtTokenController.java
new file mode 100644
index 000000000..a66ae0450
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/outapi/JwtTokenController.java
@@ -0,0 +1,28 @@
+package cn.iocoder.yudao.module.system.controller.admin.outapi;
+
+import cn.iocoder.yudao.framework.common.pojo.*;
+import cn.iocoder.yudao.module.system.service.outapi.*;
+import io.swagger.v3.oas.annotations.*;
+import io.swagger.v3.oas.annotations.tags.*;
+import org.springframework.validation.annotation.*;
+import org.springframework.web.bind.annotation.*;
+
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+
+@Tag(name = "管理后台 - jwtToken")
+@RestController
+@RequestMapping("/system/jwtToken")
+@Validated
+public class JwtTokenController {
+ @GetMapping("/getToken")
+ @Operation(summary = "获取Token")
+ public CommonResult getToken(@RequestParam("key_public") String key_public) {
+ String _out = "";
+ if (key_public != null && !"".equals(key_public.trim()) &&
+ JwtTokenService.isKeyPublic(key_public.trim(), JwtTokenService.KEY_PUBLIC_1))
+ _out = JwtTokenService.createToken();
+ else
+ _out = "key_public_error";
+ return success(_out);
+ }
+}
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/outapi/JwtTokenInterceptor.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/outapi/JwtTokenInterceptor.java
new file mode 100644
index 000000000..d3c03cd22
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/outapi/JwtTokenInterceptor.java
@@ -0,0 +1,56 @@
+package cn.iocoder.yudao.module.system.controller.admin.outapi;
+
+import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
+import cn.iocoder.yudao.module.system.service.outapi.*;
+import org.springframework.web.servlet.*;
+
+import javax.servlet.http.*;
+import java.io.*;
+import java.util.*;
+
+public class JwtTokenInterceptor implements HandlerInterceptor {
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ boolean _out = false;
+ Map params = new HashMap<>();
+ String token = request.getHeader("AuthToken");
+ if (token != null && !"".equals(token.trim())) {
+ if (JwtTokenService.verifyToken(token.trim()))
+ _out = true;
+ else {
+ params.put("code", "TokenError");
+ params.put("msg", "TokenError");
+ responseReturn(response, params);
+ _out = false;
+ }
+ } else {
+ params.put("code", "TokenEmpty");
+ params.put("msg", "TokenEmpty");
+ responseReturn(response, params);
+ _out = false;
+ }
+ return _out;
+ }
+
+ private void responseReturn(HttpServletResponse response, Map params) {
+ if (response != null) {
+ String result = "";
+ if (params == null || params.size() <= 0)
+ params = new HashMap<>();
+ result = JsonUtils.toJsonString(params);
+ PrintWriter writer = null;
+ response.setContentType("application/json");
+ response.setCharacterEncoding("UTF-8");
+ try {
+ writer = response.getWriter();
+ writer.write(result);
+
+ } catch (IOException ex) {
+ } finally {
+ if (writer != null) {
+ writer.close();
+ }
+ }
+ }
+ }
+}
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/outapi/JwtTokenService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/outapi/JwtTokenService.java
new file mode 100644
index 000000000..cd6d70f76
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/outapi/JwtTokenService.java
@@ -0,0 +1,75 @@
+package cn.iocoder.yudao.module.system.service.outapi;
+
+import com.auth0.jwt.*;
+import com.auth0.jwt.algorithms.*;
+import com.auth0.jwt.interfaces.DecodedJWT;
+import org.springframework.stereotype.*;
+
+import java.security.MessageDigest;
+import java.util.*;
+
+@Service
+public class JwtTokenService {
+ //属性
+ private static final long EXPIRE_DATE = 30 * 60 * 1000;
+ private static final String TOKEN_SECRET = "LLCfasfhua12afvQedaWSkqqklshQDB456FQAwu20flyWE";
+ public static final String KEY_PUBLIC_1 = "FLY_kyqqklsh_18152QFDW";
+
+ //方法
+ public static String createToken() {
+ String token = null;
+ try {
+ //参数
+ Date date = new Date(System.currentTimeMillis() + EXPIRE_DATE);
+ Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET);
+ Map header = new HashMap<>();
+ header.put("typ", "JWT");
+ header.put("alg", "HS256");
+ //携带信息,生成签名
+ token = JWT.create()
+ .withHeader(header)
+ .withClaim("tokenid", UUID.randomUUID().toString().replace("-", ""))
+ .withExpiresAt(date)
+ .sign(algorithm);
+ } catch (Exception ex) {
+ token = null;
+ }
+ return token;
+ }
+
+ public static boolean verifyToken(String token) {
+ boolean _out = false;
+ if (token != null && !"".equals(token.trim())) {
+ try {
+ Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET);
+ JWTVerifier verifier = JWT.require(algorithm).build();
+ DecodedJWT jwt = verifier.verify(token.trim());
+ _out = true;
+ } catch (Exception ex) {
+ _out = false;
+ }
+ }
+ return _out;
+ }
+
+ public static boolean isKeyPublic(String input, String KEY_PUBLIC) {
+ String _temp = "";
+ if (KEY_PUBLIC != null && !"".equals(KEY_PUBLIC.trim())) {
+ try {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ byte[] digest = md.digest(KEY_PUBLIC.trim().getBytes());
+ StringBuilder sb = new StringBuilder();
+ for (byte b : digest) {
+ sb.append(String.format("%02x", b));
+ }
+ _temp = sb.toString().trim();
+ } catch (Exception ex) {
+ _temp = "";
+ }
+ }
+ if (_temp != "" && input != null && input.trim().equals(_temp))
+ return true;
+ else
+ return false;
+ }
+}
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/yudao-module-system/yudao-module-system-biz/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 000000000..898585dcc
--- /dev/null
+++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1 @@
+cn.iocoder.yudao.module.system.controller.admin.outapi.JwtTokenAutoConfiguration
\ No newline at end of file
diff --git a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/PatientexamlistController.java b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/PatientexamlistController.java
index 35a5ee751..64f15507d 100644
--- a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/PatientexamlistController.java
+++ b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/PatientexamlistController.java
@@ -174,6 +174,12 @@ public class PatientexamlistController {
return success(_out);
}
+ @PostMapping("/addPatientExamInfo")
+ @Operation(summary = "患者信息")
+ public CommonResult> addPatientExamInfo(@Valid @RequestBody List createReqVOs) {
+ return success(patientexamlistService.addPatientExamInfo(createReqVOs));
+ }
+
@GetMapping("/getCheckRecord")
@Operation(summary = "云胶片-getCheckRecord")
public CommonResult