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.PmgLogFreeRelease;
import com.yuchen.saas.park.service.service.PmgLogFreeReleaseService;
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;

/**
 * @author 刘通
 * @version 1.0
 * @date 2021/3/18 13:40
 */
@RestController
@AllArgsConstructor
@RequestMapping("/logFreeRelease")
@Api(value = "免费放行记录", tags = "免费放行记录")
public class PmgLogFreeReleaseController {
    @Autowired
    private PmgLogFreeReleaseService pmgLogFreeReleaseService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入免费放行记录")
    public R<PmgLogFreeRelease> detail(PmgLogFreeRelease pmgLogFreeRelease) {
        PmgLogFreeRelease detail = pmgLogFreeReleaseService.getOne(Condition.getQueryWrapper(pmgLogFreeRelease));
        return R.data(detail);
    }
    /**
     * 通过停车场唯一编号和车牌获取免费放行原因
     */
    @GetMapping("/getFreeRelease")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "详情", notes = "传入免费放行记录")
    public R<PmgLogFreeRelease> getFreeRelease(PmgLogFreeRelease pmgLogFreeRelease) {
        PmgLogFreeRelease detail = pmgLogFreeReleaseService.getOne(Condition.getQueryWrapper(pmgLogFreeRelease).eq("plate_no",
                pmgLogFreeRelease.getPlateNo()).eq("parking_id", pmgLogFreeRelease.getParkingId()));
        return R.data(detail);
    }

    /**
     * 分页
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入免费放行记录")
    public R<IPage<PmgLogFreeRelease>> list(PmgLogFreeRelease pmgLogFreeRelease, Query query) {
        IPage<PmgLogFreeRelease> pages = pmgLogFreeReleaseService.page(Condition.getPage(query),Condition.getQueryWrapper(pmgLogFreeRelease));
        return  R.data(pages);
    }

    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入免费放行记录")
    public R save(@Valid @RequestBody PmgLogFreeRelease pmgLogFreeRelease) {
        return R.status(pmgLogFreeReleaseService.save(pmgLogFreeRelease));
    }
    /**
     * 新增或修改
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "新增或修改", notes = "传入免费放行记录")
    public R submit(@Valid @RequestBody PmgLogFreeRelease pmgLogFreeRelease) {
        return R.status(pmgLogFreeReleaseService.saveOrUpdate(pmgLogFreeRelease));
    }
    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "修改", notes = "传入免费放行记录")
    public R update(@Valid @RequestBody PmgLogFreeRelease pmgLogFreeRelease) {
        return R.status(pmgLogFreeReleaseService.updateById(pmgLogFreeRelease));
    }

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