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.biz.domain.BizCarState;
import com.cpxt.biz.service.IBizCarStateService;
import com.cpxt.common.annotation.Anonymous;
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.common.utils.poi.ExcelUtil;
import com.cpxt.common.core.page.TableDataInfo;

/**
 * 车辆实时状态Controller
 *
 * @author ruoyi
 * @date 2024-12-18
 */
@RestController
@RequestMapping("/biz/state")
public class BizCarStateController extends BaseController {
    @Autowired
    private IBizCarStateService bizCarStateService;

    /**
     * 查询车辆实时状态列表
     */
    @PreAuthorize("@ss.hasPermi('system:state:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCarState bizCarState,
                              @RequestParam(defaultValue = "1") int pageNum,
                              @RequestParam(defaultValue = "10") int pageSize) {
        Page<BizCarState> recordPage = bizCarStateService.selectBizCarStatePage(bizCarState, 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('system:state:list')")
    @Anonymous
    @GetMapping("/list2")
    public AjaxResult list2(BizCarState bizCarState) {
        return AjaxResult.success(bizCarStateService.selectBizCarStateList(bizCarState));
    }

    /**
     * 查询车辆实时状态（根据车辆id）
     */
    @PreAuthorize("@ss.hasPermi('system:state:list')")
    @GetMapping("/listByCarId")
    public AjaxResult listByCarId(BizCarState bizCarState) {
        return AjaxResult.success(bizCarStateService.selectBizCarStateByCarId(bizCarState.getCarId()));
    }

    /**
     * 导出车辆实时状态列表
     */
    @PreAuthorize("@ss.hasPermi('system:state:export')")
    @Log(title = "车辆实时状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCarState bizCarState) {
        List<BizCarState> list = bizCarStateService.selectBizCarStateList(bizCarState);
        ExcelUtil<BizCarState> util = new ExcelUtil<BizCarState>(BizCarState.class);
        util.exportExcel(response, list, "车辆实时状态数据");
    }

    /**
     * 获取车辆实时状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:state:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bizCarStateService.selectBizCarStateById(id));
    }

    /**
     * 新增车辆实时状态
     */
    @PreAuthorize("@ss.hasPermi('system:state:add')")
    @Log(title = "车辆实时状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCarState bizCarState) {
        return toAjax(bizCarStateService.insertBizCarState(bizCarState));
    }

    /**
     * 修改车辆实时状态
     */
    @PreAuthorize("@ss.hasPermi('system:state:edit')")
    @Log(title = "车辆实时状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCarState bizCarState) {
        return toAjax(bizCarStateService.updateBizCarState(bizCarState));
    }

    /**
     * 删除车辆实时状态
     */
    @PreAuthorize("@ss.hasPermi('system:state:remove')")
    @Log(title = "车辆实时状态", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizCarStateService.deleteBizCarStateByIds(ids));
    }
}
