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

/**
 * 专业领域Controller
 * 
 * @author cmc
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/oa/field")
public class CmcResourceFieldController extends BaseController
{
    @Autowired
    private ICmcResourceFieldService cmcResourceFieldService;

    /**
     * 查询专业领域列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcResourceField cmcResourceField)
    {
        startPage();
        List<CmcResourceField> list = cmcResourceFieldService.selectCmcResourceFieldList(cmcResourceField);
        return getDataTable(list);
    }

    /**
     * 导出专业领域列表
     */
    @Log(title = "专业领域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcResourceField cmcResourceField)
    {
        List<CmcResourceField> list = cmcResourceFieldService.selectCmcResourceFieldList(cmcResourceField);
        ExcelUtil<CmcResourceField> util = new ExcelUtil<CmcResourceField>(CmcResourceField.class);
        util.exportExcel(response, list, "专业领域数据");
    }

    /**
     * 获取专业领域详细信息
     */
    @GetMapping(value = "/{fieldId}")
    public AjaxResult getInfo(@PathVariable("fieldId") Integer fieldId)
    {
        return success(cmcResourceFieldService.selectCmcResourceFieldByFieldId(fieldId));
    }

    /**
     * 新增专业领域
     */
    @Log(title = "专业领域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcResourceField cmcResourceField)
    {
        return toAjax(cmcResourceFieldService.insertCmcResourceField(cmcResourceField));
    }

    /**
     * 修改专业领域
     */
    @Log(title = "专业领域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcResourceField cmcResourceField)
    {
        return toAjax(cmcResourceFieldService.updateCmcResourceField(cmcResourceField));
    }

    /**
     * 删除专业领域
     */
    @Log(title = "专业领域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fieldIds}")
    public AjaxResult remove(@PathVariable Integer[] fieldIds)
    {
        return toAjax(cmcResourceFieldService.deleteCmcResourceFieldByFieldIds(fieldIds));
    }
}
