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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
package com.qianwen.smartman.modules.dnc.service.impl;
 
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
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.google.common.base.Joiner;
import com.qianwen.core.mp.base.BaseServiceImpl;
import com.qianwen.core.oss.model.OssFile;
import com.qianwen.core.secure.utils.AuthUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.cache.UserCache;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.constant.DncConstant;
import com.qianwen.smartman.modules.dnc.convert.DncArtFileConvert;
import com.qianwen.smartman.modules.dnc.dto.ArtFileInformationDTO;
import com.qianwen.smartman.modules.dnc.dto.DncArtBagLogDTO;
import com.qianwen.smartman.modules.dnc.entity.DncArtBag;
import com.qianwen.smartman.modules.dnc.entity.DncArtFile;
import com.qianwen.smartman.modules.dnc.entity.DncFactoryFile;
import com.qianwen.smartman.modules.dnc.entity.DncProcessCatalogue;
import com.qianwen.smartman.modules.dnc.entity.TransferDirectoryFile;
import com.qianwen.smartman.modules.dnc.enums.DncEnums;
import com.qianwen.smartman.modules.dnc.mapper.DncArtFileMapper;
import com.qianwen.smartman.modules.dnc.service.IDncArtBagLogService;
import com.qianwen.smartman.modules.dnc.service.IDncArtBagService;
import com.qianwen.smartman.modules.dnc.service.IDncArtFileService;
import com.qianwen.smartman.modules.dnc.service.IDncFactoryFileService;
import com.qianwen.smartman.modules.dnc.service.IDncProcessCatalogueService;
import com.qianwen.smartman.modules.dnc.service.IFileService;
import com.qianwen.smartman.modules.dnc.service.IObsFileService;
import com.qianwen.smartman.modules.dnc.service.ITransferDirectoryFileService;
import com.qianwen.smartman.modules.dnc.util.StringMd5HashCode;
import com.qianwen.smartman.modules.dnc.vo.ArtFileAddVO;
import com.qianwen.smartman.modules.dnc.vo.BatchArchiveArtBagFilesVO;
import com.qianwen.smartman.modules.dnc.vo.DncArtFileAddVO;
import com.qianwen.smartman.modules.dnc.vo.DncArtFileVO;
import com.qianwen.smartman.modules.dnc.vo.DuplicateValidationFileVO;
import com.qianwen.smartman.modules.dnc.vo.FileSourcePathVO;
import com.qianwen.smartman.modules.dnc.vo.sync.SyncArtBagFileVO;
import com.qianwen.smartman.modules.dnc.vo.sync.SyncArtBagVO;
import com.qianwen.smartman.modules.dnc.vo.sync.SyncArtCatalogVO;
import com.qianwen.smartman.modules.dnc.vo.sync.SyncDncProcessCatalogueVO;
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
import com.qianwen.smartman.modules.system.entity.User;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/dnc/service/impl/DncArtFileServiceImpl.class */
public class DncArtFileServiceImpl extends BaseServiceImpl<DncArtFileMapper, DncArtFile> implements IDncArtFileService {
    @Autowired
    private IDncArtBagLogService dncArtBagLogService;
    @Autowired
    private IDncArtBagService dncArtBagService;
    @Autowired
    private IDncProcessCatalogueService dncProcessCatalogueService;
    @Autowired
    private IObsFileService obsFileService;
    @Autowired
    private OssBuilder ossBuilder;
    @Autowired
    @Lazy
    private ITransferDirectoryFileService transferDirectoryFileService;
    @Autowired
    private IDncFactoryFileService dncFactoryFileService;
    @Autowired
    private IFileService fileService;
 
