Browse Source

add:大模型,入库对接

zhongwei
luyie 2 months ago
parent
commit
b697f92c1c
  1. 16
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInteraction.java
  2. 17
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/KnowledgeFileInfoController.java
  3. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileFragment.java
  4. 5
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileInfo.java
  5. 13
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/KnowledgeFileInfoService.java
  6. 81
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java

16
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInteraction.java

@ -0,0 +1,16 @@
package com.hnac.hzims.bigmodel.configuration;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @Author: ypj
* @Date: 2024/9/12 16:10
*/
@Data
@ConfigurationProperties(prefix = "gglm")
@Component
public class BigModelInteraction {
private String url;
}

17
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/KnowledgeFileInfoController.java

@ -5,6 +5,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileInfo; import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileInfo;
import com.hnac.hzims.bigmodel.maintenance.service.KnowledgeFileInfoService; import com.hnac.hzims.bigmodel.maintenance.service.KnowledgeFileInfoService;
import com.hnac.hzims.bigmodel.maintenance.vo.IdRequest; import com.hnac.hzims.bigmodel.maintenance.vo.IdRequest;
import com.hnac.hzims.bigmodel.maintenance.vo.IdsRequest;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
@ -13,9 +14,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.oss.model.BladeFile; import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.resource.feign.IOssClient;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -31,14 +32,12 @@ import org.springframework.web.multipart.MultipartFile;
@AllArgsConstructor @AllArgsConstructor
public class KnowledgeFileInfoController { public class KnowledgeFileInfoController {
private final KnowledgeFileInfoService knowledgeFileInfoService; private final KnowledgeFileInfoService knowledgeFileInfoService;
private final IOssClient ossClient;
@GetMapping("/listPage") @GetMapping("/listPage")
@ApiOperation(value = "分页查询") @ApiOperation(value = "分页查询")
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
public R<IPage<KnowledgeFileInfo>> listPage(Query query, KnowledgeFileInfo req) { public R<IPage<KnowledgeFileInfo>> listPage(Query query, KnowledgeFileInfo req) {
return R.data(knowledgeFileInfoService.page(Condition.getPage(query), return R.data(knowledgeFileInfoService.listPage(Condition.getPage(query), req));
Condition.getQueryWrapper(new KnowledgeFileInfo(), req).orderByDesc(KnowledgeFileInfo::getCreateTime)));
} }
@GetMapping("/detail") @GetMapping("/detail")
@ -52,6 +51,7 @@ public class KnowledgeFileInfoController {
@ApiOperation(value = "保存") @ApiOperation(value = "保存")
@ApiOperationSupport(order = 3) @ApiOperationSupport(order = 3)
public R save(@RequestBody KnowledgeFileInfo req) { public R save(@RequestBody KnowledgeFileInfo req) {
req.setCreateUserName(AuthUtil.getUserName());
return R.status(knowledgeFileInfoService.save(req)); return R.status(knowledgeFileInfoService.save(req));
} }
@ -73,7 +73,7 @@ public class KnowledgeFileInfoController {
@ApiOperation(value = "上传文件") @ApiOperation(value = "上传文件")
@ApiOperationSupport(order = 6) @ApiOperationSupport(order = 6)
public R<BladeFile> upload(@ApiParam(value = "上传文件", required = true) @RequestPart("file") MultipartFile file) { public R<BladeFile> upload(@ApiParam(value = "上传文件", required = true) @RequestPart("file") MultipartFile file) {
return ossClient.putFile(file); return knowledgeFileInfoService.upload(file);
} }
@PostMapping("/store") @PostMapping("/store")
@ -82,4 +82,11 @@ public class KnowledgeFileInfoController {
public R store(@RequestBody IdRequest req) { public R store(@RequestBody IdRequest req) {
return R.status(knowledgeFileInfoService.store(req)); return R.status(knowledgeFileInfoService.store(req));
} }
@PostMapping("/batchStore")
@ApiOperation(value = "批量入库")
@ApiOperationSupport(order = 8)
public R batchStore(@RequestBody IdsRequest req) {
return R.status(knowledgeFileInfoService.batchStore(req));
}
} }

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileFragment.java

@ -18,7 +18,7 @@ import java.io.Serializable;
*/ */
@Data @Data
@EqualsAndHashCode(callSuper=false) @EqualsAndHashCode(callSuper=false)
@TableName("knowledge_file_fragment") @TableName("knowledge_file_segment")
@ApiModel(value = "知识库文件分片信息",description = "知识库文件分片信息") @ApiModel(value = "知识库文件分片信息",description = "知识库文件分片信息")
public class KnowledgeFileFragment extends TenantEntity implements Serializable { public class KnowledgeFileFragment extends TenantEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

5
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileInfo.java

@ -65,4 +65,9 @@ public class KnowledgeFileInfo extends TenantEntity implements Serializable {
@QueryField(condition = SqlCondition.LIKE) @QueryField(condition = SqlCondition.LIKE)
private String remark; private String remark;
@ApiModelProperty("创建人名称")
@TableField("CREATE_USER_NAME")
@QueryField(condition = SqlCondition.LIKE)
private String createUserName;
} }

13
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/KnowledgeFileInfoService.java

@ -1,13 +1,26 @@
package com.hnac.hzims.bigmodel.maintenance.service; package com.hnac.hzims.bigmodel.maintenance.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileInfo; import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileInfo;
import com.hnac.hzims.bigmodel.maintenance.vo.IdRequest; import com.hnac.hzims.bigmodel.maintenance.vo.IdRequest;
import com.hnac.hzims.bigmodel.maintenance.vo.IdsRequest;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tool.api.R;
import org.springframework.web.multipart.MultipartFile;
/** /**
* @Author: ypj * @Author: ypj
* @Date: 2024/9/10 16:42 * @Date: 2024/9/10 16:42
*/ */
public interface KnowledgeFileInfoService extends IService<KnowledgeFileInfo> { public interface KnowledgeFileInfoService extends IService<KnowledgeFileInfo> {
String SEGMENT_URL= "/kn/doc_segment";
Boolean store(IdRequest req); Boolean store(IdRequest req);
Boolean batchStore(IdsRequest req);
IPage<KnowledgeFileInfo> listPage(IPage<KnowledgeFileInfo> page, KnowledgeFileInfo req);
R<BladeFile> upload(MultipartFile file);
} }

81
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java

@ -1,17 +1,34 @@
package com.hnac.hzims.bigmodel.maintenance.service.impl; package com.hnac.hzims.bigmodel.maintenance.service.impl;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.bigmodel.configuration.BigModelInteraction;
import com.hnac.hzims.bigmodel.maintenance.constants.StoreStatus; import com.hnac.hzims.bigmodel.maintenance.constants.StoreStatus;
import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileInfo; import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileInfo;
import com.hnac.hzims.bigmodel.maintenance.mapper.KnowledgeFileInfoMapper; import com.hnac.hzims.bigmodel.maintenance.mapper.KnowledgeFileInfoMapper;
import com.hnac.hzims.bigmodel.maintenance.service.KnowledgeFileInfoService; import com.hnac.hzims.bigmodel.maintenance.service.KnowledgeFileInfoService;
import com.hnac.hzims.bigmodel.maintenance.vo.IdRequest; import com.hnac.hzims.bigmodel.maintenance.vo.IdRequest;
import com.hnac.hzims.bigmodel.maintenance.vo.IdsRequest;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.resource.feign.IOssClient;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @Author: ypj * @Author: ypj
@ -23,14 +40,72 @@ import org.springframework.stereotype.Service;
@DS("hznlm") @DS("hznlm")
public class KnowledgeFileInfoServiceImpl extends ServiceImpl<KnowledgeFileInfoMapper, KnowledgeFileInfo> implements KnowledgeFileInfoService { public class KnowledgeFileInfoServiceImpl extends ServiceImpl<KnowledgeFileInfoMapper, KnowledgeFileInfo> implements KnowledgeFileInfoService {
private final KnowledgeFileInfoMapper knowledgeFileInfoMapper; private final KnowledgeFileInfoMapper knowledgeFileInfoMapper;
private final IOssClient ossClient;
private final BigModelInteraction interactionConfig;
@Override @Override
public Boolean store(IdRequest req) { public Boolean store(IdRequest req) {
KnowledgeFileInfo knowledgeFileInfo = knowledgeFileInfoMapper.selectById(req.getId()); KnowledgeFileInfo knowledgeFileInfo = knowledgeFileInfoMapper.selectById(req.getId());
return store(knowledgeFileInfo, AuthUtil.getTenantId(), AuthUtil.getUserId(), AuthUtil.getDeptId());
}
private String getParamsJson(KnowledgeFileInfo knowledgeFileInfo, String tenantId, Long createUser, String createDept) {
Map<String, Object> params = new HashMap<>();
params.put("doc_id", knowledgeFileInfo.getId().toString());
params.put("url", knowledgeFileInfo.getUrl());
params.put("tenant_id", tenantId);
params.put("create_user", createUser.toString());
params.put("create_dept", createDept);
return JsonUtil.toJson(params);
}
private Boolean store(KnowledgeFileInfo knowledgeFileInfo, String tenantId, Long createUser, String createDept) {
HttpResponse response = HttpRequest.post(interactionConfig.getUrl() + SEGMENT_URL)
.body(getParamsJson(knowledgeFileInfo, tenantId, createUser, createDept), "application/json")
.execute();
if (!response.isOk()) {
return false;
}
LambdaUpdateWrapper<KnowledgeFileInfo> wrapper = Wrappers.<KnowledgeFileInfo>lambdaUpdate()
.set(KnowledgeFileInfo::getFileStatus, StoreStatus.STORING.getCode())
.eq(KnowledgeFileInfo::getId, knowledgeFileInfo.getId());
return this.update(wrapper);
}
LambdaUpdateWrapper<KnowledgeFileInfo> queryWrapper = Wrappers.<KnowledgeFileInfo>lambdaUpdate() @Override
public Boolean batchStore(IdsRequest req) {
List<KnowledgeFileInfo> list = knowledgeFileInfoMapper.selectBatchIds(req.getIds());
final String tenantId = AuthUtil.getTenantId();
final Long createUser = AuthUtil.getUserId();
final String createDept = AuthUtil.getDeptId();
list.forEach(knowledgeFileInfo -> {
store(knowledgeFileInfo, tenantId, createUser, createDept);
});
LambdaUpdateWrapper<KnowledgeFileInfo> wrapper = Wrappers.<KnowledgeFileInfo>lambdaUpdate()
.set(KnowledgeFileInfo::getFileStatus, StoreStatus.STORING.getCode()) .set(KnowledgeFileInfo::getFileStatus, StoreStatus.STORING.getCode())
.eq(KnowledgeFileInfo::getId, req.getId()); .in(KnowledgeFileInfo::getId, req.getIds());
return this.update(queryWrapper); return this.update(wrapper);
}
@Override
public IPage<KnowledgeFileInfo> listPage(IPage<KnowledgeFileInfo> page, KnowledgeFileInfo req) {
LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(KnowledgeFileInfo.class)
.like(ObjectUtil.isNotEmpty(req.getName()), KnowledgeFileInfo::getName, req.getName())
.like(ObjectUtil.isNotEmpty(req.getUrl()), KnowledgeFileInfo::getUrl, req.getUrl())
.like(ObjectUtil.isNotEmpty(req.getBriefs()), KnowledgeFileInfo::getBriefs, req.getBriefs())
.eq(ObjectUtil.isNotEmpty(req.getDomain()), KnowledgeFileInfo::getDomain, req.getDomain())
.eq(ObjectUtil.isNotEmpty(req.getAuthorityClass()), KnowledgeFileInfo::getAuthorityClass, req.getAuthorityClass())
.eq(ObjectUtil.isNotEmpty(req.getVisible()), KnowledgeFileInfo::getVisible, req.getVisible())
.eq(ObjectUtil.isNotEmpty(req.getFileStatus()), KnowledgeFileInfo::getFileStatus, req.getFileStatus())
.like(ObjectUtil.isNotEmpty(req.getRemark()), KnowledgeFileInfo::getRemark, req.getRemark())
.like(ObjectUtil.isNotEmpty(req.getTags()), KnowledgeFileInfo::getTags, req.getTags())
.orderByDesc(KnowledgeFileInfo::getCreateTime);
return this.page(page, wrapper);
}
@Override
public R<BladeFile> upload(MultipartFile file) {
return ossClient.putFile(file);
} }
} }

Loading…
Cancel
Save