feat: 通用问答页面

This commit is contained in:
wenjinbo 2025-10-11 14:04:57 +08:00
parent 9897dd9551
commit 0c6ca10438
5 changed files with 74 additions and 36 deletions

View File

@ -194,7 +194,12 @@ const handleAddSubmit = async () => {
// Authorization: `Bearer ${localStorage.getItem('datasetsKey')}`,
// },
// })
await createDataset(addForm.value)
const aclStore = useAclStore()
const userId = aclStore.userId
await createDataset({
...addForm.value,
userId
})
ElMessage.success(t('vabI18n.knowledge.dialog.createSuccess'))
addFormVisible.value = false

View File

@ -2,6 +2,7 @@ package com.bjtds.brichat.controller;
import com.bjtds.brichat.entity.dataset.DatasetUpdateReq;
import com.bjtds.brichat.entity.dataset.DatasetsCreateReq;
import com.bjtds.brichat.entity.dataset.TUserDataset;
import com.bjtds.brichat.entity.dify.DatasetDto;
import com.bjtds.brichat.entity.dto.UserBindDatasetDto;
@ -20,12 +21,15 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Api(tags = "知识库管理")
@Slf4j
@RestController
@CrossOrigin(value = "*",maxAge = 3600)
@CrossOrigin(value = "*", maxAge = 3600)
@RequestMapping("/datasetManage")
public class DatasetManageController {
@ -46,27 +50,28 @@ public class DatasetManageController {
/**
* 获取当前用户可访问的知识库
*
* @param pageNo
* @param pageSize
* @param userId
* @return
*/
@GetMapping("/currUserDatasets")
public Pagination<TUserDataset> getCurrUserDatasets(
@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
public Pagination<TUserDataset> getCurrUserDatasets(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", required = false, defaultValue = "9") Integer pageSize,
@RequestParam(value = "userId", required = false, defaultValue = "") Long userId){
return datasetManagerService.getCurrUserDatasets(pageNo,pageSize,userId);
@RequestParam(value = "userId", required = false, defaultValue = "") Long userId) {
return datasetManagerService.getCurrUserDatasets(pageNo, pageSize, userId);
}
/**
* 删除知识库
*
* @param id
*/
@DeleteMapping("/{id}")
public void delete(@PathVariable String id) {
//TODO 解绑与该知识库相关的用户
// 解绑与该知识库相关的用户
datasetManagerService.deleteDataset(id);
difyDatasetService.delete(id);
@ -74,25 +79,27 @@ public class DatasetManageController {
//删除es索引
try {
esTDatasetFilesService.deleteIndex(id);
log.info("删除es索引成功,知识库id:{}",id);
log.info("删除es索引成功,知识库id:{}", id);
} catch (IOException e) {
log.error("删除es索引失败,知识库id:{}",id,e);
log.error("删除es索引失败,知识库id:{}", id, e);
}
}
@PostMapping("/create")
public ResultUtils create(@RequestBody DatasetCreateRequest datasetCreateRequest) {
ResponseEntity<DatasetDto>res = difyDatasetApiService.createDataset(datasetCreateRequest.getName(), datasetCreateRequest.getDescription());
public ResultUtils create(@RequestBody DatasetsCreateReq req) {
ResponseEntity<DatasetDto> res = difyDatasetApiService.createDataset(req.getName(), req.getDescription());
DatasetDto datasetDto = res.getBody();
String datasetId = datasetDto.getId();
//构建es索引
try {
esTDatasetFilesService.createIndex(datasetId);
log.info("创建es索引成功,知识库id:{}",datasetId);
log.info("创建es索引成功,知识库id:{}", datasetId);
} catch (IOException e) {
log.error("创建es索引失败,知识库id:{}",datasetId,e);
log.error("创建es索引失败,知识库id:{}", datasetId, e);
}
//添加知识库与用户关联关系
datasetManagerService.userBindDatasets(UserBindDatasetDto.builder().userId(req.getUserId()).datasetIds(Arrays.asList(datasetId)).build());
return ResultUtils.success(res.getBody());
}
@ -108,9 +115,9 @@ public class DatasetManageController {
}
/**
* 获取用户和知识库关联列表
*
* @param pageNo
* @param pageSize
* @param nameFilter
@ -120,14 +127,12 @@ public class DatasetManageController {
* @throws Exception
*/
@GetMapping("/usersLinkDataset")
public com.bjtds.common.utils.Pagination<UserLinkDatasetDto> getUsersLinkDatasetList(
@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
public com.bjtds.common.utils.Pagination<UserLinkDatasetDto> getUsersLinkDatasetList(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
@RequestParam(value = "nameFilter", required = false, defaultValue = "") String nameFilter,
@RequestParam(value = "deptFilter", required = false, defaultValue = "") String deptFilter,
@RequestParam(value = "roleFilter", required = false, defaultValue = "") String roleFilter
) throws Exception{
return datasetManagerService.getUserLinkDatasetsList(pageNo,pageSize,nameFilter,deptFilter,roleFilter);
@RequestParam(value = "roleFilter", required = false, defaultValue = "") String roleFilter) throws Exception {
return datasetManagerService.getUserLinkDatasetsList(pageNo, pageSize, nameFilter, deptFilter, roleFilter);
}
/***
@ -145,24 +150,22 @@ public class DatasetManageController {
* @return
*/
@PostMapping("/bindDatasets")
public ResultUtils bindDatasets(@RequestBody UserBindDatasetDto userBindDatasetDto){
if (null == userBindDatasetDto.getDatasetIds() || userBindDatasetDto.getDatasetIds().isEmpty() ){
public ResultUtils bindDatasets(@RequestBody UserBindDatasetDto userBindDatasetDto) {
if (null == userBindDatasetDto.getDatasetIds() || userBindDatasetDto.getDatasetIds().isEmpty()) {
//未绑定任何知识库
log.info("用户:{} 未绑定任何知识库",userBindDatasetDto.getUserId());
log.info("用户:{} 未绑定任何知识库", userBindDatasetDto.getUserId());
return ResultUtils.success(true);
}
return ResultUtils.success(datasetManagerService.userBindDatasets(userBindDatasetDto));
}
@PostMapping("/unbindDataset")
public ResultUtils unbindDataset(@RequestParam("userId") Long userId, @RequestParam("datasetId") String datasetId ){
public ResultUtils unbindDataset(@RequestParam("userId") Long userId, @RequestParam("datasetId") String datasetId) {
datasetManagerService.unbindDataset(userId, datasetId);
log.info("用户:{} 解绑绑定{}知识库完成",userId,datasetId);
log.info("用户:{} 解绑绑定{}知识库完成", userId, datasetId);
return ResultUtils.success(true);
}
}

View File

@ -9,24 +9,39 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ChatTypeVo {
/**故障诊断问答*/
diagnose(1,"diagnose","故障诊断问答"),
/**
* 故障诊断问答
*/
diagnose(1, "diagnose", "故障诊断问答"),
/**通用问答/智能问答*/
/**
* 通用问答/智能问答
*/
intelQa(2, "intelQa", "智能问答"),
/**图形报表问答*/
chartReport(3,"chartReport","图形报表问答"),
/**
* 图形报表问答
*/
chartReport(3, "chartReport", "图形报表问答"),
/**应急助手问答*/
emerg(4,"emerg","应急助手问答"),
/**
* 应急助手问答
*/
emerg(4, "emerg", "应急助手问答"),
/**诊断代码查询**/
codeQuery(5,"codeQuery","诊断代码查询"),
/**
* 诊断代码查询
**/
codeQuery(5, "codeQuery", "诊断代码查询"),
/**
* 一事一流程数据处理
*/
ysylcDataProc(6,"ysylcDataProc","一事一流程数据处理");
ysylcDataProc(6, "ysylcDataProc", "一事一流程数据处理"),
/***
*通用问答
*/
commQA(7, "commQA", "通用问答");
private final int code;
private final String name;

View File

@ -0,0 +1,11 @@
package com.bjtds.brichat.entity.dataset;
import lombok.Data;
@Data
public class DatasetsCreateReq {
private String name;
private String description;
private Long userId;
}

View File

@ -1,10 +1,14 @@
package com.bjtds.brichat.entity.dto;
import lombok.Builder;
import lombok.Data;
import java.util.List;
@Data
@Builder
public class UserBindDatasetDto {
private Long userId;
private List<String> datasetIds;
}