package com.engine.xcy.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.xcy.service.KQXCYService;
import com.engine.xcy.service.impl.KQXCYServiceImpl;
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.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 KQXCYAction {

    private final BaseBean logger = new BaseBean();

    private KQXCYService getService(User user) {
        return (KQXCYServiceImpl) ServiceUtil.getService(KQXCYServiceImpl.class, user);
    }

    /**
     * 获取加班的工作时长
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getOverTimeDurationXcy")
    @Produces(MediaType.TEXT_PLAIN)
    public String getOverTimeDuration(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser (request , response) ;
            // 调用新创元处理逻辑
            apidatas = getService(user).getOverTimeDuration(ParamUtil.request2Map(request), user);
        } catch (Exception e) {
            apidatas.put("status", "-1");
            logger.writeLog(e);
        }
        return JSONObject.toJSONString(apidatas);
    }
}
