package cn.autoform.util.thread; import cn.autoform.factory.product.ProductMethod.IOType; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; import java.util.Properties; /** * 线程存储区的key * @author WangYX * */ @EqualsAndHashCode @Getter @ToString public class Keys { private String key; private Class clazz; private T defaultValue; private Format format; public Keys(String key, Class clazz) { super(); this.key = key; this.clazz = clazz; } public Keys(String key, Class clazz, T defaultValue) { super(); this.key = key; this.clazz = clazz; this.defaultValue = defaultValue; } public Keys(String key, Class clazz, T defaultValue, Format format) { super(); this.key = key; this.clazz = clazz; this.defaultValue = defaultValue; this.format = format; } public T format(Object obj){ if(format != null) return format.format(obj); if(clazz.equals(String.class)) return (T) obj.toString(); if(clazz.equals(Integer.class)) return (T) new Integer(Integer.parseInt(obj.toString())); return defaultValue; } public static Keys getKeys(String key, Class clazz){ return new Keys<>(key, clazz); } public static Keys getKeys(String key, Class clazz, T defaultValue){ return new Keys<>(key, clazz, defaultValue); } public static Keys getKeys(String key, Class clazz, T defaultValue, Format format){ return new Keys<>(key, clazz, defaultValue, format); } /** * 格式数据 * @author WangYX * * @param */ public static interface Format{ T format(Object obj); } /** * token令牌 */ public static final Keys TOKEN = getKeys("token" , String.class , ""); /** * 业务系统id */ public static final Keys APP_KEY = getKeys("APP_KEY" , String.class , ""); /** * 租户id */ public static final Keys TENANT_ID = getKeys("tenantID" , String.class , ""); /** * 用户id */ public static final Keys USER_ID = getKeys("USER_ID" , String.class); /** * 用户名称 */ public static final Keys USER_NAME = getKeys("USER_NAME" , String.class); /** * 用户语言 */ public static final Keys USER_LANGUAGE = getKeys("USER_LANGUAGE" , String.class , "zh-CN"); /** * 用户语言属性文件 */ public static final Keys LANGUAGE_PROP = getKeys("LANGUAGE_PROP" , Properties.class); /** * 页码 */ public static final Keys PAGE_NUM = getKeys("pageNum" , Integer.class , 1); /** * 每页条数 */ public static final Keys PAGE_SIZE = getKeys("pageSize" , Integer.class , 10); /** * 表单id */ public static final Keys FORM_ID = getKeys("formID" , String.class , ""); /** * 表单数据存储位置 */ public static final Keys IO_FLAG = getKeys("flag" , IOType.class , IOType.cloud, obj->IOType.valueOf(obj.toString())); /** * openId */ public static final Keys OPEN_ID = getKeys("openId" , String.class , ""); /** * serviceId */ public static final Keys SERVICE_ID = getKeys("serviceId" , String.class , ""); /** * comanyId */ public static final Keys COMPANY_ID = getKeys("companyId" , String.class , ""); /** * URL */ public static final Keys URL = getKeys("url" , String.class , ""); /** * URL */ public static final Keys DATA_SOURCE_ID = getKeys("dataSourceId" , String.class , ""); }