    @Override // org.springblade.modules.dnc.service.IDncArtFileService
    public List<DncArtFileAddVO> addArtFile(List<DncArtFileAddVO> dncArtFilesList) {
        if (Func.isNotEmpty(dncArtFilesList)) {
            dncArtFilesList.forEach(dncArtFileAddVO -> {
                String hash;
                Long artBagId = dncArtFileAddVO.getArtBagId();
                String fileName = dncArtFileAddVO.getFilename();
                Integer fileType = dncArtFileAddVO.getFileType();
                DncArtFile convert = DncArtFileConvert.INSTANCE.convert(dncArtFileAddVO);
                convert.setDocumentOwnership(dncArtFileAddVO.getFileOwnership());
                DncArtFile oldArtFile = getDncArtFile(artBagId, fileName, fileType);
                DncArtBagLogDTO dncArtBagLogDTO = new DncArtBagLogDTO();
                if (Func.isNotBlank(dncArtFileAddVO.getObjectKey())) {
                    OssFile ossFile = this.ossBuilder.template().statFile(dncArtFileAddVO.getObjectKey());
                    hash = ossFile.getHash();
                    convert.setContentLength(Long.valueOf(ossFile.getLength()));
                } else {
                    hash = dncArtFileAddVO.getContentMd5();
                }
                if (Func.isNull(oldArtFile)) {
                    convert.setContentMd5(hash);
                    convert.setIsCurrent(CommonConstant.VERSION_NUM);
                    convert.setVersion(CommonConstant.VERSION_NUM);
                    dncArtBagLogDTO.setOperationType(DncEnums.TodoType.ADD.getCode());
                    saveArtFile(convert, dncArtBagLogDTO);
                } else if (!hash.equals(oldArtFile.getContentMd5())) {
                    oldArtFile.setIsCurrent(DncEnums.CurrentVersion.NO.getCode());
                    updateById(oldArtFile);
                    convert.setVersion(Integer.valueOf((oldArtFile.getVersion() != null ? oldArtFile.getVersion() : CommonConstant.VERSION_NUM).intValue() + CommonConstant.VERSION_NUM.intValue()));
                    convert.setIsCurrent(Integer.valueOf(oldArtFile.getIsCurrent().intValue() + CommonConstant.VERSION_NUM.intValue()));
                    convert.setContentMd5(hash);
                    dncArtBagLogDTO.setOperationType(DncEnums.TodoType.COVER.getCode());
                    saveArtFile(convert, dncArtBagLogDTO);
                }
                dncArtFileAddVO.setId(convert.getId());
            });
        }
        return dncArtFilesList;
    }
 
    private void saveArtFile(DncArtFile convert, DncArtBagLogDTO dncArtBagLogDTO) {
        save(convert);
        dncArtBagLogDTO.setFileId(convert.getFileId()).setFileName(convert.getFilename()).setObjectKey(convert.getObjectKey()).setSuffix(convert.getSuffix()).setOperatorId(AuthUtil.getUserId()).setOperatorName(AuthUtil.getUserAccount()).setOperationTime(new Date()).setSourceType(convert.getSourceType()).setLink(convert.getLink()).setArtBagId(convert.getArtBagId()).setArtFileId(convert.getId()).setFileType(convert.getFileType()).setFileBelong(convert.getDocumentOwnership()).setVersion(convert.getVersion()).setStorage(convert.getStorageSpace());
        this.dncArtBagLogService.save(dncArtBagLogDTO);
    }
 
