Merge remote-tracking branch 'origin/dev_1.0.0' into dev_1.0.0

topo_dev
xueqingkun 9 months ago
commit d8a52d1dd8

@ -55,6 +55,10 @@
<version>5.8.26</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>

@ -0,0 +1,37 @@
package com.supervision.chat.client;
import cn.hutool.core.util.ArrayUtil;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.support.RestClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
@Configuration
public class LangChainChatConfig {
@Value("${langChain-chat.url}")
private String LangChainChatClientUrl;
@Bean
public RestClient restClient() {
return RestClient.builder().baseUrl(LangChainChatClientUrl).build();
}
@Bean
public LangChainChatService langChainChatClient(RestClient restClient) {
RestClientAdapter adapter = RestClientAdapter.create(restClient);
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
return factory.createClient(LangChainChatService.class);
}
}

@ -0,0 +1,19 @@
package com.supervision.chat.client;
import com.supervision.chat.client.dto.CreateBaseDTO;
import com.supervision.chat.client.dto.LangChainChatRes;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.service.annotation.HttpExchange;
import org.springframework.web.service.annotation.PostExchange;
@HttpExchange
public interface LangChainChatService {
@PostExchange(url = "create_knowledge_base", contentType = "application/json")
void chat(@RequestBody CreateBaseDTO createBaseDTO);
@PostExchange(url = "chat/test/testPost", contentType = "application/json")
LangChainChatRes test(@RequestBody CreateBaseDTO createBaseDTO);
}

@ -0,0 +1,32 @@
package com.supervision.chat.client;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.supervision.chat.client.dto.CreateBaseDTO;
import com.supervision.chat.client.dto.LangChainChatRes;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
@Service
public class LangChainChatServiceImpl{
@Value("${langChain-chat.url}")
private String LangChainChatClientUrl;
public LangChainChatRes chat(CreateBaseDTO createBaseDTO) {
String post = HttpUtil.post(LangChainChatClientUrl + "create_knowledge_base", JSONUtil.toJsonStr(createBaseDTO));
if (JSONUtil.isTypeJSON(post)) {
return JSONUtil.toBean(post, LangChainChatRes.class);
}
return null;
}
}

@ -0,0 +1,13 @@
package com.supervision.chat.client.dto;
import lombok.Data;
@Data
public class CreateBaseDTO {
private String knowledge_base_name;
private String vector_store_type = "faiss";
private String embed_model = "bge-large-zh";
}

@ -0,0 +1,13 @@
package com.supervision.chat.client.dto;
import lombok.Data;
@Data
public class LangChainChatRes {
private Integer code;
private String msg;
private String data;
}

@ -0,0 +1,34 @@
package com.supervision.chat.controller;
import cn.hutool.json.JSONUtil;
import com.supervision.chat.client.LangChainChatService;
import com.supervision.chat.client.dto.CreateBaseDTO;
import com.supervision.chat.client.dto.LangChainChatRes;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.service.annotation.PostExchange;
import java.util.concurrent.Executors;
@Slf4j
@RequestMapping("chat/test/")
@RestController
@RequiredArgsConstructor
public class TestController {
private final LangChainChatService langChainChatClient;
@GetMapping("test")
public void test(){
CreateBaseDTO createBaseDTO = new CreateBaseDTO();
createBaseDTO.setKnowledge_base_name("11111111");
langChainChatClient.chat(createBaseDTO);
// log.info(JSONUtil.toJsonStr(chat));
}
@PostMapping("testPost")
public void testPost(@RequestBody CreateBaseDTO createBaseDTO){
System.out.println(JSONUtil.toJsonStr(createBaseDTO));
}
}

@ -17,6 +17,7 @@ import com.supervision.common.exception.CustomException;
import com.supervision.common.utils.ExcelReader;
import com.supervision.common.utils.IPages;
import com.supervision.common.utils.StringUtils;
import com.supervision.config.BusinessException;
import com.supervision.police.domain.CasePerson;
import com.supervision.police.domain.ComDictionary;
import com.supervision.police.dto.*;
@ -29,6 +30,7 @@ import com.supervision.police.service.ModelCaseService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@ -130,10 +132,20 @@ public class ModelCaseServiceImpl extends ServiceImpl<ModelCaseMapper, ModelCase
}
@Override
@Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class)
public R<?> addOrUpd(ModelCaseBase modelCaseBase) {
int i = 0;
if (StrUtil.isBlank(modelCaseBase.getCaseNo())) {
throw new BusinessException("案件编号不能为空");
}
ModelCase modelCase = modelCaseBase.toModelCase();
if (modelCase.getId() != null) {
// 如果更新,则校验案件编码,案件编码不允许修改(案件编码作为和知识库交互的主键,是唯一的)
ModelCase exist = modelCaseMapper.selectById(modelCase.getId());
if (!StrUtil.equals(exist.getCaseNo(), modelCase.getCaseNo())) {
throw new BusinessException("案件编号不允许修改");
}
i = modelCaseMapper.updateById(modelCase);
} else {
Long num = modelCaseMapper.selectCount(null);
@ -141,12 +153,15 @@ public class ModelCaseServiceImpl extends ServiceImpl<ModelCaseMapper, ModelCase
i = modelCaseMapper.insert(modelCase);
}
if (i > 0) {
// TODO 这里需要调用知识库的接口,去保存知识库
return R.okMsg("保存成功");
} else {
return R.fail("保存失败");
}
}
@Override
public R<?> del(String id) {
ModelCase modelCase = modelCaseMapper.selectById(id);
@ -274,7 +289,7 @@ public class ModelCaseServiceImpl extends ServiceImpl<ModelCaseMapper, ModelCase
// 需要和原子指标的规则判断是否一致(解决出罪和入罪冲突的问题)
String s = indexJundgeLogicMap.get(atomic.getAtomicIndexId());
atomic.judgeWithIndexResult(s);
if (StrUtil.isBlank(atomic.getRecord())){
if (StrUtil.isBlank(atomic.getRecord())) {
atomic.setRecord("无");
}
}

@ -74,4 +74,8 @@ minio:
logging:
level:
org.springframework.ai: TRACE
org.springframework.ai: TRACE
langChain-chat:
url: http://113.128.242.110:7861/knowledge_base/
# url: http://192.168.10.27:8097/fu-hsi-server/
Loading…
Cancel
Save