ny
23 小时以前 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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
package jnpf.base.controller;
 
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.nacos.shaded.com.google.common.collect.ImmutableMap;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.base.ActionResult;
import jnpf.base.Pagination;
import jnpf.base.SystemApi;
import jnpf.base.UserInfo;
import jnpf.base.entity.ModuleEntity;
import jnpf.base.entity.SystemEntity;
import jnpf.base.model.AppAuthorizationModel;
import jnpf.base.model.AppAuthorizeVo;
import jnpf.base.model.UserAuthorize;
import jnpf.base.model.base.*;
import jnpf.base.model.module.MenuListModel;
import jnpf.base.service.CommonWordsService;
import jnpf.base.service.ModuleService;
import jnpf.base.service.SystemService;
import jnpf.base.vo.ListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.constant.JnpfConst;
import jnpf.constant.MsgCode;
import jnpf.constant.PermissionConst;
import jnpf.constant.model.MCode;
import jnpf.emnus.SysParamEnum;
import jnpf.message.NoticeApi;
import jnpf.permission.AuthorizeApi;
import jnpf.permission.RoleApi;
import jnpf.permission.RoleRelationApi;
import jnpf.permission.UserApi;
import jnpf.permission.entity.RoleEntity;
import jnpf.permission.entity.RoleRelationEntity;
import jnpf.permission.entity.UserEntity;
import jnpf.permission.model.authorize.AuthorizeVO;
import jnpf.permission.model.rolerelaiton.RoleRelationModel;
import jnpf.permission.model.user.UserSystemCountModel;
import jnpf.permission.model.user.WorkHandoverModel;
import jnpf.permission.model.user.vo.BaseInfoVo;
import jnpf.util.JsonUtil;
import jnpf.util.UploaderUtil;
import jnpf.util.UserProvider;
import org.apache.commons.collections4.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 应用中心
 *
 * @author :JNPF开发平台组
 * @version: V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date :2022/6/21 15:33
 */
@Tag(name = "系统", description = "system")
@RestController
@RequestMapping("/System")
public class SystemController extends SuperController<SystemService, SystemEntity> implements SystemApi {
 
    @Autowired
    private RoleApi roleService;
    @Autowired
    private RoleRelationApi roleRelationService;
    @Autowired
    private UserApi userApi;
    @Autowired
    private SystemService systemService;
    @Autowired
    private CommonWordsService commonWordsService;
    @Autowired
    private ModuleService moduleService;
    @Autowired
    private AuthorizeApi authorizeService;
    @Autowired
    private NoticeApi noticeApi;
 
    @Operation(summary = "应用列表")
    @SaCheckPermission(value = {"appCenter", "workFlow.flowQuickLaunch", "teamwork.printTemplate", "monitor.flowMonitor", "monitor.userOnline"}, mode = SaMode.OR)
    @GetMapping
    public ActionResult<ListVO<SystemListVO>> list(SystemPageVO page) {
        Boolean enabledMark = false;
        if (ObjectUtil.equal(page.getEnabledMark(), "0")) {
            enabledMark = null;
        }
        if (ObjectUtil.equal(page.getEnabledMark(), "1")) {
            enabledMark = true;
        }
        List<SystemEntity> list = systemService.getList(page.getKeyword(), enabledMark, true, true, true, new ArrayList<>());
        List<SystemListVO> jsonToList = JsonUtil.getJsonToList(list, SystemListVO.class);
        //有修改权限列表
        List<String> authList = systemService.getAuthListByUser(UserProvider.getUser().getUserId(), true).stream().map(SystemEntity::getId).collect(Collectors.toList());
        UserInfo user = UserProvider.getUser();
        for (SystemListVO vo : jsonToList) {
            vo.setHasDelete(user.getIsAdministrator() || user.getUserId().equals(vo.getUserId()) ? 1 : 0);
            vo.setHasUpdate(user.getIsAdministrator() || authList.contains(vo.getId()) ? 1 : 0);
        }
        return ActionResult.success(new ListVO<>(jsonToList));
    }
 
