|
@@ -0,0 +1,205 @@
|
|
|
+package org.fdkk.bim.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.fdkk.bim.bimEntity.BimResult;
|
|
|
+import org.fdkk.bim.bimEntity.dto.*;
|
|
|
+import org.fdkk.bim.bimEntity.vo.DatabagDerivativeBean;
|
|
|
+import org.fdkk.bim.bimEntity.vo.FileBean;
|
|
|
+import org.fdkk.bim.bimEntity.vo.ProjectBean;
|
|
|
+import org.fdkk.bim.client.BimCallBackClient;
|
|
|
+import org.fdkk.bim.client.BimFaceClient;
|
|
|
+import org.fdkk.bim.config.BimConfig;
|
|
|
+import org.fdkk.bim.entity.dto.BimCallBackDTO;
|
|
|
+import org.fdkk.bim.entity.dto.BimUploadDTO;
|
|
|
+import org.fdkk.bim.entity.po.BimFaceEntity;
|
|
|
+import org.fdkk.bim.enums.BusinessStatus;
|
|
|
+import org.fdkk.bim.mapper.BimFaceMapper;
|
|
|
+import org.fdkk.bim.service.BimFaceService;
|
|
|
+import org.fdkk.bim.util.BimZipUtil;
|
|
|
+import org.fdkk.bim.util.FileUploadUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Xiewj
|
|
|
+ * @date 2022/10/9
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class BimFaceServiceImpl extends ServiceImpl<BimFaceMapper, BimFaceEntity> implements BimFaceService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ BimFaceClient bimFaceClient;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ FYunFileServiceInterface ossFileService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ BimCallBackClient bimCallBackClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BimConfig bimConfig;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BimFaceEntity> getByUploadStatus(String status) {
|
|
|
+ LambdaQueryWrapper<BimFaceEntity> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(BimFaceEntity::getUploadStatus,status);
|
|
|
+ return list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BimFaceEntity> getByTranslateStatus(String status) {
|
|
|
+ LambdaQueryWrapper<BimFaceEntity> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(BimFaceEntity::getTranslateStatus,status);
|
|
|
+ return list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BimFaceEntity> getByOfflineStatus(String status) {
|
|
|
+ LambdaQueryWrapper<BimFaceEntity> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(BimFaceEntity::getOfflineStatus,status);
|
|
|
+ return list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BimFaceEntity> getByCallType(String condition ,String... callType) {
|
|
|
+ LambdaQueryWrapper<BimFaceEntity> wrapper = Wrappers.lambdaQuery();
|
|
|
+ switch (condition){
|
|
|
+ case "eq":
|
|
|
+ wrapper.eq(BimFaceEntity::getCallType,callType);
|
|
|
+ break;
|
|
|
+ case "ne":
|
|
|
+ wrapper.notIn(BimFaceEntity::getCallType,callType);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BimFaceEntity getByFiledId(String fileId) {
|
|
|
+ LambdaQueryWrapper<BimFaceEntity> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(BimFaceEntity::getFileId,fileId);
|
|
|
+ return getOne(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BimFaceEntity uploadFile(MultipartFile file, BimUploadDTO bimUploadDTO) throws IOException {
|
|
|
+ BimResult<List<ProjectBean>> projectInfo = bimFaceClient.getProjectInfo(bimUploadDTO.getProjectName());
|
|
|
+ String projectId="";
|
|
|
+ if (projectInfo.getCode().equalsIgnoreCase("success")&& ObjectUtil.isNotNull(projectInfo.getData())&& projectInfo.getData().size()>0){
|
|
|
+ for (ProjectBean datum : projectInfo.getData()) {
|
|
|
+ if (datum.getName().equals(bimUploadDTO.getProjectName())){
|
|
|
+ projectId=datum.getId();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ ProjectDTO projectDTO=new ProjectDTO();
|
|
|
+ projectDTO.setName(bimUploadDTO.getProjectName());
|
|
|
+ BimResult<ProjectBean> fileBeanBimResult = bimFaceClient.saveProject(projectDTO);
|
|
|
+ if (fileBeanBimResult.getCode().equalsIgnoreCase("success")&& ObjectUtil.isNotNull(fileBeanBimResult.getData())) {
|
|
|
+ projectId=fileBeanBimResult.getData().getId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ File absFile = FileUploadUtils.uploadAbsPath(bimConfig.getUploadPath(), file);
|
|
|
+ String ossUrl = ossFileService.uploadFile(absFile.getAbsolutePath(), bimConfig.getDefaultFolder() + "/project/"+projectId +"/upload/"+ absFile.getName());
|
|
|
+ absFile.delete();
|
|
|
+
|
|
|
+ BimResult<FileBean> fileBeanBimResult = bimFaceClient.fileItems(ossUrl,projectId,file.getOriginalFilename(), FileUtil.size(absFile), projectId);
|
|
|
+ if (fileBeanBimResult.getCode().equalsIgnoreCase("success")&& ObjectUtil.isNotNull(fileBeanBimResult.getData())) {
|
|
|
+ BimFaceEntity bimFaceEntity = new BimFaceEntity();
|
|
|
+ bimFaceEntity.setTask(bimUploadDTO.getTask());
|
|
|
+ bimFaceEntity.setFileUrl(ossUrl);
|
|
|
+ bimFaceEntity.setProjectId(projectId);
|
|
|
+ bimFaceEntity.setCallBack(bimUploadDTO.getCallBack());
|
|
|
+ bimFaceEntity.setProjectName(bimUploadDTO.getProjectName());
|
|
|
+ bimFaceEntity.setFileId(fileBeanBimResult.getData().getId());
|
|
|
+ bimFaceEntity.setFileName(fileBeanBimResult.getData().getName());
|
|
|
+ bimFaceEntity.setUploadStatus(fileBeanBimResult.getData().getStatus());
|
|
|
+ bimFaceEntity.setCallType(BusinessStatus.UPLOAD.getInfo());
|
|
|
+ bimFaceEntity.setSource(bimUploadDTO.getSource());
|
|
|
+ save(bimFaceEntity);
|
|
|
+ return bimFaceEntity;
|
|
|
+// if (save&& fileBeanBimResult.getCode().equalsIgnoreCase("success")){
|
|
|
+// rabbitSenderTemplate.sender(RabbitQueue.BIM_TOPIC,RabbitQueue.UPLOAD_QUEUE,bimFaceEntity);
|
|
|
+// }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void translate(BimFaceEntity bimFaceEntity) {
|
|
|
+ SourceDTO sourceDTO=new SourceDTO();
|
|
|
+ sourceDTO.setFileId(Long.valueOf(bimFaceEntity.getFileId()));
|
|
|
+ sourceDTO.setCompressed(false);
|
|
|
+ sourceDTO.setRootName(bimFaceEntity.getFileName());
|
|
|
+ TranslateDTO translateDTO=new TranslateDTO();
|
|
|
+ translateDTO.setSource(sourceDTO);
|
|
|
+ translateDTO.setCallback(bimConfig.getWebSite()+"/bim/call/translate/"+bimFaceEntity.getId());
|
|
|
+ Map<String, Object> config=new HashMap<>();
|
|
|
+ config.put("toBimtiles",true);
|
|
|
+ translateDTO.setConfig(config);
|
|
|
+ BimResult<FileBean> translate = bimFaceClient.translate(translateDTO);
|
|
|
+ if (translate.getCode().equalsIgnoreCase("success")&& ObjectUtil.isNotNull(translate.getData())) {
|
|
|
+ bimFaceEntity.setCallType(BusinessStatus.TRANSLATE.getInfo());
|
|
|
+ bimFaceEntity.setTranslateStatus(translate.getData().getStatus());
|
|
|
+ boolean b = updateById(bimFaceEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void offlineDatabag(BimFaceEntity bimFaceEntity) {
|
|
|
+ OfflineDatabagDTO offlineDatabagDTO=new OfflineDatabagDTO();
|
|
|
+ offlineDatabagDTO.setCallback(bimConfig.getWebSite()+"/bim/call/offline/"+bimFaceEntity.getId());
|
|
|
+ BimResult<DatabagDerivativeBean> offlineDatabag = bimFaceClient.offlineDatabag(offlineDatabagDTO,Long.valueOf(bimFaceEntity.getFileId()));
|
|
|
+ if (offlineDatabag.getCode().equalsIgnoreCase("success")&& ObjectUtil.isNotNull(offlineDatabag.getData())) {
|
|
|
+ bimFaceEntity.setOfflineStatus(offlineDatabag.getData().getStatus());
|
|
|
+ bimFaceEntity.setCallType(BusinessStatus.OFFLINE.getInfo());
|
|
|
+ boolean b = updateById(bimFaceEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void callBack(BusinessStatus upload, BimFaceEntity bimFaceEntity) {
|
|
|
+ if (StrUtil.isNotEmpty(bimFaceEntity.getCallBack())){
|
|
|
+ log.info("进入回调-{}",bimFaceEntity.getCallBack());
|
|
|
+ BimCallBackDTO callBackDTO=new BimCallBackDTO();
|
|
|
+ callBackDTO.setTask(bimFaceEntity.getTask());
|
|
|
+ callBackDTO.setItemId(bimFaceEntity.getId());
|
|
|
+ callBackDTO.setFileId(bimFaceEntity.getFileId());
|
|
|
+ callBackDTO.setCallType(upload.getInfo());
|
|
|
+ bimCallBackClient.postJson(bimFaceEntity.getCallBack(),callBackDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String downloadOffline(String fileId,String projectId) {
|
|
|
+ BimResult<String> downloadUrl = bimFaceClient.offlineDatabagDownloadUrl(fileId,"offline");
|
|
|
+ if (downloadUrl.getCode().equalsIgnoreCase("success")&& ObjectUtil.isNotNull(downloadUrl.getData())) {
|
|
|
+ String downloadPath=bimConfig.getUploadPath()+fileId+".zip";
|
|
|
+ long l = HttpUtil.downloadFile(downloadUrl.getData(), downloadPath);
|
|
|
+ return BimZipUtil.UploadDataZip(downloadPath,projectId);
|
|
|
+ }else {
|
|
|
+ return downloadUrl.getCode()+"|"+downloadUrl.getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|