package com.cpxt.web.controller.biz;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpxt.common.constant.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cpxt.common.annotation.Log;
import com.cpxt.common.core.controller.BaseController;
import com.cpxt.common.core.domain.AjaxResult;
import com.cpxt.common.enums.BusinessType;
import com.cpxt.biz.domain.BizCar;
import com.cpxt.biz.service.IBizCarService;
import com.cpxt.common.utils.poi.ExcelUtil;
import com.cpxt.common.core.page.TableDataInfo;

/**
 * 车辆Controller
 * 
 * @author YIN
 * @date 2024-12-16
 */
@RestController
@RequestMapping("/biz/car")
public class BizCarController extends BaseController
{
    @Autowired
    private IBizCarService bizCarService;

    /**
     * 查询车辆列表（分页）
     */
//    @PreAuthorize("@ss.hasPermi('biz:car:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCar bizCar,
                              @RequestParam(defaultValue = "1") int pageNum,
                              @RequestParam(defaultValue = "10") int pageSize)
    {
        Page<BizCar> recordPage = bizCarService.selectBizCarPage(bizCar,pageNum,pageSize);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(recordPage.getRecords());
        rspData.setTotal(recordPage.getTotal());
        return rspData;
    }

    /**
     * 查询车辆列表（不分页）
     */
//    @PreAuthorize("@ss.hasPermi('biz:car:list')")
    @GetMapping("/list2")
    public AjaxResult list2(BizCar bizCar)
    {
        return AjaxResult.success(bizCarService.selectBizCarList(bizCar));
    }

    /**
     * 导出车辆列表
     */
    @PreAuthorize("@ss.hasPermi('biz:car:export')")
    @Log(title = "车辆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCar bizCar)
    {
        List<BizCar> list = bizCarService.selectBizCarList(bizCar);
        ExcelUtil<BizCar> util = new ExcelUtil<BizCar>(BizCar.class);
        util.exportExcel(response, list, "车辆数据");
    }

    /**
     * 获取车辆详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:car:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCarService.selectBizCarById(id));
    }

    /**
     * 新增车辆
     */
    @PreAuthorize("@ss.hasPermi('biz:car:add')")
    @Log(title = "车辆", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCar bizCar)
    {
        return toAjax(bizCarService.insertBizCar(bizCar));
    }

    /**
     * 修改车辆
     */
    @PreAuthorize("@ss.hasPermi('biz:car:edit')")
    @Log(title = "车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCar bizCar)
    {
        return toAjax(bizCarService.updateBizCar(bizCar));
    }

    /**
     * 删除车辆
     */
    @PreAuthorize("@ss.hasPermi('biz:car:remove')")
    @Log(title = "车辆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizCarService.deleteBizCarByIds(ids));
    }

    /**
     * 查询车辆轨迹信息（不分页）
     */
//    @PreAuthorize("@ss.hasPermi('biz:car:list')")
    @GetMapping("/track/list")
    public AjaxResult trackList(@RequestParam Long carId,
                                @RequestParam String startTime,
                                @RequestParam String endTime)
    {
        return AjaxResult.success(bizCarService.selectBizTrackList(carId,startTime,endTime));
    }
}
