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
package jnpf.flowable.controller;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.ImmutableList;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.base.ActionResult;
import jnpf.base.Pagination;
import jnpf.base.controller.SuperController;
import jnpf.base.vo.ListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.constant.MsgCode;
import jnpf.exception.WorkFlowException;
import jnpf.flowable.entity.CirculateEntity;
import jnpf.flowable.entity.OperatorEntity;
import jnpf.flowable.entity.RecordEntity;
import jnpf.flowable.entity.TaskEntity;
import jnpf.flowable.enums.*;
import jnpf.flowable.model.candidates.CandidateCheckFo;
import jnpf.flowable.model.candidates.CandidateCheckVo;
import jnpf.flowable.model.candidates.CandidateUserVo;
import jnpf.flowable.model.operator.FlowBatchModel;
import jnpf.flowable.model.operator.OperatorVo;
import jnpf.flowable.model.task.AuditModel;
import jnpf.flowable.model.task.FlowModel;
import jnpf.flowable.model.task.TaskPagination;
import jnpf.flowable.model.templatenode.BackNodeModel;
import jnpf.flowable.model.util.FlowNature;
import jnpf.flowable.service.CirculateService;
import jnpf.flowable.service.OperatorService;
import jnpf.flowable.service.RecordService;
import jnpf.flowable.service.TaskService;
import jnpf.flowable.util.FlowUtil;
import jnpf.flowable.util.OperatorUtil;
import jnpf.flowable.util.RedisLock;
import jnpf.flowable.util.ServiceUtil;
import jnpf.permission.entity.UserEntity;
import jnpf.util.JsonUtil;
import jnpf.util.UserProvider;
import jnpf.util.context.RequestContext;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
 
/**
 * 类的描述
 *
 * @author JNPF@YinMai Info. Co., Ltd
 * @version 5.0.x
 * @since 2024/4/25 14:48
 */
@Tag(name = "经办", description = "OperatorController")
@RestController
@RequestMapping("/operator")
@RequiredArgsConstructor
public class OperatorController extends SuperController<OperatorService, OperatorEntity> {
    private final OperatorService operatorService;
    private final TaskService taskService;
    @Autowired
    private ServiceUtil serviceUtil;
    @Autowired
    private RecordService recordService;
    @Autowired
    private CirculateService circulateService;
    @Autowired
    private FlowUtil flowUtil;
    @Autowired
    private OperatorUtil operatorUtil;
    @Autowired
    private RedisLock redisLock;
 
    /**
     * 判断候选人
     *
     * @param id 经办主键
     * @param fo 参数类
     */
    @Operation(summary = "判断候选人")
    @PostMapping("/CandidateNode/{id}")
    public ActionResult candidates(@PathVariable("id") String id, @RequestBody CandidateCheckFo fo) throws WorkFlowException {
        OperatorEntity info = !ObjectUtil.equals(id, "0") ? operatorService.getInfo(id) : null;
        if (info != null) {
            operatorUtil.checkOperatorPermission(id);
        }
        return ActionResult.success(taskService.checkCandidates(id, fo));
    }
 
    /**
     * 获取候选人
     *
     * @param fo 参数类
     */
    @Operation(summary = "获取候选人")
    @PostMapping("/CandidateUser/{id}")
    public ActionResult candidateUser(@PathVariable("id") String id, @RequestBody CandidateCheckFo fo) throws WorkFlowException {
        OperatorEntity info = !ObjectUtil.equals(id, "0") ? operatorService.getInfo(id) : null;
        if (info != null) {
            operatorUtil.checkOperatorPermission(id);
        }
        List<CandidateUserVo> candidates = taskService.getCandidateUser(id, fo);
        PaginationVO paginationVO = JsonUtil.getJsonToBean(fo, PaginationVO.class);
        return ActionResult.page(candidates, paginationVO);
    }
 
