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