package com.engine.organization.web;

import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.organization.util.response.ReturnResult;
import com.engine.organization.wrapper.QuickSearchWrapper;
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.Map;

/**
 * @author:dxfeng
 * @createTime: 2023/08/08
 * @version: 1.0
 */
public class QuickSearchController {
    public QuickSearchWrapper getQuickSearchWrapper(User user) {
        return ServiceUtil.getService(QuickSearchWrapper.class, user);
    }

    @GET
    @Path("/getQuickSearchCondition")
    @Produces(MediaType.APPLICATION_JSON)
    public ReturnResult getQuickSearchCondition(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            Map<String, Object> map = ParamUtil.request2Map(request);
            return ReturnResult.successed(user,getQuickSearchWrapper(user).getQuickSearchCondition(map));
        } catch (Exception e) {
            return ReturnResult.exceptionHandle(e);
        }
    }

    @GET
    @Path("/getQuickSearchInfo")
    @Produces(MediaType.APPLICATION_JSON)
    public ReturnResult getQuickSearchInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            Map<String, Object> map = ParamUtil.request2Map(request);
            return ReturnResult.successed(user,getQuickSearchWrapper(user).getQuickSearchInfo(map));
        } catch (Exception e) {
            return ReturnResult.exceptionHandle(e);
        }
    }

    @POST
    @Path("/saveQuickSearchInfo")
    @Produces(MediaType.APPLICATION_JSON)
    public ReturnResult saveQuickSearchInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            Map<String, Object> map = ParamUtil.request2Map(request);
            return ReturnResult.successed(user,getQuickSearchWrapper(user).saveQuickSearchInfo(map));
        } catch (Exception e) {
            return ReturnResult.exceptionHandle(e);
        }
    }

    @GET
    @Path("/getQuickSearchDetailInfo")
    @Produces(MediaType.APPLICATION_JSON)
    public ReturnResult getQuickSearchDetailInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            Map<String, Object> map = ParamUtil.request2Map(request);
            return ReturnResult.successed(user,getQuickSearchWrapper(user).getQuickSearchDetailInfo(map));
        } catch (Exception e) {
            return ReturnResult.exceptionHandle(e);
        }
    }

    @POST
    @Path("/saveQuickSearchDetailInfo")
    @Produces(MediaType.APPLICATION_JSON)
    public ReturnResult saveQuickSearchDetailInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            Map<String, Object> map = ParamUtil.request2Map(request);
            return ReturnResult.successed(user,getQuickSearchWrapper(user).saveQuickSearchDetailInfo(map));
        } catch (Exception e) {
            return ReturnResult.exceptionHandle(e);
        }
    }
}
