From 1bb06ff92767a2c6db534dc1e78cb2d2d9dcf65c Mon Sep 17 00:00:00 2001
From: zhouxiantao <1026371446@qq.com>
Date: Wed, 11 Sep 2024 12:53:38 +0800
Subject: [PATCH] 小程序来访登记,异常抛出
---
dyh-service/dyh-mediate/src/main/java/cn/huge/module/ai/controller/AiController.java | 79 ++++++++++++++++++++++++++++-----------
1 files changed, 56 insertions(+), 23 deletions(-)
diff --git a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/ai/controller/AiController.java b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/ai/controller/AiController.java
index 6a04848..2498fbb 100644
--- a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/ai/controller/AiController.java
+++ b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/ai/controller/AiController.java
@@ -1,18 +1,20 @@
package cn.huge.module.ai.controller;
+import cn.huge.base.common.utils.GuavaCacheUtils;
import cn.huge.base.common.utils.HttpClientUtils;
+import cn.huge.base.common.utils.ObjectUtils;
import cn.huge.base.common.utils.ReturnSucUtils;
import cn.huge.module.ai.controller.domain.dto.CaseInfoDetailDto;
import cn.huge.module.ai.controller.domain.dto.CaseInfoDto;
+import cn.huge.module.ai.controller.domain.dto.CaseRiskDto;
import cn.huge.module.ai.controller.domain.dto.LawInfoDto;
+import cn.huge.module.ai.controller.domain.vo.AiRequestVo;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.support.FeignHttpClientProperties;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
@@ -30,13 +32,17 @@
@Value("${ai.url}")
private String aiUrl;
- @RequestMapping("/get-case")
- public Object getCase(@RequestParam String caseDes, @RequestParam String caseClaim, @RequestParam String caseId) {
+ @PostMapping("/get-case")
+ public Object getCase(@RequestBody AiRequestVo aiRequestVo) {
+ Object cacheAi = GuavaCacheUtils.getCacheAi("get-case"+aiRequestVo.getCaseId());
+ if(ObjectUtils.isNotEmpty(cacheAi)){
+ return ReturnSucUtils.getRepInfo("请求成功", cacheAi);
+ }
List<CaseInfoDto> caseInfoDtoList = new ArrayList<>();
Map<String, String> params = new HashMap<>();
- params.put("caseDes", caseDes);//案件描述
- params.put("caseClaim", caseClaim);//案件诉求
- params.put("caseId", caseId);//案件id
+ params.put("caseDes", aiRequestVo.getCaseDes());//案件描述
+ params.put("caseClaim", aiRequestVo.getCaseClaim());//案件诉求
+ params.put("caseId", aiRequestVo.getCaseId());//案件id
params.put("topK", "3");
params.put("metricType", "IP");
String s = HttpClientUtils.httpPostForm(aiUrl + "/queryConciliationCase", params, new HashMap<>(), "utf-8");
@@ -53,7 +59,7 @@
caseInfoDtoList.add(caseInfoDto);
}
}
- if (caseInfoDtoList.size() < 6) {
+ if (caseInfoDtoList.size() < 3) {
s = HttpClientUtils.httpPostForm(aiUrl + "/queryJudgmentCase", params, new HashMap<>(), "utf-8");
object = JSONObject.parseObject(s);
code = object.getIntValue("code");
@@ -62,8 +68,8 @@
for (int i = 0; i < data.size(); i++) {
JSONObject jsonObject = data.getJSONObject(i);
CaseInfoDto caseInfoDto = new CaseInfoDto();
- caseInfoDto.setCaseId(jsonObject.getString("id"));
- caseInfoDto.setCaseName(jsonObject.getString("case_title"));
+ caseInfoDto.setCaseId(jsonObject.getString("cpws_case_info_id"));
+ caseInfoDto.setCaseName(jsonObject.getString("case_name"));
caseInfoDto.setCaseType(2);//表示判决类案件
caseInfoDtoList.add(caseInfoDto);
if (caseInfoDtoList.size() == 3)
@@ -71,17 +77,22 @@
}
}
}
+ GuavaCacheUtils.putCacheAi("get-case"+aiRequestVo.getCaseId(), caseInfoDtoList);
return ReturnSucUtils.getRepInfo("请求成功", caseInfoDtoList);
}
- @RequestMapping("/get-law")
- public Object getLaw(@RequestParam String caseDes, @RequestParam String caseClaim, @RequestParam String caseId) {
+ @PostMapping("/get-law")
+ public Object getLaw(@RequestBody AiRequestVo aiRequestVo) {
+ Object cacheAi = GuavaCacheUtils.getCacheAi("get-law"+aiRequestVo.getCaseId());
+ if(ObjectUtils.isNotEmpty(cacheAi)){
+ return ReturnSucUtils.getRepInfo("请求成功", cacheAi);
+ }
List<LawInfoDto> lawInfoDtos = new ArrayList<>();
Map<String, String> params = new HashMap<>();
- params.put("caseDes", caseDes);//案件描述
- params.put("caseClaim", caseClaim);//案件诉求
- params.put("caseId", caseId);//案件id
+ params.put("caseDes", aiRequestVo.getCaseDes());//案件描述
+ params.put("caseClaim", aiRequestVo.getCaseClaim());//案件诉求
+ params.put("caseId", aiRequestVo.getCaseId());//案件id
String s = HttpClientUtils.httpPostForm(aiUrl + "/queryLawProvision", params, new HashMap<>(), "utf-8");
JSONObject object = JSONObject.parseObject(s);
int code = object.getIntValue("code");
@@ -97,32 +108,31 @@
lawInfoDtos.add(lawInfoDto);
}
}
+ GuavaCacheUtils.putCacheAi("get-law"+aiRequestVo.getCaseId(), lawInfoDtos);
return ReturnSucUtils.getRepInfo("请求成功", lawInfoDtos);
}
@RequestMapping("/get-case-detail")
public Object getCaseLawDetail(@RequestParam String caseId, @RequestParam int type) {
- Map<String, String> params = new HashMap<>();
- params.put("caseId", caseId);
String s = "";
CaseInfoDetailDto caseInfoDetailDto = new CaseInfoDetailDto();
if (type == 1) {//表示纠纷类案件
- s = HttpClientUtils.httpGet(aiUrl + "/getConciliationCaseText", new HashMap<>(), "utf-8");
+ s = HttpClientUtils.httpGet(aiUrl + "/getConciliationCaseText?caseId=" + caseId, new HashMap<>(), "utf-8");
JSONObject object = JSONObject.parseObject(s);
int code = object.getIntValue("code");
- if (code == 1) {
+ if (code == 200) {
JSONObject data = object.getJSONObject("data");
caseInfoDetailDto.setCaseId(data.getString("id"));
caseInfoDetailDto.setCaseTitle(data.getString("case_title"));
caseInfoDetailDto.setCaseDesc(data.getString("case_des"));
- caseInfoDetailDto.setCaseClaim("case_claim");
+ caseInfoDetailDto.setCaseClaim(data.getString("case_claim"));
caseInfoDetailDto.setAgreeContent(data.getString("agree_content"));
}
} else {
- s = HttpClientUtils.httpGet(aiUrl + "/getJudgmentCaseText", new HashMap<>(), "utf-8");
+ s = HttpClientUtils.httpGet(aiUrl + "/getJudgmentCaseText?caseId=" + caseId, new HashMap<>(), "utf-8");
JSONObject object = JSONObject.parseObject(s);
int code = object.getIntValue("code");
- if (code == 1) {
+ if (code == 200) {
JSONObject data = object.getJSONObject("data");
caseInfoDetailDto.setCaseId(data.getString("idcpws_case_info_id"));
caseInfoDetailDto.setCaseTitle(data.getString("basic_case_info"));
@@ -134,4 +144,27 @@
return ReturnSucUtils.getRepInfo("请求成功", caseInfoDetailDto);
}
+ @PostMapping("/get-clain-rise-case")
+ public Object getClaimRiskByCase(@RequestBody AiRequestVo aiRequestVo) {
+ Object cacheAi = GuavaCacheUtils.getCacheAi("get-clain-rise-case"+aiRequestVo.getCaseId());
+ if(ObjectUtils.isNotEmpty(cacheAi)){
+ return ReturnSucUtils.getRepInfo("请求成功", cacheAi);
+ }
+ CaseRiskDto caseRiskDto = new CaseRiskDto();
+ Map<String, String> params = new HashMap<>();
+ params.put("caseDes", aiRequestVo.getCaseDes());//案件描述
+ params.put("caseClaim", aiRequestVo.getCaseClaim());//案件诉求
+ params.put("caseId", aiRequestVo.getCaseId());//案件id
+ String s = HttpClientUtils.httpPostForm(aiUrl + "/getClaimRiskByCase", params, new HashMap<>(), "utf-8");
+ JSONObject object = JSONObject.parseObject(s);
+ int code = object.getIntValue("code");
+ if (code == 200) {
+ JSONObject data = object.getJSONObject("data");
+ caseRiskDto.setIsClaimRisk(data.getIntValue("is_claim_risk"));
+ caseRiskDto.setAnalysisProcess(data.getString("analysis_process"));
+ }
+ GuavaCacheUtils.putCacheAi("get-clain-rise-case"+aiRequestVo.getCaseId(), caseRiskDto);
+ return ReturnSucUtils.getRepInfo("请求成功", caseRiskDto);
+ }
+
}
--
Gitblit v1.8.0