    @Override // org.springblade.modules.dnc.service.IDncArtFileService
    @Transactional(rollbackFor = {Exception.class})
    public BatchArchiveArtBagFilesVO batchArchiveArtBagFile(BatchArchiveArtBagFilesVO bagFilesVO) {
        List<String> artBagIds = bagFilesVO.getArtBagIds();
        List<DncArtFileAddVO> dncArtFilesList = new ArrayList<>();
        List<DncArtFileAddVO> dncArtFileAdds = bagFilesVO.getDncArtFileAddList();
        artBagIds.forEach(s -> {
            List<DncArtFileAddVO> dncArtFileAddList = dncArtFileAdds.stream().map(a -> {
                return DncArtFileAddVO.builder().artBagId(Long.valueOf(Func.toLong(s))).id(a.getId()).remark(a.getRemark()).tenantId(a.getTenantId()).fileId(a.getFileId()).sourceType(a.getSourceType()).fileType(a.getFileType()).originalFilename(a.getOriginalFilename()).filename(a.getFilename()).contentLength(a.getContentLength()).contentMd5(a.getContentMd5()).contentType(a.getContentType()).objectKey(a.getObjectKey()).fileOwnership(a.getFileOwnership()).link(a.getLink()).suffix(a.getSuffix()).storageSpace(a.getStorageSpace()).build();
            }).collect(Collectors.toList());
            dncArtFilesList.addAll(dncArtFileAddList);
        });
        if (Func.isNotEmpty(dncArtFilesList)) {
            List<DncArtFileAddVO> workstationList = dncArtFilesList.stream().filter(s2 -> {
                return DncEnums.FileOwnership.WORKSTATION.getCode().equals(s2.getFileOwnership());
            }).collect(Collectors.toList());
            if (Func.isNotEmpty(workstationList)) {
                List<Long> workstationFileIds = workstationList.stream().map((v0) -> {
                    return v0.getFileId();
                }).distinct().collect(Collectors.toList());
                
                if (Func.isNotEmpty(workstationFileIds)) {
                    this.transferDirectoryFileService
                    .update(Wrappers.<TransferDirectoryFile>lambdaUpdate().set(TransferDirectoryFile::getWhetherArchive, DncEnums.WhetherArchive.not_Archive.getCode())
                      .in(TransferDirectoryFile::getId, workstationFileIds)); 
                    /*
                    this.transferDirectoryFileService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
                        return v0.getWhetherArchive();
                    }, DncEnums.WhetherArchive.not_Archive.getCode())).in((v0) -> {
                        return v0.getId();
                    }, workstationFileIds));*/
                }
            }
            List<DncArtFileAddVO> factoryList = dncArtFilesList.stream().filter(s3 -> {
                return DncEnums.FileOwnership.FACTORY.getCode().equals(s3.getFileOwnership());
            }).collect(Collectors.toList());
            if (Func.isNotEmpty(factoryList)) {
                List<Long> factoryIds = factoryList.stream().map((v0) -> {
                    return v0.getFileId();
                }).distinct().collect(Collectors.toList());
                if (Func.isNotEmpty(factoryIds)) {
                    this.dncFactoryFileService
                    .update(Wrappers.<DncFactoryFile>lambdaUpdate().set(DncFactoryFile::getWhetherArchive, DncEnums.WhetherArchive.not_Archive.getCode())
                      .in(DncFactoryFile::getId, factoryIds)); 
                    /*
                    this.dncFactoryFileService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
                        return v0.getWhetherArchive();
                    }, DncEnums.WhetherArchive.not_Archive.getCode())).in((v0) -> {
                        return v0.getId();
                    }, factoryIds));*/
                }
            }
            addArtFile(dncArtFilesList);
        }
        return bagFilesVO;
    }
 
    @Override // org.springblade.modules.dnc.service.IDncArtFileService
    public boolean duplicateValidationFile(DuplicateValidationFileVO validationFileVO) {
        String artBagId = validationFileVO.getArtBagId();
        List<ArtFileAddVO> artFileAddVOList = validationFileVO.getArtFileAddVOList();
        List<DncArtFile> list = new ArrayList<>();
        artFileAddVOList.forEach(file -> {
            String fileName = file.getFilename();
            Integer fileType = file.getFileType();
            DncArtFile dncArtFile = getDncArtFile(Long.valueOf(Long.parseLong(artBagId)), fileName, fileType);
            if (dncArtFile != null) {
                if (Func.isNotBlank(file.getObjectKey())) {
                    boolean result = this.obsFileService.verifyFileContent(file.getObjectKey(), dncArtFile.getContentMd5());
                    if (result) {
                        list.add(dncArtFile);
                    }
                } else if (!dncArtFile.getContentMd5().equals(file.getContentMd5())) {
                    list.add(dncArtFile);
                }
            }
        });
        return list.size() > 0;
    }
 
