package org.nl.system.controller.logicflow;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.base.TableDataInfo;
import org.nl.common.domain.query.PageQuery;
import org.nl.common.logging.annotation.Log;
import org.nl.system.service.logicflow.IStageService;
import org.nl.system.service.logicflow.dao.Stage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 舞台主表 前端控制器
 * </p>
 *
 * @author generator
 * @since 2023-05-08
 */
@Slf4j
@RestController
@Api(tags = "舞台管理")
@RequestMapping("/api/stage")
public class StageController {

    @Autowired
    private IStageService stageService;

    @GetMapping
    @Log("查询舞台")
    @ApiOperation("查询舞台")
    //@SaCheckPermission("stage:list")
    public ResponseEntity<Object> query(@RequestParam Map whereJson, PageQuery page) {
        return new ResponseEntity<>(TableDataInfo.build(stageService.queryAll(whereJson, page)), HttpStatus.OK);
    }

    @PostMapping
    @Log("新增舞台")
    @ApiOperation("新增舞台")
    //@SaCheckPermission("stage:add")
    public ResponseEntity<Object> create(@Validated @RequestBody Stage dto) {
        stageService.create(dto);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改舞台")
    @ApiOperation("修改舞台")
    //@SaCheckPermission("stage:edit")
    public ResponseEntity<Object> update(@Validated @RequestBody Stage dto) {
        stageService.update(dto);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除舞台")
    @ApiOperation("删除舞台")
    //@SaCheckPermission("stage:del")
    @DeleteMapping
    public ResponseEntity<Object> delete(@RequestBody Set<String> ids) {
        stageService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping("/selectList")
    @Log("下拉选舞台")
    @ApiOperation("下拉选舞台")
    //@SaCheckPermission("routePlan:list")
    public ResponseEntity<Object> selectList() {
        return new ResponseEntity<>(stageService.selectList(), HttpStatus.OK);
    }

    @PostMapping("/addNewStage")
    @Log("保存舞台数据")
    @ApiOperation("保存舞台数据")
    public ResponseEntity<Object> addNewStage(@Validated @RequestBody Stage dto) {
        log.info("dto{}",dto);
        stageService.addNewStage(dto);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PostMapping("/getNewStageDataByCode")
    @Log("根据stage_code获取舞台数据")
    @ApiOperation("根据stage_code获取舞台数据")
    public ResponseEntity<Object> getNewStageDataByCode(@RequestBody String code) {
        Stage one = stageService.getOne(new LambdaQueryWrapper<Stage>().eq(Stage::getStage_code, code));
        return new ResponseEntity<>(one, HttpStatus.CREATED);
    }

}

