lyh
2025-06-25 e756af0f5bfd1addbd5d5c145441fb34aad91a28
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
package org.jeecg.modules.dncFlow.service.impl;
 
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.dnc.entity.DeviceType;
import org.jeecg.modules.dnc.entity.PermissionStreamNew;
import org.jeecg.modules.dnc.exception.ExceptionCast;
import org.jeecg.modules.dnc.response.ActivitiCode;
import org.jeecg.modules.dnc.service.IDeviceTypeService;
import org.jeecg.modules.dncFlow.adapter.AssignEquipmentFileStreamAdapter;
import org.jeecg.modules.dncFlow.adapter.AssignFileStreamAdapter;
import org.jeecg.modules.dncFlow.adapter.DispatchFileAdapter;
import org.jeecg.modules.dncFlow.entity.AssignEquipmentFileStream;
import org.jeecg.modules.dncFlow.entity.AssignFileStream;
import org.jeecg.modules.dncFlow.entity.DispatchFile;
import org.jeecg.modules.dncFlow.handler.*;
import org.jeecg.modules.dncFlow.service.PermissionHandler;
import org.jeecg.modules.dncFlow.service.StreamTarget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
@Service
public class PermissionService {
    @Autowired
    private PermissionProcessor processor;
 
    @Autowired
    private ProductHandler productHandler;
 
    @Autowired
    private ComponentHandler componentHandler;
 
    @Autowired
    private PartsHandler partsHandler;
 
    @Autowired
    private ProcessSpecVersionHandle processSpecVersionHandler;
 
    @Autowired
    private ProcessHandle processHandler;
 
    @Autowired
    private WorkStepHandle workStepHandler;
 
    @Autowired
    private IDeviceTypeService deviceTypeService;
 
    public PermissionStreamNew getPermissionStreams(DispatchFile file) {
        return processInternal(new DispatchFileAdapter(file), file.getAttributionType());
    }
 
    public PermissionStreamNew getPermissionStreams(AssignFileStream stream) {
        return processInternal(new AssignFileStreamAdapter(stream), stream.getAttributionType());
    }
 
    public PermissionStreamNew getPermissionStreams(AssignEquipmentFileStream stream) {
        return processInternal(new AssignEquipmentFileStreamAdapter(stream), stream.getAttributionType());
    }
 
    private PermissionStreamNew processInternal(StreamTarget target, String attributionType) {
        LoginUser user = getCurrentUser();
        String resolvedId = resolveAttributionId(target.getAttributionId());
 
        PermissionHandler<?> handler = resolveHandler(attributionType);
        return processor.process(resolvedId, user, target, handler);
    }
 
    private String resolveAttributionId(String AttributionId) {
        DeviceType deviceType = deviceTypeService.getById(AttributionId);
        if (deviceType == null) {
            return AttributionId;
        }else {
            return deviceType.getAttributionId();
        }
    }
 
    private PermissionHandler<?> resolveHandler(String type) {
        switch (type) {
            case "1": return productHandler;
            case "2": return componentHandler;
            case "3": return partsHandler;
            case "4": return processSpecVersionHandler;
            case "5": return processHandler;
            case "6": return workStepHandler;
            default:
                ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE);
                return null; // 实际不会执行
        }
    }
 
    private LoginUser getCurrentUser() {
        return (LoginUser) SecurityUtils.getSubject().getPrincipal();
    }
}