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

/**
 * 前台--人事--我的考勤
 */
public class KQMyAttendanceAction extends BaseBean {

    private KQMyAttendanceService getService(User user){
        return (KQMyAttendanceService) ServiceUtil.getService(KQMyAttendanceServiceImpl.class, user);
    }

    /**
     * 我的考勤权限
     *
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/hasRight")
    @Produces(MediaType.TEXT_PLAIN)
    public String hasRight(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> retmap = new HashMap<String, Object>();
        User user = HrmUserVarify.getUser(request, response);
        retmap.put("hasRight", HrmUserVarify.checkUserRight("HrmResource:Absense", user));
        return JSONObject.toJSONString(retmap);
    }



    /**
     * 统计信息
     *
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getHrmKQReportInfo")
    @Produces(MediaType.TEXT_PLAIN)
    public String getHrmKQReportInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apiDatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apiDatas = getService(user).getHrmKQReportInfo(ParamUtil.request2Map(request), user);
            apiDatas.put("api_status", true);
        } catch (Exception e) {
            writeLog(e);
            apiDatas.put("api_status", false);
            apiDatas.put("api_errormsg", e.getMessage());
        }
        return JSONObject.toJSONString(apiDatas, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 日历信息
     *
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getHrmKQMonthReportInfo")
    @Produces(MediaType.TEXT_PLAIN)
    public String getHrmKQMonthReportInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apiDatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apiDatas = getService(user).getHrmKQMonthReportInfo(ParamUtil.request2Map(request), user);
            apiDatas.put("api_status", true);
        } catch (Exception e) {
            writeLog(e);
            apiDatas.put("api_status", false);
            apiDatas.put("api_errormsg", e.getMessage());
        }
        return JSONObject.toJSONString(apiDatas, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 明细列表
     *
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getHrmKQReportDetialInfo")
    @Produces(MediaType.TEXT_PLAIN)
    public String getHrmKQReportDetialInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apiDatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apiDatas = getService(user).getHrmKQReportDetialInfo(ParamUtil.request2Map(request), user);
            apiDatas.put("api_status", true);
        } catch (Exception e) {
            writeLog(e);
            apiDatas.put("api_status", false);
            apiDatas.put("api_errormsg", e.getMessage());
        }
        return JSONObject.toJSONString(apiDatas, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取签到签退信息
     *
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getHrmKQSignInfo")
    @Produces(MediaType.TEXT_PLAIN)
    public String getHrmKQSignInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apiDatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apiDatas = getService(user).getHrmKQSignInfo(ParamUtil.request2Map(request), user);
            apiDatas.put("api_status", true);
        } catch (Exception e) {
            writeLog(e);
            apiDatas.put("api_status", false);
            apiDatas.put("api_errormsg", e.getMessage());
        }
        return JSONObject.toJSONString(apiDatas, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 移动端【我的考勤】明细的高级搜索
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getDetailCondition4Mobile")
    @Produces(MediaType.TEXT_PLAIN)
    public String getDetailCondition4Mobile(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apiDatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apiDatas = getService(user).getDetailCondition4Mobile(ParamUtil.request2Map(request), user);
            apiDatas.put("api_status", true);
        } catch (Exception e) {
            writeLog(e);
            apiDatas.put("api_status", false);
            apiDatas.put("api_errormsg", e.getMessage());
        }
        return JSONObject.toJSONString(apiDatas, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 移动端【我的考勤】明细
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getDetailList4Mobile")
    @Produces(MediaType.TEXT_PLAIN)
    public String getDetailList4Mobile(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apiDatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apiDatas = getService(user).getDetailList4Mobile(ParamUtil.request2Map(request), user);
            apiDatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apiDatas.put("api_status", false);
            apiDatas.put("api_errormsg", e.getMessage());
        }
        return JSONObject.toJSONString(apiDatas, SerializerFeature.DisableCircularReferenceDetect);
    }
}
