package com.engine.kq.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.hrm.service.HrmStateSetService;
import com.engine.hrm.service.impl.HrmStateSetServiceImpl;
import com.engine.kq.service.KQAttendanceSetService;
import com.engine.kq.service.impl.KQAttendanceSetServiceImpl;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import weaver.general.BaseBean;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

/**
 * 新考勤 考勤流程设置
 */
public class KQAttendanceSetAction extends BaseBean {

	private KQAttendanceSetService getService(User user) {
		return (KQAttendanceSetService) ServiceUtil.getService(KQAttendanceSetServiceImpl.class, user);
	}

	/**
	 * 获取状态变更右键菜单
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getStateRightMenu")
	@Produces(MediaType.TEXT_PLAIN)
	public String getStateRightMenu(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser (request , response) ;
			apidatas = getService(user).getStateRightMenu(ParamUtil.request2Map(request), user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 获取状态变更流程的 tab页签数据
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getStateProcSetTabInfo")
	@Produces(MediaType.TEXT_PLAIN)
	public String getStateProcSetTabInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser (request , response) ;
			apidatas = getService(user).getStateProcSetTabInfo(ParamUtil.request2Map(request), user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 获取状态变更流程查询条件字段
	 * @param request
	 * @param response
	 * @return
	 */
	@GET
	@Path("/getStateProcSetListSearchCondition")
	@Produces(MediaType.TEXT_PLAIN)
	public String getStateProcSetListSearchCondition(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getStateProcSetListSearchCondition(ParamUtil.request2Map(request), user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 获取状态变更流程查询列表
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getStateProcSetListSearchList")
	@Produces(MediaType.TEXT_PLAIN)
	public String getStateProcSetListSearchList(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getStateProcSetListSearchList(ParamUtil.request2Map(request),request, user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 获取状态变更流程 流程概览信息
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getStateProcSetFlowForm")
	@Produces(MediaType.TEXT_PLAIN)
	public String getStateProcSetFlowForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getStateProcSetFlowForm(ParamUtil.request2Map(request), user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}
	
	/**
	 * 保存状态变更流程 流程概览信息
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/saveStateProcSetFlow")
	@Produces(MediaType.TEXT_PLAIN)
	public String saveStateProcSetFlow(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).saveStateProcSetFlow(ParamUtil.request2Map(request), user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 获取状态变更流程 字段对应信息
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getStateProcSetFlowWfFields")
	@Produces(MediaType.TEXT_PLAIN)
	public String getStateProcSetFlowWfFields(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getStateProcSetFlowWfFields(ParamUtil.request2Map(request), user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}
	
	/**
	 * 保存状态变更流程 字段对应信息
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/saveStateProcSetFlowWfFields")
	@Produces(MediaType.TEXT_PLAIN)
	public String saveStateProcSetFlowWfFields(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).saveStateProcSetFlowWfFields(ParamUtil.request2Map(request),request, user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 获取状态变更流程 动作设置
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getStateProcSetFlowWfSet")
	@Produces(MediaType.TEXT_PLAIN)
	public String getStateProcSetFlowWfSet(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getStateProcSetFlowWfSet(ParamUtil.request2Map(request), user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}
	
	/**
	 * 保存状态变更流程的 动作设置
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/saveStateProcSetFlowWfSet")
	@Produces(MediaType.TEXT_PLAIN)
	public String saveStateProcSetFlowWfSet(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).saveStateProcSetFlowWfSet(ParamUtil.request2Map(request),request,response, user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}
	
	/**
	 * 删除通用变更流程
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/delStateProcSet")
	@Produces(MediaType.TEXT_PLAIN)
	public String delStateProcSet(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).delStateProcSet(ParamUtil.request2Map(request),request, user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}
	
	/**
	 * 改变通用变更流程的状态
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/changeStateProcSetStatus")
	@Produces(MediaType.TEXT_PLAIN)
	public String changeStateProcSetStatus(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).changeStateProcSetStatus(ParamUtil.request2Map(request),request, user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}
	
	/**
	 * 获取状态变更流程 自动创建表单
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getStateProcSetCreateForm")
	@Produces(MediaType.TEXT_PLAIN)
	public String getStateProcSetCreateForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getStateProcSetCreateForm(ParamUtil.request2Map(request), user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}
	
	/**
	 * 保存状态变更流程 自动创建表单
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/saveStateProcSetCreateForm")
	@Produces(MediaType.TEXT_PLAIN)
	public String saveStateProcSetCreateForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).saveStateProcSetCreateForm(ParamUtil.request2Map(request),request, user);
			apidatas.put("api_status", true);
		} catch (Exception e) {
            writeLog(e);
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg","system error");
		}
		return JSONObject.toJSONString(apidatas);
	}

  /**
   * 根据基本信息页面的选择的下拉框同步，带出不同的模板文件
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getProcSetTemplet")
  @Produces(MediaType.TEXT_PLAIN)
  public String getProcSetTemplet(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser(request, response);
      apidatas = getService(user).getProcSetTemplet(ParamUtil.request2Map(request),request, user);
      apidatas.put("api_status", true);
    } catch (Exception e) {
      writeLog(e);
      apidatas.put("api_status", false);
      apidatas.put("api_errormsg","system error");
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 获取自定义考勤流程tab页签
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getCustomKQFlowTab")
  @Produces(MediaType.TEXT_PLAIN)
  public String getCustomKQFlowTab(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getCustomKQFlowTab(ParamUtil.request2Map(request), user);
      apidatas.put("api_status", true);
    } catch (Exception e) {
      writeLog(e);
      apidatas.put("api_status", false);
      apidatas.put("api_errormsg","system error");
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 考勤流程 新建校验规则
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getProcSetCheckRule")
  @Produces(MediaType.TEXT_PLAIN)
  public String getProcSetCheckRule(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getProcSetCheckRule(ParamUtil.request2Map(request), user);
      apidatas.put("api_status", true);
    } catch (Exception e) {
      writeLog(e);
      apidatas.put("api_status", false);
      apidatas.put("api_errormsg","system error");
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 考勤流程 校验规则列表
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getStateProcSetFlowCheckRuleList")
  @Produces(MediaType.TEXT_PLAIN)
  public String getStateProcSetFlowCheckRuleList(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getStateProcSetFlowCheckRuleList(ParamUtil.request2Map(request), user);
      apidatas.put("api_status", true);
    } catch (Exception e) {
      writeLog(e);
      apidatas.put("api_status", false);
      apidatas.put("api_errormsg","system error");
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 考勤流程 保存校验规则
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/saveStateProcCheckRule")
  @Produces(MediaType.TEXT_PLAIN)
  public String saveStateProcCheckRule(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).saveStateProcCheckRule(ParamUtil.request2Map(request), user);
      apidatas.put("api_status", true);
    } catch (Exception e) {
      writeLog(e);
      apidatas.put("api_status", false);
      apidatas.put("api_errormsg","system error");
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 考勤流程 删除校验规则
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/delStateProcCheckRule")
  @Produces(MediaType.TEXT_PLAIN)
  public String delStateProcCheckRule(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).delStateProcCheckRule(ParamUtil.request2Map(request), user);
      apidatas.put("api_status", true);
    } catch (Exception e) {
      writeLog(e);
      apidatas.put("api_status", false);
      apidatas.put("api_errormsg","system error");
    }
    return JSONObject.toJSONString(apidatas);
  }
}
