whyczh
2021-12-10 1ab06fa644b400182dde1621c60f904c4711f2b6
src/main/java/com/whyc/controller/PowerInfController.java
@@ -1,29 +1,54 @@
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.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 java.io.PipedWriter;
import java.util.List;
@RequestMapping("powerInf")
@RestController
@Api(tags = "电源管理")
@Api(tags = "数据管理-电源信息")
public class PowerInfController {
    @Autowired
    private PowerInfService service;
    @Autowired
    private PowerAppSysService powerAppSysService;
    @PostMapping
    @ApiOperation(value = "添加电源")
    public Response add(@RequestBody PowerInf powerInf){
        if(StringUtils.isEmpty(powerInf.getStationId())){
            powerInf.setStationId(String.valueOf(BattinfGroupFactory.searchStationId()));
        }
        powerInf.setPowerDeviceId(BattinfGroupFactory.searchmaxdev_id(powerInf.getPowerDeviceType()));
        service.add(powerInf);
        //添加电源站点时,更新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接口失败");
            }
        }
        return new Response().setII(1,"添加成功");
    }
    @PutMapping
@@ -80,16 +105,22 @@
    @GetMapping("/getExistStations")
    @ApiOperation(value = "获取机房")
    public Response getExistStations( @RequestParam String stationName1,@RequestParam String stationName2,@RequestParam String stationName5){
    @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 PageInfo<PowerInf> getPowerDevicesPage(@RequestParam(required = false) String stationId, @RequestParam(required = false) String stationName1,@RequestParam(required = false) String stationName2,@RequestParam(required = false) String stationName5){
    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();
        PageInfo<PowerInf> list = service.getPowerDevicesPage(userInf.getUId(),stationId, stationName1,stationName2,stationName5);
        return list;
        return service.getPowerDevicesPage(pageNum,pageSize,userInf.getUId(),stationId, stationName1,stationName2,stationName5);
    }
}