package com.engine.htsc.fkxnbm.web;

import com.alibaba.fastjson.JSON;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.fkxnbm.service.FkxnbmService;
import com.engine.htsc.fkxnbm.service.impl.FkxnbmServiceImpl;
import com.engine.integration.gconst.IntegrationConstant;
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.HashMap;
import java.util.Map;

public class FkxnbmAction {

    public FkxnbmService getService(){
        return ServiceUtil.getService(FkxnbmServiceImpl.class);
    }

    /**
     *
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getAllList")
    @Produces({MediaType.TEXT_PLAIN})
    public String getAllList(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.checkUser(request, response);
            if (user == null) {
                apidatas.put("msg", "登录信息超时");
                apidatas.put("errorCode", "002");
                apidatas.put("api_status", false);
                apidatas.put(IntegrationConstant.INTEGRATION_RESULT_STATUS, IntegrationConstant.INTEGRATION_RESULT_STATUS_FALSE);
            }else{
                Map<String,Object> param = ParamUtil.request2Map(request);
                FkxnbmService fkxnbmService = getService();
                apidatas = fkxnbmService.getAllList(param);
                apidatas.put("api_status", true);
            }
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }
}