    @Override // org.springblade.modules.dnc.service.IDncArtFileService
    public List<DncArtFileVO> artFileList(String artBagId) {
        List<DncArtFile> list = list(Wrappers.<DncArtFile>lambdaQuery()
                .eq(DncArtFile::getArtBagId, artBagId)
                .eq(DncArtFile::getIsCurrent, DncEnums.CurrentVersion.YES.getCode()));
        /*
        List<DncArtFile> list = list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getArtBagId();
        }, artBagId)).eq((v0) -> {
            return v0.getIsCurrent();
        }, DncEnums.CurrentVersion.YES.getCode()));*/
        List<DncArtFileVO> dncArtFileVOList = Optional.<List<DncArtFileVO>>ofNullable(DncArtFileConvert.INSTANCE.convert(list)).orElse(new ArrayList<>());
        dncArtFileVOList.forEach(dncArtFileVO -> {
            User createUser = UserCache.getUser(dncArtFileVO.getCreateUser());
            dncArtFileVO.setCreateUserName(Func.isNotEmpty(createUser) ? createUser.getAccount() : "");
            User updateUser = UserCache.getUser(dncArtFileVO.getUpdateUser());
            dncArtFileVO.setUpdateUserName(Func.isNotEmpty(updateUser) ? updateUser.getAccount() : "");
            DncArtBag dncArtBag = (DncArtBag) this.dncArtBagService.getById(dncArtFileVO.getArtBagId());
            DncProcessCatalogue dncProcessCatalogue = (DncProcessCatalogue) this.dncProcessCatalogueService.getById(dncArtBag.getCatalogueId());
            String allPath = dncProcessCatalogue.getAllPath();
            String[] split = allPath.split("/");
            StringBuilder sourcePath = new StringBuilder();
            for (String s : split) {
                DncProcessCatalogue byId = (DncProcessCatalogue) this.dncProcessCatalogueService.getById(s);
                sourcePath.append("/").append(byId.getName());
            }
            String substring = sourcePath.append("/").append(dncArtBag.getName()).append("/").append(dncArtFileVO.getFilename()).substring(1);
            dncArtFileVO.setSourcePath(substring);
            dncArtFileVO.setVersionDesc(Func.isNotEmpty(dncArtFileVO.getVersion()) ? dncArtFileVO.getVersion() + CommonConstant.FILE_SUFFIX : "");
        });
        return dncArtFileVOList;
    }
 
    @Override // org.springblade.modules.dnc.service.IDncArtFileService
    public ArtFileInformationDTO getFileInformation(Long id) {
        ArtFileInformationDTO artFileInformationDTO = new ArtFileInformationDTO();
        DncArtFile dncArtFile = (DncArtFile) getById(id);
        if (Func.isEmpty(dncArtFile)) {
            return null;
        }
        Long artBagId = dncArtFile.getArtBagId();
        DncArtBag artBag = (DncArtBag) this.dncArtBagService.getById(artBagId);
        if (Func.isEmpty(artBag)) {
            return null;
        }
        Long catalogueId = artBag.getCatalogueId();
        DncProcessCatalogue dncProcessCatalogue = (DncProcessCatalogue) this.dncProcessCatalogueService.getById(catalogueId);
        String allPath = dncProcessCatalogue.getAllPath();
        String[] split = allPath.split("/");
        StringBuilder sourcePath = new StringBuilder();
        for (String s : split) {
            DncProcessCatalogue byId = (DncProcessCatalogue) this.dncProcessCatalogueService.getById(s);
            sourcePath.append("/").append(byId.getName());
        }
        String pathName = Joiner.on("/").join(Collections.singleton(sourcePath));
        artFileInformationDTO.setDncArtBag(artBag);
        artFileInformationDTO.setFileSourceNamePath(pathName);
        return artFileInformationDTO;
    }
 
    @Override // org.springblade.modules.dnc.service.IDncArtFileService
    public Map<Long, ArtFileInformationDTO> getArtFileInformationMap(List<Long> ids) {
        Map<Long, ArtFileInformationDTO> map = new HashMap<>(16);
        if (Func.isNotEmpty(ids)) {
            ids.forEach(id -> {
                ArtFileInformationDTO fileInformation = getFileInformation(id);
                map.put(id, fileInformation);
            });
        }
        return map;
    }
 
    @Override // org.springblade.modules.dnc.service.IDncArtFileService
    public boolean batchRemoveFile(List<String> ids) {
        List<DncArtFile> list = list(Wrappers.<DncArtFile>lambdaQuery().in(DncArtFile::getId, ids));
        /*
        List<DncArtFile> list = list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getId();
        }, ids));*/
        if (Func.isNotEmpty(list)) {
            list.forEach(s -> {
                DncArtBagLogDTO dncArtBagLogDTO = new DncArtBagLogDTO();
                dncArtBagLogDTO.setOperationType(DncEnums.TodoType.DEL.getCode()).setFileId(s.getFileId()).setFileName(s.getFilename()).setObjectKey(s.getObjectKey()).setSuffix(s.getSuffix()).setOperatorId(AuthUtil.getUserId()).setOperatorName(AuthUtil.getUserAccount()).setOperationTime(new Date()).setSourceType(s.getSourceType()).setLink(s.getLink()).setArtBagId(s.getArtBagId()).setArtFileId(s.getId()).setFileType(s.getFileType()).setFileBelong(s.getDocumentOwnership()).setVersion(s.getVersion()).setStorage(s.getStorageSpace());
                this.dncArtBagLogService.save(dncArtBagLogDTO);
            });
        }
        return removeByIds(Func.toLongList(ids));
    }
 
