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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
package jnpf.flowable.util;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.ImmutableList;
import jnpf.base.model.flow.FlowStateModel;
import jnpf.base.*;
import jnpf.base.entity.DictionaryDataEntity;
import jnpf.base.entity.SystemEntity;
import jnpf.base.entity.VisualdevEntity;
import jnpf.base.model.VisualDevJsonModel;
import jnpf.base.model.base.SystemApiByIdsModel;
import jnpf.base.model.flow.DataModel;
import jnpf.base.model.flow.FlowFormDataModel;
import jnpf.base.model.schedule.ScheduleNewCrForm;
import jnpf.base.model.systemconfig.SysConfigModel;
import jnpf.base.vo.DownloadVO;
import jnpf.config.ConfigValueUtil;
import jnpf.constant.*;
import jnpf.emnus.ModuleTypeEnum;
import jnpf.emnus.SysParamEnum;
import jnpf.exception.WorkFlowException;
import jnpf.file.DocumentApi;
import jnpf.file.FileApi;
import jnpf.flowable.entity.TemplateEntity;
import jnpf.flowable.model.template.TemplateExportModel;
import jnpf.flowable.model.util.FlowContextHolder;
import jnpf.flowable.model.util.FlowNature;
import jnpf.message.SentMessageApi;
import jnpf.message.model.SentMessageForm;
import jnpf.model.ExportModel;
import jnpf.model.document.FlowFileModel;
import jnpf.onlinedev.VisualdevOnlineApi;
import jnpf.onlinedev.model.PaginationModel;
import jnpf.onlinedev.model.VisualParamModel;
import jnpf.permission.*;
import jnpf.permission.entity.*;
import jnpf.permission.model.SystemParamModel;
import jnpf.permission.model.authorize.AuthorizeVO;
import jnpf.permission.model.rolerelaiton.RoleRelationModel;
import jnpf.permission.model.sign.SignForm;
import jnpf.permission.model.user.UserModel;
import jnpf.util.StringUtil;
import jnpf.util.enums.DictionaryDataEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.*;
import java.util.stream.Collectors;
 
import static jnpf.util.Constants.ADMIN_KEY;
 
@Component
public class ServiceUtil {
    @Autowired
    private DictionaryDataApi dictionaryDataService;
    @Autowired
    private UserRelationApi userRelationService;
    @Autowired
    private UserApi userApi;
    @Autowired
    private RoleApi roleService;
    @Autowired
    private RoleRelationApi roleRelationService;
    @Autowired
    private OrganizeApi organizeService;
    @Autowired
    private PositionApi positionService;
    @Autowired
    private CodeNumApi codeNumService;
    @Autowired
    private DataInterFaceApi dataInterfaceService;
    @Autowired
    private SentMessageApi sentMessageUtil;
    @Autowired
    private FileApi fileExport;
    @Autowired
    private ConfigValueUtil configValueUtil;
    @Autowired
    private UserSettingApi signService;
    @Autowired
    private AuthorizeApi authorizeService;
    @Autowired
    private VisualdevOnlineApi visualdevApi;
    @Autowired
    private DocumentApi documentApi;
    @Autowired
    private BillRuleApi billRuleService;
    @Autowired
    private SysConfigApi systemConfigApi;
    @Autowired
    private SystemApi systemApi;
    @Autowired
    private ScheduleNewApi scheduleNewApi;
 
 
    // 创建日程
    public void createSchedule(ScheduleNewCrForm fo) throws WorkFlowException {
        ActionResult result = scheduleNewApi.create(fo);
        if (result.getCode() != 200) {
            throw new WorkFlowException(result.getMsg());
        }
    }
 
    // 获取系统配置
    public SysConfigModel getSysConfig() {
        ActionResult<SysConfigModel> actionResult = systemConfigApi.list();
        return actionResult.getData();
    }
 
    // 获取系统配置,流程签收
    public Boolean getFlowSign() {
        ActionResult<SysConfigModel> actionResult = systemConfigApi.list();
        SysConfigModel data = actionResult.getData();
        return data.getFlowSign() == 0;
    }
 
    // 获取系统配置,流程办理
    public Boolean getFlowTodo() {
        ActionResult<SysConfigModel> actionResult = systemConfigApi.list();
        SysConfigModel data = actionResult.getData();
        return data.getFlowTodo() == 0;
    }
 
