|
|
|
@ -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<KnowledgeFileInfoMapper, KnowledgeFileInfo> 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<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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LambdaUpdateWrapper<KnowledgeFileInfo> queryWrapper = Wrappers.<KnowledgeFileInfo>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<KnowledgeFileInfo> wrapper = Wrappers.<KnowledgeFileInfo>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<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()) |
|
|
|
|
.in(KnowledgeFileInfo::getId, req.getIds()); |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|