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<T> {
|
|
private String key;
|
|
private Class<T> clazz;
|
|
private T defaultValue;
|
|
private Format<T> format;
|
|
public Keys(String key, Class<T> clazz) {
|
super();
|
this.key = key;
|
this.clazz = clazz;
|
}
|
|
public Keys(String key, Class<T> clazz, T defaultValue) {
|
super();
|
this.key = key;
|
this.clazz = clazz;
|
this.defaultValue = defaultValue;
|
}
|
|
public Keys(String key, Class<T> clazz, T defaultValue, Format<T> 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 <T> Keys<T> getKeys(String key, Class<T> clazz){
|
return new Keys<>(key, clazz);
|
}
|
|
public static <T> Keys<T> getKeys(String key, Class<T> clazz, T defaultValue){
|
return new Keys<>(key, clazz, defaultValue);
|
}
|
|
public static <T> Keys<T> getKeys(String key, Class<T> clazz, T defaultValue, Format<T> format){
|
return new Keys<>(key, clazz, defaultValue, format);
|
}
|
|
/**
|
* 格式数据
|
* @author WangYX
|
*
|
* @param <T>
|
*/
|
public static interface Format<T>{
|
|
T format(Object obj);
|
}
|
|
/**
|
* token令牌
|
*/
|
public static final Keys<String> TOKEN = getKeys("token" , String.class , "");
|
|
/**
|
* 业务系统id
|
*/
|
public static final Keys<String> APP_KEY = getKeys("APP_KEY" , String.class , "");
|
|
/**
|
* 租户id
|
*/
|
public static final Keys<String> TENANT_ID = getKeys("tenantID" , String.class , "");
|
|
/**
|
* 用户id
|
*/
|
public static final Keys<String> USER_ID = getKeys("USER_ID" , String.class);
|
|
/**
|
* 用户名称
|
*/
|
public static final Keys<String> USER_NAME = getKeys("USER_NAME" , String.class);
|
|
/**
|
* 用户语言
|
*/
|
public static final Keys<String> USER_LANGUAGE = getKeys("USER_LANGUAGE" , String.class , "zh-CN");
|
|
/**
|
* 用户语言属性文件
|
*/
|
public static final Keys<Properties> LANGUAGE_PROP = getKeys("LANGUAGE_PROP" , Properties.class);
|
|
/**
|
* 页码
|
*/
|
public static final Keys<Integer> PAGE_NUM = getKeys("pageNum" , Integer.class , 1);
|
|
/**
|
* 每页条数
|
*/
|
public static final Keys<Integer> PAGE_SIZE = getKeys("pageSize" , Integer.class , 10);
|
|
/**
|
* 表单id
|
*/
|
public static final Keys<String> FORM_ID = getKeys("formID" , String.class , "");
|
|
/**
|
* 表单数据存储位置
|
*/
|
public static final Keys<IOType> IO_FLAG = getKeys("flag" , IOType.class , IOType.cloud, obj->IOType.valueOf(obj.toString()));
|
|
/**
|
* openId
|
*/
|
public static final Keys<String> OPEN_ID = getKeys("openId" , String.class , "");
|
|
/**
|
* serviceId
|
*/
|
public static final Keys<String> SERVICE_ID = getKeys("serviceId" , String.class , "");
|
|
/**
|
* comanyId
|
*/
|
public static final Keys<String> COMPANY_ID = getKeys("companyId" , String.class , "");
|
|
/**
|
* URL
|
*/
|
public static final Keys<String> URL = getKeys("url" , String.class , "");
|
|
/**
|
* URL
|
*/
|
public static final Keys<String> DATA_SOURCE_ID = getKeys("dataSourceId" , String.class , "");
|
|
|
}
|