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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.park.PmgBatParkFileRelevance;
import com.yuchen.saas.park.service.service.PmgBatParkFileRelevanceService;
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 11:33
 */
@RestController
@AllArgsConstructor
@RequestMapping("/pmgBatParkFileRelevance")
@Api(value = "文件关联对象", tags = "文件关联接口")
public class PmgBatParkFileRelevanceController {
    @Autowired
    private PmgBatParkFileRelevanceService pmgBatParkFileRelevanceService;
    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入文件关联")
    public R<PmgBatParkFileRelevance> detail(PmgBatParkFileRelevance pmgBatParkFileRelevance) {
        PmgBatParkFileRelevance detail = pmgBatParkFileRelevanceService.getOne(Condition.getQueryWrapper(pmgBatParkFileRelevance));
        return R.data(detail);
    }
    /**
     * 分页
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入文件关联")
    public R<IPage<PmgBatParkFileRelevance>> list(PmgBatParkFileRelevance pmgBatParkFileRelevance, Query query) {
        IPage<PmgBatParkFileRelevance> pages = pmgBatParkFileRelevanceService.page(Condition.getPage(query), Condition.getQueryWrapper(pmgBatParkFileRelevance));
        return  R.data(pages);
    }
    /**
     * 获取所有
     */
    @GetMapping("/getAll")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入文件关联")
    public R<List<PmgBatParkFileRelevance>> getAll(PmgBatParkFileRelevance pmgBatParkFileRelevance, Query query) {
        List<PmgBatParkFileRelevance> storeyList = pmgBatParkFileRelevanceService.list();
        return  R.data(storeyList);
    }

    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入文件关联")
    public R save(@Valid @RequestBody PmgBatParkFileRelevance pmgBatParkFileRelevance) {
        return R.status(pmgBatParkFileRelevanceService.save(pmgBatParkFileRelevance));
    }
    /**
     * 新增或修改
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改以及添加", notes = "传入文件关联")
    public R submit(@Valid @RequestBody PmgBatParkFileRelevance pmgBatParkFileRelevance) {
        return R.status(pmgBatParkFileRelevanceService.saveOrUpdate(pmgBatParkFileRelevance));
    }
    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "修改", notes = "传入文件关联")
    public R update(@Valid @RequestBody PmgBatParkFileRelevance pmgBatParkFileRelevance) {
        return R.status(pmgBatParkFileRelevanceService.updateById(pmgBatParkFileRelevance));
    }

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