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


/**
 * 班次管理
 */
public class KQShiftManagementAction {
	private BaseBean logger = new BaseBean();

	private KQShiftManagementService getService(User user) {
		return (KQShiftManagementServiceImpl) ServiceUtil.getService(KQShiftManagementServiceImpl.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("KQClass:Management", user));
			apidatas.put("status", "1");
		} catch (Exception e) {
			apidatas.put("status", "-1");
			logger.writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

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

  /**
   * 获取班次管理查询条件条件
   * @param request
   * @param response
   * @return
   */
  @GET
  @Path("/getShiftManagementSearchCondition")
  @Produces(MediaType.TEXT_PLAIN)
  public String getShiftManagementSearchCondition(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser(request, response);
      apidatas = getService(user).getShiftManagementSearchCondition(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("/getShiftManagementSearchList")
  @Produces(MediaType.TEXT_PLAIN)
  public String getShiftManagementSearchList(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser(request, response);
      apidatas = getService(user).getShiftManagementSearchList(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("/getShiftManagementBaseForm")
  @Produces(MediaType.TEXT_PLAIN)
  public String getShiftManagementBaseForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser(request, response);
      apidatas = getService(user).getShiftManagementBaseForm(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("/saveShiftManagementBaseForm")
  @Produces(MediaType.TEXT_PLAIN)
  public String saveShiftManagementBaseForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser(request, response);
      apidatas = getService(user).saveShiftManagementBaseForm(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("/getShiftManagementPersonalizedForm")
  @Produces(MediaType.TEXT_PLAIN)
  public String getShiftManagementPersonalizedForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser(request, response);
      apidatas = getService(user).getShiftManagementPersonalizedForm(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("/saveShiftManagementPersonalizedForm")
  @Produces(MediaType.TEXT_PLAIN)
  public String saveShiftManagementPersonalizedForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser(request, response);
      apidatas = getService(user).saveShiftManagementPersonalizedForm(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("/delShiftManagementForm")
  @Produces(MediaType.TEXT_PLAIN)
  public String delShiftManagementForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
    Map<String, Object> apidatas = new HashMap<String, Object>();
    try {
      User user = HrmUserVarify.getUser(request, response);
      apidatas = getService(user).delShiftManagementForm(ParamUtil.request2Map(request), user);
    } catch (Exception e) {
      apidatas.put("status", "-1");
      logger.writeLog(e);
    }
    return JSONObject.toJSONString(apidatas);
  }

    /**
     * 获取邮件提醒内容设置
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getEmailRemindForm")
    @Produces(MediaType.TEXT_PLAIN)
    public String getEmailRemindForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apidatas = getService(user).getEmailRemindForm(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("/saveEmailRemind")
    @Produces(MediaType.TEXT_PLAIN)
    public String saveEmailRemind(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apidatas = getService(user).saveEmailRemind(ParamUtil.request2Map(request), user);
        } catch (Exception e) {
            apidatas.put("status", "-1");
            logger.writeLog(e);
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 获取短信提醒内容设置
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getMessageRemindForm")
    @Produces(MediaType.TEXT_PLAIN)
    public String getMessageRemindForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apidatas = getService(user).getMessageRemindForm(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("/saveMessageRemind")
    @Produces(MediaType.TEXT_PLAIN)
    public String saveMessageRemind(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apidatas = getService(user).saveMessageRemind(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("/getDetachOperatelevel")
    @Produces(MediaType.TEXT_PLAIN)
    public String getDetachOperatelevel(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apidatas = getService(user).getDetachOperatelevel(ParamUtil.request2Map(request), user);
        } catch (Exception e) {
            apidatas.put("status", "-1");
            logger.writeLog(e);
        }
        return JSONObject.toJSONString(apidatas);
    }
}