    /**
     * 列表
     *
     * @param category   列表标识
     * @param pagination 参数
     */
    @Operation(summary = "列表")
    @GetMapping("/List/{category}")
    public ActionResult list(@PathVariable("category") String category, TaskPagination pagination) {
        List<OperatorVo> list = new ArrayList<>();
        CategoryEnum categoryEnum = CategoryEnum.getType(category);
        pagination.setCategory(categoryEnum.getType());
        pagination.setDelegateType(true);
        pagination.setSystemId(serviceUtil.getSystemCodeById(RequestContext.getAppCode()));
        switch (categoryEnum) {
            case Sign: // 待签
            case Todo: // 待办
            case Doing: // 在办
            case BatchDoing: // 批量在办
                list = operatorService.getList(pagination);
                break;
            case Done: // 已办
                list = recordService.getList(pagination);
                break;
            case Circulate: // 抄送
                list = circulateService.getList(pagination);
        }
        List<OperatorVo> vos = new ArrayList<>();
        List<UserEntity> userList = serviceUtil.getUserName(list.stream().map(OperatorVo::getCreatorUserId).collect(Collectors.toList()));
        for (OperatorVo operatorVo : list) {
            OperatorVo vo = JsonUtil.getJsonToBean(operatorVo, OperatorVo.class);
            UserEntity userEntity = userList.stream().filter(t -> t.getId().equals(vo.getCreatorUserId())).findFirst().orElse(null);
            vo.setCreatorUser(userEntity != null ? userEntity.getRealName() + "/" + userEntity.getAccount() : "");
            if (ObjectUtil.equals(operatorVo.getIsProcessing(), 1) && ObjectUtil.equals(operatorVo.getStatus(), OperatorStateEnum.Transfer.getCode())) {
                vo.setStatus(OperatorStateEnum.TransferProcessing.getCode());
            }
            vos.add(vo);
        }
        PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
        return ActionResult.page(vos, paginationVO);
    }
 
    /**
     * 签收或退签
     *
     * @param flowModel 参数类,ids 主键集合、type 0 签收 1 退签
     */
    @Operation(summary = "签收或退签")
    @PostMapping("/Sign")
    public ActionResult<String> sign(@RequestBody FlowModel flowModel) throws WorkFlowException {
        operatorService.sign(flowModel);
        return ActionResult.success(MsgCode.SU005.get());
    }
 
    /**
     * 开始办理
     *
     * @param flowModel 参数类,ids 主键集合
     */
    @Operation(summary = "开始办理")
    @PostMapping("/Transact")
    public ActionResult<String> startHandle(@RequestBody FlowModel flowModel) throws WorkFlowException {
        operatorService.startHandle(flowModel);
        return ActionResult.success(MsgCode.SU005.get());
    }
 
    /**
     * 保存草稿
     *
     * @param id        经办主键
     * @param flowModel 参数
     */
    @Operation(summary = "保存草稿")
    @PostMapping("/SaveAudit/{id}")
    public ActionResult<String> saveAudit(@PathVariable("id") String id, @RequestBody FlowModel flowModel) throws WorkFlowException {
        operatorUtil.checkOperatorPermission(id);
        operatorService.saveAudit(id, flowModel);
        return ActionResult.success(MsgCode.SU002.get());
    }
 
    /**
     * 同意拒绝
     *
     * @param id        经办主键
     * @param flowModel 参数
     */
    @Operation(summary = "同意拒绝")
    @PostMapping("/Audit/{id}")
    public ActionResult audit(@PathVariable("id") String id, @RequestBody FlowModel flowModel) throws Exception {
        OperatorEntity operator = operatorUtil.checkOperator(id);
        TaskEntity taskEntity = taskService.getInfo(operator.getTaskId());
        if (null == taskEntity) {
            throw new WorkFlowException(MsgCode.FA001.get());
        }
        operatorUtil.checkOperatorPermission(id);
        boolean lock = redisLock.lock(taskEntity.getId() + operator.getNodeId(), operator.getId(), 5, TimeUnit.SECONDS);
        if (!lock) {
            throw new WorkFlowException("当前节点正在审批中,请稍后再试");
        }
        Integer handleStatus = flowModel.getHandleStatus();
        try {
            operatorService.auditWithCheck(id, flowModel);
        } catch (Exception e) {
            operatorUtil.compensate(taskEntity);
            throw e;
        } finally {
            redisLock.unlock(taskEntity.getId() + operator.getNodeId(), operator.getId());
        }
        operatorUtil.handleOperator();
        operatorUtil.handleEvent();
        taskEntity = flowModel.getTaskEntity();
        if (taskEntity.getRejectDataId() == null) {
            operatorUtil.autoAudit(flowModel);
            operatorUtil.handleOperator();
            operatorUtil.handleEvent();
        }
        operatorUtil.handleTaskStatus();
        TaskEntity task = taskService.getById(taskEntity.getId());
        taskEntity = task == null ? taskEntity : task;
        AuditModel model = operatorUtil.getAuditModel(taskEntity.getId(), flowModel, operator);
        String msg = Objects.equals(handleStatus, FlowNature.RejectCompletion) ? MsgCode.WF065.get() : MsgCode.WF066.get();
        if (ObjectUtil.equals(operator.getIsProcessing(), FlowNature.Processing)) {
            msg = MsgCode.WF148.get();
        }
        return ActionResult.success(msg, model);
    }
 
