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

/**
 * 委外工作Controller
 * 
 * @author cmc
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/oa/outsourceWork")
public class CmcOutsourceWorkController extends BaseController
{
    @Autowired
    private ICmcOutsourceWorkService cmcOutsourceWorkService;

    /**
     * 查询委外工作列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcOutsourceWork cmcOutsourceWork)
    {
        startPage();
        List<CmcOutsourceWork> list = cmcOutsourceWorkService.selectCmcOutsourceWorkList(cmcOutsourceWork);
        return getDataTable(list);
    }

    /**
     * 导出委外工作列表
     */
    @Log(title = "委外工作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcOutsourceWork cmcOutsourceWork)
    {
        List<CmcOutsourceWork> list = cmcOutsourceWorkService.selectCmcOutsourceWorkList(cmcOutsourceWork);
        ExcelUtil<CmcOutsourceWork> util = new ExcelUtil<CmcOutsourceWork>(CmcOutsourceWork.class);
        util.exportExcel(response, list, "委外工作数据");
    }

    /**
     * 获取委外工作详细信息
     */
    @GetMapping(value = "/{workId}")
    public AjaxResult getInfo(@PathVariable("workId") Integer workId)
    {
        return success(cmcOutsourceWorkService.selectCmcOutsourceWorkByWorkId(workId));
    }

    /**
     * 新增委外工作
     */
    @Log(title = "委外工作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcOutsourceWork cmcOutsourceWork)
    {
        return toAjax(cmcOutsourceWorkService.insertCmcOutsourceWork(cmcOutsourceWork));
    }

    /**
     * 修改委外工作
     */
    @Log(title = "委外工作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcOutsourceWork cmcOutsourceWork)
    {
        return toAjax(cmcOutsourceWorkService.updateCmcOutsourceWork(cmcOutsourceWork));
    }

    /**
     * 删除委外工作
     */
    @Log(title = "委外工作", businessType = BusinessType.DELETE)
	@DeleteMapping("/{outsourceIds}")
    public AjaxResult remove(@PathVariable String[] outsourceIds)
    {
        return success(cmcOutsourceWorkService.deleteCmcOutsourceWorkByOutsourceIds(outsourceIds));
    }
}
