CustomFlowController.java
2.9 KB
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
package com.skua.modules.flow;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.skua.core.api.vo.Result;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.base.service.IBaseService;
import com.skua.modules.flow.business.service.IFlowService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* 流程状态控制器
*
* @author Jkadmin
*/
@RestController
@RequestMapping("/customFlow")
@ApiIgnore
public class CustomFlowController {
@Autowired
private IFlowService flowService;
@Autowired
private IBaseService baseService;
@Autowired
private TransactionTemplate transactionTemplate;
/**
* 删除流程实例
*/
@DeleteMapping("/delete")
@ApiOperationSupport(order = 2)
@ApiOperation(value = "删除", notes = "传入主键集合")
public Result<?> deleteCtrl(@RequestParam String tableName, @RequestParam String ids, @ApiParam(value = "删除原因") @RequestParam(defaultValue = "删除测试数据") String deleteReason) {
List<String> idList = Arrays.asList(ids.split(","));
if (!idList.isEmpty()) {
QueryWrapper<?> queryWrapper = new QueryWrapper<>().in("id", idList);
List<Map<String, Object>> queryMapList = baseService.queryForList("select id, process_instance_id from " + tableName, queryWrapper);
for (Map<String, Object> item : queryMapList) {
String id = ConvertUtils.getString(item.get("id"));
String processInstanceId = ConvertUtils.getString(item.get("process_instance_id"));
try {
transactionTemplate.execute(transactionStatus -> {
flowService.deleteProcessInstanceById(processInstanceId, deleteReason);
baseService.delete(tableName, new QueryWrapper<>().eq("id", id));
return 1;
});
} catch (Exception e) {
e.printStackTrace();
if (("No historic process instance found with id: " + processInstanceId).equals(e.getMessage())) {
baseService.delete(tableName, new QueryWrapper<>().eq("id", id));
}
}
}
}
return Result.ok();
}
}