c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
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
|
package com.objecteye.controller;
import com.objecteye.common.CommonResult;
import com.objecteye.entity.PageResult;
import com.objecteye.entity.SyEquipment;
import com.objecteye.service.EquipmentService;
import com.objecteye.utils.GlobalUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* controller
*
* @author Administrator
*/
@RestController
@RequestMapping("/equipment")
@Api(tags = "EquipmentController", description = "设备管理")
@CrossOrigin
public class EquipmentController {
@Autowired
private EquipmentService equipmentService;
@Autowired
private RedisTemplate redisTemplate;
/**
* 返回全部列表
*
* @return
*/
@ApiOperation("分页返回全部设备")
@RequestMapping(value = "/findPage", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public CommonResult findPage(@RequestParam int currentpage, @RequestParam int pagevolume) { //@RequestBody PagePara pagePara
//PageResult page1 = equipmentService.findPage(pagePara.getPage(), pagePara.getLimit());
PageResult page1 = equipmentService.findPage(currentpage, pagevolume);
if (page1 != null) {
return CommonResult.success(page1);
}
return CommonResult.success("", "无可用设备");
}
/**
* 增加
*
* @param equipment
* @return
*/
@ApiOperation("添加设备")
@RequestMapping(value = "/add", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public CommonResult add(@RequestBody SyEquipment equipment) {
SyEquipment byIp = equipmentService.findByIp(equipment.getEquipmentIp());
SyEquipment byName = equipmentService.findByName(equipment.getEquipmentName());
SyEquipment byPort = equipmentService.findByPort(equipment.getEquipmentPort());
if ((byIp == null) & (byName == null) & (byPort == null)) {
int count = equipmentService.add(equipment);
if (count > 0) {
return CommonResult.success(count);
}
return CommonResult.failed();
}
return CommonResult.failed("设备名称、ip、端口不能重复");
}
/**
* 修改
*
* @param equipment
* @return
*/
@ApiOperation("更新设备")
@RequestMapping(value = "/update", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public CommonResult update(@RequestBody SyEquipment equipment) {
int update = equipmentService.update(equipment);
if (update > 0) {
return CommonResult.success(update);
}
if (update == 0) {
return CommonResult.failed("设备名称不能重复");
}
return CommonResult.failed();
}
/**
* 获取实体
*
* @return
*/
@ApiOperation("根据id查找设备")
@RequestMapping(value = "/findOne", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public CommonResult findOne(@RequestBody Map<String, Integer> map) {
Integer id = map.get("id");
SyEquipment equipment = equipmentService.findOne(id);
if (equipment != null) {
return CommonResult.success(equipment);
}
return CommonResult.failed("设备id无效");
}
/**
* 批量删除
*
* @return
*/
@ApiOperation("删除设备")
@Transactional
@RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public CommonResult delete(@RequestBody Map<String, int[]> map) {
try {
int[] ids = map.get("ids");
equipmentService.delete(ids);
return CommonResult.success("删除成功", "操作成功");
} catch (Exception e) {
e.printStackTrace();
return CommonResult.failed(e.getMessage());
}
}
/**
* 设备开关
*
* @param map
* @return
*/
@ApiOperation("设备开关")
@RequestMapping(value = "/updateStatusById", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public CommonResult updateStatusById(@RequestBody Map<String, Integer> map) {
Integer id = map.get("id");
int i = equipmentService.updateStatusById(id);
if (i == -1) {
return CommonResult.failed("设备id无效");
}
if (i != 0) {
return CommonResult.success("设备状态更新成功");
}
return CommonResult.failed();
}
/**
* 设备开关
*
* @param map id区域id
* @return 设备是否可以删除
*/
@ApiOperation("设备是否可以删除")
@RequestMapping(value = "/checkDelete", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public CommonResult checkDelete(@RequestBody Map<String, Integer> map) {
Integer id = map.get("id");
boolean canDel = true;
List<String> msgList = new ArrayList<>();
if (redisTemplate.opsForHash().hasKey(GlobalUtil.IPWITHDEPLOYLIST, id)) {
canDel = false;
msgList.add("布控预警任务");
}
if (redisTemplate.opsForHash().hasKey(GlobalUtil.FORBIDDEN_TASK, id)) {
canDel = false;
msgList.add("禁行任务");
}
if (canDel) {
return CommonResult.success(200, "不存在设备占用情况", "");
} else {
return CommonResult.success(201, "存在" + String.join(",", msgList) + "占用设备", "");
}
}
}
|