|
|
|
@ -1,20 +1,23 @@
|
|
|
|
|
package com.hnac.hzims.bigmodel.zhipuai.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; |
|
|
|
|
import com.hnac.hzims.bigmodel.zhipuai.handler.ZhipuAnalyser; |
|
|
|
|
import com.hnac.hzims.bigmodel.zhipuai.handler.ZhipuAnalysisFactory; |
|
|
|
|
import com.hnac.hzims.bigmodel.zhipuai.service.ZhipuAnalysisInfoService; |
|
|
|
|
import com.hnac.hzims.bigmodel.zhipuai.service.ZhipuAnalysisService; |
|
|
|
|
import com.hnac.hzims.bigmodel.zhipuai.utils.ZhipuUtil; |
|
|
|
|
import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisFileRequest; |
|
|
|
|
import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisFileResponse; |
|
|
|
|
import com.hnac.hzims.common.utils.FileUtil; |
|
|
|
|
import com.hnac.hzinfo.exception.HzServiceException; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.tool.jackson.JsonUtil; |
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @Author: ypj |
|
|
|
@ -24,11 +27,14 @@ import java.util.Objects;
|
|
|
|
|
@AllArgsConstructor |
|
|
|
|
@Slf4j |
|
|
|
|
public class ZhipuAnalysisServiceImpl implements ZhipuAnalysisService { |
|
|
|
|
|
|
|
|
|
private final ZhipuAnalysisFactory analysisFactory; |
|
|
|
|
|
|
|
|
|
private final ZhipuAnalysisInfoService infoService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ZhipuAnalysisFileResponse analysis(ZhipuAnalysisFileRequest request) { |
|
|
|
|
Assert.isTrue(StringUtil.isBlank(request.getFilePath()) && StringUtil.isBlank(request.getFileContent()) && StringUtil.isBlank(request.getUrl()), () -> { |
|
|
|
|
Assert.isTrue(StringUtil.isNotBlank(request.getFilePath()) || StringUtil.isNotBlank(request.getUrl()), () -> { |
|
|
|
|
throw new HzServiceException("文件为空"); |
|
|
|
|
}); |
|
|
|
|
ZhipuAnalysisInfoEntity info = getAnalysisInfo(request); |
|
|
|
@ -44,21 +50,24 @@ public class ZhipuAnalysisServiceImpl implements ZhipuAnalysisService {
|
|
|
|
|
if (StringUtil.isNotBlank(request.getUrl())) { |
|
|
|
|
return request.getUrl(); |
|
|
|
|
} |
|
|
|
|
if (StringUtil.isNotBlank(request.getFileContent())) { |
|
|
|
|
return request.getFileContent(); |
|
|
|
|
} |
|
|
|
|
if (StringUtil.isNotBlank(request.getFilePath())) { |
|
|
|
|
return ZhipuUtil.getBase64(request.getFilePath()); |
|
|
|
|
return FileUtil.getBase64(request.getFilePath()); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ZhipuAnalysisInfoEntity getAnalysisInfo(ZhipuAnalysisFileRequest request) { |
|
|
|
|
if (Objects.isNull(request.getCode())) { |
|
|
|
|
return request.toAnalysisInfo(); |
|
|
|
|
ZhipuAnalysisInfoEntity result = null; |
|
|
|
|
if (StringUtil.isBlank(request.getCode())) { |
|
|
|
|
result = request.toAnalysisInfo(); |
|
|
|
|
} else { |
|
|
|
|
result = infoService.getOne(Wrappers.<ZhipuAnalysisInfoEntity>lambdaQuery() |
|
|
|
|
.eq(ZhipuAnalysisInfoEntity::getCode, request.getCode()) |
|
|
|
|
.last("limit 1;")); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
log.info("the analysis information is {}", Optional.ofNullable(result).map(r -> JsonUtil.toJson(r)).orElse("null")); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|