yangys
2024-03-29 153cc3fd4ef015a8b1390b2eef3d102c5859a5e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
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<DncFixedSpaceMapper, DncFixedSpace> 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.<DncFixedSpace>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.<DncFixedSpace>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.<DncFixedSpace>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.<DncFixedSpace>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<DncFixedSpace> dncFixedSpaces = this.baseMapper.selectList(Lambda.<DncFixedSpace>create().findIn(DncFixedSpace::getAllPath, id, "/"));
        /*
        List<DncFixedSpace> dncFixedSpaces = ((DncFixedSpaceMapper) this.baseMapper).selectList(Lambda.create().findIn((v0) -> {
            return v0.getAllPath();
        }, id, "/"));*/
        if (Func.isNotEmpty(dncFixedSpaces)) {
            List<Long> removeIds = dncFixedSpaces.stream().map((v0) -> {
                return v0.getId();
            }).distinct().collect(Collectors.toList());
            List<TransferDirectoryFile> list = this.directoryFileService.list(Wrappers.<TransferDirectoryFile>lambdaQuery().in(TransferDirectoryFile::getStorageSpaceId, removeIds));
            /*
            List<TransferDirectoryFile> 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<DncFixSpaceVO> getFixSpaceTree(String workstationId, String nodeId) {
        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]));
        }
        List<DncFixedSpace> list = list(Wrappers.<DncFixedSpace>lambdaQuery().eq(DncFixedSpace::getParentId, nodeId)
                .eq(DncFixedSpace::getTdId, dncWsRelationTd.getTransferDirectorId()));
        /*
        List<DncFixedSpace> 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.<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]));
        }
        
        DncFixedSpace dncFixedSpace = getOne(Wrappers.<DncFixedSpace>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.<DncFixedSpace>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<Long, String> getFixSpaceLocation(Long workstationId) {
        Map<Long, String> map = new HashMap<>(16);
        List<DncFixedSpace> list = list();
        Long rootNodeId = getRootNodeId(String.valueOf(workstationId)).getRootNodeId();
        if (Func.isNotEmpty(list)) {
            Map<Long, DncFixedSpace> 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<Long, DncWsRelationTd> getWorkstationRelationDirectory() {
        return this.wsRelationTdService.list().stream().collect(Collectors.toMap((v0) -> {
            return v0.getWorkstationId();
        }, Function.identity()));
    }
 
    @Override // org.springblade.modules.dnc.service.IDncFixedSpaceService
    public List<DncFixSpaceTreeVO> getFixSpaceDirectLoadingTree(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]));
        }
        List<DncFixedSpace> list = list(Wrappers.<DncFixedSpace>lambdaQuery().eq(DncFixedSpace::getTdId, dncWsRelationTd.getTransferDirectorId()));
        /*
        List<DncFixedSpace> 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<Long, DncFixedSpace> getRootSpace() {
        List<DncFixedSpace> list = list(Wrappers.<DncFixedSpace>lambdaQuery().eq(DncFixedSpace::getSpaceLocation,1));
        /*
        List<DncFixedSpace> 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;
    }
}