    private DncArtFile getDncArtFile(Long artBagId, String fileName, Integer fileType) {
        return getOne(Wrappers.<DncArtFile>lambdaQuery().eq(DncArtFile::getArtBagId, artBagId)
                .eq(DncArtFile::getIsCurrent, DncEnums.CurrentVersion.YES.getCode())
                .eq(DncArtFile::getFileType, fileType)
                .eq(DncArtFile::getFilename, fileName));
        /*
        return (DncArtFile) getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getArtBagId();
        }, artBagId)).eq((v0) -> {
            return v0.getIsCurrent();
        }, DncEnums.CurrentVersion.YES.getCode())).eq((v0) -> {
            return v0.getFileType();
        }, fileType)).eq((v0) -> {
            return v0.getFilename();
        }, fileName));*/
    }
 
    @Override // org.springblade.modules.dnc.service.IDncArtFileService
    public FileSourcePathVO getArtFileSourcePath(String fileId) {
        FileSourcePathVO fileSourcePathVO = new FileSourcePathVO();
        if (Func.isNotBlank(fileId)) {
            DncArtFile file = (DncArtFile) getById(fileId);
            DncArtBag dncArtBag = (DncArtBag) this.dncArtBagService.getById(file.getArtBagId());
            DncProcessCatalogue dncProcessCatalogue = (DncProcessCatalogue) this.dncProcessCatalogueService.getById(dncArtBag.getCatalogueId());
            String allPath = dncProcessCatalogue.getAllPath();
            String[] split = allPath.split("/");
            StringBuilder sourcePath = new StringBuilder();
            for (String s : split) {
                DncProcessCatalogue byId = (DncProcessCatalogue) this.dncProcessCatalogueService.getById(s);
                sourcePath.append("/").append(byId.getName());
            }
            String substring = sourcePath.append("/").append(dncArtBag.getName()).append("/").append(file.getFilename()).substring(1);
            fileSourcePathVO.setAllPathId(allPath);
            fileSourcePathVO.setAllPathName(substring);
        }
        return fileSourcePathVO;
    }
 
    @Override // org.springblade.modules.dnc.service.IDncArtFileService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean syncFile(SyncArtCatalogVO syncArtCatalogVO) {
        List<String> suffixes = this.fileService.getSuffix();
        
