package com.energy.manage.service.controller.anemometertower;


import com.energy.manage.common.base.Page;
import com.energy.manage.common.po.anemometertower.AnemometerTowerPO;
import com.energy.manage.common.reponse.ResultResp;
import com.energy.manage.service.config.annotations.UserLoginToken;
import com.energy.manage.service.controller.base.BaseServiceController;
import com.energy.manage.service.domain.dto.anemometertower.*;
import com.energy.manage.service.domain.vo.anemometertower.*;
import com.energy.manage.service.service.anemometertower.AnemometerTowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@CrossOrigin
@Api(value = "AnemometerTowerController", tags = "测风塔接口")
@RequestMapping(value = "/api/anemometer/tower")
public class AnemometerTowerController extends BaseServiceController {


    @Autowired
    private AnemometerTowerService anemometerTowerService;


    @UserLoginToken
    @PostMapping(value = "/createAnemometerTower")
    @ApiOperation(value = "创建测风塔数据")
    public ResultResp createAnemometerTower(@RequestBody @Valid AnemometerTowerCreateDto anemometerTowerCreateDto) {
        AnemometerTowerPO po = anemometerTowerService.getAnemometerTowerPOByanemometerTowerName(anemometerTowerCreateDto.getAnemometerName());
        if (po != null) {
            return ResultResp.FAIL("测风塔名称已经存在！");
        }
        anemometerTowerCreateDto.setCreateBy(getUserId());
        boolean flg = anemometerTowerService.createAnemometerTower(anemometerTowerCreateDto);
        return flg ? ResultResp.SUCCESS() : ResultResp.FAIL();
    }


    @UserLoginToken
    @PostMapping(value = "/delAnemometerTower")
    @ApiOperation(value = "删除测风塔数据")
    public ResultResp delAnemometerTower(@RequestBody @Valid AnemometerTowerDelDto anemometerTowerDelDto) {
        boolean flg = anemometerTowerService.delAnemometerTower(anemometerTowerDelDto);
        return flg ? ResultResp.SUCCESS() : ResultResp.FAIL();
    }


    @UserLoginToken
    @PostMapping(value = "/updateAnemometerTowerState")
    @ApiOperation(value = "修改测风塔状态")
    public ResultResp updateAnemometerTowerState(@RequestBody @Valid AnemometerTowerStateDto anemometerTowerStateDto) {
        boolean flg = anemometerTowerService.updateAnemometerTowerState(anemometerTowerStateDto);
        return flg ? ResultResp.SUCCESS() : ResultResp.FAIL();
    }

    @UserLoginToken
    @PostMapping(value = "/getAnemometerTowerPage")
    @ApiOperation(value = "查询测风塔分页信息")
    public ResultResp<Page<AnemometerTowerPageVo>> getAnemometerTowerPage(@RequestBody AnemometerTowerPageDto anemometerTowerPageDto) {
        Page<AnemometerTowerPageVo> page = anemometerTowerService.getAnemometerTowerPage(anemometerTowerPageDto);
        return ResultResp.SUCCESS(page);
    }

    @UserLoginToken
    @PostMapping(value = "/getAnemometerTowerNameList")
    @ApiOperation(value = "查询测风塔集合")
    public ResultResp<List<AnemometerTowerNameVo>> getAnemometerTowerNameList() {
        List<AnemometerTowerNameVo>  list = anemometerTowerService.getAnemometerTowerNameList();
        return ResultResp.SUCCESS(list);
    }

    @Deprecated
    @UserLoginToken
    @PostMapping(value = "/bathAnemometerTowerHeight")
    @ApiOperation(value = "批量绑定测风塔层高数据")
    public ResultResp bathAnemometerTowerHeight(@RequestBody AnemometerTowerHeightDto anemometerTowerHeightDto) {
        boolean flg = anemometerTowerService.bathAnemometerTowerHeight(anemometerTowerHeightDto);
        return flg ? ResultResp.SUCCESS() : ResultResp.FAIL();
    }


    @UserLoginToken
    @PostMapping(value = "/getAnemometerTower")
    @ApiOperation(value = "查询测风塔数据详情对象")
    public ResultResp<AnemometerTowerVo> getAnemometerTowerVo(@RequestBody AnemometerTowerDto anemometerTowerDto) {
        AnemometerTowerVo vo = anemometerTowerService.getAnemometerTowerVo(anemometerTowerDto);
        return ResultResp.SUCCESS(vo);
    }


    @UserLoginToken
    @PostMapping(value = "/getAnemometerTowerByField")
    @ApiOperation(value = "通过风场编号查询测风塔信息")
    public ResultResp<List<AnemometerTowerByFieldVo>> getAnemometerTowerByField(@RequestBody @Valid AnemometerTowerByFieldDto anemometerTowerByFieldDto) {
        List<AnemometerTowerByFieldVo> anemometerTowerByField = anemometerTowerService.getAnemometerTowerByField(anemometerTowerByFieldDto.getFieldCode());
        return ResultResp.SUCCESS(anemometerTowerByField);
    }


    @UserLoginToken
    @PostMapping(value = "/updateAnemometerTower")
    @ApiOperation(value = "修改测风塔数据")
    public ResultResp updateAnemometerTower(@RequestBody AnemometerTowerUpdateDto anemometerTowerUpdateDto) {
        boolean flg = anemometerTowerService.updateAnemometerTower(anemometerTowerUpdateDto);
        return flg ? ResultResp.SUCCESS() : ResultResp.FAIL();
    }


    @Deprecated
    @UserLoginToken
    @PostMapping(value = "/getAnemometerTowerHeight")
    @ApiOperation(value = "查询测风塔下层高数据")
    public ResultResp<AnemometerTowerHeightVo> getAnemometerTowerHeight(@RequestBody AnemometerTowerDto anemometerTowerDto) {
        AnemometerTowerHeightVo vo = anemometerTowerService.getAnemometerTowerHeight(anemometerTowerDto);
        return ResultResp.SUCCESS(vo);
    }


}
