z1415143022
2025-04-11 c95af62539744af5c622f91c9b4668b117211032
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
package com.zhitan.web.controller.model;
 
import com.alibaba.fastjson.JSONObject;
import com.zhitan.common.annotation.Log;
import com.zhitan.common.core.controller.BaseController;
import com.zhitan.common.core.domain.AjaxResult;
import com.zhitan.common.core.page.TableDataInfo;
import com.zhitan.common.enums.BusinessType;
import com.zhitan.common.utils.SecurityUtils;
import com.zhitan.common.utils.poi.ExcelUtil;
import com.zhitan.common.utils.uuid.UUID;
import com.zhitan.model.domain.EnergyIndex;
import com.zhitan.model.domain.ModelNode;
import com.zhitan.model.service.IEnergyIndexService;
import com.zhitan.model.service.IModelNodeService;
import com.zhitan.system.service.ISysRoleService;
import com.zhitan.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * 模型节点Controller
 *
 * @author ZhiTan
 * @date 2020-02-10
 */
@RestController
@RequestMapping("/basicsetting/modelnode")
@Api(value = "模型节点",tags = {"模型节点"})
public class ModelNodeController extends BaseController {
 
  private final IModelNodeService modelNodeService;
 
 
  @Autowired
  public ModelNodeController(
      IModelNodeService modelNodeService, IEnergyIndexService energyIndexService,
      ISysUserService sysUserService,
      ISysRoleService roleService) {
    this.modelNodeService = modelNodeService;
  }
 
  /**
   * 查询模型节点列表
   */
  @ApiOperation(value = "查询模型节点列表")
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:query')")
  @GetMapping("/list")
  public TableDataInfo list(ModelNode modelNode) {
    startPage();
    List<ModelNode> list = modelNodeService.selectModelNodeList(modelNode);
    return getDataTable(list);
  }
 
  /**
   * 查询模型节点列表
   */
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:list')")
  @GetMapping("/treelist")
  @ApiOperation(value = "查询模型节点树状列表")
  public AjaxResult treeList(String modelCode) {
    List<ModelNode> list = modelNodeService.getModelNodeByModelCode(modelCode);
    return AjaxResult.success(modelNodeService.buildModelNodeTree(list));
  }
 
  /**
   * 查询模型节点列表
   */
  @GetMapping("/treelist/withAuth")
  @ApiOperation(value = "查询模型节点列表")
  public AjaxResult treeListWithAuth(String modelCode) {
    Long userId = SecurityUtils.getUserId();
    List<ModelNode> list = modelNodeService.getModelNodeByModelCodeWithAuth(modelCode, userId);
    return AjaxResult.success(modelNodeService.buildModelNodeTree(list));
  }
 
  /**
   * 导出模型节点列表
   */
  @ApiOperation(value = "导出模型节点列表")
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:export')")
  @Log(title = "模型节点", businessType = BusinessType.EXPORT)
  @GetMapping("/export")
  public AjaxResult export(ModelNode modelNode) {
    List<ModelNode> list = modelNodeService.selectModelNodeList(modelNode);
    ExcelUtil<ModelNode> util = new ExcelUtil<ModelNode>(ModelNode.class);
    return util.exportExcel(list, "modelNode");
  }
 
  /**
   * 获取模型节点详细信息
   */
  @ApiOperation(value = "获取模型节点详细信息")
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:query')")
  @GetMapping(value = "/{nodeId}")
  public AjaxResult getInfo(@PathVariable("nodeId") String nodeId) {
    return AjaxResult.success(modelNodeService.selectModelNodeById(nodeId));
  }
 
  @GetMapping(value = "/hasEnergyIndex")
  @ApiOperation(value = "获取模型节点详细信息")
  public AjaxResult hasEnergyIndex(String nodeId) {
    return AjaxResult.success(modelNodeService.hasEnergyIndex(nodeId));
  }
 
  /**
   * 新增模型节点
   */
  @ApiOperation(value = "新增模型节点")
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:add')")
  @Log(title = "模型节点", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody ModelNode modelNode) {
    boolean isExist = modelNodeService
        .modelNodeHasExist(modelNode.getCode(), modelNode.getModelCode());
    if (isExist) {
      return AjaxResult.error("模型节点编码不能重复!");
    } else {
      modelNode.setNodeId(UUID.randomUUID().toString());
      modelNodeService.insertModelNode(modelNode);
      return AjaxResult.success(modelNode);
    }
  }
 
