diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInteraction.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInteraction.java new file mode 100644 index 0000000..36ec68a --- /dev/null +++ b/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; +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/KnowledgeFileInfoController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/KnowledgeFileInfoController.java index 5ea94d6..6d16344 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/KnowledgeFileInfoController.java +++ b/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.service.KnowledgeFileInfoService; 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.ApiOperation; 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.Query; 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.utils.Func; -import org.springblade.resource.feign.IOssClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -31,14 +32,12 @@ import org.springframework.web.multipart.MultipartFile; @AllArgsConstructor public class KnowledgeFileInfoController { private final KnowledgeFileInfoService knowledgeFileInfoService; - private final IOssClient ossClient; @GetMapping("/listPage") @ApiOperation(value = "分页查询") @ApiOperationSupport(order = 1) public R> listPage(Query query, KnowledgeFileInfo req) { - return R.data(knowledgeFileInfoService.page(Condition.getPage(query), - Condition.getQueryWrapper(new KnowledgeFileInfo(), req).orderByDesc(KnowledgeFileInfo::getCreateTime))); + return R.data(knowledgeFileInfoService.listPage(Condition.getPage(query), req)); } @GetMapping("/detail") @@ -52,6 +51,7 @@ public class KnowledgeFileInfoController { @ApiOperation(value = "保存") @ApiOperationSupport(order = 3) public R save(@RequestBody KnowledgeFileInfo req) { + req.setCreateUserName(AuthUtil.getUserName()); return R.status(knowledgeFileInfoService.save(req)); } @@ -73,7 +73,7 @@ public class KnowledgeFileInfoController { @ApiOperation(value = "上传文件") @ApiOperationSupport(order = 6) public R upload(@ApiParam(value = "上传文件", required = true) @RequestPart("file") MultipartFile file) { - return ossClient.putFile(file); + return knowledgeFileInfoService.upload(file); } @PostMapping("/store") @@ -82,4 +82,11 @@ public class KnowledgeFileInfoController { public R store(@RequestBody IdRequest 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)); + } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileFragment.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileFragment.java index 2982ae1..c0af5d7 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileFragment.java +++ b/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 @EqualsAndHashCode(callSuper=false) -@TableName("knowledge_file_fragment") +@TableName("knowledge_file_segment") @ApiModel(value = "知识库文件分片信息",description = "知识库文件分片信息") public class KnowledgeFileFragment extends TenantEntity implements Serializable { private static final long serialVersionUID = 1L; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileInfo.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileInfo.java index a1f6ab2..c414ddd 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileInfo.java +++ b/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) private String remark; + @ApiModelProperty("创建人名称") + @TableField("CREATE_USER_NAME") + @QueryField(condition = SqlCondition.LIKE) + private String createUserName; + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/KnowledgeFileInfoService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/KnowledgeFileInfoService.java index aa8482f..4997d50 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/KnowledgeFileInfoService.java +++ b/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; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileInfo; 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 * @Date: 2024/9/10 16:42 */ public interface KnowledgeFileInfoService extends IService { + String SEGMENT_URL= "/kn/doc_segment"; + Boolean store(IdRequest req); + + Boolean batchStore(IdsRequest req); + + IPage listPage(IPage page, KnowledgeFileInfo req); + + R upload(MultipartFile file); } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java index c367af7..6d7f937 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java +++ b/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; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; 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.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; 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.entity.KnowledgeFileInfo; import com.hnac.hzims.bigmodel.maintenance.mapper.KnowledgeFileInfoMapper; import com.hnac.hzims.bigmodel.maintenance.service.KnowledgeFileInfoService; import com.hnac.hzims.bigmodel.maintenance.vo.IdRequest; +import com.hnac.hzims.bigmodel.maintenance.vo.IdsRequest; import lombok.AllArgsConstructor; 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.web.multipart.MultipartFile; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @Author: ypj @@ -23,14 +40,72 @@ import org.springframework.stereotype.Service; @DS("hznlm") public class KnowledgeFileInfoServiceImpl extends ServiceImpl implements KnowledgeFileInfoService { private final KnowledgeFileInfoMapper knowledgeFileInfoMapper; + private final IOssClient ossClient; + + private final BigModelInteraction interactionConfig; @Override public Boolean store(IdRequest req) { 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 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); + } - LambdaUpdateWrapper queryWrapper = Wrappers.lambdaUpdate() + 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 wrapper = Wrappers.lambdaUpdate() .set(KnowledgeFileInfo::getFileStatus, StoreStatus.STORING.getCode()) - .eq(KnowledgeFileInfo::getId, req.getId()); - return this.update(queryWrapper); + .eq(KnowledgeFileInfo::getId, knowledgeFileInfo.getId()); + return this.update(wrapper); + } + + @Override + public Boolean batchStore(IdsRequest req) { + List 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 wrapper = Wrappers.lambdaUpdate() + .set(KnowledgeFileInfo::getFileStatus, StoreStatus.STORING.getCode()) + .in(KnowledgeFileInfo::getId, req.getIds()); + return this.update(wrapper); + } + + @Override + public IPage listPage(IPage 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 upload(MultipartFile file) { + return ossClient.putFile(file); } }