wjli
2023-05-16 caae2b2d5d7aa962cd31a334c5b8aef22f23a753
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
package ${entity.controllerPackage};
 
import cn.exrick.xboot.core.base.XbootBaseController;
import cn.exrick.xboot.core.common.utils.PageUtil;
import cn.exrick.xboot.core.common.utils.ResultUtil;
import cn.exrick.xboot.core.common.vo.PageVo;
import cn.exrick.xboot.core.common.vo.Result;
import cn.exrick.xboot.core.common.vo.SearchVo;
import ${entity.entityPackage}.${entity.className};
import ${entity.servicePackage}.${entity.className}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;
<%
if(entity.activiti){
%>
import cn.exrick.xboot.core.common.utils.SecurityUtil;
import cn.exrick.xboot.activiti.entity.ActBusiness;
import cn.exrick.xboot.activiti.service.ActBusinessService;
import cn.hutool.core.util.StrUtil;
<%
}
%>
 
/**
 * @author ${entity.author}
 */
@Slf4j
@RestController
@Api(tags = "${entity.description}管理接口")
@RequestMapping("/xboot/${entity.classNameLowerCase}")
@Transactional
public class ${entity.className}Controller extends XbootBaseController<${entity.className}, ${entity.primaryKeyType}> {
 
    @Autowired
    private ${entity.className}Service ${entity.classNameLowerCase}Service;
 
    @Override
    public ${entity.className}Service getService() {
        return ${entity.classNameLowerCase}Service;
    }
 
    <%
    if(entity.activiti){
    %>
    @Autowired
    private ActBusinessService actBusinessService;
 
    @Autowired
    private SecurityUtil securityUtil;
    <%
    }
    %>
 
    @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
    @ApiOperation(value = "多条件分页获取")
    public Result<Page<${entity.className}>> getByCondition(${entity.className} ${entity.classNameLowerCase}, SearchVo searchVo, PageVo pageVo) {
 
        Page<${entity.className}> page = ${entity.classNameLowerCase}Service.findByCondition(${entity.classNameLowerCase}, searchVo, PageUtil.initPage(pageVo));
        <%
        if(entity.activiti){
        %>
        for(${entity.className} obj: page.getContent()){
            // 关联流程表 查询关联流程状态和结果等信息
            if(StrUtil.isNotBlank(obj.getActBusinessId())){
                ActBusiness actBusiness = actBusinessService.get(obj.getActBusinessId());
                obj.setStatus(actBusiness.getStatus());
                obj.setResult(actBusiness.getResult());
                obj.setApplyTime(actBusiness.getApplyTime());
                obj.setRouteName(actBusiness.getRouteName());
                obj.setProcInstId(actBusiness.getProcInstId());
            }
        }
        <%
        }
        %>
        return new ResultUtil<Page<${entity.className}>>().setData(page);
    }
 
    <%
    if(entity.activiti){
    %>
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ApiOperation(value = "添加关联流程")
    public Result<Object> add(${entity.className} ${entity.classNameLowerCase}) {
 
        ${entity.className} obj = ${entity.classNameLowerCase}Service.save(${entity.classNameLowerCase});
        // 保存至我的申请业务
        String userId = securityUtil.getCurrUser().getId();
        ActBusiness actBusiness = new ActBusiness();
        actBusiness.setUserId(userId);
        // 记录关联业务表ID
        actBusiness.setTableId(obj.getId());
        ActBusiness a = actBusinessService.save(actBusiness);
        // 记录关联流程状态表ID
        obj.setActBusinessId(a.getId());
        ${entity.classNameLowerCase}Service.update(obj);
        return ResultUtil.success("操作成功");
    }
    <%
    }
    %>
}