package com.engine.htsc.common.web;

import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.common.service.CoWorkflowService;
import com.engine.htsc.common.service.impl.CoWorkflowServiceImpl;
import com.engine.htsc.trip.util.AjaxResult;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Map;

public class CoWorkflowAction {

  private CoWorkflowService getCoWorkflowService() {
    return ServiceUtil.getService(CoWorkflowServiceImpl.class);
  }

  @POST
  @Path("/createRequestMarkBySeq")
  @Produces(MediaType.APPLICATION_JSON)
  public AjaxResult<String> createRequestMarkByType(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    try {
      Map<String, Object> params = ParamUtil.request2Map(request);
      String wfid = (String) params.get("workflowid");
      String type = (String) params.get("type"); //类型区分总部,分支,子公司
      String requestMarkByType = this.getCoWorkflowService().createRequestMarkByType(wfid, type);
      return AjaxResult.ok(requestMarkByType);
    } catch (Exception e) {
      return AjaxResult.error(e.getMessage());
    }
  }


  @POST
  @Path("/createRequestMark")
  @Produces(MediaType.APPLICATION_JSON)
  public AjaxResult<String> createRequestMark(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    try {
      Map<String, Object> params = ParamUtil.request2Map(request);
      String wfid = (String) params.get("workflowid");

      CoWorkflowService coWorkflowService = this.getCoWorkflowService();
      String requestMark = coWorkflowService.createRequestMark(wfid);
      return AjaxResult.ok(requestMark);
    } catch (Exception e) {
      return AjaxResult.error(e.getMessage());
    }
  }

}