    @Operation(summary = "获取应用授权信息")
    @SaCheckPermission(value = {"appConfig.appAuth"})
    @GetMapping("/getAppAuthorization/{systemId}")
    public ActionResult<AppAuthorizeVo> getAppAuthorization(@PathVariable String systemId) {
        Pagination pagination = new Pagination();
        AppAuthorizeVo appAuthorizeVo = new AppAuthorizeVo();
        SystemEntity info = systemService.getInfo(systemId);
        if (BeanUtil.isEmpty(info)) {
            return ActionResult.fail(MsgCode.FA001.getDesc());
        }
        String userId = "";
        String authorizeId = "";
        List<BaseInfoVo> baseInfoVos = new ArrayList<>();
        if (null == info.getUserId() || info.getUserId().isEmpty()) {
            appAuthorizeVo.setDevUsers(new ArrayList<>());
            appAuthorizeVo.setIsAllDevUser(1);
            appAuthorizeVo.setCreateUserId(info.getCreatorUserId());
            return ActionResult.success(appAuthorizeVo);
        } else {
            userId = info.getUserId();
            List<String> strings = new ArrayList<>();
            strings.add(userId);
            baseInfoVos = getBaseInfoVos(pagination, strings);
            List<UserAuthorize> userAuthorizes = baseInfoVos.stream()
                    .map(item -> BeanUtil.copyProperties(item, UserAuthorize.class)).collect(Collectors.toList());
            appAuthorizeVo.setCreateUserId(userAuthorizes.get(0).getId());
            appAuthorizeVo.setFullName(baseInfoVos.get(0).getFullName());
        }
 
 
        if (null == info.getAuthorizeId()) {
 
            appAuthorizeVo.setDevUsers(new ArrayList<>());
            appAuthorizeVo.setIsAllDevUser(0);
            return ActionResult.success(appAuthorizeVo);
        }
        authorizeId = info.getAuthorizeId();
 
        if (PermissionConst.ALL_DEV_USER.equals(authorizeId)) {
            List<String> collect = getUserIdListByRoleId();
            baseInfoVos = getBaseInfoVos(pagination, collect);
            appAuthorizeVo.setIsAllDevUser(1);
        } else {
            String[] split = authorizeId.split(",");
            List<String> collect = Arrays.stream(split).distinct().collect(Collectors.toList());
            baseInfoVos = getBaseInfoVos(pagination, collect);
            appAuthorizeVo.setIsAllDevUser(0);
        }
 
        List<UserAuthorize> userAuthorizes = baseInfoVos.stream()
                .map(item -> BeanUtil.copyProperties(item, UserAuthorize.class)).collect(Collectors.toList());
        appAuthorizeVo.setDevUsers(userAuthorizes.stream().map(UserAuthorize::getId).collect(Collectors.toList()));
        return ActionResult.success(appAuthorizeVo);
    }
 
    @Operation(summary = "保存应用授权信息")
    @SaCheckPermission(value = {"appConfig.appAuth"})
    @PostMapping("/saveAppAuthorization")
    public ActionResult<MCode> appAuthorization(@RequestBody AppAuthorizationModel model) {
        systemService.saveSystemAuthorizion(model);
        return ActionResult.success(MsgCode.SU005.get());
    }
 
    @Operation(summary = "移交应用创建者")
    @SaCheckPermission(value = {"appConfig.appAuth"})
    @PostMapping("/changeAppAuthorization")
    public ActionResult<MCode> changeAppAuthorization(@RequestBody AppAuthorizationModel model) {
        systemService.changeSystemAuthorizion(model);
        return ActionResult.success(MsgCode.SU005.get());
    }
 
    @Operation(summary = "获取开发人员")
    @SaCheckPermission(value = {"appConfig.appAuth", "permission.user"}, mode = SaMode.OR)
    @GetMapping("/getDevUser")
    public ActionResult getDevRole(Pagination pagination) {
        List<String> collect = getUserIdListByRoleId();
        List<BaseInfoVo> baseInfoVoList = getBaseInfoVos(pagination, collect, true);
        PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
 
        return ActionResult.page(baseInfoVoList, paginationVO);
    }
 
    /**
     * 根据开发者角色获取用户id集合
     *
     * @return 返回用户id集合
     */
    private @NotNull List<String> getUserIdListByRoleId() {
        List<RoleEntity> listAll = roleService.getListAll();
        List<RoleEntity> list = listAll.stream().filter(t -> PermissionConst.DEVELOPER_CODE.equals(t.getEnCode())).collect(Collectors.toList());
        String id = list.get(0).getId();
        //获取用户id集合
        List<String> collect = roleRelationService.getListByRoleId(new RoleRelationModel(null, PermissionConst.USER, Arrays.asList(id)))
                .stream()
                .map(RoleRelationEntity::getObjectId)
                .collect(Collectors.toList());
        return collect;
    }
 
    /**
     * 根据关键词查询用户信息
     *
     * @param pagination 关键词
     * @param collect    用户id集合
     * @return 用户信息集合
     */
    private @NotNull List<BaseInfoVo> getBaseInfoVos(Pagination pagination, List<String> collect) {
        return getBaseInfoVos(pagination, collect, false);
    }
 
