package com.ruoyi.database.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.database.domain.BaseParkingLotInfo;
import com.ruoyi.database.domain.ParkingNearInfo;
import com.ruoyi.database.service.BaseParkingLotInfoService;
import com.ruoyi.database.service.ParkingNearInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/BaseParkingLotInfo")
@Api(tags = "停车场管理")
@RestController
@RequiredArgsConstructor
public class BaseParkingLotInfoController extends BaseController {

    private final BaseParkingLotInfoService baseParkingLotInfoService;
    private final ParkingNearInfoService parkingNearInfoService;

    @GetMapping
    @ApiOperation("基础管理-查询停车场管理")
    public TableDataInfo<BaseParkingLotInfo> list(BaseParkingLotInfo baseParkingLotInfo) {
        startPage();
        QueryWrapper<BaseParkingLotInfo> queryWrapper = new QueryWrapper<>(baseParkingLotInfo);
        List<BaseParkingLotInfo> list = baseParkingLotInfoService.list(queryWrapper);
        long size = baseParkingLotInfoService.count(queryWrapper);
        return getDataTableEnhance(list,size);
    }

    @PostMapping
    @ApiOperation("基础管理-新增停车场管理")
    @Log(title = "停车场管理表", businessType = BusinessType.INSERT)
    public AjaxResult insert(@RequestBody BaseParkingLotInfo baseParkingLotInfo) {
        return toAjax(baseParkingLotInfoService.save(baseParkingLotInfo));
    }

    @PutMapping
    @ApiOperation("基础管理-修改停车场管理")
    @Log(title = "停车场管理表", businessType = BusinessType.UPDATE)
    public AjaxResult update(@RequestBody BaseParkingLotInfo baseParkingLotInfo) {
        return toAjax(baseParkingLotInfoService.updateById(baseParkingLotInfo));
    }

    @DeleteMapping
    @ApiOperation("基础管理-删除停车场管理")
    @Log(title = "停车场管理表", businessType = BusinessType.DELETE)
    public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
        return toAjax(baseParkingLotInfoService.removeByIds(idList));
    }


    @GetMapping("/ParkingNear")
    @ApiOperation("查询附近常客隆超市或停车场")
    public TableDataInfo<ParkingNearInfo> list(ParkingNearInfo parkingNearInfo) {
        startPage();
        QueryWrapper<ParkingNearInfo> queryWrapper = new QueryWrapper<>(parkingNearInfo);
        List<ParkingNearInfo> list = parkingNearInfoService.list(queryWrapper);
        long size = parkingNearInfoService.count(queryWrapper);
        return getDataTableEnhance(list,size);
    }
}