    // 流水号
    public String getBillNumber() {
        return billRuleService.getBillNumber(FlowNature.REVOKE_BILL_CODE).getData();
    }
 
    // -------------------------------签名-----------------------------
    public void updateSign(String signId, String signImg) {
        SignEntity signEntity = signService.getSignInfo(signId);
        if (null != signEntity) {
            signService.uptateDefault(signId);
        } else {
            SignForm signForm = new SignForm();
            signForm.setIsDefault(1);
            signForm.setSignImg(signImg);
            signService.create(signForm);
        }
    }
 
    // -------------------------------流程编码-----------------------------
    public String getCode() {
        return codeNumService.getCodeOnce(CodeConst.LC);
    }
 
    // -------------------------------常用语-----------------------------
    public void addCommonWordsNum(String handleOpinion) {
        systemApi.addCommonWordsNum(handleOpinion);
    }
 
    // -------------------------------文件-----------------------------
    // 判断是否存在归档文件,不存在为true
    public Boolean checkFlowFile(String taskId) {
        return documentApi.checkFlowFile(taskId);
    }
 
    // 获取归档文件
    public List<Map<String, Object>> getFlowFile(FlowFileModel model) {
        return documentApi.getFlowFile(model);
    }
 
    // -------------------------------流程全部权限-----------------------------
    public List<String> getPermission(String userId) {
        return getPermission(userId, AuthorizeConst.FLOW);
    }
 
    public List<String> getPermission(String userId, String itmeType) {
        List<String> userIdList = ImmutableList.of(userId);
        List<String> objectIdList = new ArrayList<>();
        List<String> posId = getListByUserIdAll(userIdList).stream().filter(e -> Objects.equals(PermissionConst.POSITION, e.getObjectType())).map(UserRelationEntity::getObjectId).collect(Collectors.toList());
        objectIdList.addAll(posId);
        List<String> roleId = getRoleObjectId(userIdList).stream().map(RoleRelationEntity::getRoleId).collect(Collectors.toList());
        objectIdList.addAll(roleId);
        List<String> resList = new ArrayList<>();
        if (!objectIdList.isEmpty()) {
            resList = getAuthorizeObjectId(objectIdList).stream().filter(e -> e.getItemType().equals(itmeType)).map(AuthorizeEntity::getItemId).collect(Collectors.toList());
        }
        return resList;
    }
 
    // -------------------------------发起权限-----------------------------
    public List<String> getLaunchPermission() {
        AuthorizeVO authorizeByUser = getAuthorizeByUser();
        List<String> flowIdList = authorizeByUser.getFlowIdList();
        return flowIdList;
    }
 
    // true是普通用户
    public boolean isCommonUser(String userId) {
        UserEntity userInfo = getUserInfo(userId);
        return userInfo == null || !Objects.equals(userInfo.getAccount(), ADMIN_KEY);
    }
 
    // 获取流程有发起权限的人员
    public List<UserEntity> getLaunchUserByTemplateId(TemplateEntity template, Pagination pagination) {
        if (ObjectUtil.equals(template.getVisibleType(), FlowNature.All)) {
            // 公开直接返回用户分页
            return userApi.getUserPage(pagination);
        }
        // 根据流程主键、权限为流程类型 获取权限关联
        List<String> userIdList = new ArrayList<>();
        List<AuthorizeEntity> authorizeList = getListByObjectAndItemIdAndType(template.getId()).stream().filter(e -> !Objects.equals(PermissionConst.ORGANIZE, e.getObjectType())).collect(Collectors.toList());
        for (AuthorizeEntity entity : authorizeList) {
            String objectType = PermissionConst.POSITION.equals(entity.getObjectType()) ? SysParamEnum.POS.getCode() : SysParamEnum.ROLE.getCode();
            userIdList.add(entity.getObjectId() + "--" + objectType);
        }
        List<String> userListAll = this.getUserListAll(userIdList);
        return this.getUserName(userListAll, pagination);
    }
 
    //--------------------------------表单------------------------------
    public VisualdevEntity getFormInfo(String id) {
        return visualdevApi.getFormConfig(id);
    }
 
    public List<VisualdevEntity> getFormList(List<String> formIds) {
        if (formIds.isEmpty()) {
            return new ArrayList<>();
        }
        return visualdevApi.getFormConfigList(formIds);
    }
 
