刘光辉
昨天 bb638871a7fb692d80f1b7a758f991dc0879002c
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
package jnpf.base.service.impl;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.UUID;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
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.model.base.SystemPageVO;
import jnpf.base.service.SuperServiceImpl;
import jnpf.base.service.SystemService;
import jnpf.constant.CodeConst;
import jnpf.constant.JnpfConst;
import jnpf.constant.MsgCode;
import jnpf.constant.PermissionConst;
import jnpf.exception.DataException;
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 lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.Objects;
 
/**
 * 系统
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date 2019年9月27日 上午9:18
 */
@Service
@RequiredArgsConstructor
public class SystemServiceImpl extends SuperServiceImpl<SystemMapper, SystemEntity> implements SystemService {
 
 
    private final RoleApi roleApi;
 
    private final UserApi userApi;
 
 
    private final ModuleMapper moduleMapper;
 
    @Override
    public List<SystemEntity> getList() {
        return this.baseMapper.getList();
    }
 
    @Override
    public List<SystemEntity> getList(String keyword, boolean verifyAuth, boolean filterMain) {
        SystemPageVO pageVO = new SystemPageVO();
        pageVO.setKeyword(keyword);
        if (!verifyAuth) {
            pageVO.setType(null);
        } else {
            pageVO.setType(1);
        }
        pageVO.setFilterMain(filterMain);
        return this.baseMapper.getList(pageVO);
    }
 
    @Override
    public List<SystemEntity> getList(SystemPageVO pageVO) {
        return this.baseMapper.getList(pageVO);
    }
 
    @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
    @DSTransactional
    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
    @DSTransactional
    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
    @DSTransactional
    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 (Boolean.TRUE.equals(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);
    }
 
    @Override
    public void importCopy(SystemEntity entity, boolean isImport) {
        if (Boolean.TRUE.equals(isExistFullName(entity.getId(), entity.getFullName()))) {
            String copyNum = UUID.randomUUID().toString().substring(0, 5);
            String fullName = entity.getFullName() + ".副本" + copyNum;
            if (fullName.length() > 50) {
                throw new DataException(MsgCode.PRI006.get());
            }
            entity.setFullName(fullName);
        }
        entity.setEnCode(null);
        entity.setAppPortalId(null);
        entity.setPortalId(null);
        entity.setLastModifyTime(null);
        entity.setLastModifyUserId(null);
        if (isImport && !PermissionConst.ALL_DEV_USER.equals(entity.getAuthorizeId())) {
            entity.setAuthorizeId(null);
        }
        this.create(entity);
    }
 
    @Override
    public List<SystemEntity> getMainList() {
        return this.baseMapper.getMainList();
    }
}