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

/**
 * 采购计划Controller
 * 
 * @author cmc
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/oa/procurePlan")
public class CmcProcurePlanController extends BaseController
{
    @Autowired
    private ICmcProcurePlanService cmcProcurePlanService;

    /**
     * 查询采购计划列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcProcurePlan cmcProcurePlan)
    {
        startPage();
        List<CmcProcurePlan> list = cmcProcurePlanService.selectCmcProcurePlanList(cmcProcurePlan);
        return getDataTable(list);
    }

    /**
     * 导出采购计划列表
     */
    @Log(title = "采购计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcProcurePlan cmcProcurePlan)
    {
        List<CmcProcurePlan> list = cmcProcurePlanService.selectCmcProcurePlanList(cmcProcurePlan);
        ExcelUtil<CmcProcurePlan> util = new ExcelUtil<CmcProcurePlan>(CmcProcurePlan.class);
        util.exportExcel(response, list, "采购计划数据");
    }

    /**
     * 获取采购计划详细信息
     */
    @GetMapping(value = "/{procurePlanId}")
    public AjaxResult getInfo(@PathVariable("procurePlanId") Integer procurePlanId)
    {
        return success(cmcProcurePlanService.selectCmcProcurePlanByProcurePlanId(procurePlanId));
    }

    /**
     * 新增采购计划
     */
    @Log(title = "采购计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcProcurePlan cmcProcurePlan)
    {
        return toAjax(cmcProcurePlanService.insertCmcProcurePlan(cmcProcurePlan));
    }

    /**
     * 修改采购计划
     */
    @Log(title = "采购计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcProcurePlan cmcProcurePlan)
    {
        return toAjax(cmcProcurePlanService.updateCmcProcurePlan(cmcProcurePlan));
    }

    /**
     * 删除采购计划
     */
    @Log(title = "采购计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{procureApplyId}")
    public AjaxResult remove(@PathVariable String[] procureApplyId)
    {
        return success(cmcProcurePlanService.deleteCmcProcurePlanByProcureApplyIds(procureApplyId));
    }
}
