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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.park.PmgLogPlaceCount;
import com.yuchen.saas.park.service.service.PmgLogPlaceCountService;
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 刘通
 * @version 1.0
 * @date 2021/2/28 10:26
 */
@RestController
@AllArgsConstructor
@RequestMapping("/logPlaceCount")
@Api(value = "车位事件信息管理", tags = "车位事件信息管理")
public class PmgLogPlaceCountController {
    @Autowired
    PmgLogPlaceCountService pmgLogPlaceCountService;

    /**
     * 车位事件信息 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "车位事件信息 详情", notes = "车位事件信息 详情")
    public R<PmgLogPlaceCount> detail(PmgLogPlaceCount pmgLogPlaceCount) {
        PmgLogPlaceCount detail = pmgLogPlaceCountService.getOne(Condition.getQueryWrapper(pmgLogPlaceCount));
        return R.data(detail);
    }
    /**
     * 车位事件信息 分页
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "车位事件信息 分页", notes = "车位事件信息 分页")
    public R<IPage<PmgLogPlaceCount>> list(PmgLogPlaceCount pmgLogPlaceCount, Query query) {
        IPage<PmgLogPlaceCount> pages = pmgLogPlaceCountService.page(Condition.getPage(query),Condition.getQueryWrapper(pmgLogPlaceCount));
        return  R.data(pages);
    }
    /**
     * 车位事件信息 新增
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "车位事件信息 新增", notes = "车位事件信息 新增")
    public R save(@Valid @RequestBody PmgLogPlaceCount pmgLogPlaceCount) {
        return R.status(pmgLogPlaceCountService.save(pmgLogPlaceCount));
    }
    /**
     * 车位事件信息 批量新增
     */
    @PostMapping("/saveList")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "车位事件信息 批量新增", notes = "车位事件信息 批量新增")
    public R saveList(@Valid @RequestBody List<PmgLogPlaceCount> pmgLogPlaceCount) {
        return R.status(pmgLogPlaceCountService.saveOrUpdateBatch(pmgLogPlaceCount));
    }
    /**
     * 车位事件信息 修改
     */
    @PutMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "车位事件信息 修改", notes = "车位事件信息 修改")
    public R update(@Valid @RequestBody PmgLogPlaceCount pmgLogPlaceCount) {
        return R.status(pmgLogPlaceCountService.updateById(pmgLogPlaceCount));
    }

    /**
     * 车位事件信息 删除
     */
    @DeleteMapping("/remove")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "车位事件信息 删除", notes = "车位事件信息 删除")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(pmgLogPlaceCountService.deleteLogic(Func.toLongList(ids)));
    }
}
