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.kq.service.KQAttendanceEventService;
import com.engine.kq.service.impl.KQAttendanceEventServiceImpl;
import java.util.HashMap;
import java.util.Map;
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 weaver.general.BaseBean;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;


/**
 * 考勤流程相关的ajax请求事件
 */
public class KQAttendanceEventAction {
	private BaseBean logger = new BaseBean();

	private KQAttendanceEventService getService(User user) {
		return (KQAttendanceEventServiceImpl) ServiceUtil.getService(KQAttendanceEventServiceImpl.class, user);
	}

	/**
	 * 获取请假的工作时长，因为请假牵扯到请假类型和时长的关系
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getLeaveWorkDuration")
	@Produces(MediaType.TEXT_PLAIN)
	public String getLeaveWorkDuration(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getLeaveWorkDuration(ParamUtil.request2Map(request), user);

		} catch (Exception e) {
			apidatas.put("status", "-1");
			logger.writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

  /**
   * 获取出差的工作时长
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getEvectionWorkDuration")
  @Produces(MediaType.TEXT_PLAIN)
  public String getEvectionWorkDuration(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getEvectionWorkDuration(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 获取公出的工作时长
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getOutWorkDuration")
  @Produces(MediaType.TEXT_PLAIN)
  public String getOutWorkDuration(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getOutWorkDuration(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 获取加班的工作时长
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getOverTimeDuration")
  @Produces(MediaType.TEXT_PLAIN)
  public String getOverTimeDuration(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getOverTimeDuration(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 获取工作时长，这个是通用的
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getWorkDuration")
  @Produces(MediaType.TEXT_PLAIN)
  public String getWorkDuration(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getWorkDuration(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 获取假期信息
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getVacationInfo")
  @Produces(MediaType.TEXT_PLAIN)
  public String getVacationInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getVacationInfo(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 获取补卡信息
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getAttendanceCard")
  @Produces(MediaType.TEXT_PLAIN)
  public String getAttendanceCard(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getAttendanceCard(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 请假校验事件
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/checkLeave")
  @Produces(MediaType.TEXT_PLAIN)
  public String checkLeave(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).checkLeave(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 出差校验事件
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/checkEvection")
  @Produces(MediaType.TEXT_PLAIN)
  public String checkEvection(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).checkEvection(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 公出校验事件
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/checkOut")
  @Produces(MediaType.TEXT_PLAIN)
  public String checkOut(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).checkOut(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }


  /**
   * 销假校验事件
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/checkLeaveBack")
  @Produces(MediaType.TEXT_PLAIN)
  public String checkLeaveBack(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).checkLeaveBack(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }
  /**
   * 排班校验事件
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/checkShift")
  @Produces(MediaType.TEXT_PLAIN)
  public String checkShift(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).checkShift(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 销假流程用的根据流程获取相应的请假信息
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getLeaveBackInfo")
  @Produces(MediaType.TEXT_PLAIN)
  public String getLeaveBackInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getLeaveBackInfo(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 考勤变更流程根据流程获取相应的流程信息
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getProcessChangeInfo")
  @Produces(MediaType.TEXT_PLAIN)
  public String getProcessChangeInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getProcessChangeInfo(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 考勤变更流程计算时长用的
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getProcessChangeWorkDuration")
  @Produces(MediaType.TEXT_PLAIN)
  public String getProcessChangeWorkDuration(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getProcessChangeWorkDuration(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 考勤变更流程提交校验
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/checkProcessChange")
  @Produces(MediaType.TEXT_PLAIN)
  public String checkProcessChange(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).checkProcessChange(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 考获取勤变更流程类型
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getProcessChangeType")
  @Produces(MediaType.TEXT_PLAIN)
  public String getProcessChangeType(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getProcessChangeType(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 补卡流程提交校验
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/checkCard")
  @Produces(MediaType.TEXT_PLAIN)
  public String checkCard(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).checkCard(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 加班流程提交校验
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/checkOvertime")
  @Produces(MediaType.TEXT_PLAIN)
  public String checkOvertime(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).checkOvertime(ParamUtil.request2Map(request), user);

    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }
}
