package com.ruoyi.web.controller.oa;

import java.util.Date;
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.CmcDeposit;
import com.ruoyi.oa.service.ICmcDepositService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * cmc保证金审批Controller
 * 
 * @author cmc
 * @date 2024-04-29
 */
@RestController
@RequestMapping("/oa/deposit")
public class CmcDepositController extends BaseController
{
    @Autowired
    private ICmcDepositService cmcDepositService;

    /**
     * 查询cmc保证金审批列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcDeposit cmcDeposit)
    {
        startPage();
        List<CmcDeposit> list = cmcDepositService.selectCmcDepositList(cmcDeposit);
        return getDataTable(list);
    }

    /**
     * 导出cmc保证金审批列表
     */
    @Log(title = "cmc保证金审批", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcDeposit cmcDeposit)
    {
        List<CmcDeposit> list = cmcDepositService.selectCmcDepositList(cmcDeposit);
        ExcelUtil<CmcDeposit> util = new ExcelUtil<CmcDeposit>(CmcDeposit.class);
        util.exportExcel(response, list, "cmc保证金审批数据");
    }

    /**
     * 获取cmc保证金审批详细信息
     */
    @GetMapping(value = "/{depositId}")
    public AjaxResult getInfo(@PathVariable("depositId") String depositId)
    {
        return success(cmcDepositService.selectCmcDepositByDepositId(depositId));
    }

    /**
     * 新增cmc保证金审批
     */
    @Log(title = "cmc保证金审批", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcDeposit cmcDeposit)
    {
        return toAjax(cmcDepositService.insertCmcDeposit(cmcDeposit));
    }

    /**
     * 修改cmc保证金审批
     */
    @Log(title = "cmc保证金审批", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcDeposit cmcDeposit)
    {
        if (cmcDeposit.getManagerComment() != null && cmcDeposit.getRemitTime() == null) {
            cmcDeposit.setManagerUserId(getLoginUser().getUserId());
            cmcDeposit.setManagerTime(new Date());
        }
        if (cmcDeposit.getRemitTime() != null) {
            cmcDeposit.setCwUserId(getLoginUser().getUserId());
            cmcDeposit.setCwTime(new Date());
        }
        return toAjax(cmcDepositService.updateCmcDeposit(cmcDeposit));
    }

    /**
     * 删除cmc保证金审批
     */
    @Log(title = "cmc保证金审批", businessType = BusinessType.DELETE)
	@DeleteMapping("/{depositIds}")
    public AjaxResult remove(@PathVariable String[] depositIds)
    {
        return success(cmcDepositService.deleteCmcDepositByDepositIds(depositIds));
    }
}
