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

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

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.orderManagement.BasicData.domain.FleetDriverMsg;
import com.ruoyi.orderManagement.BasicData.service.IFleetDriverMsgService;
import com.ruoyi.system.service.ISysUserService;
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.common.core.page.TableDataInfo;

/**
 * 【司机】Controller
 * 
 * @author ruoyi
 * @date 2021-03-04
 */
@RestController
@RequestMapping("/fleet/driverMsg")
public class FleetDriverMsgController extends BaseController
{
    @Autowired
    private IFleetDriverMsgService fleetDriverMsgService;

    @Autowired
    private ISysUserService userService;

    /**
     * 查询【司机】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FleetDriverMsg fleetDriverMsg)
    {
        startPage();
        List<FleetDriverMsg> list = fleetDriverMsgService.selectFleetDriverMsgList(fleetDriverMsg);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('fleet:driverMsg:list')")
    @GetMapping("/qurey")
    public TableDataInfo qurey(FleetDriverMsg fleetDriverMsg)
    {
        startPage();
        // List<FleetDriverMsg> list = fleetDriverMsgService.selectFleetDriverMsgList(fleetDriverMsg);
        List<Map<String, Object>> list = fleetDriverMsgService.selectFleetDriverMsgListMap(fleetDriverMsg);
        return getDataTable(list);
    }

    /**
     * 导出【司机】列表
     */
    @PreAuthorize("@ss.hasPermi('fleet:driverMsg:export')")
    @Log(title = "【司机】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FleetDriverMsg fleetDriverMsg)
    {
        List<FleetDriverMsg> list = fleetDriverMsgService.selectFleetDriverMsgList(fleetDriverMsg);
        ExcelUtil<FleetDriverMsg> util = new ExcelUtil<FleetDriverMsg>(FleetDriverMsg.class);
        return util.exportExcel(list, "msg");
    }

    /**
     * 获取【司机】详细信息
     */
    @PreAuthorize("@ss.hasPermi('fleet:driverMsg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fleetDriverMsgService.selectFleetDriverMsgById(id));
    }

    /**
     * 新增【司机】
     */
    @PreAuthorize("@ss.hasPermi('fleet:driverMsg:add')")
    @Log(title = "【司机】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FleetDriverMsg fleetDriverMsg)
    {
        if(fleetDriverMsg.getId()==null ||  fleetDriverMsg.getId().equals("")){
            //检验登录名  唯一
            if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(fleetDriverMsg.getTel()))) {
                return AjaxResult.error("新增驾驶员'" + fleetDriverMsg.getName() + "'失败，登录账号（联系电话）已存在()");
            }
        }
        return fleetDriverMsgService.insertFleetDriverMsg(fleetDriverMsg);
    }

    /**
     * 修改【司机】
     */
    @PreAuthorize("@ss.hasPermi('fleet:driverMsg:edit')")
    @Log(title = "【司机】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FleetDriverMsg fleetDriverMsg)
    {
        fleetDriverMsg.setCreateBy(SecurityUtils.getUsername());
        return toAjax(fleetDriverMsgService.updateFleetDriverMsg(fleetDriverMsg));
    }

    /**
     * 删除【司机】
     */
    @PreAuthorize("@ss.hasPermi('fleet:driverMsg:remove')")
    @Log(title = "【司机】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fleetDriverMsgService.deleteFleetDriverMsgByIds(ids));
    }
}
