package com.engine.kq.web;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.kq.service.KQReportFieldDefineService;
import com.engine.kq.service.impl.KQReportFieldDefineServiceImpl;
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.Map;

/**
 * 考勤报表展示列支持定制
 */
public class KQReportFieldDefineAction extends BaseBean {

	private KQReportFieldDefineService getService(User user) {
		return (KQReportFieldDefineService) ServiceUtil.getService(KQReportFieldDefineServiceImpl.class, user);
	}

	/**
	 * 是否有权限
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getHasRight")
	@Produces(MediaType.TEXT_PLAIN)
	public String getHasRight(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas.put("hasRight", HrmUserVarify.checkUserRight("KQReportFieldDefine:Add", user));
			apidatas.put("status", "1");
		} catch (Exception e) {
			apidatas.put("status", "-1");
		}
		return JSONObject.toJSONString(apidatas);
	}

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

	/**
	 * 获取考勤报表定制列页签
	 * @param request
	 * @param response
	 * @return
	 */
	@GET
	@Path("/getFieldDefineTabs")
	@Produces(MediaType.TEXT_PLAIN)
	public String getFieldDefineTabs(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getFieldDefineTabs(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 获取考勤报表定制列列表
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getFieldDefineList")
	@Produces(MediaType.TEXT_PLAIN)
	public String getFieldDefineList(@Context HttpServletRequest request, @Context HttpServletResponse response){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getFieldDefineList(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 保存考勤报表定制列列表
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/saveFieldDefineList")
	@Produces(MediaType.TEXT_PLAIN)
	public String saveFieldDefineList(@Context HttpServletRequest request, @Context HttpServletResponse response){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).saveFieldDefineList(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

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

	/**
	 * 保存考勤报表定制列
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/saveFieldDefine")
	@Produces(MediaType.TEXT_PLAIN)
	public String saveFieldDefine(@Context HttpServletRequest request, @Context HttpServletResponse response){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).saveFieldDefine(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

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

	/**
	 * 获取考勤报表定制列分组列表
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getGroupList")
	@Produces(MediaType.TEXT_PLAIN)
	public String getGroupList(@Context HttpServletRequest request, @Context HttpServletResponse response){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getGroupList(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 获取考勤报表定制列分组表单
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getGroupForm")
	@Produces(MediaType.TEXT_PLAIN)
	public String getGroupForm(@Context HttpServletRequest request, @Context HttpServletResponse response){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getGroupForm(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 保存考勤报表定制列分组表单
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/saveGroup")
	@Produces(MediaType.TEXT_PLAIN)
	public String saveGroup(@Context HttpServletRequest request, @Context HttpServletResponse response){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).saveGroup(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

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

	/**
	 * 移动考勤报表定制列分组
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/changeFieldGroup")
	@Produces(MediaType.TEXT_PLAIN)
	public String changeFieldGroup(@Context HttpServletRequest request, @Context HttpServletResponse response){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).changeFieldGroup(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 获取考勤报表展示列模板页签
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getReportMoudleTabs")
	@Produces(MediaType.TEXT_PLAIN)
	public String getReportMoudleTabs(@Context HttpServletRequest request, @Context HttpServletResponse response){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getReportMoudleTabs(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}


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

	/**
	 * 保存考勤报表展示列模板页签
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/saveReportMoudle")
	@Produces(MediaType.TEXT_PLAIN)
	public String saveReportMoudle(@Context HttpServletRequest request, @Context HttpServletResponse response){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).saveReportMoudle(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 删除考勤报表展示列模板页签
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/deleteReportMoudle")
	@Produces(MediaType.TEXT_PLAIN)
	public String deleteReportMoudle(@Context HttpServletRequest request, @Context HttpServletResponse response){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).deleteReportMoudle(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 获取考勤报表排序设置
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/getFieldOrderDefine")
	@Produces(MediaType.TEXT_PLAIN)
	public String getFieldOrderDefine(@Context HttpServletRequest request, @Context HttpServletResponse response){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getFieldOrderDefine(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 保存考勤报表排序设置
	 * @param request
	 * @param response
	 * @return
	 */
	@POST
	@Path("/saveFieldOrderDefine")
	@Produces(MediaType.TEXT_PLAIN)
	public String saveFieldOrderDefine(@Context HttpServletRequest request, @Context HttpServletResponse response){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).saveFieldOrderDefine(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}
}
