package com.ruoyi.web.controller.oa;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.CmcContractSubContract;
import com.ruoyi.oa.service.ICmcContractSubContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * cmc承接分包合同Controller
 * 
 * @author cmc
 * @date 2024-06-19
 */
@RestController
@RequestMapping("/oa/contractSubcontract")
public class CmcContractSubContractController extends BaseController
{
    @Autowired
    private ICmcContractSubContractService cmcContractSubContractService;

    /**
     * 查询cmc承接分包合同列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcContractSubContract cmcContractSubContract)
    {
        startPage();
        List<CmcContractSubContract> list = cmcContractSubContractService.selectCmcContractSubContractList(cmcContractSubContract);
        return getDataTable(list);
    }

    /**
     * 导出cmc承接分包合同列表
     */
    @Log(title = "cmc承接分包合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcContractSubContract cmcContractSubContract)
    {
        List<CmcContractSubContract> list = cmcContractSubContractService.selectCmcContractSubContractList(cmcContractSubContract);
        ExcelUtil<CmcContractSubContract> util = new ExcelUtil<CmcContractSubContract>(CmcContractSubContract.class);
        util.exportExcel(response, list, "cmc承接分包合同数据");
    }

    /**
     * 获取cmc承接分包合同详细信息
     */
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") String contractId)
    {
        return success(cmcContractSubContractService.selectCmcContractSubContractByContractId(contractId));
    }

    /**
     * 新增cmc承接分包合同
     */
    @Log(title = "cmc承接分包合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcContractSubContract cmcContractSubContract)
    {
        return toAjax(cmcContractSubContractService.insertCmcContractSubContract(cmcContractSubContract));
    }

    /**
     * 修改cmc承接分包合同
     */
    @Log(title = "cmc承接分包合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcContractSubContract cmcContractSubContract)
    {
        return toAjax(cmcContractSubContractService.updateCmcContractSubContract(cmcContractSubContract));
    }

    /**
     * 删除cmc承接分包合同
     */
    @Log(title = "cmc承接分包合同", businessType = BusinessType.DELETE)
	@DeleteMapping("/{subContractIds}")
    public AjaxResult remove(@PathVariable String[] subContractIds)
    {
        return success(cmcContractSubContractService.deleteCmcContractSubContractBySubContractIds(subContractIds));
    }

    /**
     * 删除cmc承接分包合同
     */
    @Log(title = "cmc承接分包合同", businessType = BusinessType.DELETE)
    @DeleteMapping("/contractIds/{contractIds}")
    public AjaxResult removeByContractIds(@PathVariable String[] contractIds)
    {
        return success(cmcContractSubContractService.deleteCmcContractSubContractByContractId(contractIds));
    }
}
