liulingling.177216
2024-08-26 349f1cfc5fa77fbc636d542df0d8050fddec48c2
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
package com.dingzhuo.energy.project.gateway.controller;
 
import cn.hutool.core.collection.CollectionUtil;
import com.dingzhuo.energy.common.core.lang.UUID;
import com.dingzhuo.energy.common.utils.poi.ExcelUtil;
import com.dingzhuo.energy.framework.aspectj.lang.annotation.Log;
import com.dingzhuo.energy.framework.aspectj.lang.enums.BusinessType;
import com.dingzhuo.energy.framework.web.controller.BaseController;
import com.dingzhuo.energy.framework.web.domain.AjaxResult;
import com.dingzhuo.energy.framework.web.page.TableDataInfo;
import com.dingzhuo.energy.project.gateway.domain.GatewaySetting;
import com.dingzhuo.energy.project.gateway.service.IGatewaySettingService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.Comparator;
import java.util.Date;
import java.util.List;
 
/**
 * 网关配置信息Controller
 *
 * @author zhw
 * @date 2022-04-15
 */
@RestController
@RequestMapping("/gateway/gatewaysetting")
public class GatewaySettingController extends BaseController
{
    @Autowired
    private IGatewaySettingService gatewaySettingService;
 
    /**
     * 查询网关配置信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GatewaySetting gatewaySetting)
    {
        startPage();
        List<GatewaySetting> list = gatewaySettingService.selectGatewaySettingList(gatewaySetting);
        return getDataTable(list);
    }
 
    /**
     * 导出网关配置信息列表
     */
    @Log(title = "网关配置信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GatewaySetting gatewaySetting)
    {
        List<GatewaySetting> list = gatewaySettingService.selectGatewaySettingList(gatewaySetting);
        ExcelUtil<GatewaySetting> util = new ExcelUtil<GatewaySetting>(GatewaySetting.class);
        return util.exportExcel(list, "gatewaysetting");
    }
 
    /**
     * 获取网关配置信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(gatewaySettingService.selectGatewaySettingById(id));
    }
 
    /**
     * 新增网关配置信息
     */
    @Log(title = "新增网关配置信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GatewaySetting gatewaySetting)
    {
        List<GatewaySetting> gatewaySettingList =  gatewaySettingService.checkOne(gatewaySetting);
        if(!CollectionUtil.isEmpty(gatewaySettingList)){
            return AjaxResult.error("网关编号重复");
        }
        gatewaySetting.setId(UUID.fastUUID().toString());
        return toAjax(gatewaySettingService.insertGatewaySetting(gatewaySetting));
    }
 
    /**
     * 修改网关配置信息
     */
    @Log(title = "网关配置信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GatewaySetting gatewaySetting)
    {
        if(ObjectUtils.isEmpty(gatewaySetting.getId())){
            return AjaxResult.error("无网关主键");
        }
        List<GatewaySetting> gatewaySettingList =  gatewaySettingService.checkOne(gatewaySetting);
        if(!CollectionUtil.isEmpty(gatewaySettingList)){
            return AjaxResult.error("网关编号重复");
        }
        return toAjax(gatewaySettingService.updateGatewaySetting(gatewaySetting));
    }
 
    /**
     * 删除网关配置信息
     */
    @Log(title = "网关配置信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gatewaySettingService.deleteGatewaySettingByIds(ids));
    }
 
    /**
     * 查询网关配置信息列表
     */
    @GetMapping("/monitor")
    public TableDataInfo monitor()
    {
        startPage();
        List<GatewaySetting> list = gatewaySettingService.selectGatewaySettingMonitorList();
 
        if(CollectionUtils.isNotEmpty(list)){
            list.forEach(f->{
                Date dd = f.getHbtTime();
                //3分钟没有心跳就超时
                if(ObjectUtils.isEmpty(dd)){
                    f.setState("未知");
                }else  if(dd.getTime()+60000*5>(new Date()).getTime())
                {
                    f.setState("在线");
                }else{
                    f.setState("离线");
                }
            });
        }
        list.stream().sorted(Comparator.comparing(GatewaySetting::getHbtTime));
        return getDataTable(list);
    }
}