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

import java.util.List;

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.FleetCompanyMsg;
import com.ruoyi.orderManagement.BasicData.service.IFleetCompanyMsgService;
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/companyMsg")
public class FleetCompanyMsgController extends BaseController
{
    @Autowired
    private IFleetCompanyMsgService fleetCompanyMsgService;

    /**
     * 查询【车队】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FleetCompanyMsg fleetCompanyMsg)
    {
        startPage();
        List<FleetCompanyMsg> list = fleetCompanyMsgService.selectFleetCompanyMsgList(fleetCompanyMsg);
        return getDataTable(list);
    }

    /**
     * 查询【车队】列表
     */
    @PreAuthorize("@ss.hasPermi('fleet:companyMsg:list')")
    @GetMapping("/query")
    public TableDataInfo query(FleetCompanyMsg fleetCompanyMsg)
    {
        startPage();
        List<FleetCompanyMsg> list = fleetCompanyMsgService.selectFleetCompanyMsgList(fleetCompanyMsg);
        return getDataTable(list);
    }

    /**
     * 导出【车队】列表
     */
    @PreAuthorize("@ss.hasPermi('fleet:companyMsg:export')")
    @Log(title = "【车队】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FleetCompanyMsg fleetCompanyMsg)
    {
        List<FleetCompanyMsg> list = fleetCompanyMsgService.selectFleetCompanyMsgList(fleetCompanyMsg);
        ExcelUtil<FleetCompanyMsg> util = new ExcelUtil<FleetCompanyMsg>(FleetCompanyMsg.class);
        return util.exportExcel(list, "msg");
    }

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

    /**
     * 新增【车队】
     */
    @PreAuthorize("@ss.hasPermi('fleet:companyMsg:add')")
    @Log(title = "【车队】", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody FleetCompanyMsg fleetCompanyMsg)
    {
        // 校验车队唯一
        if (UserConstants.NOT_UNIQUE.equals(fleetCompanyMsgService.checkUFNoUnique(fleetCompanyMsg))) {
            return AjaxResult.error("新增车队'" + fleetCompanyMsg.getCompanyName() + "'失败，名称已存在");
        }
        return fleetCompanyMsgService.insertFleetCompanyMsg(fleetCompanyMsg);
    }

    /**
     * 修改【车队】
     */
    @PreAuthorize("@ss.hasPermi('fleet:companyMsg:edit')")
    @Log(title = "【车队】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FleetCompanyMsg fleetCompanyMsg)
    {
        fleetCompanyMsg.setCreateBy(SecurityUtils.getUsername());
        return toAjax(fleetCompanyMsgService.updateFleetCompanyMsg(fleetCompanyMsg));
    }

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