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

import com.energy.manage.common.base.Page;
import com.energy.manage.common.reponse.ConstVar;
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.windfieldbatch.WindFieldBatchDto;
import com.energy.manage.service.domain.dto.windfieldbatch.WindFileBatchPageDto;
import com.energy.manage.service.domain.vo.windfieldbatch.WindFieldBatchVo;
import com.energy.manage.service.service.windfieldbatch.WindFieldBatchService;
import com.energy.manage.service.util.IPUtils;
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.servlet.http.HttpServletRequest;

/**
 * @author chy
 * @date 2024/5/20 17:32
 * @desc
 */
@Slf4j
@Api(value = "WindFieldBatchController", tags = "风场批次管理")
@RestController
@RequestMapping("/windEnginBatch")
public class WindFieldBatchController extends BaseServiceController {

    @Autowired
    private WindFieldBatchService windFieldBatchService;

    @UserLoginToken
    @ApiOperation(value = "风场批次信息列表")
    @GetMapping("/batchList")
    public ResultResp<Page<WindFieldBatchVo>> batchList(WindFileBatchPageDto windFieldBatchPageDto){
        windFieldBatchPageDto.setRoleId(getRoleId());
        return pageResult(windFieldBatchService.queryWindFieldBatch(windFieldBatchPageDto), windFieldBatchPageDto);
    }

    @UserLoginToken
    @ApiOperation(value = "添加风场批次")
    @PostMapping("/addFieldBatch")
    public ResultResp addFieldBatch(@RequestBody WindFieldBatchDto windFieldBatchDto){
        Integer loginUserId = getUserId();
        windFieldBatchDto.setCreateBy(loginUserId);
        windFieldBatchDto.setUpdateBy(loginUserId);
        int result = windFieldBatchService.addWindFieldBatch(windFieldBatchDto);
        if (result == -1) {
            return ResultResp.FAIL(ConstVar.EXSIT_BATCH_NAME);
        }
        return result == -1 ? ResultResp.FAIL(ConstVar.EXSIT_BATCH_NAME) : success(result);
    }

    @UserLoginToken
    @ApiOperation(value = "编辑风场批次")
    @PostMapping("/updateFieldBatch")
    public ResultResp updateFieldBatch(@RequestBody WindFieldBatchDto windFieldBatchDto){
        windFieldBatchDto.setUpdateBy(getUserId());
        return success(windFieldBatchService.updateWindFieldBatch(windFieldBatchDto));
    }

    @UserLoginToken
    @ApiOperation(value = "启用/停用风场批次")
    @PostMapping("/onOrOffFieldBatch")
    public ResultResp onOrOffFieldBatch(@RequestBody WindFieldBatchDto windFieldBatchDto){
        windFieldBatchDto.setUpdateBy(getUserId());
        return success(windFieldBatchService.onOrOffFieldBatch(windFieldBatchDto));
    }

    @UserLoginToken
    @ApiOperation(value = "删除风场批次")
    @PostMapping("/deleteFieldBatch")
    public ResultResp deleteFieldBatch(@RequestBody WindFieldBatchDto windFieldBatchDto){
        windFieldBatchDto.setUpdateBy(getUserId());
        return success(windFieldBatchService.deleteWindFieldBatch(windFieldBatchDto));
    }

    @UserLoginToken
    @ApiOperation(value = "生成批次名称")
    @PostMapping("/createBatchName")
    public ResultResp createBatchName(@RequestParam String fieldName){
        return success(windFieldBatchService.createBatchName(fieldName));
    }

}
