package ink.wgink.module.activiti.controller.app.route.oa;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.activiti.service.activiti.IActivitiModelService;
import ink.wgink.module.activiti.service.oa.IOaFormReportRouteService;
import ink.wgink.pojo.result.ErrorResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @ClassName: OaFormReportAppRouteController
 * @Description: Oa管理
 * @Author: wanggeng
 * @Date: 2022/3/23 09:54
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_APP_ROUTE_PREFIX + "oa管理")
@Controller
@RequestMapping(ISystemConstant.APP_ROUTE_PREFIX + "/oa-form-report")
public class OaFormReportAppRouteController extends DefaultBaseController {

    @Autowired
    private IOaFormReportRouteService oaFormReportRouteService;
    @Autowired
    private IActivitiModelService activitiModelService;

    @GetMapping("save/definition-id/{processDefinitionId}/code/{formCode}/version/{formVersion}")
    public void get(@PathVariable("processDefinitionId") String processDefinitionId,
                    @PathVariable("formCode") String formCode,
                    @PathVariable("formVersion") Integer formVersion,
                    @RequestParam("token") String token,
                    HttpSession httpSession,
                    HttpServletRequest httpServletRequest,
                    HttpServletResponse httpServletResponse) {
        oaFormReportRouteService.appSave(token, processDefinitionId, formCode, formVersion, httpSession, httpServletRequest, httpServletResponse);
    }

    @GetMapping("update/task-id/{taskId}/code/{formCode}/version/{formVersion}/is-need-claim/{isNeedClaim}")
    public void update(@PathVariable("taskId") String taskId,
                       @PathVariable("formCode") String formCode,
                       @PathVariable("formVersion") Integer formVersion,
                       @PathVariable("isNeedClaim") Integer isNeedClaim,
                       @RequestParam("token") String token,
                       HttpSession httpSession,
                       HttpServletRequest httpServletRequest,
                       HttpServletResponse httpServletResponse) {
        oaFormReportRouteService.appUpdate(token, taskId, formCode, formVersion, isNeedClaim, httpSession, httpServletRequest, httpServletResponse);
    }

    @GetMapping("show/code/{formCode}/version/{formVersion}")
    public void show(@PathVariable("formCode") String formCode,
                     @PathVariable("formVersion") Integer formVersion,
                     @RequestParam("token") String token,
                     HttpSession httpSession,
                     HttpServletRequest httpServletRequest,
                     HttpServletResponse httpServletResponse) {
        oaFormReportRouteService.appShow(token, formCode, formVersion, httpSession, httpServletRequest, httpServletResponse);
    }

    @ApiOperation(value = "查看运行流程图", notes = "查看运行流程图接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processInstanceId", value = "流程实例ID", paramType = "path"),
            @ApiImplicitParam(name = "token", value = "token", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("get-runtime-process-image/{processInstanceId}")
    public void getRuntimeProcessImage(@PathVariable("processInstanceId") String processInstanceId, @RequestParam("token") String token, HttpServletResponse response) {
        activitiModelService.getRuntimeProcessImage(response, processInstanceId);
    }

}
