whyclxw
2024-10-31 d17a00b03b2553f16b7957abf97e1481c9a36d58
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
package com.whyc.controller;
 
import com.whyc.dto.Response;
import com.whyc.factory.BattinfGroupFactory;
import com.whyc.pojo.*;
import com.whyc.service.BattInfService;
import com.whyc.service.CircleInfService;
import com.whyc.service.StationInfService;
import com.whyc.util.ActionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
@RestController
@RequestMapping("circle")
@Api(tags = "动环管理")
public class CircleInfController {
    @Autowired
    private CircleInfService service;
 
    @Autowired
    private StationInfService sinfService;
 
    @Autowired
    private BattInfService binfService;
 
 
    @PostMapping
    @ApiOperation(value = "添加动环")
    @Transactional
    public Response add(@RequestBody CircleInf circleInf){
        int userId = ((UserInf)ActionUtil.getSession().getAttribute("user")).getUId().intValue();
        Response res = new Response();
        //校验机房站点是否存在,存在则不需要新建StationId
        StationInf sinf = sinfService.judgeStationName(circleInf.getStationName());
        if (sinf!=null) {
            circleInf.setStationId(sinf.getStationId());
        }else {
            //站点不存在,需要新建站点记录
            String nextStationId = binfService.getNextStationId();
            StationInf station = new StationInf();
            station.setStationId(nextStationId);
            station.setStationName(circleInf.getStationName());
            station.setStationName1(circleInf.getStationName1());
            station.setStationName2(circleInf.getStationName2());
            station.setStationName3(circleInf.getStationName3());
            station.setStationName5(circleInf.getStationName5());
            sinfService.insertStation(station);
            //powerInf.setStationId(String.valueOf(battInfService.searchMaxId_zj()));
            circleInf.setStationId(nextStationId);
        }
        //获取动环的设备id
        String devId = service.getDeviceId();
        circleInf.setDeviceId(devId);
        if (service.add(circleInf)>0){
            //添加机房站点到用户对应的包机组
            binfService.insertUserBattgroupBaojigroupBattgroupSelect(circleInf.getStationId(),0,userId);
            //添加电源站点时,更新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;
    }
    @PostMapping("update")
    @ApiOperation(value = "更新电源")
    public Response updateByDeviceId(@RequestBody CircleInf circleInf){
        service.updateByDeviceId(circleInf);
        return new Response().set(1,true,"更新成功");
    }
    @PostMapping("delete")
    @ApiOperation(value = "删除电源")
    public Response deleteByDeviceId(@RequestParam Integer deviceId){
        service.deleteByDeviceId(deviceId);
        return new Response().set(1,true,"删除成功");
    }
 
}