package com.ruoyi.web.controller.oa;

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

import com.ruoyi.common.utils.SnowFlake;
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.oa.domain.CmcCarExpense;
import com.ruoyi.oa.service.ICmcCarExpenseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * cmc车辆费用Controller
 * 
 * @author cmc
 * @date 2024-03-12
 */
@RestController
@RequestMapping("/oa/carExpense")
public class CmcCarExpenseController extends BaseController
{
    @Autowired
    private ICmcCarExpenseService cmcCarExpenseService;

    /**
     * 查询cmc车辆费用列表
     */
    @PreAuthorize("@ss.hasPermi('oa:expense:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmcCarExpense cmcCarExpense)
    {
        startPage();
        List<CmcCarExpense> list = cmcCarExpenseService.selectCmcCarExpenseList(cmcCarExpense);
        return getDataTable(list);
    }

    /**
     * 导出cmc车辆费用列表
     */
    @PreAuthorize("@ss.hasPermi('oa:expense:export')")
    @Log(title = "cmc车辆费用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcCarExpense cmcCarExpense)
    {
        List<CmcCarExpense> list = cmcCarExpenseService.selectCmcCarExpenseList(cmcCarExpense);
        ExcelUtil<CmcCarExpense> util = new ExcelUtil<CmcCarExpense>(CmcCarExpense.class);
        util.exportExcel(response, list, "cmc车辆费用数据");
    }

    /**
     * 获取cmc车辆费用详细信息
     */
    @PreAuthorize("@ss.hasPermi('oa:expense:query')")
    @GetMapping(value = "/{carExpenseId}")
    public AjaxResult getInfo(@PathVariable("carExpenseId") String carExpenseId)
    {
        return success(cmcCarExpenseService.selectCmcCarExpenseByCarExpenseId(carExpenseId));
    }

    /**
     * 新增cmc车辆费用
     */
    @PreAuthorize("@ss.hasPermi('oa:expense:add')")
    @Log(title = "cmc车辆费用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcCarExpense cmcCarExpense)
    {
        cmcCarExpense.setCarExpenseId(new SnowFlake().generateId());
        return toAjax(cmcCarExpenseService.insertCmcCarExpense(cmcCarExpense));
    }

    /**
     * 修改cmc车辆费用
     */
    @PreAuthorize("@ss.hasPermi('oa:expense:edit')")
    @Log(title = "cmc车辆费用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcCarExpense cmcCarExpense)
    {
        return toAjax(cmcCarExpenseService.updateCmcCarExpense(cmcCarExpense));
    }

    /**
     * 删除cmc车辆费用
     */
    @PreAuthorize("@ss.hasPermi('oa:expense:remove')")
    @Log(title = "cmc车辆费用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carExpenseIds}")
    public AjaxResult remove(@PathVariable String[] carExpenseIds)
    {
        return toAjax(cmcCarExpenseService.deleteCmcCarExpenseByCarExpenseIds(carExpenseIds));
    }
}
