init
This commit is contained in:
33
.gitignore
vendored
Normal file
33
.gitignore
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
81
pom.xml
Normal file
81
pom.xml
Normal file
@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>app_sb</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>app_sb</name>
|
||||
<description>app_sb</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<spring-boot.version>2.6.13</spring-boot.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<configuration>
|
||||
<mainClass>org.example.app_sb.AppSbApplication</mainClass>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>repackage</id>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
67
src/main/java/BasicController.java
Normal file
67
src/main/java/BasicController.java
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.example.app_sb.demos.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||
*/
|
||||
@Controller
|
||||
public class BasicController {
|
||||
|
||||
// http://127.0.0.1:8080/hello?name=lisi
|
||||
@RequestMapping("/hello")
|
||||
@ResponseBody
|
||||
public String hello(@RequestParam(name = "name", defaultValue = "unknown user") String name) {
|
||||
return "Hello " + name;
|
||||
}
|
||||
|
||||
// http://127.0.0.1:8080/user
|
||||
@RequestMapping("/user")
|
||||
@ResponseBody
|
||||
public User user() {
|
||||
User user = new User();
|
||||
user.setName("theonefx");
|
||||
user.setAge(666);
|
||||
return user;
|
||||
}
|
||||
|
||||
// http://127.0.0.1:8080/save_user?name=newName&age=11
|
||||
@RequestMapping("/save_user")
|
||||
@ResponseBody
|
||||
public String saveUser(User u) {
|
||||
return "user will save: name=" + u.getName() + ", age=" + u.getAge();
|
||||
}
|
||||
|
||||
// http://127.0.0.1:8080/html
|
||||
@RequestMapping("/html")
|
||||
public String html() {
|
||||
return "index.html";
|
||||
}
|
||||
|
||||
@ModelAttribute
|
||||
public void parseUser(@RequestParam(name = "name", defaultValue = "unknown user") String name
|
||||
, @RequestParam(name = "age", defaultValue = "12") Integer age, User user) {
|
||||
user.setName("zhangsan");
|
||||
user.setAge(18);
|
||||
}
|
||||
}
|
44
src/main/java/PathVariableController.java
Normal file
44
src/main/java/PathVariableController.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.example.app_sb.demos.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||
*/
|
||||
@Controller
|
||||
public class PathVariableController {
|
||||
|
||||
// http://127.0.0.1:8080/user/123/roles/222
|
||||
@RequestMapping(value = "/user/{userId}/roles/{roleId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public String getLogin(@PathVariable("userId") String userId, @PathVariable("roleId") String roleId) {
|
||||
return "User Id : " + userId + " Role Id : " + roleId;
|
||||
}
|
||||
|
||||
// http://127.0.0.1:8080/javabeat/somewords
|
||||
@RequestMapping(value = "/javabeat/{regexp1:[a-z-]+}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public String getRegExp(@PathVariable("regexp1") String regexp1) {
|
||||
return "URI Part : " + regexp1;
|
||||
}
|
||||
}
|
43
src/main/java/User.java
Normal file
43
src/main/java/User.java
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.example.app_sb.demos.web;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||
*/
|
||||
public class User {
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
}
|
13
src/main/java/org/example/app_sb/AppSbApplication.java
Normal file
13
src/main/java/org/example/app_sb/AppSbApplication.java
Normal file
@ -0,0 +1,13 @@
|
||||
package org.example.app_sb;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class AppSbApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AppSbApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package org.example.app_sb.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class ApiController {
|
||||
|
||||
// 实现第一个接口,返回 [spring-boot]
|
||||
@GetMapping("/api/get_1")
|
||||
public String get1() {
|
||||
return "spring-boot";
|
||||
}
|
||||
|
||||
// 实现第二个接口,根据参数 name 返回对应值
|
||||
@GetMapping("/api/get_2")
|
||||
public String get2(@RequestParam String name) {
|
||||
return name;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package org.example.app_sb.controller;
|
||||
|
||||
import org.example.app_sb.entity.Person;
|
||||
import org.example.app_sb.entity.PersonHealth;
|
||||
|
||||
import org.example.app_sb.service.HealthService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class HealthController {
|
||||
@Autowired
|
||||
private HealthService healthService;
|
||||
|
||||
@GetMapping("/api/ehrSet_805")
|
||||
public String saveHealthRecord(
|
||||
@RequestParam String sfz_id,
|
||||
@RequestParam String name,
|
||||
@RequestParam String gender,
|
||||
@RequestParam String emr,
|
||||
@RequestParam int sbp,
|
||||
@RequestParam int dbp) {
|
||||
healthService.saveOrUpdatePerson(sfz_id, name, gender, emr);
|
||||
healthService.saveHealthData(sfz_id, sbp, dbp);
|
||||
return name;
|
||||
}
|
||||
|
||||
@GetMapping("/api/ehrGet_805")
|
||||
public Object getLatestHealthRecord(@RequestParam String sfz_id) {
|
||||
PersonHealth record = healthService.getLatestHealthRecord(sfz_id);
|
||||
return record != null ? record : "未找到健康档案";
|
||||
}
|
||||
}
|
139
src/main/java/org/example/app_sb/controller/UserController.java
Normal file
139
src/main/java/org/example/app_sb/controller/UserController.java
Normal file
@ -0,0 +1,139 @@
|
||||
package org.example.app_sb.controller;
|
||||
|
||||
import org.example.app_sb.entity.User;
|
||||
import org.example.app_sb.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@GetMapping("/api/set_803")
|
||||
public String setUser(@RequestParam String name, @RequestParam String address) {
|
||||
return userService.setUser(name, address);
|
||||
}
|
||||
|
||||
@GetMapping("/api/get_803")
|
||||
public String getUser(@RequestParam String name) {
|
||||
return userService.getUserAddress(name);
|
||||
}
|
||||
|
||||
// 注册接口
|
||||
@GetMapping("/api/register_803_1")
|
||||
public String register2(
|
||||
@RequestParam String name,
|
||||
@RequestParam String password) {
|
||||
return userService.register(name, password);
|
||||
}
|
||||
|
||||
@GetMapping("/api/register_803_2")
|
||||
public String register(
|
||||
@RequestParam String name,
|
||||
@RequestParam String password) {
|
||||
System.out.println("|***********register_803_2**************|");
|
||||
System.out.println(name + " " + password);
|
||||
System.out.println("|***********register_803_2**************|");
|
||||
return userService.register(name, password);
|
||||
}
|
||||
|
||||
// 登录接口
|
||||
@GetMapping("/api/login_803_1")
|
||||
public String login(
|
||||
@RequestParam String name,
|
||||
@RequestParam String password) {
|
||||
return userService.login(name, password);
|
||||
}
|
||||
|
||||
// 登录接口
|
||||
// @RequestMapping("login_803_2")
|
||||
// public String login_803_2(User user70Entity,
|
||||
// HttpServletRequest httpServletRequest){
|
||||
// user70Entity.setPassword(DigestUtils.md5DigestAsHex(user70Entity.getPassword().getBytes()));
|
||||
// //开启session
|
||||
// HttpSession httpSession=httpServletRequest.getSession();
|
||||
//
|
||||
// if(UserService.login(user70Entity)==1){
|
||||
// httpSession.setAttribute("name",user70Entity.getName());//$_SESSION['name']
|
||||
// return "登录成功";
|
||||
// }else{
|
||||
// httpSession.setAttribute("name","");
|
||||
// return "登录失败";
|
||||
// }
|
||||
// }
|
||||
// @GetMapping("/api/login_803_2")
|
||||
// public String login(
|
||||
// @RequestParam String name,
|
||||
// @RequestParam String password,
|
||||
// HttpSession session) {
|
||||
// System.out.println("|***********login_803_2**************|");
|
||||
// System.out.println(name + " " + password);
|
||||
// System.out.println(session.getAttribute("name"));
|
||||
// System.out.println("|***********login_803_2**************|");
|
||||
// if (userService.validateLogin(name, password)) {
|
||||
// session.setAttribute("name", name);
|
||||
// return "登录成功";
|
||||
// } else {
|
||||
// return "登录失败";
|
||||
// }
|
||||
// }
|
||||
@GetMapping("/api/login_803_2")
|
||||
public String login(
|
||||
@RequestParam String name,
|
||||
@RequestParam String password,
|
||||
HttpServletRequest httpServletRequest) {
|
||||
System.out.println("|***********login_803_2**************|");
|
||||
System.out.println(name + " " + password);
|
||||
// System.out.println(session.getAttribute("name"));
|
||||
System.out.println("|***********login_803_2**************|");
|
||||
//开启session
|
||||
HttpSession httpSession=httpServletRequest.getSession();
|
||||
|
||||
if (userService.validateLogin(name, password)) {
|
||||
httpSession.setAttribute("name", name);
|
||||
return "登录成功";
|
||||
} else {
|
||||
httpSession.setAttribute("name","");
|
||||
return "登录失败";
|
||||
}
|
||||
}
|
||||
@RequestMapping("api/list_803_2")
|
||||
public String list_803_2(HttpServletRequest httpServletRequest){
|
||||
HttpSession httpSession=httpServletRequest.getSession();
|
||||
String returnValue="";
|
||||
try{
|
||||
returnValue=httpSession.getAttribute("name").toString();
|
||||
if (returnValue == "") {
|
||||
returnValue="未受权,请先登录";
|
||||
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
returnValue="未受权,请先登录";
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
// 列表访问接口
|
||||
// @RequestMapping("/api/list_803_2")
|
||||
// public String list(@RequestParam String name, HttpSession session) {
|
||||
// String loggedInUser = (String) session.getAttribute("name");
|
||||
// System.out.println("|***********list_803_2**************|");
|
||||
// System.out.println(name + " " + session.getAttribute("name"));
|
||||
// System.out.println("|***********list_803_2**************|");
|
||||
// if (loggedInUser != null && loggedInUser.equals(name)) {
|
||||
// return loggedInUser;
|
||||
// } else {
|
||||
// return "未受权,请先登录";
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
65
src/main/java/org/example/app_sb/entity/Person.java
Normal file
65
src/main/java/org/example/app_sb/entity/Person.java
Normal file
@ -0,0 +1,65 @@
|
||||
package org.example.app_sb.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "person_805")
|
||||
public class Person {
|
||||
@Id
|
||||
private String sfzId;
|
||||
private String name;
|
||||
private String gender;
|
||||
private String emr;
|
||||
private int createTime;
|
||||
private int updateTime;
|
||||
|
||||
public String getSfzId() {
|
||||
return sfzId;
|
||||
}
|
||||
|
||||
public void setSfzId(String sfzId) {
|
||||
this.sfzId = sfzId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(String gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public String getEmr() {
|
||||
return emr;
|
||||
}
|
||||
|
||||
public void setEmr(String emr) {
|
||||
this.emr = emr;
|
||||
}
|
||||
|
||||
public int getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(int createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public int getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(int updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
}
|
60
src/main/java/org/example/app_sb/entity/PersonHealth.java
Normal file
60
src/main/java/org/example/app_sb/entity/PersonHealth.java
Normal file
@ -0,0 +1,60 @@
|
||||
package org.example.app_sb.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "person_health_805")
|
||||
public class PersonHealth {
|
||||
@Id
|
||||
private String id;
|
||||
private String sfzId;
|
||||
private int height;
|
||||
|
||||
private int heartRate;
|
||||
private int sbp;
|
||||
private int dbp;
|
||||
private int createTime;
|
||||
private int updateTime;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSfzId() {
|
||||
return sfzId;
|
||||
}
|
||||
|
||||
public void setSfzId(String sfzId) {
|
||||
this.sfzId = sfzId;
|
||||
}
|
||||
|
||||
public int getSbp() {
|
||||
return sbp;
|
||||
}
|
||||
|
||||
public void setSbp(int sbp) {
|
||||
this.sbp = sbp;
|
||||
}
|
||||
|
||||
public int getDbp() {
|
||||
return dbp;
|
||||
}
|
||||
|
||||
public void setDbp(int dbp) {
|
||||
this.dbp = dbp;
|
||||
}
|
||||
|
||||
public int getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(int createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
39
src/main/java/org/example/app_sb/entity/User.java
Normal file
39
src/main/java/org/example/app_sb/entity/User.java
Normal file
@ -0,0 +1,39 @@
|
||||
package org.example.app_sb.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "user_70")
|
||||
public class User {
|
||||
@Id
|
||||
private String name;
|
||||
private String address;
|
||||
private String password;
|
||||
|
||||
// Getters and setters
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package org.example.app_sb.repository;
|
||||
|
||||
import org.example.app_sb.entity.PersonHealth;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PersonHealthRepository extends JpaRepository<PersonHealth, String> {
|
||||
List<PersonHealth> findBySfzIdOrderByCreateTimeDesc(String sfzId);
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.example.app_sb.repository;
|
||||
|
||||
import org.example.app_sb.entity.Person;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PersonRepository extends JpaRepository<Person, String> {
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package org.example.app_sb.repository;
|
||||
|
||||
import org.example.app_sb.entity.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface UserRepository extends JpaRepository<User, String> {
|
||||
User findByName(String name);
|
||||
}
|
48
src/main/java/org/example/app_sb/service/HealthService.java
Normal file
48
src/main/java/org/example/app_sb/service/HealthService.java
Normal file
@ -0,0 +1,48 @@
|
||||
package org.example.app_sb.service;
|
||||
|
||||
import org.example.app_sb.entity.Person;
|
||||
import org.example.app_sb.entity.PersonHealth;
|
||||
import org.example.app_sb.repository.PersonHealthRepository;
|
||||
import org.example.app_sb.repository.PersonRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class HealthService {
|
||||
@Autowired
|
||||
private PersonRepository personRepository;
|
||||
|
||||
@Autowired
|
||||
private PersonHealthRepository personHealthRepository;
|
||||
|
||||
public void saveOrUpdatePerson(String sfzId, String name, String gender, String emr) {
|
||||
Person person = personRepository.findById(sfzId).orElse(new Person());
|
||||
int now = (int) Instant.now().getEpochSecond();
|
||||
person.setSfzId(sfzId);
|
||||
person.setName(name);
|
||||
person.setGender(gender);
|
||||
person.setEmr(emr);
|
||||
person.setUpdateTime(now);
|
||||
if (person.getCreateTime() == 0) {
|
||||
person.setCreateTime(now);
|
||||
}
|
||||
personRepository.save(person);
|
||||
}
|
||||
|
||||
public void saveHealthData(String sfzId, int sbp, int dbp) {
|
||||
PersonHealth health = new PersonHealth();
|
||||
health.setId(String.valueOf(Instant.now().toEpochMilli()));
|
||||
health.setSfzId(sfzId);
|
||||
health.setSbp(sbp);
|
||||
health.setDbp(dbp);
|
||||
health.setCreateTime((int) Instant.now().getEpochSecond());
|
||||
personHealthRepository.save(health);
|
||||
}
|
||||
|
||||
public PersonHealth getLatestHealthRecord(String sfzId) {
|
||||
return personHealthRepository.findBySfzIdOrderByCreateTimeDesc(sfzId).stream().findFirst().orElse(null);
|
||||
}
|
||||
}
|
87
src/main/java/org/example/app_sb/service/UserService.java
Normal file
87
src/main/java/org/example/app_sb/service/UserService.java
Normal file
@ -0,0 +1,87 @@
|
||||
package org.example.app_sb.service;
|
||||
|
||||
import org.example.app_sb.entity.User;
|
||||
import org.example.app_sb.repository.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Transactional
|
||||
public String setUser(String name, String address) {
|
||||
User user = userRepository.findByName(name);
|
||||
if (user != null) {
|
||||
user.setAddress(address);
|
||||
userRepository.save(user);
|
||||
return "Updated successfully!";
|
||||
} else {
|
||||
User newUser = new User();
|
||||
newUser.setName(name);
|
||||
newUser.setAddress(address);
|
||||
newUser.setPassword("default_password");
|
||||
userRepository.save(newUser);
|
||||
return "Inserted successfully!";
|
||||
}
|
||||
}
|
||||
|
||||
public String getUserAddress(String name) {
|
||||
User user = userRepository.findByName(name);
|
||||
return user != null ? user.getAddress() : "User not found!";
|
||||
}
|
||||
|
||||
// MD5 加密
|
||||
public String encryptPassword(String password) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] digest = md.digest(password.getBytes());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : digest) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
return sb.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("Error encrypting password", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 注册或更新密码
|
||||
@Transactional
|
||||
public String register(String name, String password) {
|
||||
User user = userRepository.findByName(name);
|
||||
String encryptedPassword = encryptPassword(password);
|
||||
if (user != null) {
|
||||
user.setPassword(encryptedPassword);
|
||||
userRepository.save(user);
|
||||
return "用户密码修改成功";
|
||||
} else {
|
||||
User newUser = new User();
|
||||
newUser.setName(name);
|
||||
newUser.setPassword(encryptedPassword);
|
||||
userRepository.save(newUser);
|
||||
return "新用户注册成功";
|
||||
}
|
||||
}
|
||||
|
||||
// 登录
|
||||
public String login(String name, String password) {
|
||||
User user = userRepository.findByName(name);
|
||||
if (user != null && user.getPassword().equals(encryptPassword(password))) {
|
||||
return "登录成功";
|
||||
}
|
||||
return "登录失败";
|
||||
}
|
||||
|
||||
// 登录验证
|
||||
public boolean validateLogin(String name, String password) {
|
||||
User user = userRepository.findByName(name);
|
||||
return user != null && user.getPassword().equals(encryptPassword(password));
|
||||
}
|
||||
|
||||
}
|
9
src/main/resources/application.properties
Normal file
9
src/main/resources/application.properties
Normal file
@ -0,0 +1,9 @@
|
||||
# 应用服务 WEB 访问端口
|
||||
server.port=58340
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/exam_20241226_58040?useSSL=false&serverTimezone=UTC
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=
|
||||
spring.jpa.hibernate.ddl-auto=none
|
||||
spring.jpa.show-sql=true
|
||||
|
||||
|
6
src/main/resources/static/index.html
Normal file
6
src/main/resources/static/index.html
Normal file
@ -0,0 +1,6 @@
|
||||
<html>
|
||||
<body>
|
||||
<h1>hello word!!!</h1>
|
||||
<p>this is a html page</p>
|
||||
</body>
|
||||
</html>
|
13
src/test/java/org/example/app_sb/AppSbApplicationTests.java
Normal file
13
src/test/java/org/example/app_sb/AppSbApplicationTests.java
Normal file
@ -0,0 +1,13 @@
|
||||
package org.example.app_sb;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class AppSbApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user