package com.qianwen.smartman.modules.dnc.service.impl;
|
|
import java.io.File;
|
import java.io.IOException;
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Objects;
|
import java.util.Optional;
|
import java.util.stream.Collectors;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.apache.commons.io.FileUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.google.common.collect.Lists;
|
import com.qianwen.core.excel.util.ExcelUtil;
|
import com.qianwen.core.log.exception.ServiceException;
|
import com.qianwen.core.oss.OssTemplate;
|
import com.qianwen.core.oss.model.BladeFile;
|
import com.qianwen.core.oss.model.OssFile;
|
import com.qianwen.core.secure.utils.AuthUtil;
|
import com.qianwen.core.tool.api.ResultCode;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.common.constant.CommonConstant;
|
import com.qianwen.smartman.common.constant.DncConstant;
|
import com.qianwen.smartman.common.utils.LocalDateTimeUtils;
|
import com.qianwen.smartman.common.utils.MessageUtils;
|
import com.qianwen.smartman.modules.cps.service.IWorkstationService;
|
import com.qianwen.smartman.modules.cps.vo.WorkstationVO;
|
import com.qianwen.smartman.modules.dnc.context.DncFileNameProcessRuleContext;
|
import com.qianwen.smartman.modules.dnc.context.DncFileNameProcessRuleFactory;
|
import com.qianwen.smartman.modules.dnc.dto.ArtFileInformationDTO;
|
import com.qianwen.smartman.modules.dnc.dto.DncOperationLogDto;
|
import com.qianwen.smartman.modules.dnc.entity.DncArtBag;
|
import com.qianwen.smartman.modules.dnc.entity.DncFixedSpace;
|
import com.qianwen.smartman.modules.dnc.entity.DncWsRelationTd;
|
import com.qianwen.smartman.modules.dnc.entity.TransferDirectory;
|
import com.qianwen.smartman.modules.dnc.entity.TransferDirectoryFile;
|
import com.qianwen.smartman.modules.dnc.enums.DncEnums;
|
import com.qianwen.smartman.modules.dnc.service.IDncFixedSpaceService;
|
import com.qianwen.smartman.modules.dnc.service.IDncOperationLogService;
|
import com.qianwen.smartman.modules.dnc.service.IDncWsRelationTdService;
|
import com.qianwen.smartman.modules.dnc.service.IDockingFtpService;
|
import com.qianwen.smartman.modules.dnc.service.ITransferDirectoryFileService;
|
import com.qianwen.smartman.modules.dnc.service.ITransferDirectoryService;
|
import com.qianwen.smartman.modules.dnc.vo.DncFixSpaceVO;
|
import com.qianwen.smartman.modules.dnc.vo.EntityInfoVO;
|
import com.qianwen.smartman.modules.dnc.vo.FtpDirectoryVO;
|
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
|
|
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.util.StrUtil;
|
|
@Service
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/dnc/service/impl/DockingFtpServiceImpl.class */
|
public class DockingFtpServiceImpl implements IDockingFtpService {
|
private static final Logger log = LoggerFactory.getLogger(DockingFtpServiceImpl.class);
|
private final ITransferDirectoryService transferDirectoryService;
|
private final ITransferDirectoryFileService transferDirectoryFileService;
|
private final IWorkstationService workstationService;
|
private final OssBuilder ossBuilder;
|
private final IDncOperationLogService logService;
|
private final IDncFixedSpaceService fixedSpaceService;
|
private final IDncWsRelationTdService wsRelationTdService;
|
|
public DockingFtpServiceImpl(final ITransferDirectoryService transferDirectoryService, final ITransferDirectoryFileService transferDirectoryFileService, final IWorkstationService workstationService, final OssBuilder ossBuilder, final IDncOperationLogService logService, final IDncFixedSpaceService fixedSpaceService, final IDncWsRelationTdService wsRelationTdService) {
|
this.transferDirectoryService = transferDirectoryService;
|
this.transferDirectoryFileService = transferDirectoryFileService;
|
this.workstationService = workstationService;
|
this.ossBuilder = ossBuilder;
|
this.logService = logService;
|
this.fixedSpaceService = fixedSpaceService;
|
this.wsRelationTdService = wsRelationTdService;
|
}
|
|
@Override // org.springblade.modules.dnc.service.IDockingFtpService
|
public FtpDirectoryVO readDirectory(String path) {
|
List<EntityInfoVO> list = findByDirectoryPath(path);
|
return FtpDirectoryVO.builder().path(path).list(list).build();
|
}
|
|
@Override // org.springblade.modules.dnc.service.IDockingFtpService
|
public String readFile(String path) {
|
Long workstationId = getWorkstationByPath();
|
TransferDirectory transferDirectory = getTransferDirectoryByPath(workstationId);
|
if (Objects.isNull(transferDirectory)) {
|
throw new ServiceException(MessageUtils.message("dnc.transfer.directory.no", new Object[0]));
|
}
|
String fileName = fileName(path);
|
if (Func.isNotBlank(fileName)) {
|
DncFixedSpace dncFixedSpace = getDirectoryName(path, workstationId);
|
if (dncFixedSpace == null) {
|
throw new ServiceException(MessageUtils.message("dnc.ftp.relation.workstation.normal.use", new Object[0]));
|
}
|
TransferDirectoryFile transferDirectoryFile = this.transferDirectoryFileService.getOne(new QueryWrapper<TransferDirectoryFile>().lambda()
|
.eq(TransferDirectoryFile::getTransferDirectoryId, transferDirectory.getId())
|
.eq(TransferDirectoryFile::getOriginalFilename, fileName)
|
.eq(TransferDirectoryFile::getFileType, 1)
|
.eq(Func.isNotEmpty(dncFixedSpace), TransferDirectoryFile::getStorageSpaceId, dncFixedSpace.getId())
|
.eq(TransferDirectoryFile::getIsCurrent, DncEnums.CurrentVersion.YES.getCode()));
|
/*
|
TransferDirectoryFile transferDirectoryFile = (TransferDirectoryFile) this.transferDirectoryFileService.getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getTransferDirectoryId();
|
}, transferDirectory.getId())).eq((v0) -> {
|
return v0.getOriginalFilename();
|
}, fileName)).eq((v0) -> {
|
return v0.getFileType();
|
}, 1)).eq(Func.isNotEmpty(dncFixedSpace), (v0) -> {
|
return v0.getStorageSpaceId();
|
}, dncFixedSpace.getId()).eq((v0) -> {
|
return v0.getIsCurrent();
|
}, DncEnums.CurrentVersion.YES.getCode()));*/
|
if (transferDirectoryFile == null) {
|
throw new ServiceException(MessageUtils.message("dnc.file.is.not.exists", new Object[0]));
|
}
|
String link = transferDirectoryFile.getLink();
|
WorkstationVO workstationVO = this.workstationService.getDetail(transferDirectoryFile.getWorkstationId());
|
this.logService.insertLog(new DncOperationLogDto().setLink(link).setWorkstationId(transferDirectoryFile.getWorkstationId()).setTargetPathName(workstationVO.getGroupName() + "/" + workstationVO.getName() + "/" + transferDirectoryFile.getOriginalFilename()).setTargetPathId(transferDirectory.getGroupAllPath()).setTargetType(DncEnums.LogFileSourceType.PROCESSING_PROGRAM.getCode()).setOperationTime(DateTime.now()).setSourceType(DncEnums.LogFileSourceType.FTP.getCode()).setOperationResponse(1).setSourcePathName(DncConstant.FTP_PATH).setOperatorName("机床回传").setOperationType(DncEnums.LogOperationType.DOWNLOAD.getCode()).setSuffix(transferDirectoryFile.getSuffix()).setObjectKey(transferDirectoryFile.getObjectKey()).setFileName(transferDirectoryFile.getFilename()).setVersion(transferDirectoryFile.getVersion()).setFileId(transferDirectoryFile.getId()));
|
return link;
|
}
|
return "";
|
}
|
|
@Override // org.springblade.modules.dnc.service.IDockingFtpService
|
public EntityInfoVO getByPath(String path) {
|
TransferDirectoryFile transferDirectoryFile = getTransferDirectoryFileByPath(path);
|
return (EntityInfoVO) Optional.ofNullable(transferDirectoryFile.getId()).map(c -> {
|
return EntityInfoVO.builder().id(String.valueOf(transferDirectoryFile.getId())).objectKey(transferDirectoryFile.getObjectKey()).isDirectory(Boolean.FALSE).canWrite(Boolean.FALSE).name(transferDirectoryFile.getFilename()).size(transferDirectoryFile.getContentLength()).creationTime(transferDirectoryFile.getCreateTime() != null ? LocalDateTimeUtils.DateToLocalDateTime(transferDirectoryFile.getCreateTime()) : LocalDateTime.now()).updateTime(transferDirectoryFile.getLastModified() == null ? LocalDateTime.now() : LocalDateTimeUtils.DateToLocalDateTime(transferDirectoryFile.getLastModified())).owner(String.valueOf(transferDirectoryFile.getCreateUser())).hash(transferDirectoryFile.getContentMd5()).build();
|
}).orElse(new EntityInfoVO());
|
}
|
|
@Override // org.springblade.modules.dnc.service.IDockingFtpService
|
public EntityInfoVO createFile(String path, HttpServletRequest request) {
|
Long workstationId = getWorkstationByPath();
|
if (Func.isBlank(path)) {
|
return new EntityInfoVO();
|
}
|
log.info("path:{}", path);
|
DncFixedSpace dncFixedSpace = getDirectoryName(path, workstationId);
|
if (dncFixedSpace == null) {
|
throw new ServiceException(MessageUtils.message("dnc.ftp.relation.workstation.normal.use", new Object[0]));
|
}
|
log.info("storageSpace:{}", dncFixedSpace);
|
String fileName = fileName(path);
|
log.info("fileName:{}", fileName);
|
Long workStationId = getWorkstationByPath();
|
TransferDirectory transferDirectory = getTransferDirectoryByPath(workstationId);
|
if (Objects.isNull(transferDirectory)) {
|
throw new ServiceException(MessageUtils.message("dnc.transfer.directory.no", new Object[0]));
|
}
|
OssTemplate template = this.ossBuilder.template();
|
BladeFile bladeFile = null;
|
try {
|
File file = new File(System.getProperty("java.io.tmpdir") + "/" + fileName);
|
FileUtils.copyToFile(request.getInputStream(), file);
|
MultipartFile multipartFile = ExcelUtil.fileToMultipartFile(file);
|
log.info("multipartFile:{}", Boolean.valueOf(multipartFile.isEmpty()));
|
bladeFile = template.putFile(multipartFile.getOriginalFilename(), multipartFile);
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
log.info("BladeFile:{}", bladeFile);
|
OssFile ossFile = template.statFile(((BladeFile) Objects.requireNonNull(bladeFile)).getName());
|
log.info("OssFile:{}", ossFile);
|
String hash = ossFile.getHash();
|
TransferDirectoryFile currentFile = this.transferDirectoryFileService.getOne(Wrappers.<TransferDirectoryFile>lambdaQuery()
|
.eq(TransferDirectoryFile::getTransferDirectoryId, transferDirectory.getId())
|
.eq(TransferDirectoryFile::getFilename, fileName)
|
.eq(TransferDirectoryFile::getIsCurrent, DncEnums.CurrentVersion.YES.getCode())
|
.eq(TransferDirectoryFile::getFileType, DncEnums.FileType.PROCESSING_PROGRAM.getCode())
|
.eq(TransferDirectoryFile::getStorageSpaceId, dncFixedSpace.getId()));
|
/*
|
TransferDirectoryFile currentFile = (TransferDirectoryFile) this.transferDirectoryFileService.getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getTransferDirectoryId();
|
}, transferDirectory.getId())).eq((v0) -> {
|
return v0.getFilename();
|
}, fileName)).eq((v0) -> {
|
return v0.getIsCurrent();
|
}, DncEnums.CurrentVersion.YES.getCode())).eq((v0) -> {
|
return v0.getFileType();
|
}, DncEnums.FileType.PROCESSING_PROGRAM.getCode())).eq((v0) -> {
|
return v0.getStorageSpaceId();
|
}, dncFixedSpace.getId()));*/
|
TransferDirectoryFile directoryFile = TransferDirectoryFile.builder().transferDirectoryId(transferDirectory.getId()).workstationId(workStationId).fileType(1).fileSource(DncEnums.FileSource.FTP.getCode()).filename(fileName).originalFilename(fileName).contentMd5(hash).contentLength(Long.valueOf(ossFile.getLength())).contentType(ossFile.getContentType()).objectKey(bladeFile.getName()).suffix(getFileSuffix(fileName)).storageSpace(dncFixedSpace.getSpaceLocation()).storageSpaceId(dncFixedSpace.getId()).isCurrent(DncEnums.CurrentVersion.YES.getCode()).whetherArchive(DncEnums.WhetherArchive.Archive.getCode()).link(ossFile.getLink()).build();
|
if (Func.isNull(currentFile)) {
|
directoryFile.setVersion(CommonConstant.VERSION_NUM);
|
this.transferDirectoryFileService.save(directoryFile);
|
} else if (!hash.equals(currentFile.getContentMd5())) {
|
currentFile.setIsCurrent(DncEnums.CurrentVersion.NO.getCode());
|
this.transferDirectoryFileService.updateById(currentFile);
|
directoryFile.setVersion(Integer.valueOf(currentFile.getVersion().intValue() + CommonConstant.VERSION_NUM.intValue()));
|
this.transferDirectoryFileService.save(directoryFile);
|
}
|
WorkstationVO workstationVO = this.workstationService.getDetail(workStationId);
|
return (EntityInfoVO) Optional.ofNullable(directoryFile).map(c -> {
|
this.logService.insertLog(new DncOperationLogDto().setLink(directoryFile.getLink()).setWorkstationId(directoryFile.getWorkstationId()).setTargetPathName(workstationVO.getGroupName() + "/" + workstationVO.getName() + "/" + directoryFile.getOriginalFilename()).setTargetPathId(transferDirectory.getGroupAllPath()).setTargetType(DncEnums.LogFileSourceType.PROCESSING_PROGRAM.getCode()).setOperationTime(DateTime.now()).setSourceType(DncEnums.LogFileSourceType.FTP.getCode()).setSourcePathName(DncConstant.FTP_PATH).setOperatorName("机床回传").setVersion(directoryFile.getVersion()).setOperationResponse(1).setOperationType(DncEnums.LogOperationType.UPLOAD.getCode()).setSuffix(directoryFile.getSuffix()).setObjectKey(directoryFile.getObjectKey()).setFileName(directoryFile.getFilename()).setFileId(directoryFile.getId()));
|
return EntityInfoVO.builder().id(String.valueOf(c.getId())).objectKey(c.getObjectKey()).isDirectory(Boolean.FALSE).canWrite(Boolean.FALSE).name(c.getFilename()).size(c.getContentLength()).creationTime(c.getCreateTime() != null ? LocalDateTimeUtils.DateToLocalDateTime(c.getCreateTime()) : LocalDateTime.now()).updateTime(c.getLastModified() == null ? LocalDateTime.now() : LocalDateTimeUtils.DateToLocalDateTime(c.getLastModified())).owner(String.valueOf(c.getCreateUser())).hash(c.getContentMd5()).build();
|
}).orElse(new EntityInfoVO());
|
}
|
|
private String getFileSuffix(String name) {
|
int i = name.lastIndexOf(DncConstant.POINT) + CommonConstant.VERSION_NUM.intValue();
|
if (i == CommonConstant.NOT_SEALED_ID.intValue()) {
|
return "";
|
}
|
return name.substring(i);
|
}
|
|
private void coverFile(String path, Long workStationId) {
|
this.transferDirectoryFileService.update(Wrappers.<TransferDirectoryFile>lambdaUpdate()
|
.set(TransferDirectoryFile::getIsCurrent, DncEnums.CurrentVersion.NO.getCode())
|
.set(TransferDirectoryFile::getCovertTime, DateTime.now())
|
.eq(TransferDirectoryFile::getFileType, DncEnums.FileType.PROCESSING_PROGRAM.getCode())
|
.eq(TransferDirectoryFile::getOriginalFilename, path)
|
.eq(TransferDirectoryFile::getWorkstationId, workStationId)
|
.eq(TransferDirectoryFile::getIsCurrent, DncEnums.CurrentVersion.YES.getCode()));
|
|
/*
|
this.transferDirectoryFileService.update((Wrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
|
return v0.getIsCurrent();
|
}, DncEnums.CurrentVersion.NO.getCode())).set((v0) -> {
|
return v0.getCovertTime();
|
}, DateTime.now())).eq((v0) -> {
|
return v0.getFileType();
|
}, DncEnums.FileType.PROCESSING_PROGRAM.getCode())).eq((v0) -> {
|
return v0.getOriginalFilename();
|
}, path)).eq((v0) -> {
|
return v0.getWorkstationId();
|
}, workStationId)).eq((v0) -> {
|
return v0.getIsCurrent();
|
}, DncEnums.CurrentVersion.YES.getCode()));*/
|
}
|
|
@Override // org.springblade.modules.dnc.service.IDockingFtpService
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean renameFile(String oldFileName, String newFileName) {
|
Long workstationId = getWorkstationByPath();
|
DncFixedSpace dncFixedSpace = getDirectoryName(oldFileName, workstationId);
|
if (dncFixedSpace == null) {
|
throw new ServiceException(MessageUtils.message("dnc.ftp.relation.workstation.normal.use", new Object[0]));
|
}
|
Long storageSpaceId = dncFixedSpace.getId();
|
String oldName = fileName(oldFileName);
|
String newName = fileName(newFileName);
|
|
Long count = Long.valueOf(this.transferDirectoryFileService.count(Wrappers.<TransferDirectoryFile>lambdaQuery()
|
.eq(TransferDirectoryFile::getWorkstationId, workstationId)
|
.eq(TransferDirectoryFile::getStorageSpaceId, storageSpaceId)
|
.eq(TransferDirectoryFile::getFileType, DncEnums.FileType.PROCESSING_PROGRAM.getCode())
|
.eq(TransferDirectoryFile::getIsCurrent, DncEnums.CurrentVersion.YES.getCode())
|
.eq(TransferDirectoryFile::getOriginalFilename, newName)));
|
|
/*
|
Long count = Long.valueOf(this.transferDirectoryFileService.count((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getWorkstationId();
|
}, workstationId)).eq((v0) -> {
|
return v0.getStorageSpaceId();
|
}, storageSpaceId)).eq((v0) -> {
|
return v0.getFileType();
|
}, DncEnums.FileType.PROCESSING_PROGRAM.getCode())).eq((v0) -> {
|
return v0.getIsCurrent();
|
}, DncEnums.CurrentVersion.YES.getCode())).eq((v0) -> {
|
return v0.getOriginalFilename();
|
}, newName)));*/
|
if (count.longValue() > 0) {
|
throw new ServiceException(MessageUtils.message("dnc.file.name.exist", new Object[0]));
|
}
|
TransferDirectoryFile directoryFile = getTransferDirectoryFile(storageSpaceId, oldName, workstationId);
|
TransferDirectory directory = (TransferDirectory) this.transferDirectoryService.getById(directoryFile.getTransferDirectoryId());
|
WorkstationVO workstationVO = this.workstationService.getDetail(workstationId);
|
this.logService.insertLog(new DncOperationLogDto().setLink(directoryFile.getLink()).setWorkstationId(directoryFile.getWorkstationId()).setTargetPathName(workstationVO.getGroupName() + "/" + workstationVO.getName() + "/" + directoryFile.getOriginalFilename()).setTargetPathId(directory.getGroupAllPath()).setTargetType(DncEnums.LogFileSourceType.PROCESSING_PROGRAM.getCode()).setOperationTime(DateTime.now()).setSourceType(DncEnums.LogFileSourceType.FTP.getCode()).setOperationResponse(1).setOperationType(DncEnums.LogOperationType.TO_UPDATE.getCode()).setSuffix(directoryFile.getSuffix()).setObjectKey(directoryFile.getObjectKey()).setFileName(directoryFile.getFilename()).setVersion(directoryFile.getVersion()).setSourcePathName(DncConstant.FTP_PATH).setOperatorName("机床回传").setFileId(directoryFile.getId()));
|
|
return this.transferDirectoryFileService.update(Wrappers.<TransferDirectoryFile>lambdaUpdate()
|
.set(TransferDirectoryFile::getOriginalFilename, newName)
|
.set(TransferDirectoryFile::getFilename, newName)
|
.eq(TransferDirectoryFile::getFileType, DncEnums.FileType.PROCESSING_PROGRAM.getCode())
|
.eq(TransferDirectoryFile::getWorkstationId, workstationId)
|
.eq(TransferDirectoryFile::getStorageSpaceId, storageSpaceId)
|
.eq(TransferDirectoryFile::getIsCurrent, DncEnums.CurrentVersion.YES.getCode())
|
.and(i -> i.eq(TransferDirectoryFile::getOriginalFilename, oldName).or().eq(TransferDirectoryFile::getFilename, oldName)));
|
/*
|
return this.transferDirectoryFileService.update((Wrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
|
return v0.getOriginalFilename();
|
}, newName)).set((v0) -> {
|
return v0.getFilename();
|
}, newName)).eq((v0) -> {
|
return v0.getFileType();
|
}, DncEnums.FileType.PROCESSING_PROGRAM.getCode())).eq((v0) -> {
|
return v0.getWorkstationId();
|
}, workstationId)).eq((v0) -> {
|
return v0.getStorageSpaceId();
|
}, storageSpaceId)).eq((v0) -> {
|
return v0.getIsCurrent();
|
}, DncEnums.CurrentVersion.YES.getCode())).and(i -> {
|
LambdaUpdateWrapper lambdaUpdateWrapper = (LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) i.eq((v0) -> {
|
return v0.getOriginalFilename();
|
}, oldName)).or()).eq((v0) -> {
|
return v0.getFilename();
|
}, oldName);
|
}));*/
|
}
|
|
private TransferDirectoryFile getTransferDirectoryFile(Long storageSpaceId, String oldFileName, Long workstationId) {
|
return (TransferDirectoryFile)this.transferDirectoryFileService.getOne(Wrappers.<TransferDirectoryFile>lambdaQuery()
|
.eq(TransferDirectoryFile::getWorkstationId, workstationId)
|
.eq(TransferDirectoryFile::getFileType, DncEnums.FileType.PROCESSING_PROGRAM.getCode())
|
.eq(TransferDirectoryFile::getIsCurrent, DncEnums.CurrentVersion.YES.getCode())
|
.eq(TransferDirectoryFile::getStorageSpaceId, storageSpaceId)
|
.and(i -> i.eq(TransferDirectoryFile::getOriginalFilename, oldFileName).or().eq(TransferDirectoryFile::getFilename, oldFileName)));
|
/*
|
return (TransferDirectoryFile) this.transferDirectoryFileService.getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getWorkstationId();
|
}, workstationId)).eq((v0) -> {
|
return v0.getFileType();
|
}, DncEnums.FileType.PROCESSING_PROGRAM.getCode())).eq((v0) -> {
|
return v0.getIsCurrent();
|
}, DncEnums.CurrentVersion.YES.getCode())).eq((v0) -> {
|
return v0.getStorageSpaceId();
|
}, storageSpaceId)).and(i -> {
|
LambdaQueryWrapper lambdaQueryWrapper = (LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) i.eq((v0) -> {
|
return v0.getOriginalFilename();
|
}, oldFileName)).or()).eq((v0) -> {
|
return v0.getFilename();
|
}, oldFileName);
|
}));*/
|
}
|
|
@Override // org.springblade.modules.dnc.service.IDockingFtpService
|
public boolean deleteFile(String filename) {
|
Long workstationId = getWorkstationByPath();
|
DncFixedSpace dncFixedSpace = getDirectoryName(filename, workstationId);
|
if (dncFixedSpace == null) {
|
throw new ServiceException(MessageUtils.message("dnc.ftp.relation.workstation.normal.use", new Object[0]));
|
}
|
Long storageSpaceId = dncFixedSpace.getId();
|
String name = fileName(filename);
|
TransferDirectoryFile directoryFile = getTransferDirectoryFile(storageSpaceId, name, workstationId);
|
TransferDirectory directory = (TransferDirectory) this.transferDirectoryService.getById(directoryFile.getTransferDirectoryId());
|
WorkstationVO workstationVO = this.workstationService.getDetail(workstationId);
|
this.logService.insertLog(new DncOperationLogDto().setLink(directoryFile.getLink()).setWorkstationId(directoryFile.getWorkstationId()).setTargetPathName(workstationVO.getGroupName() + "/" + workstationVO.getName() + "/" + directoryFile.getOriginalFilename()).setTargetPathId(directory.getGroupAllPath()).setTargetType(DncEnums.LogFileSourceType.PROCESSING_PROGRAM.getCode()).setOperationTime(DateTime.now()).setSourceType(DncEnums.LogFileSourceType.FTP.getCode()).setOperationResponse(1).setOperationType(DncEnums.LogOperationType.DELETE.getCode()).setSuffix(directoryFile.getSuffix()).setObjectKey(directoryFile.getObjectKey()).setFileName(directoryFile.getFilename()).setSourcePathName(DncConstant.FTP_PATH).setOperatorName("机床回传").setVersion(directoryFile.getVersion()).setFileId(directoryFile.getId()));
|
return this.transferDirectoryFileService.removeById(directoryFile);
|
}
|
|
@Override // org.springblade.modules.dnc.service.IDockingFtpService
|
public Integer getOrderCwd(String path) {
|
Long workstationId = getWorkstationByPath();
|
Long ftpNodeParentId = getFtpNodeParentId(path, workstationId);
|
if (Func.isBlank(path) || ftpNodeParentId.longValue() > 0) {
|
return Integer.valueOf(ResultCode.SUCCESS.getCode());
|
}
|
return Integer.valueOf(ResultCode.NOT_FOUND.getCode());
|
}
|
|
private TransferDirectoryFile getTransferDirectoryFileByPath(String path) {
|
Long workstationId = getWorkstationByPath();
|
DncFixedSpace dncFixedSpace = getDirectoryName(path, workstationId);
|
if (dncFixedSpace == null) {
|
throw new ServiceException(MessageUtils.message("dnc.ftp.relation.workstation.normal.use", new Object[0]));
|
}
|
TransferDirectory transferDirectory = getTransferDirectoryByPath(workstationId);
|
if (Objects.isNull(transferDirectory)) {
|
throw new ServiceException(MessageUtils.message("dnc.transfer.directory.no", new Object[0]));
|
}
|
String fileName = fileName(path);
|
|
return Optional.<TransferDirectoryFile>ofNullable(this.transferDirectoryFileService.getOne(new QueryWrapper<TransferDirectoryFile>().lambda()
|
.eq(TransferDirectoryFile::getTransferDirectoryId, transferDirectory.getId())
|
.eq(TransferDirectoryFile::getOriginalFilename, fileName)
|
.eq(TransferDirectoryFile::getFileType, Integer.valueOf(1))
|
.eq(TransferDirectoryFile::getIsCurrent, DncEnums.CurrentVersion.YES.getCode())
|
.eq(Func.isNotEmpty(dncFixedSpace), TransferDirectoryFile::getStorageSpaceId, dncFixedSpace.getId()))
|
)
|
|
.orElse(new TransferDirectoryFile());
|
|
/*
|
return (TransferDirectoryFile) Optional.ofNullable(this.transferDirectoryFileService.getOne(((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().eq((v0) -> {
|
return v0.getTransferDirectoryId();
|
}, transferDirectory.getId())).eq((v0) -> {
|
return v0.getOriginalFilename();
|
}, fileName)).eq((v0) -> {
|
return v0.getFileType();
|
}, 1)).eq((v0) -> {
|
return v0.getIsCurrent();
|
}, DncEnums.CurrentVersion.YES.getCode())).eq(Func.isNotEmpty(dncFixedSpace), (v0) -> {
|
return v0.getStorageSpaceId();
|
}, dncFixedSpace.getId()))).orElse(new TransferDirectoryFile());
|
*/
|
}
|
|
private DncFixedSpace getDirectoryName(String path, Long workstationId) {
|
|
DncFixedSpace dncFixedSpace2;
|
DncFixedSpace fixedSpace = null;
|
String[] split = StrUtil.split(path, "/");
|
if (Func.isNotEmpty(split)) {
|
int len = split.length;
|
if (len < 2) {
|
Long rootNodeId = this.fixedSpaceService.getRootNodeId(String.valueOf(workstationId)).getRootNodeId();
|
if (Func.isNotEmpty(rootNodeId)) {
|
DncFixedSpace dncFixedSpace = (DncFixedSpace)this.fixedSpaceService.getById(rootNodeId);
|
if (dncFixedSpace != null) {
|
fixedSpace = dncFixedSpace;
|
}
|
}
|
/*
|
if (Func.isNotEmpty(rootNodeId) && (dncFixedSpace2 = (DncFixedSpace) this.fixedSpaceService.getById(rootNodeId)) != null) {
|
fixedSpace = dncFixedSpace2;
|
}*/
|
}
|
if (len >= 2) {
|
String substr = path.substring(0, path.lastIndexOf("/"));
|
Long parentId = getFtpNodeParentId(substr, workstationId);
|
String directoryName = substr.substring(substr.lastIndexOf("/") + 1);
|
DncWsRelationTd wsRelationTd = this.wsRelationTdService.getOne(Wrappers.<DncWsRelationTd>lambdaQuery().eq(DncWsRelationTd::getWorkstationId, workstationId));
|
|
if (wsRelationTd != null) {
|
DncFixedSpace dncFixedSpace = this.fixedSpaceService.getOne(Wrappers.<DncFixedSpace>lambdaQuery()
|
.eq(DncFixedSpace::getTdId, wsRelationTd.getTransferDirectorId())
|
.eq(DncFixedSpace::getParentId, parentId)
|
.eq(DncFixedSpace::getName, directoryName));
|
if (dncFixedSpace != null) {
|
fixedSpace = dncFixedSpace;
|
}
|
}
|
|
/*
|
DncWsRelationTd wsRelationTd = (DncWsRelationTd) this.wsRelationTdService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getWorkstationId();
|
}, workstationId));*/
|
/*
|
if (wsRelationTd != null) && (dncFixedSpace = (DncFixedSpace) this.fixedSpaceService.getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getTdId();
|
}, wsRelationTd.getTransferDirectorId())).eq((v0) -> {
|
return v0.getParentId();
|
}, parentId)).eq((v0) -> {
|
return v0.getName();
|
}, directoryName))) != null) {
|
fixedSpace = dncFixedSpace;
|
}*/
|
}
|
}
|
return fixedSpace;
|
}
|
|
private Integer getStorageSpace(String path) {
|
Integer storageSpace = null;
|
String[] split = StrUtil.split(path, "/");
|
if (Func.isNotEmpty(split)) {
|
int len = split.length;
|
if (len < 2) {
|
storageSpace = DncEnums.StorageSpace.ROUTINE.getCode();
|
}
|
if (len == 2) {
|
String fixedSpace = split[split.length - 2];
|
if (CommonConstant.FIXED_SPACE.equals(fixedSpace)) {
|
storageSpace = DncEnums.StorageSpace.FIXED.getCode();
|
} else {
|
storageSpace = DncEnums.StorageSpace.ROUTINE.getCode();
|
}
|
}
|
}
|
return storageSpace;
|
}
|
|
private TransferDirectory getTransferDirectoryByPath(Long workstationId) {
|
DncWsRelationTd dncWsRelationTd = this.wsRelationTdService.getOne(Wrappers.<DncWsRelationTd>lambdaQuery().eq(DncWsRelationTd::getWorkstationId, workstationId));
|
/*
|
DncWsRelationTd dncWsRelationTd = (DncWsRelationTd) this.wsRelationTdService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getWorkstationId();
|
}, workstationId));*/
|
if (dncWsRelationTd == null) {
|
throw new ServiceException(MessageUtils.message("dnc.workstation.not.binding.ftp.directory", new Object[0]));
|
}
|
TransferDirectory transferDirectory = (TransferDirectory) this.transferDirectoryService.getById(dncWsRelationTd.getTransferDirectorId());
|
if (transferDirectory == null) {
|
throw new ServiceException(MessageUtils.message("dnc.relation.ftp.directory.not.exist", new Object[0]));
|
}
|
return transferDirectory;
|
}
|
|
private String fileName(String path) {
|
String fileName = "";
|
String[] split = StrUtil.split(path, "/");
|
if (Func.isNotEmpty(split)) {
|
int len = split.length;
|
if (len < 2) {
|
fileName = path;
|
}
|
if (len >= 2) {
|
fileName = path.substring(path.lastIndexOf("/") + 1);
|
}
|
}
|
return fileName;
|
}
|
|
private List<EntityInfoVO> findByDirectoryPath(String path) {
|
Long rootNodeId;
|
Long workstationId = getWorkstationByPath();
|
int length = path.split("/").length;
|
DncWsRelationTd dncWsRelationTd = this.wsRelationTdService.getOne(Wrappers.<DncWsRelationTd>lambdaQuery().eq(DncWsRelationTd::getWorkstationId, workstationId));
|
/*
|
DncWsRelationTd dncWsRelationTd = (DncWsRelationTd) this.wsRelationTdService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getWorkstationId();
|
}, workstationId));*/
|
if (dncWsRelationTd == null) {
|
throw new ServiceException(MessageUtils.message("dnc.workstation.not.binding.ftp.directory", new Object[0]));
|
}
|
TransferDirectory transferDirectory = (TransferDirectory) this.transferDirectoryService.getById(dncWsRelationTd.getTransferDirectorId());
|
if (Func.isEmpty(transferDirectory)) {
|
return Lists.newArrayList();
|
}
|
List<TransferDirectoryFile> fileList = this.transferDirectoryFileService.findProgram(transferDirectory.getId());
|
if (Func.isEmpty(fileList)) {
|
return Lists.newArrayList();
|
}
|
List<Long> artFileIds = fileList.stream().filter(s -> {
|
return DncEnums.FileSource.PROCESSING_PROGRAM.getCode().equals(s.getFileSource());
|
}).map((v0) -> {
|
return v0.getCraftFileId();
|
}).collect(Collectors.toList());
|
Map<Long, ArtFileInformationDTO> artFileInformationMap = this.transferDirectoryFileService.artFileInformationMap(artFileIds);
|
if (StrUtil.isBlank(path) && (rootNodeId = this.fixedSpaceService.getRootNodeId(String.valueOf(workstationId)).getRootNodeId()) != null) {
|
List<EntityInfoVO> collect = fileList.stream().filter(s2 -> {
|
return rootNodeId.equals(s2.getStorageSpaceId());
|
}).map(c -> {
|
EntityInfoVO build = EntityInfoVO.builder().id(String.valueOf(c.getId())).objectKey(c.getObjectKey()).isDirectory(Boolean.FALSE).canWrite(Boolean.FALSE).name(c.getOriginalFilename()).size(c.getContentLength()).creationTime(c.getCreateTime() != null ? LocalDateTimeUtils.DateToLocalDateTime(c.getCreateTime()) : LocalDateTime.now()).updateTime(c.getLastModified() == null ? LocalDateTime.now() : LocalDateTimeUtils.DateToLocalDateTime(c.getLastModified())).owner(String.valueOf(c.getCreateUser())).hash(c.getContentMd5()).build();
|
return getEntityInfoVO(artFileInformationMap, c, build);
|
}).collect(Collectors.toList());
|
List<DncFixSpaceVO> fixSpaceTree = this.fixedSpaceService.getFixSpaceTree(String.valueOf(workstationId), String.valueOf(rootNodeId));
|
if (Func.isNotEmpty(fixSpaceTree)) {
|
List<EntityInfoVO> fixSpaceList = getFixSpaceList(fixSpaceTree);
|
collect.addAll(fixSpaceList);
|
}
|
return collect;
|
} else if (length >= CommonConstant.VERSION_NUM.intValue()) {
|
List<EntityInfoVO> collect2 = new ArrayList<>();
|
DncFixedSpace dncFixedSpace = getDirectory(path, workstationId);
|
if (dncFixedSpace == null) {
|
throw new ServiceException(MessageUtils.message("dnc.ftp.relation.workstation.normal.use", new Object[0]));
|
}
|
List<DncFixSpaceVO> fixSpaceVOList = this.fixedSpaceService.getFixSpaceTree(String.valueOf(workstationId), String.valueOf(dncFixedSpace.getId()));
|
if (Func.isNotEmpty(fixSpaceVOList)) {
|
List<EntityInfoVO> fixSpaceList2 = getFixSpaceList(fixSpaceVOList);
|
collect2.addAll(fixSpaceList2);
|
}
|
List<TransferDirectoryFile> files = fileList.stream().filter(s3 -> {
|
return dncFixedSpace.getId().equals(s3.getStorageSpaceId());
|
}).collect(Collectors.toList());
|
if (Func.isNotEmpty(files)) {
|
List<EntityInfoVO> entityInfos = files.stream().map(c2 -> {
|
EntityInfoVO build = EntityInfoVO.builder().id(String.valueOf(c2.getId())).isDirectory(Boolean.FALSE).canWrite(Boolean.FALSE).name(c2.getOriginalFilename()).size(c2.getContentLength()).creationTime(c2.getCreateTime() != null ? LocalDateTimeUtils.DateToLocalDateTime(c2.getCreateTime()) : LocalDateTime.now()).updateTime(c2.getLastModified() == null ? LocalDateTime.now() : LocalDateTimeUtils.DateToLocalDateTime(c2.getLastModified())).owner(String.valueOf(c2.getCreateUser())).hash(c2.getContentMd5()).build();
|
return getEntityInfoVO(artFileInformationMap, c2, build);
|
}).collect(Collectors.toList());
|
collect2.addAll(entityInfos);
|
}
|
return collect2;
|
} else {
|
return new ArrayList<>();
|
}
|
}
|
|
private EntityInfoVO getEntityInfoVO(Map<Long, ArtFileInformationDTO> artFileInformationMap, TransferDirectoryFile c, EntityInfoVO build) {
|
ArtFileInformationDTO fileInformation;
|
if (DncEnums.FileSource.PROCESSING_PROGRAM.getCode().equals(c.getFileSource()) && !artFileInformationMap.isEmpty() && (fileInformation = artFileInformationMap.get(c.getCraftFileId())) != null) {
|
String fileSourceNamePath = fileInformation.getFileSourceNamePath();
|
DncArtBag dncArtBag = fileInformation.getDncArtBag();
|
if (Func.isNotEmpty(dncArtBag) && Func.isNotBlank(fileSourceNamePath)) {
|
DncFileNameProcessRuleContext context = DncFileNameProcessRuleContext.builder().artBag(dncArtBag).directoryPath(fileSourceNamePath).fileName(c.getFilename()).build();
|
String dncFileName = DncFileNameProcessRuleFactory.getDncFileName(context);
|
if (Func.isNotBlank(dncFileName)) {
|
build.setName(dncFileName);
|
}
|
}
|
}
|
return build;
|
}
|
|
private List<EntityInfoVO> getFixSpaceList(List<DncFixSpaceVO> fixSpaceVOList) {
|
List<EntityInfoVO> collect = new ArrayList<>();
|
fixSpaceVOList.forEach(item -> {
|
EntityInfoVO dto = new EntityInfoVO();
|
dto.setCanWrite(Boolean.FALSE);
|
dto.setCreationTime(LocalDateTime.now());
|
dto.setUpdateTime(LocalDateTime.now());
|
dto.setHash("");
|
dto.setSize(0L);
|
dto.setOwner(DncConstant.OWNER);
|
dto.setId("0");
|
dto.setIsDirectory(Boolean.TRUE);
|
dto.setName(item.getName());
|
collect.add(dto);
|
});
|
return collect;
|
}
|
|
private DncFixedSpace getDirectory(String path, Long workstationId) {
|
//DncFixedSpace dncFixedSpace;
|
DncFixedSpace fixedSpace = null;
|
String directoryName = "";
|
String[] split = StrUtil.split(path, "/");
|
if (Func.isNotEmpty(split)) {
|
int len = split.length;
|
if (len < 2) {
|
directoryName = path;
|
}
|
if (len >= 2) {
|
directoryName = path.substring(path.lastIndexOf("/") + 1);
|
}
|
Long parentId = getFtpNodeParentId(path, workstationId);
|
DncWsRelationTd wsRelationTd = this.wsRelationTdService.getOne(Wrappers.<DncWsRelationTd>lambdaQuery().eq(DncWsRelationTd::getWorkstationId, workstationId));
|
if (wsRelationTd != null) {
|
DncFixedSpace dncFixedSpace = this.fixedSpaceService.getOne(Wrappers.<DncFixedSpace>lambdaQuery()
|
.eq(DncFixedSpace::getTdId, wsRelationTd.getTransferDirectorId())
|
.eq(DncFixedSpace::getName, directoryName)
|
.eq(DncFixedSpace::getParentId, parentId)
|
.eq(DncFixedSpace::getSpaceLocation, CommonConstant.CREATE_SAME_DIRECTORY));
|
if (dncFixedSpace != null)
|
fixedSpace = dncFixedSpace;
|
}
|
|
/*
|
DncWsRelationTd wsRelationTd = (DncWsRelationTd) this.wsRelationTdService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getWorkstationId();
|
}, workstationId));
|
if (wsRelationTd != null && (dncFixedSpace = (DncFixedSpace) this.fixedSpaceService.getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getTdId();
|
}, wsRelationTd.getTransferDirectorId())).eq((v0) -> {
|
return v0.getName();
|
}, directoryName)).eq((v0) -> {
|
return v0.getParentId();
|
}, parentId)).eq((v0) -> {
|
return v0.getSpaceLocation();
|
}, CommonConstant.CREATE_SAME_DIRECTORY))) != null) {
|
fixedSpace = dncFixedSpace;
|
}*/
|
}
|
return fixedSpace;
|
}
|
|
private Long getFtpNodeParentId(String path, Long workstationId) {
|
String completePathName;
|
Long rootNodeId = this.fixedSpaceService.getRootNodeId(String.valueOf(workstationId)).getRootNodeId();
|
DncFixedSpace rootNode = this.fixedSpaceService.getById(rootNodeId);
|
String rootName = rootNode.getName();
|
if (Func.isNotBlank(path)) {
|
completePathName = rootName + "/" + path;
|
} else {
|
completePathName = rootName;
|
}
|
Map<Long, String> stringMap = this.fixedSpaceService.getFixSpaceLocation(workstationId);
|
String str = completePathName;
|
Long nodeId = (Long) (stringMap.entrySet().stream().filter(kvEntry -> {
|
return Objects.equals(str, kvEntry.getValue());
|
}).map((v0) -> {
|
return v0.getKey();
|
}).collect(Collectors.toList())).get(0);
|
DncFixedSpace node = (DncFixedSpace) this.fixedSpaceService.getById(nodeId);
|
return node.getParentId();
|
}
|
|
private Long getWorkstationByPath() {
|
String machineCode = AuthUtil.getUser().getAccount();
|
List<Long> ids = this.workstationService.findByMachineShortCode(machineCode);
|
if (Func.isEmpty(ids)) {
|
throw new ServiceException(MessageUtils.message("dnc.machine.no.workstation", new Object[0]));
|
}
|
return ids.get(0);
|
}
|
}
|