package com.engine.htsc.mhjc.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.mhjc.service.HtscPortalService;
import com.engine.htsc.mhjc.service.impl.HtscPortalServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
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;

/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: weaver.K1810007
 * @version: 1.0
 * @CreateDate: 2022-08-22
 * @Description: 门户接口，提供给门户的看越总数
 * @ModifyLog:
 *
 **/

@Slf4j
public class htscPortalAction {

    public HtscPortalService getService(){
        return ServiceUtil.getService(HtscPortalServiceImpl.class);
    }

    @GET
    @Path("/getKanyueTotalForPortal")
    @Produces({MediaType.TEXT_PLAIN})
    public String getKanyueTotalForPortal(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            String usercode = request.getHeader("iv-user");
            log.info("usercode:"+usercode);
            if(StringUtils.isNotEmpty(usercode))
            {
                param.put("workcode",usercode);
            }
            apidatas.putAll(getService().getKanyueTotalForPortal(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 JSONObject.toJSONString(apidatas);
    }


    @GET
    @Path("/getGonggaoTotalForDocCenter")
    @Produces({MediaType.TEXT_PLAIN})
    public String getGonggaoTotal(@Context HttpServletRequest request, @Context HttpServletResponse response){

        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            Map<String,Object> param = ParamUtil.request2Map(request);
            apidatas.putAll(getService().getGonggaoTotalForDocCenter(param,user));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }


}
