package com.ruoyi.web.controller.oa;

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

import com.ruoyi.common.utils.SnowFlake;
import com.ruoyi.oa.domain.CmcPartner;
import com.ruoyi.oa.service.ICmcPartnerService;
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.CmcSubContract;
import com.ruoyi.oa.service.ICmcSubContractService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * cmc分包合同评审Controller
 * 
 * @author cmc
 * @date 2024-04-18
 */
@RestController
@RequestMapping("/oa/subContract")
public class CmcSubContractController extends BaseController
{
    @Autowired
    private ICmcSubContractService cmcSubContractService;

    @Autowired
    private ICmcPartnerService cmcPartnerService;

    /**
     * 查询cmc分包合同评审列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcSubContract cmcSubContract)
    {
        startPage();
        List<CmcSubContract> list = cmcSubContractService.selectCmcSubContractList(cmcSubContract);
        return getDataTable(list);
    }

    /**
     * 导出cmc分包合同评审列表
     */
    @Log(title = "cmc分包合同评审", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcSubContract cmcSubContract)
    {
        List<CmcSubContract> list = cmcSubContractService.selectCmcSubContractList(cmcSubContract);
        ExcelUtil<CmcSubContract> util = new ExcelUtil<CmcSubContract>(CmcSubContract.class);
        util.exportExcel(response, list, "cmc分包合同评审数据");
    }

    /**
     * 获取cmc分包合同评审详细信息
     */
    @GetMapping(value = "/{subContractId}")
    public AjaxResult getInfo(@PathVariable("subContractId") String subContractId)
    {
        return success(cmcSubContractService.selectCmcSubContractBySubContractId(subContractId));
    }

    /**
     * 新增cmc分包合同评审
     */
    @Log(title = "cmc分包合同评审", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcSubContract cmcSubContract)
    {
        return toAjax(cmcSubContractService.insertCmcSubContract(cmcSubContract));
    }

    /**
     * 修改cmc分包合同评审
     */
    @Log(title = "cmc分包合同评审", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcSubContract cmcSubContract)
    {
        if (cmcSubContract.getManagerComment() != null && cmcSubContract.getGmComment() == null) {
            cmcSubContract.setManagerUserId(getLoginUser().getUserId());
            cmcSubContract.setManagerTime(new Date());
        }
        if (cmcSubContract.getGmComment() != null && cmcSubContract.getSignDate() == null) {
            cmcSubContract.setGmUserId(getLoginUser().getUserId());
            cmcSubContract.setGmTime(new Date());
        }
        return toAjax(cmcSubContractService.updateCmcSubContract(cmcSubContract));
    }

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