        DncProcessCatalogue root = this.dncProcessCatalogueService.getOne(Wrappers.<DncProcessCatalogue>lambdaQuery()
                .eq(DncProcessCatalogue::getParentId, Long.valueOf(Func.toLong(DncConstant.DNC_DEFAULT_PARENT_ID))));
        /*
        DncProcessCatalogue root = (DncProcessCatalogue) this.dncProcessCatalogueService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getParentId();
        }, Long.valueOf(Func.toLong(DncConstant.DNC_DEFAULT_PARENT_ID))));*/
        if (root != null) {
            String path = syncArtCatalogVO.getCatalog();
            boolean result = path.startsWith("/");
            String catalog = "/" + root.getName() + (result ? "" : "/") + syncArtCatalogVO.getCatalog();
            if (Func.isNotBlank(catalog)) {
                LinkedHashMap<String, String> nameMap = getNameMap(catalog);
                nameMap.forEach((k, v) -> {
                    Map<String, SyncDncProcessCatalogueVO> map = getCatalogueNameMap();
                    String parentPath = getParentName(k);
                    SyncDncProcessCatalogueVO parentCatalogue = map.get(parentPath);
                    SyncDncProcessCatalogueVO syncDncProcessCatalogueVO = map.get(k);
                    if (parentCatalogue != null && syncDncProcessCatalogueVO == null) {
                        DncProcessCatalogue dncProcessCatalogue = new DncProcessCatalogue();
                        dncProcessCatalogue.setParentId(parentCatalogue.getId());
                        dncProcessCatalogue.setName(v);
                        this.dncProcessCatalogueService.save(dncProcessCatalogue);
                        dncProcessCatalogue.setAllPath(parentCatalogue.getAllPath() + "/" + dncProcessCatalogue.getId());
                        this.dncProcessCatalogueService.updateById(dncProcessCatalogue);
                    }
                });
            }
            Map<String, SyncDncProcessCatalogueVO> catalogueNameMap = getCatalogueNameMap();
            SyncDncProcessCatalogueVO syncDncProcessCatalogueVO = catalogueNameMap.get(catalog);
            if (syncDncProcessCatalogueVO != null) {
                Long catalogued = syncDncProcessCatalogueVO.getId();
                List<DncArtBag> artBags = this.dncArtBagService.list();
                Map<String, DncArtBag> artBagMap = artBags.stream().collect(Collectors.toMap(s -> {
                    return s.getCode() + "#" + s.getName() + "#" + s.getCatalogueId();
                }, Function.identity()));
                List<SyncArtBagVO> artBagList = syncArtCatalogVO.getArtBag();
                if (Func.isNotEmpty(artBagList)) {
                    artBagList.forEach(s2 -> {
                        String artBag = s2.getCode() + "#" + s2.getName() + "#" + catalogued;
                        DncArtBag dncArtBag = (DncArtBag) artBagMap.get(artBag);
                        if (dncArtBag == null) {
                            DncArtBag bag = new DncArtBag();
                            bag.setName(s2.getName());
                            bag.setCode(s2.getCode());
                            bag.setCatalogueId(catalogued);
                            this.dncArtBagService.save(bag);
                        }
                        DncArtBag currentArtBag = this.dncArtBagService.getOne(Wrappers.<DncArtBag>lambdaQuery()
                                .eq(DncArtBag::getCatalogueId, catalogued)
                                .eq(DncArtBag::getCode, s2.getCode())
                                .eq(DncArtBag::getName, s2.getName()));
                        /*
                        DncArtBag currentArtBag = (DncArtBag) this.dncArtBagService.getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
                            return v0.getCatalogueId();
                        }, catalogued)).eq((v0) -> {
                            return v0.getCode();
                        }, s2.getCode())).eq((v0) -> {
                            return v0.getName();
                        }, s2.getName()));*/
                        if (currentArtBag != null) {
                            addSync(currentArtBag, s2.getFileList(), suffixes);
                        }
                    });
                }
            }
        }
        return Boolean.TRUE;
    }
 
    private Map<String, SyncDncProcessCatalogueVO> getCatalogueNameMap() {
        List<DncProcessCatalogue> list = this.dncProcessCatalogueService.list();
        List<SyncDncProcessCatalogueVO> catalogues = list.stream().map(s -> {
            SyncDncProcessCatalogueVO syncDncProcessCatalogueVO = new SyncDncProcessCatalogueVO();
            syncDncProcessCatalogueVO.setId(s.getId());
            syncDncProcessCatalogueVO.setName(s.getName());
            syncDncProcessCatalogueVO.setAllPath(s.getAllPath());
            syncDncProcessCatalogueVO.setAllPathName(pathName(s.getAllPath(), list));
            return syncDncProcessCatalogueVO;
        }).collect(Collectors.toList());
        return catalogues.stream().filter(s2 -> {
            return Func.isNotBlank(s2.getAllPathName());
        }).collect(Collectors.toMap((v0) -> {
            return v0.getAllPathName();
        }, Function.identity()));
    }
 
    private void addSync(DncArtBag currentArtBag, List<SyncArtBagFileVO> fileList, List<String> suffixes) {
        if (Func.isNotEmpty(fileList)) {
            Long artBagId = currentArtBag.getId();
            List<DncArtFile> list = list(Wrappers.<DncArtFile>lambdaQuery().eq(DncArtFile::getArtBagId, artBagId));
           
            if (Func.isEmpty(list)) {
                saveBatch(addDncArtFiles(artBagId, fileList, suffixes));
                return;
            }
            List<SyncArtBagFileVO> files = new ArrayList<>();
            Map<String, DncArtFile> dncArtFileMap = list.stream().filter(c -> {
                return DncEnums.CurrentVersion.YES.getCode().equals(c.getIsCurrent());
            }).collect(Collectors.toMap(s -> {
                return s.getArtBagId() + "$" + s.getFilename();
            }, Function.identity()));
            fileList.forEach(s2 -> {
                String fileName = s2.getFileName();
                DncArtFile dncArtFile = (DncArtFile) dncArtFileMap.get(artBagId + "$" + fileName);
                if (dncArtFile == null) {
                    files.add(s2);
                }
                if (dncArtFile != null) {
                    Integer current = dncArtFile.getVersion();
                    Integer now = s2.getFileVersion();
                    if (!current.equals(now) && now.intValue() > current.intValue()) {
                        dncArtFile.setIsCurrent(DncEnums.CurrentVersion.NO.getCode());
                        updateById(dncArtFile);
                        files.add(s2);
                    }
                }
            });
            if (Func.isNotEmpty(files)) {
                saveBatch(addDncArtFiles(artBagId, files, suffixes));
            }
        }
    }
 
    private List<DncArtFile> addDncArtFiles(Long artBagId, List<SyncArtBagFileVO> fileList, List<String> suffixes) {
        boolean notSuffix = suffixes.contains(CommonConstant.NOT_SUFFIX);
        return fileList.stream().map(s -> {
            DncArtFile dncArtFile = new DncArtFile();
            dncArtFile.setArtBagId(artBagId);
            dncArtFile.setLink(s.getFileLink());
            dncArtFile.setFilename(s.getFileName());
            dncArtFile.setOriginalFilename(s.getFileName());
            dncArtFile.setContentLength(s.getContentLength());
            dncArtFile.setSuffix(s.getSuffix());
            try {
                int linkMd5HashCode = StringMd5HashCode.getMd5(s.getFileLink() + s.getFileVersion()).hashCode();
                dncArtFile.setContentMd5(String.valueOf(linkMd5HashCode));
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
            if (suffixes.contains(s.getSuffix()) || (notSuffix && Func.isBlank(s.getSuffix()))) {
                dncArtFile.setFileType(DncEnums.FileType.PROCESSING_PROGRAM.getCode());
            } else {
                dncArtFile.setFileType(DncEnums.FileType.PROCESS_DOCUMENTS.getCode());
            }
            dncArtFile.setIsCurrent(DncEnums.CurrentVersion.YES.getCode());
            dncArtFile.setVersion(s.getFileVersion());
            return dncArtFile;
        }).collect(Collectors.toList());
    }
 
    private String getParentName(String catalog) {
        int i = catalog.lastIndexOf("/");
        return catalog.substring(0, i);
    }
 
    private String pathName(String pathIds, List<DncProcessCatalogue> list) {
        Map<Long, DncProcessCatalogue> catalogueMap = list.stream().collect(Collectors.toMap((v0) -> {
            return v0.getId();
        }, Function.identity()));
        String[] split = pathIds.split("/");
        StringBuilder pathName = new StringBuilder();
        for (String id : split) {
            DncProcessCatalogue dncProcessCatalogue = catalogueMap.get(Long.valueOf(Func.toLong(id)));
            if (dncProcessCatalogue != null) {
                pathName.append("/").append(dncProcessCatalogue.getName());
            } else {
                return "";
            }
        }
        return pathName.toString();
    }
 
    private LinkedHashMap<String, String> getNameMap(String catalog) {
        LinkedHashMap<String, String> map = new LinkedHashMap<>(16);
        List<Integer> characterPosition = getCharacterPosition(catalog);
        for (Integer i : characterPosition) {
            if (i.intValue() != 0) {
                String path = catalog.substring(0, i.intValue());
                String catalogName = path.substring(path.lastIndexOf("/") + 1);
                map.put(path, catalogName);
            }
        }
        map.put(catalog, catalog.substring(catalog.lastIndexOf("/") + 1));
        return map;
    }
 
    public static List<Integer> getCharacterPosition(String catalog) {
        List<Integer> positions = new ArrayList<>();
        int indexOf = catalog.indexOf("/");
        while (true) {
            int a = indexOf;
            if (a != -1) {
                System.out.print(a + "\t");
                positions.add(Integer.valueOf(a));
                indexOf = catalog.indexOf("/", a + 1);
            } else {
                return positions;
            }
        }
    }
}