Blame view

src/main/java/com/objecteye/controller/AreaEquipmentController.java 5.31 KB
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
  package com.objecteye.controller;
  
  
  import com.objecteye.common.CommonResult;
  import com.objecteye.entity.SyAreaEquipment;
  import com.objecteye.service.AreaEquipmentService;
  import io.swagger.annotations.Api;
  import io.swagger.annotations.ApiOperation;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.web.bind.annotation.*;
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  /**
   * controller
   *
   * @author Administrator
   */
  @RestController
  @Api(tags = "AreaEquipmentController", description = "区域设备管理")
  @RequestMapping("/areaEquipment")
  @CrossOrigin
  public class AreaEquipmentController {
  
      @Autowired
      private AreaEquipmentService areaEquipmentService;
  
      /**
       * 返回全部列表
       *
       * @return
       */
      @ApiOperation("区域设备树的展示==区域可操作")
      @RequestMapping(value = "/findAll", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
      public CommonResult findAll() {
          if (areaEquipmentService.findAll() == null) {
              return CommonResult.success("", "无符合条件的数据");
          }
          return CommonResult.success(areaEquipmentService.findAll());
      }
  
      /**
       * 返回全部列表
       *
       * @return
       */
      @ApiOperation("区域设备树的展示==区域设备可操作")
      @RequestMapping(value = "/findAllEquipAndArea", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
      public CommonResult findAllEquipAndArea() {
          if (areaEquipmentService.findAllEquipAndArea() == null) {
              return CommonResult.success("", "无符合条件的数据");
          }
          return CommonResult.success(areaEquipmentService.findAllEquipAndArea());
      }
  
      /**
       * 增加
       *
       * @param areaEquipment
       * @return
       */
      @ApiOperation("添加区域")
      @RequestMapping(value = "/add", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
      public CommonResult add(@RequestBody SyAreaEquipment areaEquipment) {
          Integer parentId = areaEquipment.getParentId();
          if (parentId == 1) {
              int count = areaEquipmentService.add(areaEquipment);
              if (count > 0) {
                  return CommonResult.success(count);
              }
          }
          return CommonResult.failed("该区域下只能创建设备");
      }
  
      /**
       * 修改
       *
       * @param areaEquipment
       * @return
       */
      @ApiOperation("修改区域名称")
      @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
      public CommonResult update(@RequestBody SyAreaEquipment areaEquipment) {
          int count = areaEquipmentService.update(areaEquipment);
          if (count > 0) {
              return CommonResult.success(count);
          }
          return CommonResult.failed("节点id无效");
      }
  
      /**
       * 获取实体
       *
       * @return
       */
      /*@ApiOperation("查找区域或者设备")
  	@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");
          if(areaEquipmentService.findOne(id)==null){
              return CommonResult.success("","节点无效");
          }
          return CommonResult.success(areaEquipmentService.findOne(id));
  	}*/
  
      /**
       * 删除区域
       *
       * @param map
       * @return
       */
      @ApiOperation("删除区域")
      @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");
              areaEquipmentService.delete(ids);
              return CommonResult.success("删除成功", "删除成功");
          } catch (Exception e) {
              e.printStackTrace();
              return CommonResult.failed(e.getMessage());
          }
      }
  
      @ApiOperation("判断该区域下是否有设备")
      @RequestMapping(value = "/isHaveChild", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
      public CommonResult isHaveChild(@RequestBody Map<String, Integer> map) {
          int id = map.get("id");
          List<Integer> ids = areaEquipmentService.findCaptureById(id);
          if (ids == null || ids.size() == 0) {
              return CommonResult.success(ids, "是否确认删除该区域?");
          }
          return CommonResult.success(ids, "该区域下存在设备,且可能存在正在执行的布控任务,请确认是否删除该区域?");
      }
  
  
      @ApiOperation("根据id查找该区域下所有设备")
      @RequestMapping(value = "/findCaptureById", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
      public CommonResult findCaptureById(@RequestBody Map<String, Integer> map) {
          try {
              Integer id = map.get("id");
              List<HashMap<String, Object>> captureMsgById = areaEquipmentService.findCaptureMsgById(id);
              if (captureMsgById == null) {
                  return CommonResult.success("", "该区域下无设备");
              }
              return CommonResult.success(captureMsgById);
          } catch (Exception e) {
              e.printStackTrace();
              return CommonResult.failed();
          }
      }
  
  }