package com.changhong.epc.constter.base; import com.changhong.epc.constter.system.UserInfo; import com.iemsoft.framework.cloud.core.thread.ThreadData; import com.iemsoft.framework.cloud.core.tools.JSONTool; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.math.NumberUtils; import java.io.Serializable; import java.util.Objects; /** * 上下文常量类 */ @Slf4j public class Context implements BaseConst{ /** * 租户id * @return */ public static Integer getTenantId(){ return NumberUtils.createInteger(Objects.toString(ThreadData.get(TENANT_ID), "0")); } public static String getTenantIdStr(){ return Objects.toString(getTenantId(), ""); } /** * 公司id * @return */ public static Integer getCompanyId(){ if(ObjectUtil.empty(ThreadData.get(COMPANY_ID))){ return null; } return NumberUtils.createInteger(Objects.toString(ThreadData.get(COMPANY_ID), "0")); } public static String getCompanyIdStr(){ return Objects.toString(getCompanyId(), ""); } /** * 用户信息 * @return */ public static UserInfo getUserInfo(){ UserInfo userInfo = ThreadData.get(USER_INFO); log.debug("获取用户信息:{}", JSONTool.toJson(userInfo)); return userInfo; } /** * 获得登陆标示 * @return */ public static UserInfo.LogInInfo getLoginInfo() { return new UserInfo.LogInInfo(ThreadData.get(TOKEN), ThreadData.get(OPEN_ID)); } /** * 获得用户openId * @return */ public static String getOpenId(){ return ThreadData.get(OPEN_ID); } /** * 获得用户token * @return */ public static String getToken(){ return ThreadData.get(TOKEN); } /** * @Author WangYX * @Description 获得mq参数 * @Date 2019/3/6 10:15 AM */ public static MQParam getMQParam(T data){ MQParam mq = new MQParam<>(); mq.setTenantId(getTenantIdStr()); mq.setCompanyId(getCompanyIdStr()); mq.setOpenId(getOpenId()); mq.setToken(getToken()); mq.setData(data); return mq; } @Data @AllArgsConstructor @NoArgsConstructor public static class MQParam implements Serializable { private String tenantId; private String companyId; private String openId; private String token; private T data; } }