yangys
2025-09-29 4c7296d45efe849dc70a3b2e2240c905481a91c9
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
package org.springblade.mdm.machinefile.listeners;
 
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.mdm.flow.entity.MesSync;
import org.springblade.mdm.flow.entity.TaskDispatch;
import org.springblade.mdm.flow.excution.events.CureFinishedEvent;
import org.springblade.mdm.flow.service.MesSyncService;
import org.springblade.mdm.flow.service.TaskDispatchService;
import org.springblade.mdm.machinefile.entity.MachineAcceptedFile;
import org.springblade.mdm.machinefile.entity.MachineFile;
import org.springblade.mdm.machinefile.events.ExportedToInnerEvent;
import org.springblade.mdm.machinefile.service.MachineAcceptedFileService;
import org.springblade.mdm.machinefile.service.MachineFileService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.List;
import java.util.Optional;
 
/**
 * 视情况将已经导出的现场编程文件,保存到PROGRAM文件夹
 */
@Slf4j
@Component
public class ExportToInnerListener {
    @Autowired
    private MachineFileService machineFileService;
    @Autowired
    private MachineAcceptedFileService machineAcceptedService;
 
    @EventListener(value = ExportedToInnerEvent.class)
    public void hello(ExportedToInnerEvent event) {
        //已经导出到涉密网事件,检查是否有导出的现场编程数据。如果有则加入program文件夹
        if(Func.isEmpty(event.getAcceptedFiles())){
            return;
        }
        List<MachineFile> onMachineFiles = machineAcceptedService.exportedProgramOnMachineFiles(event.getAcceptedFiles());
 
        //保存入program
        saveOrUpdateToProgramFolder(onMachineFiles,event.getAcceptedFiles());
    }
 
    /**
     * 更新或爆粗文件到program文件夹
     * @param onMachineFiles 现场编程文件列表
     * @param acceptedFiles 导出涉密网的文件列表
     */
    void saveOrUpdateToProgramFolder(List<MachineFile> onMachineFiles,List<MachineAcceptedFile> acceptedFiles){
 
        for(MachineFile machineFile : onMachineFiles){
            Optional<MachineAcceptedFile> accFileOpt = acceptedFiles.stream().filter(a -> a.getMachineFileId().equals(machineFile.getId())).findFirst();
            if(accFileOpt.isEmpty()){
                continue;
            }
 
            MachineFile existsFile = machineFileService.getByNameAndMachineInDir(machineFile.getName(),machineFile.getMachineCode(),MachineFile.DIR_TYPE_PROGRAM);
            if(existsFile != null){
                BeanUtils.copyProperties(machineFile,existsFile);
 
                existsFile.setDirType(MachineFile.DIR_TYPE_PROGRAM);
                existsFile.setOssName(accFileOpt.get().getOssName());
                existsFile.setStatus(MachineFile.STATUS_NORMAL);
                existsFile.setOssName(existsFile.getOssName());
                machineFileService.updateById(existsFile);
            }else{
                MachineFile newProgFile = new MachineFile();
                BeanUtils.copyProperties(machineFile,newProgFile);
                newProgFile.setDirType(MachineFile.DIR_TYPE_PROGRAM);
                newProgFile.setStatus(MachineFile.STATUS_NORMAL);
                newProgFile.setOssName(accFileOpt.get().getOssName());
                newProgFile.setId(null);
                machineFileService.save(newProgFile);
            }
        }
 
 
    }
 
}