修改数据库配置
This commit is contained in:
parent
f159a8869f
commit
10d065a4d8
|
@ -2,12 +2,13 @@ package edu.zrh.healthsystem;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author han
|
* @author han
|
||||||
*/
|
*/
|
||||||
|
@EnableJpaRepositories
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class HealthSystemApplication {
|
public class HealthSystemApplication {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package edu.zrh.healthsystem.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Data;
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name = "talk_info")
|
||||||
|
public class TalkInfo {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "talk_id")
|
||||||
|
private int talkId;
|
||||||
|
|
||||||
|
@Column(name = "talk_prompt")
|
||||||
|
private String talkPrompt;
|
||||||
|
|
||||||
|
@Column(name = "talk_response")
|
||||||
|
private String talkResponse;
|
||||||
|
|
||||||
|
@Column(name = "talk_time")
|
||||||
|
private String talkTime;
|
||||||
|
|
||||||
|
@Column(name="talk_user")
|
||||||
|
private String talkUser;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package edu.zrh.healthsystem.repository;
|
||||||
|
|
||||||
|
import edu.zrh.healthsystem.entity.TalkInfo;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface TalkInfoRepository extends JpaRepository<TalkInfo, Integer> {
|
||||||
|
}
|
|
@ -1,10 +1,14 @@
|
||||||
package edu.zrh.healthsystem.service;
|
package edu.zrh.healthsystem.service;
|
||||||
|
|
||||||
|
import edu.zrh.healthsystem.entity.TalkInfo;
|
||||||
import edu.zrh.healthsystem.model.Talk;
|
import edu.zrh.healthsystem.model.Talk;
|
||||||
import edu.zrh.healthsystem.model.TalkResponse;
|
import edu.zrh.healthsystem.model.TalkResponse;
|
||||||
|
import edu.zrh.healthsystem.repository.TalkInfoRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,9 +17,10 @@ import java.util.Map;
|
||||||
@Service
|
@Service
|
||||||
public class TalkService {
|
public class TalkService {
|
||||||
private final RestTemplate restTemplate;
|
private final RestTemplate restTemplate;
|
||||||
|
private final TalkInfoRepository talkInfoRepository;
|
||||||
public TalkService(RestTemplate restTemplate) {
|
public TalkService(RestTemplate restTemplate, TalkInfoRepository talkInfoRepository) {
|
||||||
this.restTemplate = restTemplate;
|
this.restTemplate = restTemplate;
|
||||||
|
this.talkInfoRepository = talkInfoRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String callApi(String url) {
|
public String callApi(String url) {
|
||||||
|
@ -23,6 +28,14 @@ public class TalkService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TalkResponse callApiChat(Talk request) {
|
public TalkResponse callApiChat(Talk request) {
|
||||||
return restTemplate.postForObject("http://10.10.10.44:11434/api/generate", request, TalkResponse.class);
|
TalkResponse response = restTemplate.postForObject("http://10.10.10.44:11434/api/generate", request, TalkResponse.class);
|
||||||
|
|
||||||
|
TalkInfo talkInfo = new TalkInfo();
|
||||||
|
talkInfo.setTalkPrompt(request.getPrompt());
|
||||||
|
talkInfo.setTalkResponse(response.getResponse());
|
||||||
|
talkInfo.setTalkTime(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||||
|
|
||||||
|
talkInfoRepository.save(talkInfo);
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue