package com.ruoyi.web.controller.oa;

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

import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
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.CmcContractMeeting;
import com.ruoyi.oa.service.ICmcContractMeetingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * cmc合同会审Controller
 * 
 * @author cmc
 * @date 2024-04-19
 */
@RestController
@RequestMapping("/oa/contractMeeting")
public class CmcContractMeetingController extends BaseController
{
    @Autowired
    private ICmcContractMeetingService cmcContractMeetingService;

    /**
     * 查询cmc合同会审列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcContractMeeting cmcContractMeeting)
    {
        startPage();
        List<CmcContractMeeting> list = cmcContractMeetingService.selectCmcContractMeetingList(cmcContractMeeting);
        return getDataTable(list);
    }

    /**
     * 导出cmc合同会审列表
     */
    @Log(title = "cmc合同会审", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcContractMeeting cmcContractMeeting)
    {
        List<CmcContractMeeting> list = cmcContractMeetingService.selectCmcContractMeetingList(cmcContractMeeting);
        ExcelUtil<CmcContractMeeting> util = new ExcelUtil<CmcContractMeeting>(CmcContractMeeting.class);
        util.exportExcel(response, list, "cmc合同会审数据");
    }

    /**
     * 获取cmc合同会审详细信息
     */
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") String contractId)
    {
        return success(cmcContractMeetingService.selectCmcContractMeetingByContractId(contractId));
    }

    /**
     * 新增cmc合同会审
     */
    @Log(title = "cmc合同会审", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestParam("form")String formData)
    {
        JSONObject formDataJson = JSONObject.parse(formData);
        CmcContractMeeting cmcContractMeeting = new CmcContractMeeting();
        cmcContractMeeting.setContractId(formDataJson.getString("contractId"));
        cmcContractMeeting.setMeetingTime(formDataJson.getDate("meetingTime"));
        cmcContractMeeting.setPlace(formDataJson.getString("place"));
        cmcContractMeeting.setHostId(formDataJson.getLong("hostId"));
        if (formDataJson.getJSONArray("users").size() > 0) {
            String userString = formDataJson.getString("users").substring(1, formDataJson.getString("users").length() - 1);
            cmcContractMeeting.setUsers(userString);
        }
        return toAjax(cmcContractMeetingService.insertCmcContractMeeting(cmcContractMeeting));
    }

    /**
     * 修改cmc合同会审
     */
    @Log(title = "cmc合同会审", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestParam("form")String formData)
    {
        JSONObject formDataJson = JSONObject.parse(formData);
        CmcContractMeeting cmcContractMeeting = cmcContractMeetingService.selectCmcContractMeetingByContractId(formDataJson.getString("contractId"));
        cmcContractMeeting.setDocument(formDataJson.getString("document"));
        cmcContractMeeting.setConclusion(formDataJson.getString("conclusion"));
        cmcContractMeeting.setCommentTime(new Date());
        return toAjax(cmcContractMeetingService.updateCmcContractMeeting(cmcContractMeeting));
    }

    /**
     * 删除cmc合同会审
     */
    @Log(title = "cmc合同会审", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable String[] contractIds)
    {
        return success(cmcContractMeetingService.deleteCmcContractMeetingByContractIds(contractIds));
    }
}
