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> getCheckRecord(@RequestParam("no") String no, @RequestParam("orgId") String orgId) { diff --git a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/vo/PatientExamInfoAddReqVO.java b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/vo/PatientExamInfoAddReqVO.java new file mode 100644 index 000000000..49d899df8 --- /dev/null +++ b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/controller/admin/patientexamlist/vo/PatientExamInfoAddReqVO.java @@ -0,0 +1,59 @@ +package cn.iocoder.yudao.module.tblist.controller.admin.patientexamlist.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.time.*; + +@Schema(description = "管理后台 - PatientExamInfoAddReqVO") +@Data +public class PatientExamInfoAddReqVO { + + @Schema(description = "主键", example = "23598") + private String id; + + @Schema(description = "检查ID:体检编号、住院号、门诊号等", example = "26467") + private String examId; + + @Schema(description = "患者姓名", example = "赵六") + private String pname; + + @Schema(description = "性别") + private String gender; + + @Schema(description = "出生日期") + private LocalDateTime birthday; + + @Schema(description = "设备类型:CT DR MR B超 彩超等", example = "2") + private String deviceType; + + @Schema(description = "影像设备名称") + private String deviceName; + + @Schema(description = "seri_dicomCount:序列数量/dicom数量") + private String seDc; + + @Schema(description = "检查日期:年月日时分秒") + private LocalDateTime examDate; + + @Schema(description = "检查项目代码", example = "16416496") + private String examItemCode; + + @Schema(description = "检查项目名称", example = "张三") + private String examItemName; + + @Schema(description = "报告状态", example = "1") + private String reportstatus; + + @Schema(description = "申请日期:年月日时分秒") + private LocalDateTime applicationDate; + + @Schema(description = "机构ID", example = "29289") + private String orgId; + + @Schema(description = "机构名称", example = "芋艿") + private String orgName; + + @Schema(description = "登记单号") + private String regId; +} diff --git a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/service/patientexamlist/PatientexamlistService.java b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/service/patientexamlist/PatientexamlistService.java index 5a040f32f..eafe8f914 100644 --- a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/service/patientexamlist/PatientexamlistService.java +++ b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/service/patientexamlist/PatientexamlistService.java @@ -78,6 +78,14 @@ public interface PatientexamlistService extends IService { */ List dicomDataSync(); + /** + * 患者信息 + * + * @param createReqVOs 创建信息 + * @return 编号集合 + */ + List addPatientExamInfo(@Valid List createReqVOs); + /** * 更新examItemName * diff --git a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/service/patientexamlist/PatientexamlistServiceImpl.java b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/service/patientexamlist/PatientexamlistServiceImpl.java index 51852b0c2..ef870f610 100644 --- a/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/service/patientexamlist/PatientexamlistServiceImpl.java +++ b/yudao-module-tblist/yudao-module-tblist-biz/src/main/java/cn/iocoder/yudao/module/tblist/service/patientexamlist/PatientexamlistServiceImpl.java @@ -186,6 +186,36 @@ public class PatientexamlistServiceImpl extends ServiceImpl addPatientExamInfo(List createReqVOs) { + List ids = new ArrayList<>(); + + LocalDateTime dateTime = null; + UUID guid = null; + PatientexamlistDO patientexamlist = null; + if (createReqVOs != null && createReqVOs.size() > 0) { + for (PatientExamInfoAddReqVO createReqVO : createReqVOs) { + if (createReqVO != null) { + patientexamlist = BeanUtils.toBean(createReqVO, PatientexamlistDO.class); + + dateTime = LocalDateTime.parse(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + guid = UUID.randomUUID(); + + patientexamlist.setId(guid.toString()); + patientexamlist.setPName(createReqVO.getPname()); + patientexamlist.setCreateDate(dateTime); + + ids.add(patientexamlist.getId()); + patientexamlistMapper.insert(patientexamlist); + } + } + } + + if (!(ids != null && ids.size() > 0)) + ids = Collections.emptyList(); + return ids; + } + @Override public void updateExamItemNameById(String id, String examItemName) { validatePatientexamlistExists(id); diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/ultrasonicController.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/ultrasonicController.java index 76174e4a0..f720520a4 100644 --- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/ultrasonicController.java +++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/ultrasonicController.java @@ -41,7 +41,6 @@ import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.http.HttpHeaders; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -493,10 +492,8 @@ public class ultrasonicController { @PostMapping("/InsImageInfo") @Operation(summary = "影像信息") - public CommonResult InsImageInfo(@RequestBody List patientInfoVOS,@RequestHeader HttpHeaders headers) throws ParseException { + public CommonResult InsImageInfo(@RequestBody List patientInfoVOS) throws ParseException { try { - // 从headers中获取特定的header参数 - // String someHeaderValue = headers.getFirst("Some-Header-Name"); if(!patientInfoVOS.isEmpty()) { List dicompatientsDOList=new ArrayList<>(); diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index c1238383b..84bb41b92 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -160,6 +160,8 @@ yudao: - /admin-api/tblist/patientexamlist/getCheckRecord - /admin-api/ultrasoniccom/ultrasonic/insimagescreenshot - /admin-api/ultrasoniccom/ultrasonic/InsImageInfo + - /admin-api/tblist/patientexamlist/addPatientExamInfo + - /admin-api/system/jwtToken/getToken websocket: enable: true # websocket的开关 path: /infra/ws # 路径 @@ -205,6 +207,8 @@ yudao: - /admin-api/tblist/patientexamlist/getCheckRecord - /admin-api/ultrasoniccom/ultrasonic/insimagescreenshot - /admin-api/ultrasoniccom/ultrasonic/InsImageInfo + - /admin-api/tblist/patientexamlist/addPatientExamInfo + - /admin-api/system/jwtToken/getToken ignore-tables: - system_tenant - system_tenant_package