New file |
| | |
| | | package cn.huge.module.ai.controller; |
| | | |
| | | import cn.huge.base.common.utils.HttpClientUtils; |
| | | 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.LawInfoDto; |
| | | 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 java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * AI请求调用/get-case获取案件列表(一般包含3个纠纷类和3个判决类),/get-law获取法条推荐列表;案件详情在根据案件列表的id及type调用/get-case-detail获取案件详情 |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/api/ai/case-law") |
| | | public class AiController { |
| | | |
| | | @Value("${ai.url}") |
| | | private String aiUrl; |
| | | |
| | | @RequestMapping("/get-case") |
| | | public Object getCase(@RequestParam String caseDes, @RequestParam String caseClaim, @RequestParam String caseId) { |
| | | 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("topK", "3"); |
| | | params.put("metricType", "IP"); |
| | | String s = HttpClientUtils.httpPostForm(aiUrl + "/queryConciliationCase", params, new HashMap<>(), "utf-8"); |
| | | JSONObject object = JSONObject.parseObject(s); |
| | | int code = object.getIntValue("code"); |
| | | if (code == 200) { |
| | | JSONArray data = object.getJSONArray("data"); |
| | | 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.setCaseType(1);//表示调解类案件 |
| | | caseInfoDtoList.add(caseInfoDto); |
| | | } |
| | | } |
| | | if (caseInfoDtoList.size() < 6) { |
| | | s = HttpClientUtils.httpPostForm(aiUrl + "/queryJudgmentCase", params, new HashMap<>(), "utf-8"); |
| | | object = JSONObject.parseObject(s); |
| | | if (code == 200) { |
| | | JSONArray data = object.getJSONArray("data"); |
| | | 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.setCaseType(2);//表示判决类案件 |
| | | caseInfoDtoList.add(caseInfoDto); |
| | | if (caseInfoDtoList.size() == 3) |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | return ReturnSucUtils.getRepInfo("请求成功", caseInfoDtoList); |
| | | } |
| | | |
| | | |
| | | @RequestMapping("/get-law") |
| | | public Object getLaw(@RequestParam String caseDes, @RequestParam String caseClaim, @RequestParam String caseId) { |
| | | List<LawInfoDto> lawInfoDtos = new ArrayList<>(); |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("caseDes", caseDes);//案件描述 |
| | | params.put("caseClaim", caseClaim);//案件诉求 |
| | | params.put("caseId", caseId);//案件id |
| | | String s = HttpClientUtils.httpPostForm(aiUrl + "/queryLawProvision", params, new HashMap<>(), "utf-8"); |
| | | JSONObject object = JSONObject.parseObject(s); |
| | | int code = object.getIntValue("code"); |
| | | if (code == 200) { |
| | | JSONArray data = object.getJSONArray("data"); |
| | | for (int i = 0; i < data.size(); i++) { |
| | | JSONObject jsonObject = data.getJSONObject(i); |
| | | LawInfoDto lawInfoDto = new LawInfoDto(); |
| | | lawInfoDto.setLawInfoId(jsonObject.getString("law_info_id")); |
| | | lawInfoDto.setLawIndex(jsonObject.getString("provision_index")); |
| | | lawInfoDto.setLawDesc(jsonObject.getString("provision_text")); |
| | | lawInfoDto.setLawTitle(jsonObject.getString("law_title")); |
| | | lawInfoDtos.add(lawInfoDto); |
| | | } |
| | | } |
| | | 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"); |
| | | JSONObject object = JSONObject.parseObject(s); |
| | | int code = object.getIntValue("code"); |
| | | if (code == 1) { |
| | | 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.setAgreeContent(data.getString("agree_content")); |
| | | } |
| | | } else { |
| | | s = HttpClientUtils.httpGet(aiUrl + "/getJudgmentCaseText", new HashMap<>(), "utf-8"); |
| | | JSONObject object = JSONObject.parseObject(s); |
| | | int code = object.getIntValue("code"); |
| | | if (code == 1) { |
| | | JSONObject data = object.getJSONObject("data"); |
| | | caseInfoDetailDto.setCaseId(data.getString("idcpws_case_info_id")); |
| | | caseInfoDetailDto.setCaseTitle(data.getString("basic_case_info")); |
| | | caseInfoDetailDto.setCaseDesc(data.getString("full_text")); |
| | | caseInfoDetailDto.setAgreeContent(data.getString("judgment")); |
| | | caseInfoDetailDto.setLegalBasis(data.getString("legal_basis")); |
| | | } |
| | | } |
| | | return ReturnSucUtils.getRepInfo("请求成功", caseInfoDetailDto); |
| | | } |
| | | |
| | | } |