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.KQReport4EService;
import com.engine.kq.service.impl.KQReport4EServiceImpl;
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;


/**
 * 考勤按钮控制
 */
public class KQReport4EAction {
	private BaseBean logger = new BaseBean();

	private KQReport4EService getService(User user) {
		return (KQReport4EServiceImpl) ServiceUtil.getService(KQReport4EServiceImpl.class, user);
	}

  /**
   * 小e 签到签退
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/punchButton4E")
  @Produces(MediaType.TEXT_PLAIN)
  public String punchButton4E(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).punchButton4E(request,ParamUtil.request2Map(request), user);

//      response.addHeader("Access-Control-Allow-Origin", "*");
//      response.addHeader("Vary", "Origin");
//      // Access-Control-Allow-Credentials
//      response.addHeader("Access-Control-Allow-Credentials", "true");
//      // Access-Control-Allow-Methods
//      response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
//      // Access-Control-Allow-Headers
//      response.addHeader("Access-Control-Allow-Headers",
//          "Origin, X-Requested-With, Content-Type, Accept, " + "X-CSRF-TOKEN");
    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 小e 我的考勤情况
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getScheduleData")
  @Produces(MediaType.TEXT_PLAIN)
  public String getScheduleData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getScheduleData(request,ParamUtil.request2Map(request), user);
//      response.addHeader("Access-Control-Allow-Origin", "*");
    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

  /**
   * 小e 我的假期情况
   * @param request
   * @param response
   * @return
   */
  @POST
  @Path("/getBalanceInfo")
  @Produces(MediaType.TEXT_PLAIN)
  public String getBalanceInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser (request , response) ;
      apidatas = getService(user).getBalanceInfo(request,ParamUtil.request2Map(request), user);
//      response.addHeader("Access-Control-Allow-Origin", "*");
    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }
}
