package com.yuchen.saas.park.service.controller.basic;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.park.NestPark;
import com.yuchen.saas.park.service.service.NestParkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.nest.springwrap.core.mp.support.Condition;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * @author 黄辉
 * @version 1.0
 * @date 2021/4/24 14:32
 */
@Api(tags = "园区拓展表 管理")
@RestController
@RequestMapping("/nestpark")
public class NestParkController {
    @Autowired
    private NestParkService nestParkService;


    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入园区信息")
    public R<NestPark> detail(NestPark nestPark) {
        return R.data(nestParkService.getOne(Condition.getQueryWrapper(nestPark)));
    }

    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入园区信息")
    public R<IPage<NestPark>> list(Query query, NestPark nestPark) {
        return R.data(nestParkService.page(Condition.getPage(query), Condition.getQueryWrapper(nestPark)));
    }

    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增", notes = "传入园区信息")
    public R<NestPark> save(@RequestBody NestPark nestPark) {
        return R.status(nestParkService.save(nestPark));
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "修改", notes = "传入园区信息")
    public R<NestPark> update(@Valid @RequestBody NestPark nestPark) {
        return R.status(nestParkService.updateById(nestPark));
    }

    /**
     * 删除
     */
    @DeleteMapping("/remove")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(nestParkService.deleteLogic(Func.toLongList(ids)));
    }

}