    /**
     * 加签
     *
     * @param id        经办主键
     * @param flowModel 参数
     */
    @Operation(summary = "加签")
    @PostMapping("/AddSign/{id}")
    public ActionResult<String> freeApprover(@PathVariable("id") String id, @RequestBody FlowModel flowModel) throws Exception {
        operatorUtil.checkOperatorPermission(id);
        operatorService.addSign(id, flowModel);
        operatorUtil.autoAudit(flowModel);
        operatorUtil.handleOperator();
        operatorUtil.handleEvent();
        return ActionResult.success(MsgCode.WF004.get());
    }
 
 
    /**
     * 获取加签的人
     *
     * @param id         经办主键
     * @param pagination 参数
     */
    @Operation(summary = "获取加签的人")
    @PostMapping("/AddSignUserIdList/{id}")
    public ActionResult getAddSignUserIdList(@PathVariable("id") String id, @RequestBody Pagination pagination) throws WorkFlowException {
        List<CandidateUserVo> reduceList = operatorService.getReduceList(id, pagination);
        PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
        return ActionResult.page(reduceList, paginationVO);
    }
 
    /**
     * 减签
     *
     * @param flowModel 参数
     * @param id        记录主键
     */
    @Operation(summary = "减签")
    @PostMapping("/ReduceApprover/{id}")
    public ActionResult<String> reduceApprover(@RequestBody FlowModel flowModel, @PathVariable("id") String id) throws WorkFlowException {
        RecordEntity record = recordService.getInfo(id);
        if (null == record) {
            throw new WorkFlowException(MsgCode.FA001.get());
        }
        if (!Objects.equals(record.getHandleId(), UserProvider.getLoginUserId())) {
            throw new WorkFlowException(MsgCode.AD104.get());
        }
        operatorService.reduce(id, flowModel);
        return ActionResult.success(MsgCode.WF069.get());
    }
 
    /**
     * 获取退回的节点
     *
     * @param id 经办主键
     */
    @Operation(summary = "获取退回的节点")
    @GetMapping("/SendBackNodeList/{id}")
    public ActionResult getFallbacks(@PathVariable("id") String id) throws WorkFlowException {
        ListVO<BackNodeModel> vo = new ListVO<>();
        vo.setList(operatorService.getFallbacks(id));
        return ActionResult.success(vo);
    }
 
    /**
     * 退回
     *
     * @param id        经办主键
     * @param flowModel 参数
     */
    @Operation(summary = "退回")
    @PostMapping("/SendBack/{id}")
    public ActionResult<String> reject(@PathVariable("id") String id, @RequestBody FlowModel flowModel) throws Exception {
        OperatorEntity operator = operatorUtil.checkOperator(id);
        TaskEntity taskEntity = taskService.getInfo(operator.getTaskId());
        if (null == taskEntity) {
            throw new WorkFlowException(MsgCode.FA001.get());
        }
        operatorUtil.checkOperatorPermission(id);
        try {
            operatorService.back(id, flowModel);
        } catch (Exception e) {
            operatorUtil.compensate(taskEntity);
            throw e;
        }
        operatorUtil.handleOperator();
        operatorUtil.handleTaskStatus();
        operatorUtil.handleEvent();
        return ActionResult.success(MsgCode.WF002.get());
    }
 
