ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
package jnpf.base.service.impl;
 
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jnpf.base.entity.ModuleEntity;
import jnpf.base.entity.SystemEntity;
import jnpf.base.mapper.ModuleMapper;
import jnpf.base.mapper.SystemMapper;
import jnpf.base.model.AppAuthorizationModel;
import jnpf.base.service.SuperServiceImpl;
import jnpf.base.service.SystemService;
import jnpf.constant.CodeConst;
import jnpf.constant.JnpfConst;
import jnpf.constant.PermissionConst;
import jnpf.permission.RoleApi;
import jnpf.permission.UserApi;
import jnpf.permission.entity.RoleEntity;
import jnpf.permission.entity.UserEntity;
import jnpf.permission.model.user.WorkHandoverModel;
import jnpf.permission.util.CodeNumUtil;
import jnpf.util.RandomUtil;
import jnpf.util.StringUtil;
import jnpf.util.UserProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
import java.util.Objects;
 
/**
 * 系统
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date 2019年9月27日 上午9:18
 */
@Service
public class SystemServiceImpl extends SuperServiceImpl<SystemMapper, SystemEntity> implements SystemService {
 
    @Autowired
    private RoleApi roleApi;
    @Autowired
    private UserApi userApi;
 
    @Autowired
    private ModuleMapper moduleMapper;
 
    @Override
    public List<SystemEntity> getList() {
        return this.baseMapper.getList();
    }
 
    @Override
    public List<SystemEntity> getList(String keyword, Boolean filterEnableMark, boolean verifyAuth, Boolean filterMain, boolean isList, List<String> moduleAuthorize) {
        return this.baseMapper.getList(keyword, filterEnableMark, verifyAuth, filterMain, isList, moduleAuthorize);
    }
 
    @Override
    public List<SystemEntity> getListByIdsKey(List<String> ids, String keyword) {
        return this.baseMapper.getListByIdsKey(ids, keyword);
    }
 
    @Override
    public SystemEntity getInfo(String id) {
        return this.baseMapper.getInfo(id);
    }
 
    @Override
    public Boolean isExistFullName(String id, String fullName) {
        return this.baseMapper.isExistFullName(id, fullName);
    }
 
    @Override
    public Boolean isExistEnCode(String id, String enCode) {
        return this.baseMapper.isExistEnCode(id, enCode);
    }
 
    @Override
    @Transactional
    public Boolean create(SystemEntity entity) {
        if (StringUtil.isEmpty(entity.getEnCode())) {
            entity.setEnCode(CodeNumUtil.getCodeFunction(CodeConst.YY, code -> this.isExistEnCode(null, code)));
        }
        this.baseMapper.create(entity);
        //创建审批中心菜单
        this.createWorkMenu(entity.getId());
        return true;
    }
 
    private void createWorkMenu(String systemId) {
        SystemEntity workFlowSys = this.baseMapper.getInfoByEnCode(JnpfConst.WORK_FLOW_CODE);
        QueryWrapper<ModuleEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(ModuleEntity::getEnCode, JnpfConst.MODULE_CODE);
        queryWrapper.lambda().eq(ModuleEntity::getSystemId, workFlowSys.getId());
        List<ModuleEntity> list = moduleMapper.selectList(queryWrapper);
        String parentId;
        //审批中心 目录id
        String workId = RandomUtil.uuId();
        for (ModuleEntity item : list) {
            String id = RandomUtil.uuId();
            ModuleEntity moduleEntity = BeanUtil.copyProperties(item, ModuleEntity.class);
            if (JnpfConst.WORK_FLOW_CODE.equals(moduleEntity.getEnCode())) {
                parentId = "-1";
                id = workId;
                moduleEntity.setSortCode(0l);
            } else {
                parentId = workId;
            }
            moduleEntity.setId(id);
            moduleEntity.setSystemId(systemId);
            moduleEntity.setParentId(parentId);
            moduleMapper.insert(moduleEntity);
        }
        String appParentId;
        //APP审批中心 目录id
        String appWorkId = RandomUtil.uuId();
        for (ModuleEntity item : list) {
            if (JnpfConst.WORK_FLOWQUICKLAUNCH.equalsIgnoreCase(item.getEnCode())) continue;
            String appId = RandomUtil.uuId();
            ModuleEntity moduleEntity = BeanUtil.copyProperties(item, ModuleEntity.class);
            if (JnpfConst.WORK_FLOW_CODE.equals(moduleEntity.getEnCode())) {
                appParentId = "-1";
                appId = appWorkId;
                moduleEntity.setSortCode(0l);
            } else {
                appParentId = appWorkId;
            }
            moduleEntity.setId(appId);
            moduleEntity.setCategory(JnpfConst.APP);
            moduleEntity.setSystemId(systemId);
            moduleEntity.setParentId(appParentId);
            moduleMapper.insert(moduleEntity);
        }
    }
 
