package com.qianwen.smartman.modules.dnc.service.impl; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.qianwen.core.log.exception.ServiceException; import com.qianwen.core.mp.base.BaseServiceImpl; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.common.constant.CommonConstant; import com.qianwen.smartman.common.utils.Lambda; import com.qianwen.smartman.common.utils.MessageUtils; import com.qianwen.smartman.modules.dnc.entity.DncFixedSpace; import com.qianwen.smartman.modules.dnc.entity.DncWsRelationTd; import com.qianwen.smartman.modules.dnc.entity.TransferDirectoryFile; import com.qianwen.smartman.modules.dnc.mapper.DncFixedSpaceMapper; import com.qianwen.smartman.modules.dnc.service.IDncFixedSpaceService; import com.qianwen.smartman.modules.dnc.service.IDncWsRelationTdService; import com.qianwen.smartman.modules.dnc.service.ITransferDirectoryFileService; import com.qianwen.smartman.modules.dnc.vo.DncFixSpaceTreeVO; import com.qianwen.smartman.modules.dnc.vo.DncFixSpaceVO; import com.qianwen.smartman.modules.dnc.vo.DncFixedSpaceAdVO; import com.qianwen.smartman.modules.dnc.vo.DncFixedSpaceUpVO; import com.qianwen.smartman.modules.dnc.vo.SpaceRootNodeVO; @Service /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/dnc/service/impl/DncFixedSpaceServiceImpl.class */ public class DncFixedSpaceServiceImpl extends BaseServiceImpl implements IDncFixedSpaceService { @Autowired @Lazy private IDncWsRelationTdService wsRelationTdService; @Autowired @Lazy private ITransferDirectoryFileService directoryFileService; @Override // org.springblade.modules.dnc.service.IDncFixedSpaceService public boolean initializeRootNode(String workstationId, String workstationName, String tdId) { DncFixedSpace space = getOne(Wrappers.lambdaQuery().eq(DncFixedSpace::getName, workstationName) .eq(DncFixedSpace::getParentId, workstationId).eq(DncFixedSpace::getTdId, tdId)); /* DncFixedSpace space = (DncFixedSpace) getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getName(); }, workstationName)).eq((v0) -> { return v0.getParentId(); }, workstationId)).eq((v0) -> { return v0.getTdId(); }, tdId));*/ boolean result = Boolean.FALSE.booleanValue(); if (space == null) { DncFixedSpace fixedSpace = new DncFixedSpace(); fixedSpace.setName(workstationName).setSpaceLocation(CommonConstant.ASSOCIATED_DIRECTORY).setTdId(Long.valueOf(Long.parseLong(tdId))).setTenantId("000000"); save(fixedSpace); if (CommonConstant.ASSOCIATED_DIRECTORY.equals(fixedSpace.getSpaceLocation())) { fixedSpace.setAllPath(Long.parseLong(workstationId) + "/" + fixedSpace.getId()).setParentId(Long.valueOf(Long.parseLong(workstationId))); } result = updateById(fixedSpace); } return result; } @Override // org.springblade.modules.dnc.service.IDncFixedSpaceService public Boolean updateName(DncFixedSpaceUpVO dncFixedSpaceUpVO) { return Boolean.valueOf(update(Wrappers.lambdaUpdate().eq(DncFixedSpace::getTdId, Long.parseLong(dncFixedSpaceUpVO.getDirectoryId())) .eq(DncFixedSpace::getId, dncFixedSpaceUpVO.getId()) .set(DncFixedSpace::getName, dncFixedSpaceUpVO.getName()))); /* return Boolean.valueOf(update((Wrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().eq((v0) -> { return v0.getTdId(); }, Long.valueOf(Long.parseLong(dncFixedSpaceUpVO.getDirectoryId())))).eq((v0) -> { return v0.getId(); }, dncFixedSpaceUpVO.getId())).set((v0) -> { return v0.getName(); }, dncFixedSpaceUpVO.getName())));*/ } @Override // org.springblade.modules.dnc.service.IDncFixedSpaceService @Transactional(rollbackFor = {Exception.class}) public DncFixSpaceVO saveFixSpace(DncFixedSpaceAdVO dncFixedSpaceAdVO) { DncFixSpaceVO dncFixSpaceVO = new DncFixSpaceVO(); DncFixedSpace one = getOne(Wrappers.lambdaQuery().eq(DncFixedSpace::getTdId, dncFixedSpaceAdVO.getDirectoryId()) .eq(DncFixedSpace::getParentId, dncFixedSpaceAdVO.getParentId()).eq(DncFixedSpace::getName, dncFixedSpaceAdVO.getName())); /* DncFixedSpace one = (DncFixedSpace) getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getTdId(); }, dncFixedSpaceAdVO.getDirectoryId())).eq((v0) -> { return v0.getParentId(); }, dncFixedSpaceAdVO.getParentId())).eq((v0) -> { return v0.getName(); }, dncFixedSpaceAdVO.getName()));*/ if (one != null) { throw new ServiceException(MessageUtils.message("dnc.ftp.directory.already.exist.please.duplicate.creation", new Object[0])); } DncFixedSpace parentDncFixedSpace = (DncFixedSpace) getById(dncFixedSpaceAdVO.getParentId()); if (parentDncFixedSpace == null) { throw new ServiceException(MessageUtils.message("dnc.ftp.failed.to.create.new.directory.the.fixed.space.directory.parent.node.does.not.exist", new Object[0])); } DncFixedSpace dncFixedSpace = new DncFixedSpace(); dncFixedSpace.setSpaceLocation(CommonConstant.CREATE_SAME_DIRECTORY); dncFixedSpace.setName(dncFixedSpaceAdVO.getName()); dncFixedSpace.setTdId(Long.valueOf(Long.parseLong(dncFixedSpaceAdVO.getDirectoryId()))); dncFixedSpace.setParentId(Long.valueOf(Long.parseLong(dncFixedSpaceAdVO.getParentId()))); save(dncFixedSpace); update(Wrappers.lambdaUpdate().eq(DncFixedSpace::getId, dncFixedSpace.getId()) .set(DncFixedSpace::getAllPath, parentDncFixedSpace.getAllPath() + "/" + dncFixedSpace.getId())); /* update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().eq((v0) -> { return v0.getId(); }, dncFixedSpace.getId())).set((v0) -> { return v0.getAllPath(); }, parentDncFixedSpace.getAllPath() + "/" + dncFixedSpace.getId()));*/ return dncFixSpaceVO.setId(dncFixedSpace.getId()).setAllPath(parentDncFixedSpace.getAllPath() + "/" + dncFixedSpace.getId()).setName(dncFixedSpaceAdVO.getName()).setParentId(Long.valueOf(Long.parseLong(dncFixedSpaceAdVO.getParentId()))).setTdId(Long.valueOf(Long.parseLong(dncFixedSpaceAdVO.getDirectoryId()))); } @Override // org.springblade.modules.dnc.service.IDncFixedSpaceService public boolean deleteFixSpace(String id) { DncFixedSpace dncFixedSpace = (DncFixedSpace) getById(id); if (dncFixedSpace == null) { throw new ServiceException(MessageUtils.message("dnc.ftp.del.directory.fail", new Object[0])); } List dncFixedSpaces = this.baseMapper.selectList(Lambda.create().findIn(DncFixedSpace::getAllPath, id, "/")); /* List dncFixedSpaces = ((DncFixedSpaceMapper) this.baseMapper).selectList(Lambda.create().findIn((v0) -> { return v0.getAllPath(); }, id, "/"));*/ if (Func.isNotEmpty(dncFixedSpaces)) { List removeIds = dncFixedSpaces.stream().map((v0) -> { return v0.getId(); }).distinct().collect(Collectors.toList()); List list = this.directoryFileService.list(Wrappers.lambdaQuery().in(TransferDirectoryFile::getStorageSpaceId, removeIds)); /* List list = this.directoryFileService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> { return v0.getStorageSpaceId(); }, removeIds));*/ if (Func.isNotEmpty(list)) { this.directoryFileService.removeBatchByIds(list); } } return removeById(Long.valueOf(Long.parseLong(id))); } @Override // org.springblade.modules.dnc.service.IDncFixedSpaceService public List getFixSpaceTree(String workstationId, String nodeId) { DncWsRelationTd dncWsRelationTd = this.wsRelationTdService.getOne(Wrappers.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])); } List list = list(Wrappers.lambdaQuery().eq(DncFixedSpace::getParentId, nodeId) .eq(DncFixedSpace::getTdId, dncWsRelationTd.getTransferDirectorId())); /* List list = list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getParentId(); }, nodeId)).eq((v0) -> { return v0.getTdId(); }, dncWsRelationTd.getTransferDirectorId()));*/ if (Func.isNotEmpty(list)) { return list.stream().map(item -> { DncFixSpaceVO dncFixSpace = new DncFixSpaceVO(); dncFixSpace.setId(item.getId()); dncFixSpace.setName(item.getName()); if (Func.isNotEmpty(item.getParentId())) { dncFixSpace.setHasChildren(Boolean.TRUE); } else { dncFixSpace.setHasChildren(Boolean.FALSE); } dncFixSpace.setParentId(item.getParentId()); dncFixSpace.setAllPath(item.getAllPath()); dncFixSpace.setTdId(dncWsRelationTd.getTransferDirectorId()); return dncFixSpace; }).collect(Collectors.toList()); } return new ArrayList(); } @Override // org.springblade.modules.dnc.service.IDncFixedSpaceService public SpaceRootNodeVO getRootNodeId(String workstationId) { SpaceRootNodeVO spaceRootNodeVO = new SpaceRootNodeVO(); DncWsRelationTd dncWsRelationTd = this.wsRelationTdService.getOne(Wrappers.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])); } DncFixedSpace dncFixedSpace = getOne(Wrappers.lambdaQuery() .eq(DncFixedSpace::getTdId, dncWsRelationTd.getTransferDirectorId()) .eq(DncFixedSpace::getSpaceLocation, CommonConstant.ASSOCIATED_DIRECTORY)); /* DncFixedSpace dncFixedSpace = (DncFixedSpace) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getTdId(); }, dncWsRelationTd.getTransferDirectorId())).eq((v0) -> { return v0.getSpaceLocation(); }, CommonConstant.ASSOCIATED_DIRECTORY));*/ if (dncFixedSpace != null) { spaceRootNodeVO.setRootNodeId(dncFixedSpace.getId()).setName(dncFixedSpace.getName()).setParentId(dncFixedSpace.getParentId()).setTitle(dncFixedSpace.getName()); } return spaceRootNodeVO; } @Override // org.springblade.modules.dnc.service.IDncFixedSpaceService public Boolean isRootSpace(Long fixId) { DncFixedSpace dncFixedSpace = getOne(Wrappers.lambdaQuery() .eq(DncFixedSpace::getId, fixId).eq(DncFixedSpace::getSpaceLocation, CommonConstant.ASSOCIATED_DIRECTORY)); /* DncFixedSpace dncFixedSpace = (DncFixedSpace) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getId(); }, fixId)).eq((v0) -> { return v0.getSpaceLocation(); }, CommonConstant.ASSOCIATED_DIRECTORY));*/ if (dncFixedSpace != null) { return Boolean.TRUE; } return Boolean.FALSE; } @Override // org.springblade.modules.dnc.service.IDncFixedSpaceService public Map getFixSpaceLocation(Long workstationId) { Map map = new HashMap<>(16); List list = list(); Long rootNodeId = getRootNodeId(String.valueOf(workstationId)).getRootNodeId(); if (Func.isNotEmpty(list)) { Map dncFixedSpaceMap = list.stream().collect(Collectors.toMap((v0) -> { return v0.getId(); }, Function.identity())); list.forEach(fix -> { String allPath = fix.getAllPath(); String[] split = allPath.split("/"); StringBuilder sourcePath = new StringBuilder(); for (String id : split) { if ("0".equals(id)) { sourcePath.append("/").append(((DncFixedSpace) dncFixedSpaceMap.get(rootNodeId)).getName()); } else { DncFixedSpace dncFixedSpace = (DncFixedSpace) dncFixedSpaceMap.get(Long.valueOf(Long.parseLong(id))); if (dncFixedSpace != null) { sourcePath.append("/").append(dncFixedSpace.getName()); } } } String name = sourcePath.toString(); int index = name.indexOf("/"); map.put(fix.getId(), name.substring(name.indexOf("/", index + 1) + 1)); }); return map; } return null; } @Override // org.springblade.modules.dnc.service.IDncFixedSpaceService public Map getWorkstationRelationDirectory() { return this.wsRelationTdService.list().stream().collect(Collectors.toMap((v0) -> { return v0.getWorkstationId(); }, Function.identity())); } @Override // org.springblade.modules.dnc.service.IDncFixedSpaceService public List getFixSpaceDirectLoadingTree(Long workstationId) { DncWsRelationTd dncWsRelationTd = this.wsRelationTdService.getOne(Wrappers.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])); } List list = list(Wrappers.lambdaQuery().eq(DncFixedSpace::getTdId, dncWsRelationTd.getTransferDirectorId())); /* List list = list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getTdId(); }, dncWsRelationTd.getTransferDirectorId()));*/ if (Func.isNotEmpty(list)) { return list.stream().map(item -> { DncFixSpaceTreeVO dncFixSpace = new DncFixSpaceTreeVO(); dncFixSpace.setId(item.getId()); dncFixSpace.setName(item.getName()); dncFixSpace.setParentId(item.getParentId()); dncFixSpace.setAllPath(item.getAllPath()); dncFixSpace.setTdId(dncWsRelationTd.getTransferDirectorId()); return dncFixSpace; }).collect(Collectors.toList()); } return new ArrayList<>(); } @Override // org.springblade.modules.dnc.service.IDncFixedSpaceService public Map getRootSpace() { List list = list(Wrappers.lambdaQuery().eq(DncFixedSpace::getSpaceLocation,1)); /* List list = list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getSpaceLocation(); }, 1));*/ if (Func.isNotEmpty(list)) { return list.stream().collect(Collectors.toMap((v0) -> { return v0.getTdId(); }, Function.identity())); } return null; } }