  /**
   * 修改模型节点
   */
  @ApiOperation(value = "修改模型节点")
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "模型节点", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@RequestBody ModelNode modelNode) {
    boolean isExist = modelNodeService.modelNodeHasExist(modelNode);
    if (isExist) {
      return AjaxResult.error("模型节点编码不能重复!");
    } else {
      return toAjax(modelNodeService.updateModelNode(modelNode));
    }
  }
 
  /**
   * 修改模型节点
   */
  @ApiOperation(value = "模型节点排序")
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "模型节点", businessType = BusinessType.UPDATE)
  @PutMapping("/order")
  public AjaxResult order(@RequestBody JSONObject param) {
    String nodeId = param.getString("nodeId");
    String parentId = param.getString("parentId");
    String[] children = param.getJSONArray("children").toJavaList(String.class).toArray(
            new String[]{});
    modelNodeService.updateOrder(nodeId, parentId, children);
    return AjaxResult.success();
  }
 
  /**
   * 删除模型节点
   */
  @ApiOperation(value = "删除模型节点")
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:remove')")
  @Log(title = "模型节点", businessType = BusinessType.DELETE)
  @DeleteMapping("/{nodeIds}")
  public AjaxResult remove(@PathVariable String[] nodeIds) {
    return toAjax(modelNodeService.deleteModelNodeByIds(nodeIds));
  }
 
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "设置模型节点关联设备", businessType = BusinessType.UPDATE)
  @GetMapping("/device/{nodeId}")
  @ApiOperation(value = "设置模型节点关联设备")
  public AjaxResult getSettingDevice(@PathVariable("nodeId") String nodeId) {
    try {
      return AjaxResult.success(modelNodeService.getSettingDevice(nodeId));
    } catch (Exception ex) {
      logger.error("获取关联设备出错!", ex);
      return AjaxResult.error("获取关联设备出错!");
    }
  }
 
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "设置模型节点关联设备", businessType = BusinessType.UPDATE)
  @PostMapping("/device/{nodeId}")
  @ApiOperation(value = "设置模型节点关联设备")
  public AjaxResult setDevice(@PathVariable("nodeId") String nodeId,
      @RequestBody String[] deviceIds) {
    try {
      modelNodeService.setDevice(nodeId, deviceIds);
      return AjaxResult.success();
    } catch (Exception ex) {
      logger.error("设置关联设备出错!", ex);
      return AjaxResult.error();
    }
  }
 
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "设置模型节点关联设备", businessType = BusinessType.UPDATE)
  @DeleteMapping("/device/{nodeId}")
  @ApiOperation(value = "删除模型节点关联设备")
  public AjaxResult delDevice(@PathVariable("nodeId") String nodeId,
      @RequestBody String[] deviceIds) {
    try {
      modelNodeService.delDevice(nodeId, deviceIds);
      return AjaxResult.success();
    } catch (Exception ex) {
      logger.error("删除关联设备出错!", ex);
      return AjaxResult.error();
    }
  }
 
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "设置模型节点关联能源", businessType = BusinessType.UPDATE)
  @GetMapping("/energy/{nodeId}")
  @ApiOperation(value = "获取模型节点关联能源")
  public AjaxResult getSettingEnergy(@PathVariable("nodeId") String nodeId) {
    try {
      return AjaxResult.success(modelNodeService.getSettingEnergy(nodeId));
    } catch (Exception ex) {
      logger.error("获取关联能源出错!", ex);
      return AjaxResult.error("获取关联能源出错!");
    }
  }
 
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "设置模型节点关联能源", businessType = BusinessType.UPDATE)
  @PostMapping("/energy/{nodeId}")
  @ApiOperation(value = "设置模型节点关联能源")
  public AjaxResult setEnergy(@PathVariable("nodeId") String nodeId,
      @RequestBody Integer[] energyIds) {
    try {
      modelNodeService.setEnergy(nodeId, energyIds);
      return AjaxResult.success();
    } catch (Exception ex) {
      logger.error("设置关联能源出错!", ex);
      return AjaxResult.error();
    }
  }
 
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "设置模型节点关联能源", businessType = BusinessType.UPDATE)
  @DeleteMapping("/energy/{nodeId}")
  @ApiOperation(value = "删除模型节点关联能源")
  public AjaxResult delEnergy(@PathVariable("nodeId") String nodeId,
      @RequestBody Integer[] energyIds) {
    try {
      modelNodeService.delEnergy(nodeId, energyIds);
      return AjaxResult.success();
    } catch (Exception ex) {
      logger.error("删除关联能源出错!", ex);
      return AjaxResult.error();
    }
  }
 
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "设置模型节点关联产品", businessType = BusinessType.UPDATE)
  @GetMapping("/product/{nodeId}")
  @ApiOperation(value = "获取模型节点关联产品")
  public AjaxResult getSettingProduct(@PathVariable("nodeId") String nodeId) {
    try {
      return AjaxResult.success(modelNodeService.getSettingProduct(nodeId));
    } catch (Exception ex) {
      logger.error("获取关联产品出错!", ex);
      return AjaxResult.error("获取关联产品出错!");
    }
  }
 
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "设置模型节点关联产品", businessType = BusinessType.UPDATE)
  @PostMapping("/product/{nodeId}")
  @ApiOperation(value = "设置模型节点关联产品")
  public AjaxResult setProduct(@PathVariable("nodeId") String nodeId,
      @RequestBody Integer[] productIds) {
    try {
      modelNodeService.setProduct(nodeId, productIds);
      return AjaxResult.success();
    } catch (Exception ex) {
      logger.error("设置关联产品出错!", ex);
      return AjaxResult.error();
    }
  }
 
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "设置模型节点关联产品", businessType = BusinessType.UPDATE)
  @DeleteMapping("/product/{nodeId}")
  @ApiOperation(value = "删除模型节点关联产品")
  public AjaxResult delProduct(@PathVariable("nodeId") String nodeId,
      @RequestBody Integer[] productIds) {
    try {
      modelNodeService.delProduct(nodeId, productIds);
      return AjaxResult.success();
    } catch (Exception ex) {
      logger.error("删除关联产品出错!", ex);
      return AjaxResult.error();
    }
  }
 
  @GetMapping("/energyIndex/{nodeId}")
  @ApiOperation(value = "获取模型节点关联指标")
  public AjaxResult getSettingIndex(@PathVariable("nodeId") String nodeId) {
    try {
      return AjaxResult.success(modelNodeService.getSettingIndex(nodeId));
    } catch (Exception ex) {
      logger.error("获取关联采集指标出错!", ex);
      return AjaxResult.error("获取关联指标出错!");
    }
  }
 
  @GetMapping("/energyIndex/{indexType}/{nodeId}")
  @ApiOperation(value = "获取模型节点关联指标")
  public AjaxResult getSettingIndex(@PathVariable("indexType") String indexType,
      @PathVariable("nodeId") String nodeId, String code,
                                    String name, Long pageNum, Long pageSize) {
    try {
      return AjaxResult.success(modelNodeService.getSettingIndex(indexType, nodeId,code, name,pageNum,pageSize));
    } catch (Exception ex) {
      logger.error("获取关联采集指标出错!", ex);
      return AjaxResult.error("获取关联指标出错!");
    }
  }
 
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "设置模型节点关联采集指标", businessType = BusinessType.UPDATE)
  @PostMapping("/energyIndex/{nodeId}/{indexType}")
  @ApiOperation(value = "设置模型节点关联指标")
  public AjaxResult setSettingIndex(@PathVariable("nodeId") String nodeId,
      @PathVariable("indexType") String indexType,
      @RequestBody String[] indexIds) {
    try {
      modelNodeService.setIndex(nodeId, indexType, indexIds);
      return AjaxResult.success();
    } catch (Exception ex) {
      logger.error("设置关联采集指标出错!", ex);
      return AjaxResult.error();
    }
  }
 
  @PreAuthorize("@ss.hasPermi('basicsetting:modelNode:edit')")
  @Log(title = "删除模型节点关联采集指标", businessType = BusinessType.UPDATE)
  @DeleteMapping("/energyIndex/{nodeId}")
  @ApiOperation(value = "删除模型节点关联指标")
  public AjaxResult delSettingIndex(@PathVariable("nodeId") String nodeId,
                                    @RequestBody String[] indexIds) {
    try {
      modelNodeService.delIndex(nodeId, indexIds);
      return AjaxResult.success();
    } catch (Exception ex) {
      logger.error("删除关联采集指标出错!", ex);
      return AjaxResult.error();
    }
  }
 
  @Log(title = "根据nodeId查询点位信息", businessType = BusinessType.UPDATE)
  @GetMapping("/getIndexInforByNodeId")
  @ApiOperation(value = "根据nodeId查询点位信息")
  public AjaxResult getIndexInforByNodeId(String nodeId) {
    try {
      List<EnergyIndex> settingIndex = modelNodeService.getSettingIndex(nodeId);
 
 
      return AjaxResult.success();
    } catch (Exception ex) {
      logger.error("删除关联采集指标出错!", ex);
      return AjaxResult.error();
    }
  }
 
 
 
  @GetMapping("/energyIndex/meterImplement/{nodeId}")
  @ApiOperation(value = "根据nodeid获取计量器具,然后获取模型节点关联指标")
  public TableDataInfo getIndexByMeterImplement(@PathVariable("nodeId") String nodeId,
                                                String code,
                                                String name,
                                                @RequestParam Long pageNum,  
                                                @RequestParam Long pageSize) {
      return getDataTable(modelNodeService.getIndexByMeterImplement(nodeId,code,name,pageNum,pageSize));
  }
}