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.PmgBatParkPublicDict;
import com.yuchen.saas.park.service.service.PmgBatParkPublicDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
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;
import java.util.List;

/**
 * @author 刘碧清
 * @date 2021/04/26 12:00
 */
@RestController
@AllArgsConstructor
@RequestMapping("/pmgBatParkPublicDict")
@Api(value = "公共区域管理对象", tags = "公共区域管理接口")
public class PmgBatParkPublicDictController {
    @Autowired
    private PmgBatParkPublicDictService pmgBatParkPublicDictService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入公共区域管理对象")
    public R<PmgBatParkPublicDict> detail(PmgBatParkPublicDict pmgBatParkPublicDict) {
        PmgBatParkPublicDict detail = pmgBatParkPublicDictService.getOne(Condition.getQueryWrapper(pmgBatParkPublicDict));
        return R.data(detail);
    }

    /**
     * 分页
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入公共区域管理对象")
    public R<IPage<PmgBatParkPublicDict>> list(PmgBatParkPublicDict pmgBatParkPublicDict, Query query) {
        IPage<PmgBatParkPublicDict> pages = pmgBatParkPublicDictService.page(Condition.getPage(query), Condition.getQueryWrapper(pmgBatParkPublicDict));
        return  R.data(pages);
    }
    /**
     * 获取所有
     */
    @GetMapping("/getAll")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入公共区域管理对象")
    public R<List<PmgBatParkPublicDict>> getAll(PmgBatParkPublicDict pmgBatParkPublicDict, Query query) {
        List<PmgBatParkPublicDict> storeyList = pmgBatParkPublicDictService.list();
        return  R.data(storeyList);
    }

    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入公共区域管理对象")
    public R save(@Valid @RequestBody PmgBatParkPublicDict pmgBatParkPublicDict) {
        return R.status(pmgBatParkPublicDictService.save(pmgBatParkPublicDict));
    }
    /**
     * 新增或修改
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改以及添加", notes = "传入公共区域管理对象")
    public R submit(@Valid @RequestBody PmgBatParkPublicDict pmgBatParkPublicDict) {
        return R.status(pmgBatParkPublicDictService.saveOrUpdate(pmgBatParkPublicDict));
    }
    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "修改", notes = "传入公共区域管理对象")
    public R update(@Valid @RequestBody PmgBatParkPublicDict pmgBatParkPublicDict) {
        return R.status(pmgBatParkPublicDictService.updateById(pmgBatParkPublicDict));
    }

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