package com.gci.boot.modules.gis.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gci.boot.common.vo.Result;
import com.gci.boot.modules.gis.entity.TbGisRunningbus;
import com.gci.boot.modules.gis.service.ITbGisRunningbusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * <p>
 * 车辆实时信息表 前端控制器
 * </p>
 *
 * @author 2464
 * @since 2023-09-01
 */
@RestController
@RequestMapping("/gis/runningbus")
public class TbGisRunningbusController {
    @Autowired
    private ITbGisRunningbusService iTbGisRunningbusService;

    /**
     * 分页列表查询
     *
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @GetMapping(value = "/list")
    public Result<?> queryPageList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            HttpServletRequest req) {
        Page<TbGisRunningbus> page = new Page<TbGisRunningbus>(pageNo, pageSize);
        LambdaQueryWrapper<TbGisRunningbus> lambdaQueryWrapper = new LambdaQueryWrapper<TbGisRunningbus>();
        IPage<TbGisRunningbus> pageList = iTbGisRunningbusService.page(page, lambdaQueryWrapper);
        return Result.ok(pageList);
    }

    /**
     * 添加
     */
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody TbGisRunningbus tbGisRunningbus) {
        iTbGisRunningbusService.save(tbGisRunningbus);
        return Result.ok("添加成功！");
    }

    /**
     * 编辑
     */
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody TbGisRunningbus tbGisRunningbus) {
        iTbGisRunningbusService.updateById(tbGisRunningbus);
        return Result.ok("编辑成功！");
    }

    /**
     * 删除
     */
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        iTbGisRunningbusService.removeById(id);
        return Result.ok("删除成功！");
    }

    /**
     * 批量删除
     */
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        iTbGisRunningbusService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功！");
    }
}