    /**
     * 撤回
     *
     * @param id        记录主键
     * @param flowModel 参数
     */
    @Operation(summary = "撤回")
    @PostMapping("/Recall/{taskRecordId}")
    public ActionResult<String> recall(@PathVariable("taskRecordId") String id, @RequestBody FlowModel flowModel) throws Exception {
        RecordEntity record = recordService.getInfo(id);
        if (null == record) {
            throw new WorkFlowException(MsgCode.FA001.get());
        }
        if (record.getStatus().equals(FlowNature.Invalid)) {
            throw new WorkFlowException(MsgCode.WF005.get());
        }
        OperatorEntity operator = operatorService.getInfo(record.getOperatorId());
        if (null == operator) {
            throw new WorkFlowException(MsgCode.FA001.get());
        }
        TaskEntity taskEntity = taskService.getInfo(operator.getTaskId());
        if (null == taskEntity) {
            throw new WorkFlowException(MsgCode.FA001.get());
        }
        if (!Objects.equals(record.getHandleId(), UserProvider.getLoginUserId())) {
            return ActionResult.fail(MsgCode.AD104.get());
        }
        flowModel.setRecordEntity(record);
        flowModel.setOperatorEntity(operator);
        try {
            operatorService.recall(id, flowModel);
        } catch (Exception e) {
            operatorUtil.compensate(taskEntity);
            throw e;
        }
        operatorUtil.handleOperator();
        operatorUtil.handleTaskStatus();
        flowUtil.event(flowModel, EventEnum.Recall.getStatus());
        return ActionResult.success(MsgCode.WF008.get());
    }
 
    /**
     * 转审
     *
     * @param id        经办主键
     * @param flowModel 参数
     */
    @Operation(summary = "转审")
    @PostMapping("/Transfer/{id}")
    public ActionResult<String> transfer(@PathVariable("id") String id, @RequestBody FlowModel flowModel) throws Exception {
        operatorUtil.checkOperatorPermission(id);
        operatorService.transfer(id, flowModel);
        operatorUtil.autoAudit(flowModel);
        operatorUtil.handleOperator();
        operatorUtil.handleEvent();
        OperatorEntity operator = operatorService.getById(id);
        return ActionResult.success(ObjectUtil.equals(operator.getIsProcessing(), FlowNature.Processing) ? MsgCode.WF003.get() : MsgCode.WF152.get());
    }
 
    /**
     * 协办
     *
     * @param id        主键
     * @param flowModel 参数
     */
    @Operation(summary = "协办")
    @PostMapping("/Assist/{id}")
    public ActionResult<String> assist(@PathVariable("id") String id, @RequestBody FlowModel flowModel) throws WorkFlowException {
        operatorUtil.checkOperatorPermission(id);
        operatorService.assist(id, flowModel);
        return ActionResult.success(MsgCode.WF067.get());
    }
 
    /**
     * 协办保存
     *
     * @param id        主键
     * @param flowModel 参数
     */
    @Operation(summary = "协办保存")
    @PostMapping("/AssistSave/{id}")
    public ActionResult<String> assistSave(@PathVariable("id") String id, @RequestBody FlowModel flowModel) throws WorkFlowException {
        operatorUtil.checkOperatorPermission(id);
        operatorService.assistSave(id, flowModel);
        return ActionResult.success(MsgCode.WF068.get());
    }
 
    /**
     * 批量审批流程分类列表
     */
    @Operation(summary = "批量审批流程分类列表")
    @GetMapping("/BatchFlowSelector")
    public ActionResult<List<FlowBatchModel>> batchFlowSelector() {
        List<FlowBatchModel> list = operatorService.batchFlowSelector();
        return ActionResult.success(list);
    }
 
    /**
     * 批量审批流程版本列表
     *
     * @param templateId 流程定义主键
     */
    @Operation(summary = "批量审批流程版本列表")
    @GetMapping("/BatchVersionSelector/{templateId}")
    public ActionResult<List<FlowBatchModel>> batchVersionSelector(@PathVariable("templateId") String templateId) {
        List<FlowBatchModel> list = operatorService.batchVersionSelector(templateId);
        return ActionResult.success(list);
    }
 
