package com.ruoyi.web.controller.oa;

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

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.CmcDeviceExpense;
import com.ruoyi.oa.service.ICmcDeviceExpenseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * cmc仪器费用Controller
 * 
 * @author cmc
 * @date 2024-05-20
 */
@RestController
@RequestMapping("/oa/deviceExpense")
public class CmcDeviceExpenseController extends BaseController
{
    @Autowired
    private ICmcDeviceExpenseService cmcDeviceExpenseService;

    /**
     * 查询cmc仪器费用列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcDeviceExpense cmcDeviceExpense)
    {
        startPage();
        List<CmcDeviceExpense> list = cmcDeviceExpenseService.selectCmcDeviceExpenseList(cmcDeviceExpense);
        return getDataTable(list);
    }

    /**
     * 导出cmc仪器费用列表
     */
    @Log(title = "cmc仪器费用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcDeviceExpense cmcDeviceExpense)
    {
        List<CmcDeviceExpense> list = cmcDeviceExpenseService.selectCmcDeviceExpenseList(cmcDeviceExpense);
        ExcelUtil<CmcDeviceExpense> util = new ExcelUtil<CmcDeviceExpense>(CmcDeviceExpense.class);
        util.exportExcel(response, list, "cmc仪器费用数据");
    }

    /**
     * 获取cmc仪器费用详细信息
     */
    @GetMapping(value = "/{deviceExpenseId}")
    public AjaxResult getInfo(@PathVariable("deviceExpenseId") Integer deviceExpenseId)
    {
        return success(cmcDeviceExpenseService.selectCmcDeviceExpenseByDeviceExpenseId(deviceExpenseId));
    }

    /**
     * 新增cmc仪器费用
     */
    @Log(title = "cmc仪器费用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcDeviceExpense cmcDeviceExpense)
    {
        if (cmcDeviceExpense.getDeviceId() != null && cmcDeviceExpense.getCarId() == null) {
            cmcDeviceExpense.setCarId(0);
        }
        if (cmcDeviceExpense.getCarId() != null && cmcDeviceExpense.getDeviceId() == null) {
            cmcDeviceExpense.setDeviceId(0);
        }
        return toAjax(cmcDeviceExpenseService.insertCmcDeviceExpense(cmcDeviceExpense));
    }

    /**
     * 修改cmc仪器费用
     */
    @Log(title = "cmc仪器费用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcDeviceExpense cmcDeviceExpense)
    {
        return toAjax(cmcDeviceExpenseService.updateCmcDeviceExpense(cmcDeviceExpense));
    }

    /**
     * 删除cmc仪器费用
     */
    @Log(title = "cmc仪器费用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceExpenseIds}")
    public AjaxResult remove(@PathVariable Integer[] deviceExpenseIds)
    {
        return success(cmcDeviceExpenseService.deleteCmcDeviceExpenseByDeviceExpenseIds(deviceExpenseIds));
    }
}