    @Override
    @Transactional
    public Boolean update(String id, SystemEntity entity) {
        if (StringUtil.isEmpty(entity.getEnCode())) {
            entity.setEnCode(CodeNumUtil.getCodeFunction(CodeConst.YY, code -> this.isExistEnCode(id, code)));
        }
        return this.baseMapper.update(id, entity);
    }
 
    @Override
    @Transactional
    public Boolean delete(String id) {
        moduleMapper.deleteBySystemId(id);
        return this.removeById(id);
    }
 
    @Override
    public List<SystemEntity> getListByIds(List<String> list, List<String> moduleAuthorize) {
        return this.baseMapper.getListByIds(list, moduleAuthorize);
    }
 
    @Override
    public SystemEntity getInfoByEnCode(String enCode) {
        return this.baseMapper.getInfoByEnCode(enCode);
    }
 
    @Override
    public List<SystemEntity> findSystemAdmin(List<String> moduleAuthorize) {
        return this.baseMapper.findSystemAdmin(moduleAuthorize);
    }
 
    @Override
    public boolean saveSystemAuthorizion(AppAuthorizationModel model) {
        return this.baseMapper.saveSystemAuthorizion(model);
    }
 
    @Override
    public List<SystemEntity> getAuthListByUser(String userId, Boolean isStand) {
        UserEntity user = userApi.getInfoById(userId);
        List<RoleEntity> userRoles = roleApi.getUserRoles(userId);
        boolean isDevRole = userRoles.stream().anyMatch(t -> PermissionConst.DEVELOPER_CODE.equals(t.getEnCode()));
        if (isStand) {
            isDevRole = UserProvider.getUser().getIsDevRole();
        }
        boolean isAdmin = Objects.equals(user.getIsAdministrator(), 1);
 
        QueryWrapper<SystemEntity> queryWrapper = new QueryWrapper<>();
        //开发人员才有编辑权限
        if (isDevRole || isAdmin) {
            //判断权限列表
            if (!isAdmin) {
                queryWrapper.lambda().eq(SystemEntity::getUserId, userId).or();
                queryWrapper.lambda().like(SystemEntity::getAuthorizeId, userId).or();
                queryWrapper.lambda().eq(SystemEntity::getAuthorizeId, PermissionConst.ALL_DEV_USER);
            }
        } else {
            queryWrapper.lambda().eq(SystemEntity::getUserId, userId);
        }
        return list(queryWrapper);
    }
 
    @Override
    public void workHandover(WorkHandoverModel workHandoverModel) {
        this.baseMapper.workHandover(workHandoverModel);
    }
 
    @Override
    public void changeSystemAuthorizion(AppAuthorizationModel model) {
        this.baseMapper.changeSystemAuthorizion(model);
    }
 
    @Override
    public List<SystemEntity> getListByIds(List<String> list, List<String> moduleAuthorize, int type) {
        return this.baseMapper.getListByIds(list, moduleAuthorize, type);
    }
 
    @Override
    public List<SystemEntity> getListByCreUser(String userId) {
        return this.baseMapper.getListByCreUser(userId);
    }
 
}