From 10d065a4d82cc5036aadae502523b9b92c083ed2 Mon Sep 17 00:00:00 2001 From: zrh050423 <14331304+zrh050423@user.noreply.gitee.com> Date: Tue, 10 Dec 2024 14:28:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../healthsystem/HealthSystemApplication.java | 3 ++- .../edu/zrh/healthsystem/entity/TalkInfo.java | 26 +++++++++++++++++++ .../repository/TalkInfoRepository.java | 9 +++++++ .../zrh/healthsystem/service/TalkService.java | 19 +++++++++++--- 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 src/main/java/edu/zrh/healthsystem/entity/TalkInfo.java create mode 100644 src/main/java/edu/zrh/healthsystem/repository/TalkInfoRepository.java diff --git a/src/main/java/edu/zrh/healthsystem/HealthSystemApplication.java b/src/main/java/edu/zrh/healthsystem/HealthSystemApplication.java index 22be50e..7e90565 100644 --- a/src/main/java/edu/zrh/healthsystem/HealthSystemApplication.java +++ b/src/main/java/edu/zrh/healthsystem/HealthSystemApplication.java @@ -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 { diff --git a/src/main/java/edu/zrh/healthsystem/entity/TalkInfo.java b/src/main/java/edu/zrh/healthsystem/entity/TalkInfo.java new file mode 100644 index 0000000..0308a33 --- /dev/null +++ b/src/main/java/edu/zrh/healthsystem/entity/TalkInfo.java @@ -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; +} + diff --git a/src/main/java/edu/zrh/healthsystem/repository/TalkInfoRepository.java b/src/main/java/edu/zrh/healthsystem/repository/TalkInfoRepository.java new file mode 100644 index 0000000..70b70da --- /dev/null +++ b/src/main/java/edu/zrh/healthsystem/repository/TalkInfoRepository.java @@ -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 { +} diff --git a/src/main/java/edu/zrh/healthsystem/service/TalkService.java b/src/main/java/edu/zrh/healthsystem/service/TalkService.java index 655e7bf..07a27a3 100644 --- a/src/main/java/edu/zrh/healthsystem/service/TalkService.java +++ b/src/main/java/edu/zrh/healthsystem/service/TalkService.java @@ -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; } }