fix
Helius
2021-08-05 8bbb027dc36b3f3c7f2d505fc75180261fb4d640
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
package com.xzx.gc.user.service;
 
 
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.xzx.gc.common.constant.CommonEnum;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.constant.UserEnum;
import com.xzx.gc.entity.OtherUserInfo;
import com.xzx.gc.entity.UserAuth;
import com.xzx.gc.entity.UserRole;
import com.xzx.gc.model.dto.FunctionNodeView;
import com.xzx.gc.user.mapper.OtherUserMapper;
import com.xzx.gc.user.mapper.UserAuthMapper;
import com.xzx.gc.user.mapper.UserRoleMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;
 
@Service
@Transactional
@Slf4j
public class UserAuthService {
 
    @Autowired
    private UserAuthMapper userAuthMapper;
 
    @Autowired
    private UserRoleMapper userRoleMapper;
 
    @Autowired
    private OtherUserMapper otherUserMapper;
 
    @Autowired
    private OtherUserService otherUserService;
 
    /**
     * @param userId
     * @param homePageType 0:查询权限,1:查询首页
     * @return
     */
    public List<UserAuth> findMenu(String userId, int homePageType) {
        List<UserAuth> list = new ArrayList<>();
        OtherUserInfo otherUserInfo = otherUserMapper.selectByPrimaryKey(userId);
        String mobilePhone = otherUserInfo.getMobilePhone();
 
        List<OtherUserInfo> select = otherUserService.findByMobile(mobilePhone);
 
        String roleIds = select.stream().map(OtherUserInfo::getRoleIds).collect(Collectors.joining(","));
        String userIds = select.stream().map(OtherUserInfo::getUserId).collect(Collectors.joining(","));
        String userTypes = select.stream().map(OtherUserInfo::getUserType).collect(Collectors.joining(","));
        if (StrUtil.isNotBlank(roleIds) && !Constants.NULL.equals(roleIds)) {
            String[] split = roleIds.split(",");
            String[] split2 = userIds.split(",");
            String[] split3 = userTypes.split(",");
 
            for (int i = 0; i < split.length; i++) {
                String roleId = split[i];
                String authUserId = split2[i];
                String authUserType = split3[i];
                if (StrUtil.isNotBlank(roleId) && !Constants.NULL.equals(roleId)) {
                    UserRole userRole = userRoleMapper.selectByPrimaryKey(roleId);
 
                    if (userRole != null && StrUtil.isNotBlank(userRole.getAuthIds())) {
                        String authIds = userRole.getAuthIds();
                        String roleCode = userRole.getRoleCode();
 
                        String[] split1 = authIds.split(",");
 
                        for (String authId : split1) {
                            if (StrUtil.isNotBlank(authId)) {
                                UserAuth userAuth = userAuthMapper.selectByPrimaryKey(authId);
                                if (0 == userAuth.getDelFlag()) {
                                    if (CommonEnum.回收员.getValue().equals(roleCode) && UserEnum.统计.getValue().equals(userAuth.getAuthCode())) {
                                        userAuth.setAuthName("回收" + userAuth.getAuthName());
                                    } else if (CommonEnum.入库员.getValue().equals(roleCode) && UserEnum.统计.getValue().equals(userAuth.getAuthCode())) {
                                        userAuth.setAuthName("入库" + userAuth.getAuthName());
                                    }
                                    userAuth.setUserId(authUserId);
                                    userAuth.setUserType(authUserType);
                                    list.add(userAuth);
                                }
                            }
                        }
 
                    }
 
                }
            }
        }
 
        //list去重
        list = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparingLong(UserAuth::getId))), ArrayList::new));
 
        if(homePageType==0) {
            //过滤掉可配置的首页的
            list = list.stream().filter(x -> x.getHomePageFlag() == null || Convert.toShort(0).equals(x.getHomePageFlag())).collect(Collectors.toList());
        }else if(homePageType==1){
            //只查询首页的
            list = list.stream().filter(x -> x.getHomePageFlag() != null && Convert.toShort(1).equals(x.getHomePageFlag())).collect(Collectors.toList());
        }
 
        return list;
 
    }
 
 
    public List<FunctionNodeView> buildViewList() {
        List<FunctionNodeView> viewList = new ArrayList<>();
        List<UserAuth> list = userAuthMapper.selectAll();
        //客户管理
        FunctionNodeView userManager = new FunctionNodeView();
        userManager.setCode("KH");
        userManager.setName("客户管理");
        userManager.setId(Long.parseLong("10000"));
        List<FunctionNodeView> userChildren = new ArrayList<>();
        //数据统计
        FunctionNodeView dateManager = new FunctionNodeView();
        dateManager.setCode("SJ");
        dateManager.setName("数据统计");
        dateManager.setId(Long.parseLong("10001"));
        List<FunctionNodeView> dateChildren = new ArrayList<>();
        //物品价格
        FunctionNodeView productManager = new FunctionNodeView();
        productManager.setCode("WP");
        productManager.setName("工作管理");
        productManager.setId(Long.parseLong("10002"));
        List<FunctionNodeView> productChildren = new ArrayList<>();
        for (UserAuth authInfo : list) {
 
            if (authInfo.getCategoryCode().equals(userManager.getCode())) {
                FunctionNodeView uc = new FunctionNodeView();
                uc.setName(authInfo.getAuthName());
                uc.setCode(authInfo.getAuthCode());
                uc.setId(authInfo.getId());
                userChildren.add(uc);
            } else if (authInfo.getCategoryCode().equals(dateManager.getCode())) {
                FunctionNodeView uc = new FunctionNodeView();
                uc.setName(authInfo.getAuthName());
                uc.setCode(authInfo.getAuthCode());
                uc.setId(authInfo.getId());
                dateChildren.add(uc);
            } else {
                FunctionNodeView uc = new FunctionNodeView();
                uc.setName(authInfo.getAuthName());
                uc.setCode(authInfo.getAuthCode());
                uc.setId(authInfo.getId());
                productChildren.add(uc);
            }
        }
        userManager.setChildren(userChildren);
        dateManager.setChildren(dateChildren);
        productManager.setChildren(productChildren);
        viewList.add(userManager);
        viewList.add(dateManager);
        viewList.add(productManager);
        return viewList;
    }
 
 
}