whyclxw
2021-12-16 1af4c9c2ec01ce9760771cd2a6cb9120b22cecfe
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
package com.whyc.controller;
 
import com.baomidou.mybatisplus.extension.api.R;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.factory.BattinfGroupFactory;
import com.whyc.pojo.PowerInf;
import com.whyc.pojo.UserInf;
import com.whyc.service.BattInfService;
import com.whyc.service.PowerAppSysService;
import com.whyc.service.PowerInfService;
import com.whyc.util.ActionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.io.PipedWriter;
import java.util.List;
 
@RequestMapping("powerInf")
@RestController
@Api(tags = "数据管理-电源信息")
public class PowerInfController {
    @Autowired
    private PowerInfService service;
    @Autowired
    private BattInfService battInfService;
    @Autowired
    private PowerAppSysService powerAppSysService;
 
    @PostMapping
    @ApiOperation(value = "添加电源")
    public Response add(@RequestBody PowerInf powerInf){
        Response res = new Response();
        if(StringUtils.isEmpty(powerInf.getStationId())){
            powerInf.setStationId(String.valueOf(BattinfGroupFactory.searchStationId()));
        }
        int devId = battInfService.searchMaxDevId(powerInf.getPowerDeviceType());
        powerInf.setPowerDeviceId(devId);
        if (service.add(powerInf)>0){
            //添加电源站点时,更新ReInit字段为1,通讯程序监控变化重新初始化
            if(powerInf.getPowerDeviceType()==BattinfGroupFactory.DEVICE_POWER) {
                boolean flag = powerAppSysService.updateFlag("AppServer_Reinit_PowerData_EN");
                if (!flag) {
                    System.out.println("更新updateReInit接口失败");
                }
            }else{
                //充电机和绝缘装置的,更新另一个ReInit字段为1
                boolean flag = powerAppSysService.updateFlag("AppServer_Reinit_BattGroupData_EN");
                if (!flag) {
                    System.out.println("更新updateReInit接口失败");
                }
            }
            res.set(1,true,"添加成功");
        }else{
            res.set(1,false,"添加失败");
        }
 
        return res;
    }
    @PutMapping
    @ApiOperation(value = "更新电源")
    public Response update(@RequestBody PowerInf powerInf){
        service.updateByPowerDeviceId(powerInf);
        return new Response().set(1,true,"更新成功");
    }
    @DeleteMapping
    @ApiOperation(value = "删除电源")
    public Response delete(@RequestParam Integer powerDeviceId){
        service.deleteByPowerDeviceId(powerDeviceId);
        return new Response().set(1,true,"删除成功");
    }
 
 
 
    @GetMapping("/getProvincesContainBatt")
    @ApiOperation(value = "获取所有省份")
    public Response getProvincesContainBatt(){
        return service.getProvincesContainBatt();
    }
 
    @GetMapping("/getCitiesContainBatt")
    @ApiOperation(value = "获取所有城市")
    public Response getCitiesContainBatt(@RequestParam String stationName1){
        return service.getCitiesContainBatt(stationName1);
    }
 
    @GetMapping("/getDistrictsContainBatt")
    @ApiOperation(value = "获取所有地区")
    public Response getDistrictsContainBatt(@RequestParam String stationName1,@RequestParam String stationName2){
        return service.getDistrictsContainBatt(stationName1,stationName2);
    }
 
    @GetMapping("/getProvinces")
    @ApiOperation(value = "用户管理的机房省份")
    public Response getProvinces(){
        UserInf userInf = (UserInf) ActionUtil.getUser();
        return service.getProvinces(userInf.getUId());
    }
    @GetMapping("/getCities")
    @ApiOperation(value = "用户管理的省份的城市")
    public Response getCities(@RequestParam(required = false) String stationName1){
        UserInf userInf = (UserInf) ActionUtil.getUser();
        return service.getCities(userInf.getUId(),stationName1);
    }
    @GetMapping("/getDistricts")
    @ApiOperation(value = "用户管理的地区")
    public Response getDistricts(@RequestParam(required = false) String stationName1,@RequestParam(required = false) String stationName2){
        UserInf userInf = (UserInf) ActionUtil.getUser();
        return service.getDistricts(userInf.getUId(),stationName1,stationName2);
    }
 
 
    @GetMapping("/getExistStations")
    @ApiOperation(value = "获取所有机房")
    public Response getExistStations( @RequestParam(required = false) String stationName1,@RequestParam(required = false) String stationName2,@RequestParam(required = false) String stationName5){
        return service.getExistStations(stationName1,stationName2,stationName5);
    }
 
    @GetMapping("/getStations")
    @ApiOperation(value = "获取用户管理的机房")
    public Response getStations(@RequestParam(required = false) String stationName5){
        UserInf userInf = (UserInf) ActionUtil.getUser();
        return service.getStations(userInf.getUId(),stationName5);
    }
 
    @GetMapping("/getPowerDevicesPage")
    @ApiOperation(value = "用户管理的电源信息分页")
    public Response getPowerDevicesPage(@RequestParam int pageNum,@RequestParam int pageSize,@RequestParam(required = false) String stationId, @RequestParam(required = false) String stationName1,@RequestParam(required = false) String stationName2,@RequestParam(required = false) String stationName5){
        UserInf userInf = (UserInf) ActionUtil.getUser();
        return service.getPowerDevicesPage(pageNum,pageSize,userInf.getUId(),stationId, stationName1,stationName2,stationName5);
    }
 
 
    @GetMapping("/getPowerDevices")
    @ApiOperation(value = "用户管理的电源信息")
    public Response getPowerDevices(@RequestParam String stationId){
        UserInf userInf = (UserInf) ActionUtil.getUser();
        return service.getPowerDevices(stationId);
    }
 
    @GetMapping("/getInfoById")
    @ApiOperation(value = "在线监测-实时监控-查询某个电源的详细信息")
    public Response getInfoById(@RequestParam int powerDeviceId){
        return service.getInfoById(powerDeviceId);
    }
 
    @GetMapping("/getPowerInfoById")
    @ApiOperation(value = "在线监测-实时监控-获取配电柜的实时数据")
    public Response getPowerInfoById(@RequestParam int powerDeviceId){
        return service.getPowerInfoById(powerDeviceId);
    }
 
 
}