月球大数据地理空间分析展示平台-【后端】-月球后台服务
13693261870
2023-06-02 544d000c2ee4d749210b6748ec97acf5597da9aa
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
package com.moon.server.controller.sys;
 
import com.moon.server.annotation.SysLog;
import com.moon.server.controller.all.BaseController;
import com.moon.server.entity.all.ResponseMsg;
import com.moon.server.entity.sys.DepEntity;
import com.moon.server.entity.sys.UserEntity;
import com.moon.server.helper.StringHelper;
import com.moon.server.service.sys.DepService;
import com.moon.server.service.sys.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
 
/**
 * 组织机构
 * @author sws
 * @date   2022-09-23
 */
@Api(tags = "运维管理\\单位管理")
@RestController
@RequestMapping("/dep")
public class DepController extends BaseController {
    @Autowired
    DepService depService;
 
    @Autowired
    TokenService tokenService;
 
    @SysLog()
    @ApiOperation(value = "插入一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "DepEntity", paramType = "body", example = "")
    })
    @PostMapping(value = "/insertDep", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insertDep(@RequestBody DepEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setCreateUser(ue.getId());
            }
 
            int count = depService.insertDep(entity);
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "插入多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "DepEntity", paramType = "body", example = "")
    })
    @PostMapping(value = "/insertDes", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insertDes(@RequestBody List<DepEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (DepEntity entity : list) {
                    entity.setCreateUser(ue.getId());
                }
            }
 
            int count = depService.insertDeps(list);
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "删除一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/deleteDep")
    public ResponseMsg<Integer> deleteDep(int id) {
        try {
            int count = depService.deleteDep(id);
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "删除多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/deleteDeps")
    public ResponseMsg<Integer> deleteDeps(@RequestParam List<Integer> ids) {
        try {
            if (ids == null || ids.isEmpty()) {
                return fail("id数组不能为空", -1);
            }
 
            int count = depService.deleteDeps(ids);
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "更新一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "DepEntity", paramType = "body", example = "")
    })
    @ResponseBody
    @PostMapping(value = "/updateDep", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> updateDep(@RequestBody DepEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setUpdateUser(ue.getId());
            }
 
            int count = depService.updateDep(entity);
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "更新多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "DepEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/updateDeps", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> updateDeps(@RequestBody List<DepEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (DepEntity entity : list) {
                    entity.setUpdateUser(ue.getId());
                }
            }
 
            int count = depService.updateDeps(list);
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "根据ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectDep")
    public ResponseMsg<DepEntity> selectDep(int id) {
        try {
            DepEntity de = depService.selectDep(id);
            return success(de);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "查询所有数据")
    @GetMapping(value = "/selectDepAll")
    public ResponseMsg<List<DepEntity>> selectDepAll() {
        try {
            List<DepEntity> list = depService.selectDepAll();
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "递归查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "单位名称", dataType = "String", paramType = "query", required = false, example = "中国xxx工程有限公司")
    })
    @GetMapping(value = "/selectDepRecursive")
    public ResponseMsg<List<DepEntity>> selectDepRecursive(String name) {
        try {
            if (StringHelper.isEmpty(name)) {
                name = "中国xxx工程有限公司";
            }
            List<DepEntity> list = depService.selectDepRecursive(name);
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
}