修改数据库配置

This commit is contained in:
zrh050423 2024-12-10 14:28:10 +08:00
parent f159a8869f
commit 10d065a4d8
4 changed files with 53 additions and 4 deletions

View File

@ -2,12 +2,13 @@ package edu.zrh.healthsystem;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
/**
* @author han
*/
@EnableJpaRepositories
@SpringBootApplication
public class HealthSystemApplication {

View File

@ -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;
}

View File

@ -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> {
}

View File

@ -1,10 +1,14 @@
package edu.zrh.healthsystem.service;
import edu.zrh.healthsystem.entity.TalkInfo;
import edu.zrh.healthsystem.model.Talk;
import edu.zrh.healthsystem.model.TalkResponse;
import edu.zrh.healthsystem.repository.TalkInfoRepository;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
/**
@ -13,9 +17,10 @@ import java.util.Map;
@Service
public class TalkService {
private final RestTemplate restTemplate;
public TalkService(RestTemplate restTemplate) {
private final TalkInfoRepository talkInfoRepository;
public TalkService(RestTemplate restTemplate, TalkInfoRepository talkInfoRepository) {
this.restTemplate = restTemplate;
this.talkInfoRepository = talkInfoRepository;
}
public String callApi(String url) {
@ -23,6 +28,14 @@ public class TalkService {
}
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;
}
}