package com.ruoyi.basetyre.controller;

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

import com.ruoyi.basetyre.domain.BaseCarQueue;
import com.ruoyi.basetyre.domain.BaseCarType;
import com.ruoyi.basetyre.domain.BaseDevice;
import com.ruoyi.basetyre.service.IBaseCarQueueService;
import com.ruoyi.basetyre.service.IBaseCarTypeService;
import com.ruoyi.basetyre.service.IBaseDeviceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basetyre.domain.BaseCar;
import com.ruoyi.basetyre.service.IBaseCarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆基础信息Controller
 * 
 * @author Yangwl
 * @date 2023-02-08
 */
@RestController
@RequestMapping("/basecar/car")
public class BaseCarController extends BaseController
{
    @Autowired
    private IBaseCarService baseCarService;
    @Autowired
    private IBaseCarQueueService baseCarQueueService;
    @Autowired
    private IBaseCarTypeService baseCarTypeService;
    @Autowired
    private IBaseDeviceService baseDeviceService;
    /**
     * 查询车辆基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('basecar:car:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseCar baseCar)
    {
        startPage();
        List<BaseCar> list = baseCarService.queryList(baseCar);
        return getDataTable(list);
    }

    /**
     * 导出车辆基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('basecar:car:export')")
    @Log(title = "车辆基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseCar baseCar)
    {
        List<BaseCar> list = baseCarService.selectBaseCarList(baseCar);
        ExcelUtil<BaseCar> util = new ExcelUtil<BaseCar>(BaseCar.class);
        util.exportExcel(response, list, "车辆基础信息数据");
    }

    /**
     * 获取车辆基础信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('basecar:car:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(baseCarService.selectBaseCarById(id));
    }

    /**
     * 新增车辆基础信息
     */
    @PreAuthorize("@ss.hasPermi('basecar:car:add')")
    @Log(title = "车辆基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody BaseCar baseCar)
    {
        return toAjax(baseCarService.insertBaseCar(baseCar));
    }

    /**
     * 修改车辆基础信息
     */
    @PreAuthorize("@ss.hasPermi('basecar:car:edit')")
    @Log(title = "车辆基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseCar baseCar)
    {
        return toAjax(baseCarService.updateBaseCar(baseCar));
    }

    /**
     * 删除车辆基础信息
     */
    @PreAuthorize("@ss.hasPermi('basecar:car:remove')")
    @Log(title = "车辆基础信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(baseCarService.deleteBaseCarByIds(ids));
    }

    /**
     * 获取车队和车型接口
     */
    @GetMapping("/getCarQueueAndType")
    public AjaxResult getCarQueue_Type(){
        BaseCarQueue baseCarQueue=new BaseCarQueue();
        BaseCarType  baseCarType = new BaseCarType();
        baseCarQueue.setState((long) 0);
        baseCarQueue.setState((long) 0);
        List<BaseCarQueue> baseCarQueueList = baseCarQueueService.selectBaseCarQueueList(baseCarQueue);
        List<BaseCarType> baseCarTypeList = baseCarTypeService.selectBaseCarTypeList(baseCarType);
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put("CarQueueList",baseCarQueueList);
        ajaxResult.put("CarTypeList",baseCarTypeList);
        return ajaxResult;
    }

    /**
     * 设备列表
     * @param baseCar
     * @return
     */

    @PostMapping("/getDeviceList")
    public TableDataInfo getDeviceList(@RequestBody BaseCar baseCar){
        BaseDevice baseDevice = new BaseDevice();
        baseDevice.setState((long) 0);
        baseDevice.setInternetThingsNo(baseCar.getDeviceId());
        List<BaseDevice> baseDeviceList = baseDeviceService.selectBaseDeviceList(baseDevice);
        return getDataTable(baseDeviceList);
    }

}
