package com.ruoyi.web.controller.fleet.basicData;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.basicData.domain.FleetCarManage;
import com.ruoyi.basicData.service.IFleetCarManageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
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.common.core.page.TableDataInfo;

/**
 * 【车辆】Controller
 * 
 * @author ruoyi
 * @date 2021-03-04
 */
@RestController
@RequestMapping("/fleet/carManage")
public class FleetCarManageController extends BaseController
{
    @Autowired
    private IFleetCarManageService fleetCarManageService;

    /**
     * 下拉列表查询【车辆】列表id name
     */
    @GetMapping("/list")
    public List<FleetCarManage> list(FleetCarManage fleetCarManage)
    {
        return fleetCarManageService.selectFleetCarManageIdNameList(fleetCarManage);
    }

    /**
     * 查询【车辆】列表
     */
    @PreAuthorize("@ss.hasPermi('fleet:carManage:list')")
    @GetMapping("/query")
    public TableDataInfo query(FleetCarManage fleetCarManage)
    {
        startPage();
        //List<FleetCarManage> list = fleetCarManageService.selectFleetCarManageList(fleetCarManage);
        List<Map<String, Object>> list = fleetCarManageService.selectFleetCarManageListMap(fleetCarManage);
        return getDataTable(list);
    }

    /**
     * 导出【车辆】列表
     */
    @PreAuthorize("@ss.hasPermi('fleet:carManage:export')")
    @Log(title = "【车辆】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FleetCarManage fleetCarManage)
    {
        List<FleetCarManage> list = fleetCarManageService.selectFleetCarManageList(fleetCarManage);
        ExcelUtil<FleetCarManage> util = new ExcelUtil<FleetCarManage>(FleetCarManage.class);
        return util.exportExcel(list, "manage");
    }

    /**
     * 获取【车辆】详细信息
     */
    @PreAuthorize("@ss.hasPermi('fleet:carManage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fleetCarManageService.selectFleetCarManageByIdMap(id));
    }

    /**
     * 新增【车辆】
     */
    /*@PreAuthorize("@ss.hasPermi('fleet:carManage:add')")
    @Log(title = "【车辆】", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody FleetCarManage fleetCarManage)
    {

        return fleetCarManageService.insertFleetCarManage(fleetCarManage);
    }*/
    @PreAuthorize("@ss.hasPermi('fleet:carManage:add')")
    @Log(title = "【车辆】", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestParam("fleetCarManage") String fleetCarManage,
                          @RequestParam("fTmsorderbillsattachs") String fTmsorderbillsattachs )
    {
        return fleetCarManageService.insertFleetCarManageAdd(fleetCarManage,fTmsorderbillsattachs);
    }


    /**
     * 修改【车辆】
     */
    @PreAuthorize("@ss.hasPermi('fleet:carManage:edit')")
    @Log(title = "【车辆】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FleetCarManage fleetCarManage)
    {
        fleetCarManage.setCreateBy(SecurityUtils.getUsername());
        return toAjax(fleetCarManageService.updateFleetCarManage(fleetCarManage));
    }

    /**
     * 删除【车辆】
     */
    @PreAuthorize("@ss.hasPermi('fleet:carManage:remove')")
    @Log(title = "【车辆】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return fleetCarManageService.deleteFleetCarManageByIds(ids);
    }
}
