package com.ruoyi.web.controller.oa;

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

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

/**
 * cmc项目Controller
 * 
 * @author cmc
 * @date 2024-01-30
 */
@RestController
@RequestMapping("/oa/project")
public class CmcProjectController extends BaseController
{
    @Autowired
    private ICmcProjectService cmcProjectService;

    /**
     * 查询cmc项目列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcProject cmcProject)
    {
        startPage();
        List<CmcProject> list = cmcProjectService.selectCmcProjectList(cmcProject);
        return getDataTable(list);
    }

    /**
     * 导出cmc项目列表
     */
    @Log(title = "cmc项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcProject cmcProject)
    {
        List<CmcProject> list = cmcProjectService.selectCmcProjectList(cmcProject);
        ExcelUtil<CmcProject> util = new ExcelUtil<CmcProject>(CmcProject.class);
        util.exportExcel(response, list, "cmc项目数据");
    }

    /**
     * 获取cmc项目详细信息
     */
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") String projectId)
    {
        return success(cmcProjectService.selectCmcProjectByProjectId(projectId));
    }

    /**
     * 新增cmc项目
     */
    @Log(title = "cmc项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcProject cmcProject)
    {
        cmcProject.setProjectId(new SnowFlake().generateId());
        return toAjax(cmcProjectService.insertCmcProject(cmcProject));
    }

    /**
     * 修改cmc项目
     */
    @Log(title = "cmc项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcProject cmcProject)
    {
        return toAjax(cmcProjectService.updateCmcProject(cmcProject));
    }

    /**
     * 删除cmc项目
     */
    @Log(title = "cmc项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable String[] projectIds)
    {
        return toAjax(cmcProjectService.deleteCmcProjectByProjectIds(projectIds));
    }
}
