package com.bonus.material.work.controller;


import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import com.bonus.material.work.domain.SysWorkflowNode;
import com.bonus.material.work.domain.SysWorkflowRecordHistory;
import com.bonus.material.work.service.SysWorkflowRecordHistoryService;
import com.bonus.material.work.service.SysWorkflowRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "工作流详情表")
@RestController
@RequestMapping("/sysWorkflowRecordHistory")
public class SysWorkflowRecordHisController extends BaseController {


    @Resource
    private SysWorkflowRecordHistoryService sysWorkflowRecordHistoryService;

    /**
     * 审批
     */
    @ApiOperation(value = "审批")
    @PostMapping("/update")
    @PreventRepeatSubmit
    public AjaxResult update(@RequestBody SysWorkflowRecordHistory sysWorkflowRecordHistory)
    {
        try {
            sysWorkflowRecordHistoryService.updateSysWorkflowRecordHistory(sysWorkflowRecordHistory);
            return new AjaxResult(200,"修改成功！");
        }catch (Exception e){
            logger.error("修改失败{}", e.getMessage(), e);
            System.err.println("修改失败" + e.getMessage());
            return error(e.getMessage());
        }
    }

    /**
     * 审批
     */
    @ApiOperation(value = "直转审批")
    @PostMapping("/directUpdate")
    @PreventRepeatSubmit
    public AjaxResult directUpdate(@RequestBody SysWorkflowRecordHistory sysWorkflowRecordHistory)
    {
        try {
            sysWorkflowRecordHistoryService.updateDirectSysWorkflowRecordHistory(sysWorkflowRecordHistory);
            return new AjaxResult(200,"修改成功！");
        }catch (Exception e){
            logger.error("修改失败{}", e.getMessage(), e);
            System.err.println("修改失败" + e.getMessage());
            return error(e.getMessage());
        }
    }

    /**
     * 审批
     */
    @ApiOperation(value = "审批")
    @GetMapping("/getAuditStatus")
    public AjaxResult getAuditStatus(SysWorkflowRecordHistory sysWorkflowRecordHistory)
    {
        try {
            SysWorkflowRecordHistory audit =sysWorkflowRecordHistoryService.getAuditStatus(sysWorkflowRecordHistory);
            return success(audit);
        }catch (Exception e){
            logger.error("修改失败{}", e.getMessage(), e);
            System.err.println("修改失败" + e.getMessage());
            return error(e.getMessage());
        }
    }

}
