zf
2023-09-12 513437f432c227191f7a05d41d9127f080f4659b
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
package com.ruoyi.web.controller.system;
 
 
 
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysOperateType;
import com.ruoyi.system.domain.req.OperateTypeEditReqDTO;
import com.ruoyi.system.domain.req.OperateTypeListReqDTO;
import com.ruoyi.system.domain.req.OperateTypeAddReqDTO;
import com.ruoyi.system.service.SysOperateTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;
 
/**
 * @author hz
 * @since 2023-09-07 17:10:06
 */
@Api(tags = "获取作业类型与操作管理接口")
@RestController
@RequestMapping("/system/operateType")
public class SysOperateTypeController  extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private SysOperateTypeService sysOperateTypeService;
 
    /**
     * 获取作业类型列表
     */
    @ApiOperation(value = "获取作业类型列表",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", dataTypeClass = String.class,value = "作业类型名称"),
    })
    @PostMapping("/list")
    public AjaxResult list(@RequestBody OperateTypeListReqDTO reqDTO) {
        List<SysOperateType> operateTypes = sysOperateTypeService.selectOperateTypeList(reqDTO);
        return success(operateTypes);
    }
 
    /**
     * 根据作业类型编号获取详细信息
     */
    @ApiOperation(value = "获取操作类型信息",httpMethod = "GET")
    @ApiImplicitParam(name = "operateTypeId",dataTypeClass = Long.class,value = "操作类型id",required = true)
    @GetMapping(value = "/getInfoById/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return success(sysOperateTypeService.selectOperateTypeById(id));
    }
 
    /**
     * 新增作业类型
     */
    @PostMapping("/add")
    @Log(title = "作业类型管理", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增作业类型",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId",dataTypeClass = Long.class, value = "父作业类型id",required = true),
            @ApiImplicitParam(name = "code", dataTypeClass = String.class,value = "作业类型代码",required = true),
            @ApiImplicitParam(name = "name", dataTypeClass = String.class,value = "作业类型名称",required = true),
    })
    public AjaxResult add(@Validated @RequestBody OperateTypeAddReqDTO type) {
        if (!sysOperateTypeService.checkOperateTypeNameUnique(type.getName(),type.getParentId())) {
            return error("新增作业类型'" + type.getName() + "'失败,作业类型名称已存在");
        }
        return toAjax(sysOperateTypeService.insertOperateType(type));
    }
 
    /**
     * 修改作业类型
     */
    @Log(title = "作业类型管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ApiOperation(value = "修改作业类型",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", dataTypeClass = Long.class,value = "作业类型id",required = true),
            @ApiImplicitParam(name = "parentId", dataTypeClass = Long.class,value = "父作业类型id",required = true),
            @ApiImplicitParam(name = "code", dataTypeClass = String.class,value = "作业类型代码",required = true),
            @ApiImplicitParam(name = "name", dataTypeClass = String.class,value = "作业类型名称",required = true),
    })
    public AjaxResult edit(@Validated @RequestBody OperateTypeEditReqDTO reqDTO)
    {
        Long id = reqDTO.getId();
        if (!sysOperateTypeService.checkOperateTypeNameUnique(reqDTO.getName(),reqDTO.getParentId()))
        {
            return error("修改作业类型'" + reqDTO.getName() + "'失败,作业类型名称已存在");
        }
        else if (reqDTO.getParentId().equals(id))
        {
            return error("修改作业类型'" + reqDTO.getName() + "'失败,上级作业类型不能是自己");
        }
        return toAjax(sysOperateTypeService.updateOperateType(reqDTO));
    }
 
    /**
     * 删除作业类型
     */
    @Log(title = "作业类型管理", businessType = BusinessType.DELETE)
    @GetMapping("/removeById/{id}")
    @ApiOperation(value = "删除操作类型信息",httpMethod = "GET")
    @ApiImplicitParam(name = "id",dataTypeClass = Long.class,value = "操作类型id",required = true)
    public AjaxResult remove(@PathVariable Long id)
    {
        if (sysOperateTypeService.hasChildByOperateTypeId(id))
        {
            return warn("存在下级作业类型,不允许删除");
        }
        // TODO (HZ,2023/9/11 9:31,后面完善 由于不知道和哪些表关联)
        //if (sysOperateTypeService.checkDeptExistUser(deptId))
        //{
        //    return warn("作业类型存在用户,不允许删除");
        //}
        return toAjax(sysOperateTypeService.deleteOperateTypeById(id));
    }
}