package com.engine.htxc.contract.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ServiceUtil;
import com.engine.htxc.contract.service.CounterpartyService;
import com.engine.htxc.contract.service.impl.CounterpartyServiceImpl;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.general.BaseBean;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

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;

/**
 * @author K1810036
 * @version 1.0.0
 * @ClassName CounterpartyAction.java
 * @createTime 2022年09月05日 09:56:00
 */
@Slf4j
public class CounterpartyAction {
    private static final Logger logger= LoggerFactory.getLogger(CounterpartyAction.class);

    private CounterpartyService getService() {
        return ServiceUtil.getService(CounterpartyServiceImpl.class);
    }


    @POST
    @Path("/getRoleName")
    @Produces({MediaType.TEXT_PLAIN})
    public String getRoleName(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        HashMap<String, Object> apidatas = new HashMap<>();
        BaseBean bb = new BaseBean();
        try {
            User user = HrmUserVarify.getUser(request, response);
            int userId = user.getUID();
            Map<String,Object> paramMap = Maps.newHashMap();
            paramMap.put("userId",userId);

            return JSONObject.toJSONString(getService().getRoleName(paramMap));
        } catch (Exception e) {
            log.error("get rolename fail [{}]", e);
            return JAVATools.Apiretrun("400","error");
        }
    }
}
