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.KQGroupWifiService;
import com.engine.kq.service.impl.KQGroupWifiServiceImpl;
import weaver.general.BaseBean;
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.Map;

/**
 * 考勤组WIFI
 */
public class KQGroupWifiAction extends BaseBean {

	private KQGroupWifiService getService(User user) {
		return (KQGroupWifiService) ServiceUtil.getService(KQGroupWifiServiceImpl.class, user);
	}

  /**
   * 获取新建编辑表单
   * @param request
   * @param response
   * @return
   */
  @GET
  @Path("/getGroupWifiList")
  @Produces(MediaType.TEXT_PLAIN)
  public String getGroupWifiList(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser(request, response);
      apidatas = getService(user).getGroupWifiList(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);
	}
}
