net.wicp.tams.common.callback.impl.convertvalue.ConvertValueEasyUICombobox Maven / Gradle / Ivy
package net.wicp.tams.common.callback.impl.convertvalue;
import java.util.Map;
import org.apache.commons.collections.MapUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import net.wicp.tams.common.Conf;
import net.wicp.tams.common.apiext.IOUtil;
import net.wicp.tams.common.apiext.StringUtil;
import net.wicp.tams.common.callback.IConvertValue;
import net.wicp.tams.common.thread.threadlocal.PerThreadValue;
import net.wicp.tams.common.thread.threadlocal.PerthreadManager;
@Slf4j
public class ConvertValueEasyUICombobox implements IConvertValue {
private final String url;
public ConvertValueEasyUICombobox(String url) {
String context = Conf.get("common.apiext.context");
log.info("后端使用的context为:{}", context);
this.url = StringUtil.isNull(context) ? url : IOUtil.mergeFolderAndFilePath(context, url);
}
@Override
public String getStr(String keyObj) {
if (StringUtil.isNull(keyObj)) {
return "";
}
try {
String[] head = null;
Map querymap = Conf.getPre("common.jdbc.sqlIntercept.colnameQuery", true);
if (MapUtils.isNotEmpty(querymap) && querymap.containsKey("tenant_id")) {
PerThreadValue value = PerthreadManager.getInstance().createValue(querymap.get("tenant_id"),
String.class);
if (value.exists() && StringUtil.isNotNull(value.get())) {
// head头错误:tams:sqlIntercept:tenant_id改为:"tenant_id"
head = new String[] { "tenant_id", value.get() };
}
}
String result = IOUtil.doPostOrGet(url, "", head);
JSONArray objs = JSONArray.parseArray(result);
for (int i = 0; i < objs.size(); i++) {
JSONObject object = objs.getJSONObject(i);
if (keyObj.equals(object.getString("value"))) {
return object.getString("text");
}
}
return keyObj;
} catch (Throwable e) {
return keyObj;
}
}
}