package com.engine.organization.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.organization.entity.logview.param.LogViewSearchParam;
import com.engine.organization.util.response.ReturnResult;
import com.engine.organization.wrapper.LogViewWrapper;
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.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Map;

/**
 * @author:dxfeng
 * @createTime: 2022/07/05
 * @version: 1.0
 */
public class LogViewController {
    public LogViewWrapper getLogViewWrapper(User user) {
        return ServiceUtil.getService(LogViewWrapper.class, user);
    }


    @GET
    @Path("/listPage")
    @Produces(MediaType.APPLICATION_JSON)
    public ReturnResult listPage(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            Map<String, Object> map = ParamUtil.request2Map(request);
            LogViewSearchParam params = JSONObject.toJavaObject((JSON) JSON.toJSON(map), LogViewSearchParam.class);
            return ReturnResult.successed(getLogViewWrapper(user).listPage(params));
        } catch (Exception e) {
            return ReturnResult.exceptionHandle(e);
        }
    }


    @GET
    @Path("/getSearchCondition")
    @Produces(MediaType.APPLICATION_JSON)
    public ReturnResult getSearchCondition(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            return ReturnResult.successed(getLogViewWrapper(user).getSearchCondition());
        } catch (Exception e) {
            return ReturnResult.exceptionHandle(e);
        }
    }
}
