whyclxw
2024-11-04 8dd1d1ce18876c78d30e8c2d9876af892711037f
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
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.service.SubInfService;
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;
 
    @Autowired
    private SubInfService subService;
 
 
    @PostMapping("addCinf")
    @ApiOperation(value = "添加动环")
    @Transactional
    public Response addCinf(@RequestBody CircleInf circleInf){
        int userId = ActionUtil.getUser().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(circleInf.getSubList()!=null){
            circleInf.setSubCount(circleInf.getSubList().size());
        }
        if (service.add(circleInf)>0){
            //添加机房站点到用户对应的包机组
            binfService.insertUserBattgroupBaojigroupBattgroupSelect(circleInf.getStationId(),0,userId);
            //添加子件信息
            if(circleInf.getSubList()!=null&&circleInf.getSubList().size()>0){
                subService.addSubList(devId,circleInf.getSubList());
            }
 
            //添加电源站点时,更新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("updateCinf")
    @ApiOperation(value = "更新电源")
    public Response updateCinf(@RequestBody CircleInf circleInf){
        service.updateByDeviceId(circleInf);
        return new Response().set(1,true,"更新成功");
    }
 
    @GetMapping("deleteCinf")
    @ApiOperation(value = "删除电源")
    public Response deleteCinf(@RequestParam Integer deviceId){
        service.deleteByDeviceId(deviceId);
        return new Response().set(1,true,"删除成功");
    }
 
    @PostMapping("getCinf")
    @ApiOperation(value = "获取动环信息")
    public Response getCinf(@RequestBody CircleInf cinf,@RequestParam int pageCurr,@RequestParam int pageSize){
        return service.getCinf(cinf,pageCurr,pageSize);
    }
 
    @PostMapping("getSub")
    @ApiOperation(value = "获取子件信息")
    public Response getSub(@RequestBody SubInf sub,@RequestParam int pageCurr,@RequestParam int pageSize){
        return subService.getSub(sub,pageCurr,pageSize);
    }
 
    @PostMapping("updateSub")
    @ApiOperation(value = "更新子件")
    public Response updateSub(@RequestBody  SubInf sub){
        subService.updateSub(sub);
        return new Response().set(1,true,"更新成功");
    }
 
    @GetMapping("deleteSub")
    @ApiOperation(value = "删除子件")
    public Response deleteSub(@RequestParam Integer subId){
        subService.deleteSub(subId);
        return new Response().set(1,true,"删除成功");
    }
    @PostMapping("addSub")
    @ApiOperation(value = "添加子件")
    public Response addSub(@RequestBody  SubInf sub){
        subService.addSub(sub);
        return new Response().set(1,true,"添加成功");
    }
 
}