最终版

This commit is contained in:
zrh050423 2024-12-24 12:24:22 +08:00
parent e8f8ea5565
commit 83b93221ab
16 changed files with 19 additions and 80 deletions

View File

@ -6,9 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
/**
* @author han
*/
@EnableJpaRepositories
@SpringBootApplication
public class HealthSystemApplication {

View File

@ -5,9 +5,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
* @author han
*/
@Configuration
public class WebConfig {

View File

@ -2,9 +2,7 @@ package edu.zrh.healthsystem.entity;
import jakarta.persistence.*;
import lombok.Data;
/**
* @author han
*/
@Data
@Entity
@Table(name = "talk_info")

View File

@ -2,9 +2,7 @@ package edu.zrh.healthsystem.entity;
import jakarta.persistence.*;
import lombok.Data;
/**
* @author han
*/
@Entity
@Data
@Table(name = "user_login")

View File

@ -1,9 +1,7 @@
package edu.zrh.healthsystem.entity;
import jakarta.persistence.*;
import lombok.Data;
/**
* @author han
*/
@Entity
@Data
@Table(name = "user_main")

View File

@ -12,9 +12,7 @@ import java.time.LocalDateTime;
import java.util.List;
/**
* @author han
*/
@Mapper
public interface UserMapper {

View File

@ -2,9 +2,7 @@ package edu.zrh.healthsystem.model;
import lombok.Data;
/**
* @author han
*/
@Data
public class Login {
private String username;

View File

@ -2,9 +2,7 @@ package edu.zrh.healthsystem.model;
import lombok.Data;
/**
* @author han
*/
public @Data class Message {
private String from;
private String text;

View File

@ -6,10 +6,14 @@ import java.util.List;
/**
* @author han
*
* 模型输入参数
*/
public @Data class Talk {
//模型名称
private String model="glm4:latest";
//模型输入
private String prompt;
//是否流式输出
private Boolean stream=false;
}

View File

@ -5,9 +5,7 @@ import lombok.Data;
import java.time.LocalDateTime;
/**
* @author han
*/
@Data
public class User {
private Long id;

View File

@ -3,9 +3,7 @@ package edu.zrh.healthsystem.model.response;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @author han
*/
@Data
@AllArgsConstructor
public class LoginResponse {

View File

@ -31,11 +31,4 @@ public class ResultResponse<T> implements Serializable {
return resultResponse;
}
public static <T> ResultResponse<T> error(String msg) {
ResultResponse resultResponse = new ResultResponse();
resultResponse.msg = msg;
resultResponse.code = 0;
return resultResponse;
}
}

View File

@ -5,9 +5,7 @@ import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* @author han
*/
public @Data class TalkResponse {
private String model;
private Date createdAt;

View File

@ -4,9 +4,7 @@ import edu.zrh.healthsystem.entity.UserLoginInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* @author han
*/
@Repository
public interface LoginRepository extends JpaRepository<UserLoginInfo, Long> {
UserLoginInfo findByUsername(String username);

View File

@ -11,9 +11,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
/**
* @author han
*/
@Service
public class LoginService {
@ -59,38 +57,8 @@ public class LoginService {
return result;
}
/**
* 用户注册逻辑
* @param login 用户注册信息
* @return LoginResult 注册结果
*/
public LoginResponse register(Login login) {
LoginResponse result = new LoginResponse();
// 假设我们先验证用户是否已经存在
UserLoginInfo existingUser = loginRepository.findByUsername(login.getUsername());
if (existingUser != null) {
result.setCode(400);
result.setMessage("用户名已存在");
} else {
UserLoginInfo newUser = new UserLoginInfo();
newUser.setPwd(login.getPwd());
newUser.setUsername(login.getUsername());
newUser.setPermission("1");
// 如果用户不存在则可以进行注册这里假设保存用户到数据库
loginRepository.save(newUser);
result.setCode(200);
result.setMessage("注册成功");
}
return result;
}
/**
* 生成 JWT Token
* @param id 用户的唯一标识例如用户 ID
* @return 生成的 JWT Token
*/
@Value("${jwt.secret-key}")
private String SECRET_KEY;

View File

@ -14,9 +14,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
/**
* @author han
*/
@Service
public class TalkService {
private final RestTemplate restTemplate;