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

/**
 * 学习资料Controller
 * 
 * @author cmc
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/oa/resource")
public class CmcResourceController extends BaseController
{
    @Autowired
    private ICmcResourceService cmcResourceService;

    /**
     * 查询学习资料列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcResource cmcResource)
    {
        startPage();
        List<CmcResource> list = cmcResourceService.selectCmcResourceList(cmcResource);
        return getDataTable(list);
    }

    /**
     * 查询学习资料列表
     */
    @GetMapping("/getListBelow")
    public TableDataInfo listByFieldId(CmcResource cmcResource)
    {
        startPage();
        List<CmcResource> list = cmcResourceService.selectCmcResourceListBelow(cmcResource);
        return getDataTable(list);
    }

    /**
     * 导出学习资料列表
     */
    @Log(title = "学习资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcResource cmcResource)
    {
        List<CmcResource> list = cmcResourceService.selectCmcResourceList(cmcResource);
        ExcelUtil<CmcResource> util = new ExcelUtil<CmcResource>(CmcResource.class);
        util.exportExcel(response, list, "学习资料数据");
    }

    /**
     * 获取学习资料详细信息
     */
    @GetMapping(value = "/{resourceId}")
    public AjaxResult getInfo(@PathVariable("resourceId") Integer resourceId)
    {
        return success(cmcResourceService.selectCmcResourceByResourceId(resourceId));
    }

    /**
     * 新增学习资料
     */
    @Log(title = "学习资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcResource cmcResource)
    {
        return toAjax(cmcResourceService.insertCmcResource(cmcResource));
    }

    /**
     * 修改学习资料
     */
    @Log(title = "学习资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcResource cmcResource)
    {
        return toAjax(cmcResourceService.updateCmcResource(cmcResource));
    }

    /**
     * 删除学习资料
     */
    @Log(title = "学习资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{resourceIds}")
    public AjaxResult remove(@PathVariable Integer[] resourceIds)
    {
        return toAjax(cmcResourceService.deleteCmcResourceByResourceIds(resourceIds));
    }
}
