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
package org.jeecg.modules.dncFlow.handler;
 
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.dnc.entity.PermissionStreamNew;
import org.jeecg.modules.dnc.exception.ExceptionCast;
import org.jeecg.modules.dnc.response.CommonCode;
import org.jeecg.modules.dnc.service.IDeviceTypeService;
import org.jeecg.modules.dnc.service.IPermissionStreamNewService;
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.Component;
 
import java.util.Optional;
 
@Component
public class PermissionProcessor {
    @Autowired
    private IDeviceTypeService deviceTypeService;
 
    @Autowired
    private IPermissionStreamNewService permissionStreamNewService;
 
    public <T> PermissionStreamNew process(
            String attributionId,
            LoginUser user,
            StreamTarget target,
            PermissionHandler<T> handler
    ) {
        // 1. 加载业务实体
        T entity = handler.loadEntity(attributionId);
        if (entity == null) {
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        }
 
        // 2. 设置关联关系
        handler.setRelations(entity, target);
 
        // 3. 设置设备类型
        setupDeviceType(target);
 
        // 4. 获取权限流
        return permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(
                handler.getBusinessId(entity),
                user.getId(),
                handler.getTypeCode()
        );
    }
 
    private void setupDeviceType(StreamTarget target) {
        Optional.ofNullable(deviceTypeService.getById(target.getAttributionId()))
                .ifPresent(device ->
                        target.setDeviceTypeId(device.getId())
                );
    }
}