    private @NotNull List<BaseInfoVo> getBaseInfoVos(Pagination pagination, List<String> collect, Boolean filter) {
        if (null == collect) {
            return Collections.emptyList();
        }
 
 
        List<UserEntity> entities = userApi.page(new UserSystemCountModel(pagination,filter,collect));
        if (CollectionUtils.isEmpty(entities)) {
            return Collections.emptyList();
        }
        return entities.stream()
                .map(item -> {
                    BaseInfoVo vo = JsonUtil.getJsonToBean(item, BaseInfoVo.class);
                    vo.setType(SysParamEnum.USER.getCode());
                    vo.setHeadIcon(UploaderUtil.uploaderImg(vo.getHeadIcon()));
                    vo.setFullName(vo.getRealName() + "/" + vo.getAccount());
                    return vo;
                }).collect(Collectors.toList());
    }
 
 
    @Operation(summary = "应用基础设置详情")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true)
    })
    @SaCheckPermission(value = {"appConfig.baseConfig"})
    @GetMapping("/{id}")
    public ActionResult<SystemVO> info(@PathVariable("id") String id) {
        SystemEntity entity = systemService.getInfo(id);
        if (entity == null) {
            return ActionResult.fail(MsgCode.FA001.get());
        }
        SystemVO jsonToBean = JsonUtil.getJsonToBean(entity, SystemVO.class);
        return ActionResult.success(jsonToBean);
    }
 
    @Operation(summary = "应用主题配置保存")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true)
    })
    @SaCheckPermission(value = {"appConfig.baseConfig"})
    @PostMapping("/preferenceSave/{id}")
    public ActionResult<SystemVO> preferenceSave(@PathVariable("id") String id, @RequestBody SystemUpModel upModel) {
        SystemEntity entity = systemService.getInfo(id);
        if (entity == null) {
            return ActionResult.fail(MsgCode.FA001.get());
        }
        entity.setPreferenceJson(upModel.getPreferenceJson());
        systemService.saveOrUpdate(entity);
        return ActionResult.success(MsgCode.SU005.get());
    }
 
 
    @Operation(summary = "新建应用")
    @Parameters({
            @Parameter(name = "systemCrModel", description = "新建模型", required = true)
    })
    @SaCheckPermission(value = {"appCenter"})
    @PostMapping
    public ActionResult create(@RequestBody SystemCrModel systemCrModel) {
        SystemEntity entity = JsonUtil.getJsonToBean(systemCrModel, SystemEntity.class);
        if (systemService.isExistEnCode(entity.getId(), entity.getEnCode())) {
            return ActionResult.fail(MsgCode.EXIST002.get());
        }
        systemService.create(entity);
        return ActionResult.success(MsgCode.SU001.get(), entity.getEnCode());
    }
 
    @Operation(summary = "修改应用")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
            @Parameter(name = "systemCrModel", description = "修改模型", required = true)
    })
    @SaCheckPermission(value = {"appConfig.baseConfig"})
    @PutMapping("/{id}")
    public ActionResult update(@PathVariable("id") String id, @RequestBody SystemUpModel systemUpModel) {
        SystemEntity systemEntity = systemService.getInfo(id);
        if (systemEntity == null) {
            return ActionResult.fail(MsgCode.FA002.get());
        }
        SystemEntity entity = JsonUtil.getJsonToBean(systemUpModel, SystemEntity.class);
        entity.setIsMain(systemEntity.getIsMain());
        if (systemService.isExistEnCode(id, entity.getEnCode())) {
            return ActionResult.fail(MsgCode.EXIST002.get());
        }
 
        systemService.update(id, entity);
        // 如果禁用了系统,则需要将系统
        if (systemEntity.getEnabledMark() == 1 && entity.getEnabledMark() == 0) {
            // 通知下线
            noticeApi.autoSystem(ImmutableMap.of("entity", systemEntity, "message", "应用已被禁用,正为您切换应用"));
        }
        return ActionResult.success(MsgCode.SU004.get());
    }
 
    @Operation(summary = "删除应用")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true)
    })
    @SaCheckPermission(value = {"appCenter"})
    @DeleteMapping("/{id}")
    public ActionResult<String> delete(@PathVariable("id") String id) {
        SystemEntity entity = systemService.getInfo(id);
        if (entity == null) {
            return ActionResult.fail(MsgCode.FA003.get());
        }
        // 查询平台下菜单
        MenuListModel paramW = new MenuListModel();
        paramW.setAppCode(entity.getEnCode());
        paramW.setCategory(JnpfConst.WEB);
        paramW.setRelease(false);
        AuthorizeVO authorize = authorizeService.getAuthorize(true, entity.getEnCode(), null);
        paramW.setModuleList(authorize.getModuleList());
        MenuListModel paramA = BeanUtil.copyProperties(paramW, MenuListModel.class);
        paramW.setCategory(JnpfConst.APP);
        List<ModuleEntity> webData = moduleService.getList(paramW);
        List<ModuleEntity> appData = moduleService.getList(paramA);
        if (CollectionUtils.isNotEmpty(webData) || CollectionUtils.isNotEmpty(appData)) {
            return ActionResult.fail(MsgCode.SYS040.get());
        }
        if (entity.getIsMain() != null && entity.getIsMain() == 1) {
            return ActionResult.fail(MsgCode.SYS102.get());
        }
        // 系统绑定审批常用语时不允许被删除
        if (commonWordsService.existSystem(id)) {
            return ActionResult.fail(MsgCode.SYS103.get());
        } else {
            systemService.delete(id);
            // 通知下线
            noticeApi.autoSystem(ImmutableMap.of("entity", entity, "message", "应用已被删除,正为您切换应用"));
        }
        return ActionResult.success(MsgCode.SU003.get());
    }
 
    @Operation(summary = "获取当前用户有权限的应用")
    @GetMapping("/userAuthList")
    public ActionResult<List<SystemListVO>> userAuthList(Pagination pagination) {
        AuthorizeVO authorizeByUser = authorizeService.getAuthorizeByUser(false);
        List<String> systemIds = authorizeByUser.getSystemList().stream().filter(t -> !Objects.equals(t.getIsMain(), 1))
                .map(SystemBaeModel::getId).collect(Collectors.toList());
        List<SystemEntity> list = systemService.getListByIdsKey(systemIds, pagination.getKeyword());
        List<SystemListVO> listVo = JsonUtil.getJsonToList(list, SystemListVO.class);
        return ActionResult.success(listVo);
    }
 
    @Operation(summary = "获取所有应用")
    @GetMapping("/Selector")
    public ActionResult<List<SystemListVO>> getSelector() {
        List<SystemEntity> list = systemService.getList().stream().filter(t -> !Objects.equals(t.getIsMain(), 1)).collect(Collectors.toList());
        List<SystemListVO> listVo = JsonUtil.getJsonToList(list, SystemListVO.class);
        return ActionResult.success(listVo);
    }
 
    //++++++++++++++++++++++++++++++++++以下为api接口
    @Override
    @GetMapping("/getList")
    public List<SystemEntity> getList() {
        return systemService.getList();
    }
 
    @Override
    @PostMapping("/getList")
    public List<SystemEntity> getList(@RequestBody SystemApiListModel model) {
        return systemService.getList(model.getKeyword(), model.getFilterEnableMark(), model.getVerifyAuth(), model.getFilterMain(), model.getIsList(), model.getModuleAuthorize());
    }
 
    @Override
    @PostMapping("/getListByIds")
    public List<SystemEntity> getListByIds(@RequestBody SystemApiByIdsModel model) {
        return systemService.getListByIds(model.getIds(), model.getModuleAuthorize(), model.getStand());
    }
 
    @Override
    @GetMapping("/getInfoById")
    public SystemEntity getInfoById(@RequestParam("systemId") String systemId) {
        return systemService.getInfo(systemId);
    }
 
    @Override
    @GetMapping("/getInfoByEnCode")
    public SystemEntity getInfoByEnCode(@RequestParam("enCode") String enCode) {
        return systemService.getInfoByEnCode(enCode);
    }
 
    @Override
    @PostMapping("/findSystemAdmin")
    public List<SystemEntity> findSystemAdmin(@RequestBody SystemApiModel model) {
        return systemService.findSystemAdmin(model.getModuleAuthorize());
    }
 
    @Override
    @PostMapping("/getListAll")
    public List<SystemEntity> getListAll() {
        return systemService.getList();
    }
 
    @PostMapping("/addCommonWordsNum")
    public void addCommonWordsNum(@RequestBody String commonWordsText) {
        commonWordsService.addCommonWordsNum(commonWordsText);
    }
 
    @Override
    @GetMapping("/getListByCreUser")
    public List<SystemEntity> getListByCreUser(@RequestParam("userId") String userId) {
        return systemService.getListByCreUser(userId);
    }
 
    @Override
    @GetMapping("/getAuthListByUser")
    public List<SystemEntity> getAuthListByUser(@RequestParam("userId")String userId, @RequestParam(value = "isStand")Boolean isStand) {
        return systemService.getAuthListByUser(userId, isStand);
    }
 
    @Override
    @PostMapping("/workHandover")
    public void workHandover(@RequestBody WorkHandoverModel workHandoverModel) {
        systemService.workHandover(workHandoverModel);
    }
 
    @Override
    @PostMapping("/changeSystemAuthorizion")
    public void changeSystemAuthorizion(@RequestBody AppAuthorizationModel model) {
        systemService.changeSystemAuthorizion(model);
    }
}