    public void saveOrUpdateFormData(FlowFormDataModel model) throws WorkFlowException {
        ActionResult actionResult = visualdevApi.saveOrUpdate(model);
        if (actionResult.getCode() != 200) {
            throw new WorkFlowException(actionResult.getMsg());
        }
    }
 
    public void deleteFormData(String formId, String id) {
        if (StringUtil.isBlank(formId) || StringUtil.isBlank(id)) {
            return;
        }
        try {
            visualdevApi.delete(formId, id);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public Map<String, Object> infoData(String formId, String id) throws WorkFlowException {
        // 流程调用表单接口
        Map<String, Object> dataAll = new HashMap<>();
        if (StringUtil.isNotEmpty(formId) && StringUtil.isNotEmpty(id)) {
            ActionResult result = visualdevApi.info(formId, id);
            if (null != result && null != result.getData()) {
                dataAll = (Map<String, Object>) result.getData();
            }
        }
        return dataAll;
    }
 
    public void handleFormData(String flowId, Boolean isTransfer) throws WorkFlowException {
        try {
            Map<String, Map<String, Object>> allData = FlowContextHolder.getAllData();
            Map<String, List<Map<String, Object>>> formOperates = FlowContextHolder.getFormOperates();
            List<String> writeIdList = FlowContextHolder.getWriteIdList();
            for (String key : writeIdList) {
                String[] idList = key.split(JnpfConst.SIDE_MARK);
                List<Map<String, Object>> operates = formOperates.get(key);
                Map<String, Object> formData = allData.get(key);
                formData = formData == null ? new HashMap<>() : formData;
                FlowFormDataModel formDataModel = FlowFormDataModel.builder().formId(idList[1]).id(idList[0]).map(formData).formOperates(operates)
                        .flowId(flowId).isTransfer(isTransfer).build();
                this.saveOrUpdateFormData(formDataModel);
            }
        } catch (WorkFlowException e) {
            throw e;
        } finally {
            FlowContextHolder.clearAll();
        }
    }
 
    public List<Map<String, Object>> getListWithTableList(VisualDevJsonModel visualDevJsonModel, PaginationModel pagination, UserInfo userInfo) {
        VisualParamModel visualParamModel = VisualParamModel.builder().visualDevJsonModel(visualDevJsonModel).pagination(pagination).userInfo(userInfo).build();
        return visualdevApi.getListWithTableList(visualParamModel);
    }
 
    public VisualdevEntity getReleaseInfo(String formId) {
        return visualdevApi.getReleaseInfo(formId);
    }
 
    public DataModel visualCreate(VisualdevEntity visualdevEntity, Map<String, Object> data) throws Exception {
        VisualParamModel visualParamModel = VisualParamModel.builder().visualdevEntity(visualdevEntity).data(data).build();
        ActionResult result = visualdevApi.visualCreate(visualParamModel);
        if (null == result) {
            throw new WorkFlowException(MsgCode.SYS122.getCode());
        }
        if (!ObjectUtil.equals(result.getCode(), 200)) {
            throw new WorkFlowException(result.getMsg());
        }
        if (result.getData() instanceof DataModel) {
            return (DataModel) result.getData();
        }
        return null;
    }
 
    public DataModel visualUpdate(VisualdevEntity visualdevEntity, Map<String, Object> data, String id) throws Exception {
        VisualParamModel visualParamModel = VisualParamModel.builder().visualdevEntity(visualdevEntity).data(data).id(id).onlyUpdate(true).build();
        ActionResult result = visualdevApi.visualUpdate(visualParamModel);
        if (null == result) {
            throw new WorkFlowException(MsgCode.SYS122.get());
        }
        if (!ObjectUtil.equals(result.getCode(), 200)) {
            throw new WorkFlowException(result.getMsg());
        }
        if (result.getData() instanceof DataModel) {
            return (DataModel) result.getData();
        }
        return null;
    }
 
    public void visualDelete(VisualdevEntity visualdevEntity, List<Map<String, Object>> dataList) throws Exception {
        VisualParamModel visualParamModel = VisualParamModel.builder().visualdevEntity(visualdevEntity).dataList(dataList).build();
        ActionResult result = visualdevApi.visualDelete(visualParamModel);
        if (null == result) {
            throw new WorkFlowException(MsgCode.SYS122.get());
        }
        if (!ObjectUtil.equals(result.getCode(), 200)) {
            throw new WorkFlowException(result.getMsg());
        }
    }
 
    public void deleteSubTable(FlowFormDataModel model) throws Exception {
        ActionResult result = visualdevApi.deleteByTableName(model);
        if (null == result) {
            throw new WorkFlowException(MsgCode.SYS122.get());
        }
        if (!ObjectUtil.equals(result.getCode(), 200)) {
            throw new WorkFlowException(result.getMsg());
        }
    }
 
    public void saveState(FlowStateModel stateModel){
        visualdevApi.saveState(stateModel);
    }
 
    //--------------------------------数据字典------------------------------
    public List<DictionaryDataEntity> getDiList() {
        ActionResult<List<DictionaryDataEntity>> result = dictionaryDataService.getListByTypeDataCode(DictionaryDataEnum.FLOWWOEK_ENGINE.getDictionaryTypeId());
        List<DictionaryDataEntity> dictionList = new ArrayList<>();
        if (result.getData() != null) {
            dictionList.addAll(result.getData());
        }
        return dictionList;
    }
 
    public List<DictionaryDataEntity> getDictionName(List<String> id) {
        List<DictionaryDataEntity> dictionList = dictionaryDataService.getDictionName(id);
        return dictionList;
    }
 
    //--------------------------------用户关系表------------------------------
    public List<UserRelationEntity> getListByUserIdAll(List<String> id) {
        List<UserRelationEntity> list = userRelationService.getListByUserIdAll(id).stream().filter(t -> StringUtil.isNotEmpty(t.getObjectId())).collect(Collectors.toList());
        return list;
    }
 
    public List<UserRelationEntity> getListByObjectIdAll(List<String> id) {
        List<UserRelationEntity> list = userRelationService.getListByObjectIdAll(id);
        return list;
    }
 
    //--------------------------------用户权限------------------------------
 
    public List<AuthorizeEntity> getAuthorizeObjectId(List<String> objectIdList) {
        List<AuthorizeEntity> list = authorizeService.getListByObjectId(objectIdList);
        return list;
    }
 
    public List<AuthorizeEntity> getListByObjectAndItemIdAndType(String templateId) {
        List<AuthorizeEntity> flowAuthList = authorizeService.getListByObjectAndItemIdAndType(templateId, AuthorizeConst.FLOW);
        return flowAuthList;
    }
 
    public AuthorizeVO getAuthorizeByUser() {
        AuthorizeVO authorize = authorizeService.getAuthorizeByUser(false);
        return authorize;
    }
 
    //--------------------------------用户------------------------------
 
    public String getAdmin() {
        UserEntity admin = userApi.getInfoByAccount(ADMIN_KEY);
        return admin.getId();
    }
 
    public List<UserEntity> getUserByAccount(List<String> accountList) {
        List<UserEntity> list = new ArrayList<>();
        if (CollectionUtil.isEmpty(accountList)) {
            return list;
        }
        for (String account : accountList) {
            UserEntity user = userApi.getInfoByAccount(account);
            if (null != user) {
                list.add(user);
            }
        }
        return list;
    }
 
    public List<UserEntity> getUserName(List<String> id) {
        List<UserEntity> list = getUserName(id, false);
        return list;
    }
 
    public List<UserEntity> getUserName(List<String> id, boolean enableMark) {
        List<UserEntity> list = userApi.getUserName(id);
        if (enableMark) list = list.stream().filter(t -> t.getEnabledMark() == 1).collect(Collectors.toList());
        return list;
    }
 
    public List<UserEntity> getUserName(List<String> id, Pagination pagination) {
        UserModel userModel = new UserModel();
        userModel.setId(id);
        userModel.setPagination(pagination);
        List<UserEntity> list = userApi.getUserNamePagination(userModel);
        return list;
    }
 
    public UserEntity getUserInfo(String id) {
        UserEntity entity = null;
        if (StringUtil.isNotEmpty(id)) {
            entity = id.equalsIgnoreCase(ADMIN_KEY) ? userApi.getInfoByAccount(id) : userApi.getInfoById(id);
        }
        return entity;
    }
 
    public List<String> getUserListAll(List<String> idList) {
        List<String> userIdList = userApi.getUserIdList(idList);
        return userIdList;
    }
 
    //--------------------------------角色关系表------------------------------
 
    public List<RoleRelationEntity> getListByRoleId(List<String> roleIdList) {
        List<RoleRelationEntity> list = roleRelationService.getListByRoleId(new RoleRelationModel(new ArrayList<>(), PermissionConst.USER, roleIdList));
        return list;
    }
 
    public List<RoleRelationEntity> getRoleObjectId(List<String> userId) {
        List<RoleRelationEntity> list = roleRelationService.getListByObjectId(new RoleRelationModel(userId, PermissionConst.USER));
        return list;
    }
 
    //--------------------------------角色------------------------------
    public List<RoleEntity> getRoleList(List<String> id) {
        return roleService.getListByIds(id);
    }
 
 
    //--------------------------------组织------------------------------
 
    public OrganizeEntity getOrganizeInfo(String id) {
        OrganizeEntity entity = StringUtil.isNotEmpty(id) ? organizeService.getInfoById(id) : null;
        return entity;
    }
 
    public List<OrganizeEntity> getDepartmentAll(String organizeId) {
        List<OrganizeEntity> departmentAll = organizeService.getOrganizeDepartmentAll(organizeId);
        return departmentAll;
    }
 
    public List<OrganizeEntity> getOrganizeList(List<String> idList) {
        List<OrganizeEntity> departmentAll = organizeService.getListByIds(idList);
        return departmentAll;
    }
 
    //--------------------------------岗位------------------------------
 
    public PositionEntity getPositionInfo(String id) {
        PositionEntity entity = StringUtil.isNotEmpty(id) ? positionService.queryInfoById(id) : null;
        return entity;
    }
 
    public List<PositionEntity> getChildPosition(String id) {
        List<PositionEntity> list = StringUtil.isNotEmpty(id) ? positionService.getAllChild(id) : new ArrayList<>();
        return list;
    }
 
    public List<PositionEntity> getListByOrgIds(List<String> orgIds) {
        List<PositionEntity> list = positionService.getListByOrgIds(orgIds);
        return list;
    }
 
    public List<PositionEntity> getPosList(List<String> idList) {
        List<PositionEntity> list = positionService.getListByIds(idList);
        return list;
    }
 
    //--------------------------------远端------------------------------
    public ActionResult infoToId(String interId, Map<String, String> parameterMap) {
        return dataInterfaceService.infoToIdById(interId, parameterMap);
    }
 
    public Map<String, String> getSystemFieldValue() {
        Map<String, String> paramDataMap = userApi.getSystemFieldValue(new SystemParamModel());
        return paramDataMap;
    }
 
    //--------------------------------应用------------------------------
 
    public String getSystemCodeById(String systemCode) {
        List<String> systemIdList = ImmutableList.of(JnpfConst.MAIN_SYSTEM_CODE, JnpfConst.WORK_FLOW_CODE);
        String systemId = JnpfConst.MAIN_SYSTEM_CODE;
        if (StringUtil.isEmpty(systemCode)) {
            return systemId;
        }
        if (systemIdList.contains(systemCode)) {
            return "";
        }
        SystemEntity entity = getInfoByEnCode(systemCode);
        if (entity != null) {
            systemId = entity.getId();
        }
        return systemId;
    }
 
    public SystemEntity getInfoByEnCode(String systemCode) {
        SystemEntity entity = systemApi.getInfoByEnCode(systemCode);
        return entity;
    }
 
    public List<SystemEntity> getSystemList(List<String> idList) {
        SystemApiByIdsModel model = new SystemApiByIdsModel(idList, new ArrayList<>(), 0);
        List<SystemEntity> list = systemApi.getListByIds(model);
        return list;
    }
 
    //--------------------------------发送消息------------------------------
    public void sendMessage(List<SentMessageForm> messageListAll) {
        for (SentMessageForm messageForm : messageListAll) {
            if (messageForm.isSysMessage()) {
                sentMessageUtil.sendMessage(messageForm);
            }
        }
    }
 
    public List<String> sendDelegateMsg(List<SentMessageForm> messageListAll) {
        List<String> list = new ArrayList<>();
        for (SentMessageForm messageForm : messageListAll) {
            List<String> errList = sentMessageUtil.sendScheduleMessage(messageForm);
            list.addAll(errList);
        }
        return list;
    }
 
    //------------------------------导出-------------------------------
    public DownloadVO exportData(TemplateExportModel model) {
        DownloadVO downloadVO = fileExport.exportFile(new ExportModel(model, FileTypeConstant.TEMPORARY,
                configValueUtil.getTemporaryFilePath(), model.getTemplate().getFullName(), ModuleTypeEnum.FLOW_FLOWENGINE.getTableName()));
        return downloadVO;
    }
}