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.biz.KQGroupBiz;
import com.engine.kq.service.KQGroupLocationService;
import com.engine.kq.service.impl.KQGroupLocationServiceImpl;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

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.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 考勤组办公地点
 */
public class KQGroupLocationAction extends BaseBean {

	private KQGroupLocationService getService(User user) {
		return (KQGroupLocationService) ServiceUtil.getService(KQGroupLocationServiceImpl.class, user);
	}


  /**
   * 查列表
   * @param request
   * @param response
   * @return
   */
  @GET
  @Path("/getGroupLocationList")
  @Produces(MediaType.TEXT_PLAIN)
  public String getGroupLocationList(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser(request, response);
      apidatas = getService(user).getGroupLocationList(ParamUtil.request2Map(request), user);

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

	/**
	 * 获取新建编辑表单
	 * @param request
	 * @param response
	 * @return
	 */
	@GET
	@Path("/getForm")
	@Produces(MediaType.TEXT_PLAIN)
	public String getForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getForm(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}


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

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


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

	/**
	 * 获办公地点信息
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getLocationWifiInfo")
	@Produces(MediaType.TEXT_PLAIN)
	public String getLocationWifiInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			String userId = Util.null2String(request.getParameter("userId"));
      String showWifiList = Util.null2String(request.getParameter("showWifiList"));
			if(userId.length()==0)userId = ""+user.getUID();
			apidatas = new KQGroupBiz().getLocationWifiInfo(userId,showWifiList);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

}
