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.TbGisFenceVehicle;
import com.gci.boot.modules.gis.service.ITbGisFenceVehicleService;
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-08-30
 */
@RestController
@RequestMapping("/gps/gisFenceVehicle")
public class TbGisFenceVehicleController {
    @Autowired
    private ITbGisFenceVehicleService iTbGisFenceVehicleService;

    /**
     * 分页列表查询
     *
     * @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<TbGisFenceVehicle> page = new Page<TbGisFenceVehicle>(pageNo, pageSize);
        LambdaQueryWrapper<TbGisFenceVehicle> lambdaQueryWrapper = new LambdaQueryWrapper<TbGisFenceVehicle>();
        IPage<TbGisFenceVehicle> pageList = iTbGisFenceVehicleService.page(page, lambdaQueryWrapper);
        return Result.ok(pageList);
    }

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

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

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

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