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

/**
 * 学习记录Controller
 * 
 * @author cmc
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/oa/study")
public class CmcStudyController extends BaseController
{
    @Autowired
    private ICmcStudyService cmcStudyService;

    /**
     * 查询学习记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcStudy cmcStudy)
    {
        startPage();
        List<CmcStudy> list = cmcStudyService.selectCmcStudyList(cmcStudy);
        return getDataTable(list);
    }

    /**
     * 查询学习记录列表
     */
    @GetMapping("/statistic")
    public TableDataInfo getStudyStatistic(CmcStudy cmcStudy)
    {
        startPage();
        List<CmcStudy> list = cmcStudyService.selectCmcStudyStatistic(cmcStudy);
        return getDataTable(list);
    }

    /**
     * 导出学习记录列表
     */
    @Log(title = "学习记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcStudy cmcStudy)
    {
        List<CmcStudy> list = cmcStudyService.selectCmcStudyList(cmcStudy);
        ExcelUtil<CmcStudy> util = new ExcelUtil<CmcStudy>(CmcStudy.class);
        util.exportExcel(response, list, "学习记录数据");
    }

    /**
     * 获取学习记录详细信息
     */
    @GetMapping(value = "/{studyId}")
    public AjaxResult getInfo(@PathVariable("studyId") Integer studyId)
    {
        return success(cmcStudyService.selectCmcStudyByStudyId(studyId));
    }

    /**
     * 新增学习记录
     */
    @Log(title = "学习记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcStudy cmcStudy)
    {
        return toAjax(cmcStudyService.insertCmcStudy(cmcStudy));
    }

    /**
     * 修改学习记录
     */
    @Log(title = "学习记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcStudy cmcStudy)
    {
        return toAjax(cmcStudyService.updateCmcStudy(cmcStudy));
    }

    /**
     * 删除学习记录
     */
    @Log(title = "学习记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{studyIds}")
    public AjaxResult remove(@PathVariable Integer[] studyIds)
    {
        return toAjax(cmcStudyService.deleteCmcStudyByStudyIds(studyIds));
    }
}