    /**
     * 批量审批节点列表
     *
     * @param flowId 定义版本主键
     */
    @Operation(summary = "批量审批节点列表")
    @GetMapping("/BatchNodeSelector/{flowId}")
    public ActionResult<List<FlowBatchModel>> batchNodeSelector(@PathVariable("flowId") String flowId) {
        List<FlowBatchModel> list = operatorService.batchNodeSelector(flowId);
        return ActionResult.success(list);
    }
 
    /**
     * 批量审批节点属性
     *
     * @param flowModel 参数
     */
    @Operation(summary = "批量审批节点属性")
    @GetMapping("/BatchNode")
    public ActionResult batchNode(FlowModel flowModel) throws WorkFlowException {
        Map<String, Object> nodeMap = operatorService.batchNode(flowModel);
        return ActionResult.success(nodeMap);
    }
 
    /**
     * 批量获取候选人
     *
     * @param flowId     版本主键
     * @param operatorId 经办主键
     * @param batchType  类型,0.同意  1.拒绝
     */
    @Operation(summary = "批量获取候选人")
    @GetMapping("/BatchCandidate")
    public ActionResult batchCandidate(String flowId, String operatorId, Integer batchType) throws WorkFlowException {
        CandidateCheckVo vo = operatorService.batchCandidates(flowId, operatorId, batchType);
        return ActionResult.success(vo);
    }
 
    /**
     * 批量审批
     *
     * @param flowModel 参数
     */
    @Operation(summary = "批量审批")
    @PostMapping("/BatchOperation")
    public ActionResult batchOperation(@RequestBody FlowModel flowModel) throws Exception {
        try {
            operatorService.batch(flowModel);
        } catch (Exception e) {
            List<TaskEntity> taskList = flowModel.getTaskList();
            if (CollectionUtil.isNotEmpty(taskList)) {
                for (TaskEntity taskEntity : taskList) {
                    operatorUtil.compensate(taskEntity);
                }
            }
            throw e;
        }
        operatorUtil.handleOperator();
        operatorUtil.handleTaskStatus();
        operatorUtil.handleEvent();
        return ActionResult.success(MsgCode.WF011.get());
    }
 
    /**
     * 消息跳转工作流
     *
     * @param id 经办或抄送主键
     */
    @Operation(summary = "消息跳转工作流")
    @GetMapping("/{id}/Info")
    public ActionResult checkInfo(@PathVariable("id") String id, @RequestParam(value = "opType", required = false) String opType) throws WorkFlowException {
        Map<String, String> map = new HashMap<>();
        List<String> list = ImmutableList.of(OpTypeEnum.LaunchDetail.getType(), OpTypeEnum.LaunchCreate.getType());
        if (list.contains(opType)) {
            String type = OpTypeEnum.LaunchDetail.getType();
            TaskEntity task = taskService.getById(id);
            if (null != task) {
                operatorUtil.checkTemplateHide(task.getTemplateId());
                if (ObjectUtil.equals(task.getStatus(), TaskStatusEnum.TO_BE_SUBMIT.getCode())) {
                    type = OpTypeEnum.LaunchCreate.getType();
                }
            }
            map.put("opType", type);
            return ActionResult.success(map);
        }
        String type = taskService.checkInfo(id);
        map.put("opType", type);
        return ActionResult.success(map);
    }
 
    /**
     * 进度节点记录列表
     *
     * @param taskId 任务主键
     * @param nodeId 节点id
     */
    @Operation(summary = "进度节点记录列表")
    @GetMapping("/RecordList")
    public ActionResult getRecordList(@RequestParam("taskId") String taskId, @RequestParam("nodeId") String nodeId) {
        return ActionResult.success(recordService.getList(taskId, nodeId));
    }
 
    /**
     * 节点抄送列表
     *
     * @param taskId 任务主键
     * @param nodeId 节点id
     */
    @Operation(summary = "节点抄送列表")
    @GetMapping("/CirculateList")
    public ActionResult getCirculateList(@RequestParam("taskId") String taskId, @RequestParam("nodeId") String nodeId) {
        List<CirculateEntity> list = circulateService.getNodeList(taskId, nodeId);
        return ActionResult.success(operatorUtil.getCirculateList(list));
    }
}