Commit 49da27e1 by WeiCong

第三版完成

1.支持restoreData模型
2.支持渠道类型判断方式
3.支持sysmod下的spt模型加载
4.支持精确控制lst返回列
5.支持分页查询
parent edc9a29a
......@@ -52,9 +52,9 @@
</orderEntry>
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.30" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.12.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.12.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.12.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.18.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.18.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.18.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.7" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.7" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.7" level="project" />
......
......@@ -27,7 +27,7 @@
<spring.version>5.1.3.RELEASE</spring.version>
<slf4j-api_version>1.7.25</slf4j-api_version>
<jul-to-slf4j_version>1.7.30</jul-to-slf4j_version>
<log4j2.version>2.12.1</log4j2.version>
<log4j2.version>2.18.0</log4j2.version>
<ehcache.version>2.10.4</ehcache.version>
<jackson.version>2.9.7</jackson.version>
<hibernate.version>5.6.9.Final</hibernate.version>
......
......@@ -10,12 +10,13 @@ import org.hibernate.transform.Transformers;
import org.sss.common.model.Argument;
import org.sss.common.model.IModule;
import org.sss.common.model.IModuleRoot;
import org.sss.common.model.IParent;
import org.sss.module.hibernate.HibernateUtils;
import org.sss.presentation.noui.context.NoUiContext;
import org.sss.presentation.noui.util.PropertyUtil;
import org.sss.presentation.noui.util.StringUtil;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -55,12 +56,21 @@ public class PreHandle {
}
public static boolean needPreHandle(String mappingUrl) {
return config.containsKey(mappingUrl);
public static boolean needPreHandle(String trnName, Map<String, ?> paramsMap) {
return config.containsKey(trnName) || paramsMap.containsKey("__sptinr");
}
public static void preHandle(String trnName, Map<String, ?> paramsMap, NoUiContext context) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
public static void preHandle(String trnName, Map<String, ?> paramsMap, NoUiContext context) throws Exception {
//区别app还是zk版本
String terminalType = StringUtil.isEmpty(context.getNoUiRequest().getTerminalType()) ? "APP" : context.getNoUiRequest().getTerminalType();
context.getSession().storeData("__terminalType", terminalType);
if (paramsMap.containsKey("__sptinr")) {
loadSpt(context, paramsMap);
}
String[] handles = config.get(trnName);
if (handles == null) {
return;
}
for (String handle : handles) {
if (StringUtil.isEmpty(handle)) {
continue;
......@@ -77,16 +87,17 @@ public class PreHandle {
}
MethodUtils.invokeStaticMethod(PreHandle.class, method, new Object[]{context, paramsMap, args});
}
}
public static void sureBtn(NoUiContext ctx, Map<String, ?> paramsMap, Object... otherParams) throws Exception {
if (otherParams.length != 2) {
log.warn("执行sureBtn预处理方法,需要两个参数:'Module名称'和'待跳转的交易名称'");
return;
log.error("执行sureBtn预处理方法,需要两个参数:'Module名称'和'待跳转的交易名称'");
throw new RuntimeException("执行sureBtn预处理方法,需要两个参数:'Module名称'和'待跳转的交易名称'");
}
if (paramsMap.get("__inr") == null) {
log.warn("执行sureBtn预处理方法,params中需要__inr关键字对应的模型inr");
return;
if (paramsMap.get("__modelinr") == null) {
log.error("执行sureBtn预处理方法,params中需要'__modelinr'关键字对应的模型inr");
throw new RuntimeException("执行sureBtn预处理方法,params参数中需要'__modelinr'映射的模型inr");
}
String grpNam = (String) otherParams[0];
String toTrs = (String) otherParams[1];
......@@ -97,11 +108,24 @@ public class PreHandle {
new Object[]{toTrs, (IModule) ConstructorUtils.invokeConstructor(clazz, new Object[0])}
, new Class[]{String.class, IModule.class});
IModule grp = (IModule) ctx.getSession().getBaseObject(root, grpNam + "\\rec");
ctx.getSupport().get(grp, new Argument[]{new Argument("inr", paramsMap.get("__inr"))});
ctx.getSupport().get(grp, new Argument[]{new Argument("inr", paramsMap.get("__modelinr"))});
ctx.getError();
ctx.getSession().storeData("com.brilliance." + toTrs + ".ref", grp);
}
public static void loadSpt(NoUiContext ctx, Map<String, ?> paramsMap) throws Exception {
if (paramsMap.get("__sptinr") == null) {
log.error("执行loadSpt预处理方法,params中需要'__sptinr'关键字对应的模型inr");
throw new RuntimeException("执行sureBtn预处理方法,params参数中需要'__sptinr'映射的模型inr");
}
Field sysmodClaz = AbstractPOJOModuleSession.class.getDeclaredField("sysmod");
sysmodClaz.setAccessible(true);
IParent sysmod = (IParent) sysmodClaz.get(ctx.getSession());
IModule spt = (IModule) ctx.getSession().getBaseObject(sysmod, "spt");
ctx.getSupport().get(spt, new Argument[]{new Argument("inr", paramsMap.get("__sptinr"))});
ctx.getError();
}
public static boolean initUserInr(String cid, String oid) {
Session session = HibernateUtils.openSession(null);
String ptySql = "select inr,ptytyp from pty where (ptytyp='2' or PTYTYP='1') and cid=?";
......
......@@ -57,31 +57,33 @@ public abstract class AbstractCommonController {
NoUiContext context = null;
Result ret = null;
String serverEnc = null;
NoUiRequest noUiRequest=null;
NoUiRequest noUiRequest = null;
try {
noUiRequest= new NoUiRequest(request, mappingUrl, dataMap);
noUiRequest = new NoUiRequest(request, mappingUrl, dataMap);
Alias alias = new Alias(mappingUrl);
String trnName = alias.getTrnName();
putTxInfo(alias,mappingUrl);//记录交易信息
putTxInfo(alias, mappingUrl);//记录交易信息
Map<String, ?> paramsMap = noUiRequest.getParamsMap();
context = NoUiContextManager.createNoUiContext(noUiRequest);
// 交易参数赋值
if(PreHandle.needPreHandle(trnName)){
PreHandle.preHandle(trnName,paramsMap,context);
if (PreHandle.needPreHandle(trnName, paramsMap)) {
PreHandle.preHandle(trnName, paramsMap, context);
}
for (String key : paramsMap.keySet()) {
context.getSession().storeData(key, paramsMap.get(key));
}
// 设置old sysmod
LoginInfo loginInfo = null;
if (!StringUtils.isEmpty(noUiRequest.getUserId())){
if (!StringUtils.isEmpty(noUiRequest.getUserId())) {
loginInfo = (LoginInfo) EhcacheUtils.get(StringUtil.userUniqueId(noUiRequest));
if (loginInfo != null) {
if(loginInfo.getSysmod()!=null){
if (loginInfo.getSysmod() != null) {
NoUiPresentationUtil.setSysmod(context, (byte[]) loginInfo.getSysmod());
}
context.setLoginInfo(loginInfo);
......@@ -102,9 +104,9 @@ public abstract class AbstractCommonController {
//数据安全性拦截-篡改数据拦截
if (DataSecurityUtil.isSafeMode() && noUiRequest.isSecurity()) {
if (DataSecurityUtil.needDecrypt(noUiRequest.getReqUrl())) {
String[] clientpars = DataSecurityUtil.getSafeConfigByReqUrl(context,noUiRequest, noUiRequest.getReqUrl() + DataSecurityUtil.DECRYPT_FIX);
if(!ArrayUtils.isEmpty(clientpars)){
if(!DataSecurityUtil.isIgnoreCheck(paramsMap)){
String[] clientpars = DataSecurityUtil.getSafeConfigByReqUrl(context, noUiRequest, noUiRequest.getReqUrl() + DataSecurityUtil.DECRYPT_FIX);
if (!ArrayUtils.isEmpty(clientpars)) {
if (!DataSecurityUtil.isIgnoreCheck(paramsMap)) {
if (paramsMap.containsKey(DataSecurityUtil.BACKGROUND_ID)) {
//合法性校验操作(场景:用户做修改、删除时调用)
serverEnc = (String) paramsMap.get(DataSecurityUtil.BACKGROUND_ID);
......@@ -119,15 +121,15 @@ public abstract class AbstractCommonController {
}
}
}
}else if("infsmh".equals(trnName) && "_recpan_show".equals(alias.getAliasActionUrl())){
} else if ("infsmh".equals(trnName) && "_recpan_show".equals(alias.getAliasActionUrl())) {
String res = request.getHeader("res");
String docpth = (String) paramsMap.get("docpth");
String errmsg="Access Forbidden, Unauthorized!!!";
if(res==null || docpth ==null){
String errmsg = "Access Forbidden, Unauthorized!!!";
if (res == null || docpth == null) {
Result rt = new Result(ErrorCodes.ERROR, errmsg, null, noUiVersion.getVersion());
return rt;
}
if(!res.equals(docpth)){
if (!res.equals(docpth)) {
Result rt = new Result(ErrorCodes.ERROR, errmsg, null, noUiVersion.getVersion());
return rt;
}
......@@ -177,29 +179,28 @@ public abstract class AbstractCommonController {
EhcacheUtils.set(StringUtil.userUniqueId(noUiRequest), loginInfo);
}
Map<String, Object> paginationData = new HashMap<>();
Map<String, Object> afterReturnData = handleReturnData(eventType, context, noUiRequest, alias,paginationData);
Map<String, Object> afterReturnData = handleReturnData(eventType, context, noUiRequest, alias, paginationData);
//数据安全性拦截-篡改数据加密
if (DataSecurityUtil.isSafeMode() && noUiRequest.isSecurity()) {
if (DataSecurityUtil.needEncrypt(noUiRequest.getReqUrl())) {
//加密操作(场景:用户查询指定信息时调用,后续会做修改,删除等操作)
String[] pars = DataSecurityUtil.getSafeConfigByReqUrl(context, noUiRequest,noUiRequest.getReqUrl() + DataSecurityUtil.ENCRYPT_FIX);
String[] pars = DataSecurityUtil.getSafeConfigByReqUrl(context, noUiRequest, noUiRequest.getReqUrl() + DataSecurityUtil.ENCRYPT_FIX);
serverEnc = DataSecurityUtil.encrypt(pars, noUiRequest.getUserId());
afterReturnData.put(DataSecurityUtil.BACKGROUND_ID, serverEnc);
}else if(!ErrorCodes.SUCCESS.equals(NoUiPresentationUtil.retCode(context)) && DataSecurityUtil.needDecrypt(noUiRequest.getReqUrl())){
String[] pars = DataSecurityUtil.getSafeConfigByReqUrl(context, noUiRequest,noUiRequest.getReqUrl() + DataSecurityUtil.DECRYPT_FIX);
} else if (!ErrorCodes.SUCCESS.equals(NoUiPresentationUtil.retCode(context)) && DataSecurityUtil.needDecrypt(noUiRequest.getReqUrl())) {
String[] pars = DataSecurityUtil.getSafeConfigByReqUrl(context, noUiRequest, noUiRequest.getReqUrl() + DataSecurityUtil.DECRYPT_FIX);
serverEnc = DataSecurityUtil.encrypt(pars, noUiRequest.getUserId());
afterReturnData.put(DataSecurityUtil.BACKGROUND_ID, serverEnc);
}
}
ret = ResultUtil.result(NoUiPresentationUtil.retCode(context), NoUiPresentationUtil.retMsg(context), afterReturnData,paginationData,
ret = ResultUtil.result(NoUiPresentationUtil.retCode(context), NoUiPresentationUtil.retMsg(context), afterReturnData, paginationData,
NoUiPresentationUtil.handleErrorReturnData(context, alias), NoUiPresentationUtil.handleCodeTableReturnData(context, alias), noUiVersion.getVersion());
}
catch (Throwable e) {
if(e.getCause() instanceof ExitTransactionException){
ExitTransactionException exitTrans=ExitTransactionException.class.cast(e.getCause());
} catch (Throwable e) {
if (e.getCause() instanceof ExitTransactionException) {
ExitTransactionException exitTrans = ExitTransactionException.class.cast(e.getCause());
ret = ResultUtil.result(exitTrans.getErrorCode(), exitTrans.getMessage(), exitTrans.getMessage(), noUiVersion.getVersion());
}else{
} else {
log.error("OnClick command error", e);
ret = ResultUtil.result(ErrorCodes.ERROR, "hander error", "service error", noUiVersion.getVersion());
TxInfo.recordException(e);
......@@ -216,12 +217,11 @@ public abstract class AbstractCommonController {
}
private void putTxInfo(Alias alias,String mappingUrl)
{
private void putTxInfo(Alias alias, String mappingUrl) {
String trnName = alias.getTrnName();
String aliasActionUrl = alias.getAliasActionUrl();
String actionUrl = alias.getRel().get(aliasActionUrl);
TxInfo.putTxInfo(trnName,mappingUrl,actionUrl);
TxInfo.putTxInfo(trnName, mappingUrl, actionUrl);
}
private IBaseObject baseObject(NoUiContext context, NoUiRequest noUiRequest, Alias alias) {
......@@ -233,19 +233,19 @@ public abstract class AbstractCommonController {
return baseObject;
}
private void putModuleListPagination(String aliasKey,Map<String,Object> paginationMap,IModuleList moduleList)
{
private void putModuleListPagination(String aliasKey, Map<String, Object> paginationMap, IModuleList moduleList) {
//没有做分页
if(moduleList.getPageSize() == 0)
if (moduleList.getPageSize() == 0)
return;
int total = moduleList.fullSize();
int index = moduleList.getPage();
Map<String,Integer> map = new HashMap<>();
map.put("total",total);
map.put("index",index);
paginationMap.put(aliasKey,map);
Map<String, Integer> map = new HashMap<>();
map.put("total", total);
map.put("index", index);
paginationMap.put(aliasKey, map);
}
private Map<String, Object> handleReturnData(String eventType, NoUiContext context, NoUiRequest noUiRequest, Alias alias, Map<String,Object> paginationMap) {
private Map<String, Object> handleReturnData(String eventType, NoUiContext context, NoUiRequest noUiRequest, Alias alias, Map<String, Object> paginationMap) {
Map<String, Object> data = new HashMap<String, Object>();
// 初始化事件
......@@ -256,9 +256,8 @@ public abstract class AbstractCommonController {
}
String realPath = alias.getRelPath(aliasKey);
IBaseObject baseObject = context.getSession().getBaseObject(context.getRoot(), realPath);
if( baseObject instanceof IModuleList)
{
putModuleListPagination( aliasKey,paginationMap,(IModuleList)baseObject);
if (baseObject instanceof IModuleList) {
putModuleListPagination(aliasKey, paginationMap, (IModuleList) baseObject);
}
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, baseObject, realPath));
}
......@@ -282,17 +281,18 @@ public abstract class AbstractCommonController {
}
if (aliasPath.startsWith(modifyEntry.getKey())) {
int modifyKeyLen = modifyEntry.getKey().length();
//要么字符串相等,要么后续字符应该为 \\ 才可以
if(!(aliasPath.length() == modifyKeyLen || aliasPath.charAt(modifyKeyLen) == '\\'))
if (!(aliasPath.length() == modifyKeyLen || aliasPath.charAt(modifyKeyLen) == '\\')) {
continue;
}
Object val = modifyEntry.getValue();
if (aliasKey == null)
if (aliasKey == null) {
continue;
if( val instanceof IModuleList)
{
putModuleListPagination(aliasKey,paginationMap,(IModuleList)val);
}
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, val, aliasEntry.getValue()));
if (val instanceof IModuleList) {
putModuleListPagination(aliasKey, paginationMap, (IModuleList) val);
aliasPath = alias.getRel().get(aliasPath);
}
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, val, aliasPath));
containsKeys.add(modifyEntry.getKey());
}
......@@ -302,13 +302,12 @@ public abstract class AbstractCommonController {
// 不能修改
for (String key : modifyMap.keySet()) {
if (!containsKeys.contains(key)) {
if (key == null){
if (key == null) {
continue;
}
Object baseObject = modifyMap.get(key);
if( baseObject instanceof IModuleList)
{
putModuleListPagination(key,paginationMap,(IModuleList)baseObject);
Object baseObject = modifyMap.get(key);
if (baseObject instanceof IModuleList) {
putModuleListPagination(key, paginationMap, (IModuleList) baseObject);
}
data.put(key, NoUiPresentationUtil.handIBaseObject(context, baseObject, key));
}
......
......@@ -24,423 +24,433 @@ import java.text.SimpleDateFormat;
import java.util.*;
public class NoUiPresentationUtil {
protected static final Log log = LogFactory.getLog(NoUiPresentationUtil.class);
public static void hanleInput(NoUiContext context, NoUiRequest request, Alias alias) {
Map<String, ?> dataMap = request.getDataMap();
for (String aliasKey : dataMap.keySet()) {
if (aliasKey.startsWith(Constants.MAPPING_PRE)) {
continue;
}
String url = alias.getRelPath(aliasKey);
if (StringUtils.isEmpty(url)) {
continue;
}
IBaseObject baseObject = null;
try {
baseObject = context.getSession().getBaseObject(context.getRoot(), url);
if (null == baseObject) {
throw new NoUiException("not found url :" + url + " ,alias name is:" + aliasKey);
} else {
Object value = dataMap.get(aliasKey);
if (null != value) {
if (baseObject instanceof IDatafield<?>) {
IDatafield<Object> dataField = (IDatafield<Object>) baseObject;
handleDatafield(context, dataField, value);
// dataField.invokeDefaultRules(context);
// dataField.invokeCheckRules(context);
// dataField.invokeEventRules(context,
// EventType.ON_CHANGE, null, 0);
}
if (baseObject instanceof IModuleList<?> && value instanceof List<?>) {
IModuleList<IModule> moduleList = (IModuleList<IModule>) baseObject;
moduleList.clear();
List<Map<String, Object>> valueList = (List<Map<String, Object>>) value;
for (Map<String, Object> m : valueList) {
IModule module = moduleList.add();
for (Map.Entry<String, Object> entry : m.entrySet())
handleDatafield(context, (IDatafield<Object>) module.get(obfuscationPath(entry.getKey())), entry.getValue());
}
}
}
}
} catch (Exception e) {
log.error("Input command error", e);
throw new NoUiException("Input command error", e);
}
}
//处理分页信息
Map<String,?> paginationMap = request.getPaginationMap();
for (String aliasKey : paginationMap.keySet()) {
String url = alias.getRelPath(aliasKey);
if (StringUtils.isEmpty(url)) {
url = aliasKey;
}
IBaseObject baseObject = null;
try {
baseObject = context.getSession().getBaseObject(context.getRoot(), url);
if (null == baseObject) {
throw new NoUiException("not found url :" + url + " ,alias name is:" + aliasKey);
}
if(!(baseObject instanceof IModuleList))
throw new NoUiException( url + " is not a moduleList");
//处理分页信息
IModuleList moduleList = (IModuleList) baseObject;
Map<String,Integer> paginationItem = (Map<String,Integer>)paginationMap.get(aliasKey);
putPaginationCache(paginationItem,moduleList);
} catch (Exception e) {
log.error("Pagination command error", e);
throw new NoUiException("Pagination command error", e);
}
}
}
private static void putPaginationCache(Map<String,Integer> paginationItem,IModuleList moduleList)
{
Map<String,Map<String,Integer>> paginationCache = (Map<String,Map<String,Integer>>)AbstractCache.paginationMap.get();
if(paginationCache == null)
{
paginationCache = new HashMap<>();
AbstractCache.paginationMap.set(paginationCache);
}
paginationCache.put(moduleList.getUrl(),paginationItem);
}
private static void handleDatafield(IContext context, IDatafield<Object> dataField, Object value) {
if (null == value || dataField == null)
return;
Class<?> dataType = dataField.getDataType();
if (dataType.equals(String.class)) {
String valStr = value.toString();
protected static final Log log = LogFactory.getLog(NoUiPresentationUtil.class);
public static void hanleInput(NoUiContext context, NoUiRequest request, Alias alias) {
Map<String, ?> dataMap = request.getDataMap();
for (String aliasKey : dataMap.keySet()) {
if (aliasKey.startsWith(Constants.MAPPING_PRE)) {
continue;
}
String url = alias.getRelPath(aliasKey);
if (StringUtils.isEmpty(url)) {
continue;
}
IBaseObject baseObject = null;
try {
baseObject = context.getSession().getBaseObject(context.getRoot(), url);
if (null == baseObject) {
throw new NoUiException("not found url :" + url + " ,alias name is:" + aliasKey);
} else {
Object value = dataMap.get(aliasKey);
if (null != value) {
if (baseObject instanceof IDatafield<?>) {
IDatafield<Object> dataField = (IDatafield<Object>) baseObject;
handleDatafield(context, dataField, value);
// dataField.invokeDefaultRules(context);
// dataField.invokeCheckRules(context);
// dataField.invokeEventRules(context,
// EventType.ON_CHANGE, null, 0);
}
if (baseObject instanceof IModuleList<?> && value instanceof List<?>) {
IModuleList<IModule> moduleList = (IModuleList<IModule>) baseObject;
moduleList.clear();
List<Map<String, Object>> valueList = (List<Map<String, Object>>) value;
for (Map<String, Object> m : valueList) {
IModule module = moduleList.add();
for (Map.Entry<String, Object> entry : m.entrySet())
handleDatafield(context, (IDatafield<Object>) module.get(obfuscationPath(entry.getKey())), entry.getValue());
}
}
}
}
} catch (Exception e) {
log.error("Input command error", e);
throw new NoUiException("Input command error", e);
}
}
//处理分页信息
Map<String, ?> paginationMap = request.getPaginationMap();
for (String aliasKey : paginationMap.keySet()) {
String url = alias.getRelPath(aliasKey);
if (StringUtils.isEmpty(url)) {
url = aliasKey;
}
IBaseObject baseObject = null;
try {
baseObject = context.getSession().getBaseObject(context.getRoot(), url);
if (null == baseObject) {
throw new NoUiException("not found url :" + url + " ,alias name is:" + aliasKey);
}
if (!(baseObject instanceof IModuleList))
throw new NoUiException(url + " is not a moduleList");
//处理分页信息
IModuleList moduleList = (IModuleList) baseObject;
Map<String, Integer> paginationItem = (Map<String, Integer>) paginationMap.get(aliasKey);
putPaginationCache(paginationItem, moduleList);
} catch (Exception e) {
log.error("Pagination command error", e);
throw new NoUiException("Pagination command error", e);
}
}
}
private static void putPaginationCache(Map<String, Integer> paginationItem, IModuleList moduleList) {
Map<String, Map<String, Integer>> paginationCache = (Map<String, Map<String, Integer>>) AbstractCache.paginationMap.get();
if (paginationCache == null) {
paginationCache = new HashMap<>();
AbstractCache.paginationMap.set(paginationCache);
}
paginationCache.put(moduleList.getUrl(), paginationItem);
}
private static void handleDatafield(IContext context, IDatafield<Object> dataField, Object value) {
if (null == value || dataField == null)
return;
Class<?> dataType = dataField.getDataType();
if (dataType.equals(String.class)) {
String valStr = value.toString();
// if ("true".equalsIgnoreCase(valStr.trim()))
// dataField.setValue("X");
// else if ("false".equalsIgnoreCase(valStr.trim()))
// dataField.setValue("");
// else
dataField.setValue(valStr);
return;
}
if (dataType.equals(Integer.TYPE) || dataType.equals(Integer.class)) {
String data = value.toString().trim();
if (StringUtils.isEmpty(data))
{
if(dataField.isNullable())
dataField.setValue(null);
else
dataField.setValue(0);
}
else
dataField.setValue(Double.valueOf(data.replaceAll(",", "")).intValue());
return;
}
if (dataType.equals(BigDecimal.class)) {
String data = value.toString().trim();
if (StringUtils.isEmpty(data))
dataField.setValue(new BigDecimal(0));
else
dataField.setValue(new BigDecimal(data.replaceAll(",", "")));
return;
}
if (dataType.equals(Date.class)) {
String data = value.toString().trim();
dataField.setValue(dealDateFormat(data));
return;
}
if (dataType.equals(Long.TYPE) || dataType.equals(Long.class)) {
String data = value.toString().trim();
if (StringUtils.isEmpty(data))
dataField.setValue(0L);
else
dataField.setValue(Double.valueOf(data.replaceAll(",", "")).longValue());
return;
}
throw new NoUiException("Unsupported data type", ErrorCodes.UNSUPPORTED_DATA_TYPE);
}
private static Date dealDateFormat(String s) {
if (StringUtils.isEmpty(s))
return null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
return sdf.parse(s);
} catch (ParseException e) {
}
sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
try {
return sdf.parse(s);
} catch (ParseException e) {
}
sdf = new SimpleDateFormat("yyyy/MM/dd");
try {
return sdf.parse(s);
} catch (ParseException e) {
}
sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
return sdf.parse(s);
} catch (ParseException e) {
}
try {
return new Date(Long.valueOf(s));
} catch (Exception e) {
throw new NoUiException("Uncorrect data format", ErrorCodes.UNCORRECT_DATA_FORMAT);
}
}
public static String retMsg(NoUiContext context) {
NoUiPresentation gui = (NoUiPresentation) context.getGui();
return StringUtil.isEmpty(gui.getMessage()) ? ErrorCodes.SUCCESS_INFO : gui.getMessage();
}
public static String retCode(NoUiContext context) {
NoUiPresentation gui = (NoUiPresentation) context.getGui();
return gui.getMessageCode();
}
public static Map<String, Object> handleEventReturnData(EventType eventType, NoUiContext context, NoUiRequest request, Alias alias) {
Map<String, Object> data = new HashMap<String, Object>();
// 初始化事件
if (eventType == null) {
for (String aliasKey : alias.getRel().keySet()) {
if (aliasKey.startsWith("_")) {
continue;
}
String realPath = alias.getRelPath(aliasKey);
IBaseObject baseObject = context.getSession().getBaseObject(context.getRoot(), realPath);
data.put(aliasKey, handIBaseObject(context, baseObject, realPath));
}
return data;
}
NoUiPresentation gui = (NoUiPresentation) context.getGui();
Map<String, Object> modifyMap = gui.getModifyMap();
for (Map.Entry<String, Object> modifyEntry : modifyMap.entrySet()) {
for (Map.Entry<String, String> aliasEntry : alias.getRel().entrySet()) {
String aliasKey = aliasEntry.getKey();
String aliasPath = aliasEntry.getValue();
if (aliasPath.startsWith(modifyEntry.getKey())) {
Object val = modifyEntry.getValue();
data.put(aliasKey, handIBaseObject(context, val, aliasEntry.getValue()));
}
}
}
return data;
}
private static String handle(Object value, IDatafield<Object> dataField) {
if (null == value)
return null;
Class<?> dataType = dataField.getDataType();
if (dataType.equals(String.class)) {
String valStr = value.toString();
return valStr;
}
if (dataType.equals(Integer.TYPE) || dataType.equals(Integer.class)) {
String data = value.toString().trim();
return data;
}
if (dataType.equals(Double.TYPE) || dataType.equals(Double.class)) {
java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
nf.setGroupingUsed(false);
// 设置数的小数部分所允许的最小位数
nf.setMinimumFractionDigits(0);
// 设置数的小数部分所允许的最大位数
nf.setMaximumFractionDigits(2);
return nf.format(value);
}
if (dataType.equals(BigDecimal.class)) {
String data = value.toString().trim();
return data;
}
if (dataType.equals(Date.class)) {
Date date = (Date) value;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
if (dataType.equals(Long.TYPE) || dataType.equals(Long.class)) {
String data = value.toString().trim();
return data;
}
return null;
}
public static Object handIBaseObject(IContext context, Object val, String path) {
if (val == null)
return null;
if ((val instanceof IModuleList)) {
List list = new ArrayList();
IModuleList moduleList = (IModuleList)val;
for (int index = 0; index < moduleList.size(); index++) {
Map map = new HashMap();
IModule module = (IModule)moduleList.get(index);
Collection<IDatafield> datafields = module.getDatafields();
for (IDatafield datafield : datafields) {
map.put(obfuscationPath(datafield.getName()), handle(datafield.getValue(), datafield));
}
list.add(map);
}
return list;
}if ((val instanceof IModule)) {
val = context.getSession().getBaseObject(context.getRoot(), path);
return handIBaseObject(context, val, path);
}if ((val instanceof IDatafield)) {
IDatafield datafield = (IDatafield)val;
return handle(datafield.getValue(), datafield);
}
return null;
}
public static Map<String, Object> getWholeAliasData(IContext context,String mappingUrl)
{
Map<String, Object> data = new HashMap<String, Object>();
Alias alias = new Alias(mappingUrl);
for (String aliasKey : alias.getRel().keySet()) {
if (aliasKey.startsWith(Constants.MAPPING_PRE)) {
continue;
}
String realPath = alias.getRelPath(aliasKey);
IBaseObject baseObject = context.getSession().getBaseObject(context.getRoot(), realPath);
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, baseObject, realPath));
}
return data;
}
public static Map<String, Object> handleErrorReturnData(NoUiContext context, Alias alias) {
NoUiPresentation gui = (NoUiPresentation) context.getGui();
Map<String, Object> errorMap = gui.getError();
Map<String, Object> n_errorMap = new HashMap<String,Object>();
for (Map.Entry<String, Object> errorEntity : errorMap.entrySet()) {
String key = errorEntity.getKey();
String realKey = alias.getRevertRel().get(key);
if (!StringUtils.isEmpty(realKey))
n_errorMap.put(realKey, errorEntity.getValue());
else
n_errorMap.put(key, errorEntity.getValue());
}
return n_errorMap;
}
public static Map<String, Object> handleCodeTableReturnData(NoUiContext context, Alias alias) {
NoUiPresentation gui = (NoUiPresentation) context.getGui();
Map<String, Object> codeTableMap = gui.getCodetable();
Map<String, Object> retCodeTableMap = new HashMap<>();
for (Map.Entry<String, Object> codeTableEntity : codeTableMap.entrySet()) {
String key = codeTableEntity.getKey();
String realKey = alias.getRevertRel().get(key);
if (!StringUtils.isEmpty(realKey))
retCodeTableMap.put(realKey, codeTableEntity.getValue());
else
retCodeTableMap.put(key, codeTableEntity.getValue());
}
return retCodeTableMap;
}
public static void setSysmod(NoUiContext context, byte[] oldSysmod) {
AbstractPOJOModuleSession session = (AbstractPOJOModuleSession) context.getSession();
Field sysmod = null;
try {
sysmod = AbstractPOJOModuleSession.class.getDeclaredField("sysmod");
sysmod.setAccessible(true);
// sysmod.set(session, oldSysmod);
StreamImpl simp = new StreamImpl();
IOUtils.write(oldSysmod, simp.getOutputStream());
context.getSession().loadData((IParent) sysmod.get(session), simp);
} catch (Exception e) {
log.error("setSysmod exception",e);
}
}
public static byte[] sysmodToBytes(NoUiContext context) {
IParent sysmod = (IParent) context.getSession().getBaseObject(context.getRoot(), "sysmod");
StreamImpl stream = new StreamImpl();
context.getSession().saveData(sysmod, stream);
byte[] sysmodBytes = null;
try {
sysmodBytes = IOUtils.toByteArray(stream.getInputStream());
} catch (IOException e) {
log.error("sysmodToBytes exception",e);
}
return sysmodBytes;
}
//混淆路径,算法:偏移 头4 尾7
public static String obfuscationPath(String str){
if(NoUiUtils.fieldencode){
dataField.setValue(valStr);
return;
}
if (dataType.equals(Integer.TYPE) || dataType.equals(Integer.class)) {
String data = value.toString().trim();
if (StringUtils.isEmpty(data)) {
if (dataField.isNullable())
dataField.setValue(null);
else
dataField.setValue(0);
} else
dataField.setValue(Double.valueOf(data.replaceAll(",", "")).intValue());
return;
}
if (dataType.equals(BigDecimal.class)) {
String data = value.toString().trim();
if (StringUtils.isEmpty(data))
dataField.setValue(new BigDecimal(0));
else
dataField.setValue(new BigDecimal(data.replaceAll(",", "")));
return;
}
if (dataType.equals(Date.class)) {
String data = value.toString().trim();
dataField.setValue(dealDateFormat(data));
return;
}
if (dataType.equals(Long.TYPE) || dataType.equals(Long.class)) {
String data = value.toString().trim();
if (StringUtils.isEmpty(data))
dataField.setValue(0L);
else
dataField.setValue(Double.valueOf(data.replaceAll(",", "")).longValue());
return;
}
throw new NoUiException("Unsupported data type", ErrorCodes.UNSUPPORTED_DATA_TYPE);
}
private static Date dealDateFormat(String s) {
if (StringUtils.isEmpty(s))
return null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
return sdf.parse(s);
} catch (ParseException e) {
}
sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
try {
return sdf.parse(s);
} catch (ParseException e) {
}
sdf = new SimpleDateFormat("yyyy/MM/dd");
try {
return sdf.parse(s);
} catch (ParseException e) {
}
sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
return sdf.parse(s);
} catch (ParseException e) {
}
try {
return new Date(Long.valueOf(s));
} catch (Exception e) {
throw new NoUiException("Uncorrect data format", ErrorCodes.UNCORRECT_DATA_FORMAT);
}
}
public static String retMsg(NoUiContext context) {
NoUiPresentation gui = (NoUiPresentation) context.getGui();
return StringUtil.isEmpty(gui.getMessage()) ? ErrorCodes.SUCCESS_INFO : gui.getMessage();
}
public static String retCode(NoUiContext context) {
NoUiPresentation gui = (NoUiPresentation) context.getGui();
return gui.getMessageCode();
}
public static Map<String, Object> handleEventReturnData(EventType eventType, NoUiContext context, NoUiRequest request, Alias alias) {
Map<String, Object> data = new HashMap<String, Object>();
// 初始化事件
if (eventType == null) {
for (String aliasKey : alias.getRel().keySet()) {
if (aliasKey.startsWith("_")) {
continue;
}
String realPath = alias.getRelPath(aliasKey);
IBaseObject baseObject = context.getSession().getBaseObject(context.getRoot(), realPath);
data.put(aliasKey, handIBaseObject(context, baseObject, realPath));
}
return data;
}
NoUiPresentation gui = (NoUiPresentation) context.getGui();
Map<String, Object> modifyMap = gui.getModifyMap();
for (Map.Entry<String, Object> modifyEntry : modifyMap.entrySet()) {
for (Map.Entry<String, String> aliasEntry : alias.getRel().entrySet()) {
String aliasKey = aliasEntry.getKey();
String aliasPath = aliasEntry.getValue();
if (aliasPath.startsWith(modifyEntry.getKey())) {
Object val = modifyEntry.getValue();
data.put(aliasKey, handIBaseObject(context, val, aliasEntry.getValue()));
}
}
}
return data;
}
private static String handle(Object value, IDatafield<Object> dataField) {
if (null == value)
return null;
Class<?> dataType = dataField.getDataType();
if (dataType.equals(String.class)) {
String valStr = value.toString();
return valStr;
}
if (dataType.equals(Integer.TYPE) || dataType.equals(Integer.class)) {
String data = value.toString().trim();
return data;
}
if (dataType.equals(Double.TYPE) || dataType.equals(Double.class)) {
java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
nf.setGroupingUsed(false);
// 设置数的小数部分所允许的最小位数
nf.setMinimumFractionDigits(0);
// 设置数的小数部分所允许的最大位数
nf.setMaximumFractionDigits(2);
return nf.format(value);
}
if (dataType.equals(BigDecimal.class)) {
String data = value.toString().trim();
return data;
}
if (dataType.equals(Date.class)) {
Date date = (Date) value;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
if (dataType.equals(Long.TYPE) || dataType.equals(Long.class)) {
String data = value.toString().trim();
return data;
}
return null;
}
public static Object handIBaseObject(IContext context, Object val, String path) {
if (val == null)
return null;
if ((val instanceof IModuleList)) {
List list = new ArrayList();
IModuleList moduleList = (IModuleList) val;
boolean isAll = true;
if (!StringUtil.isEmpty(path)) {
isAll = false;
}
for (int index = 0; index < moduleList.size(); index++) {
Map map = new HashMap();
IModule module = (IModule) moduleList.get(index);
if (isAll) {
Collection<IDatafield> datafields = module.getDatafields();
for (IDatafield datafield : datafields) {
String dataFieldName = obfuscationPath(datafield.getName());
map.put(dataFieldName, handle(datafield.getValue(), datafield));
}
} else {
String[] pths = path.split(",");
for (String pth : pths) {
IDatafield datafieldtmp = (IDatafield) context.getSession().getBaseObject(module, pth);
String dataFieldName = obfuscationPath(datafieldtmp.getName());
map.put(dataFieldName, handle(datafieldtmp.getValue(), datafieldtmp));
}
}
list.add(map);
}
return list;
}
if ((val instanceof IModule)) {
val = context.getSession().getBaseObject(context.getRoot(), path);
return handIBaseObject(context, val, path);
}
if ((val instanceof IDatafield)) {
IDatafield datafield = (IDatafield) val;
return handle(datafield.getValue(), datafield);
}
return null;
}
public static Map<String, Object> getWholeAliasData(IContext context, String mappingUrl) {
Map<String, Object> data = new HashMap<String, Object>();
Alias alias = new Alias(mappingUrl);
for (String aliasKey : alias.getRel().keySet()) {
if (aliasKey.startsWith(Constants.MAPPING_PRE)) {
continue;
}
String realPath = alias.getRelPath(aliasKey);
IBaseObject baseObject = context.getSession().getBaseObject(context.getRoot(), realPath);
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, baseObject, realPath));
}
return data;
}
public static Map<String, Object> handleErrorReturnData(NoUiContext context, Alias alias) {
NoUiPresentation gui = (NoUiPresentation) context.getGui();
Map<String, Object> errorMap = gui.getError();
Map<String, Object> n_errorMap = new HashMap<String, Object>();
for (Map.Entry<String, Object> errorEntity : errorMap.entrySet()) {
String key = errorEntity.getKey();
String realKey = alias.getRevertRel().get(key);
if (!StringUtils.isEmpty(realKey))
n_errorMap.put(realKey, errorEntity.getValue());
else
n_errorMap.put(key, errorEntity.getValue());
}
return n_errorMap;
}
public static Map<String, Object> handleCodeTableReturnData(NoUiContext context, Alias alias) {
NoUiPresentation gui = (NoUiPresentation) context.getGui();
Map<String, Object> codeTableMap = gui.getCodetable();
Map<String, Object> retCodeTableMap = new HashMap<>();
for (Map.Entry<String, Object> codeTableEntity : codeTableMap.entrySet()) {
String key = codeTableEntity.getKey();
String realKey = alias.getRevertRel().get(key);
if (!StringUtils.isEmpty(realKey))
retCodeTableMap.put(realKey, codeTableEntity.getValue());
else
retCodeTableMap.put(key, codeTableEntity.getValue());
}
return retCodeTableMap;
}
public static void setSysmod(NoUiContext context, byte[] oldSysmod) {
AbstractPOJOModuleSession session = (AbstractPOJOModuleSession) context.getSession();
Field sysmod = null;
try {
sysmod = AbstractPOJOModuleSession.class.getDeclaredField("sysmod");
sysmod.setAccessible(true);
// sysmod.set(session, oldSysmod);
StreamImpl simp = new StreamImpl();
IOUtils.write(oldSysmod, simp.getOutputStream());
context.getSession().loadData((IParent) sysmod.get(session), simp);
} catch (Exception e) {
log.error("setSysmod exception", e);
}
}
public static byte[] sysmodToBytes(NoUiContext context) {
IParent sysmod = (IParent) context.getSession().getBaseObject(context.getRoot(), "sysmod");
StreamImpl stream = new StreamImpl();
context.getSession().saveData(sysmod, stream);
byte[] sysmodBytes = null;
try {
sysmodBytes = IOUtils.toByteArray(stream.getInputStream());
} catch (IOException e) {
log.error("sysmodToBytes exception", e);
}
return sysmodBytes;
}
//混淆路径,算法:偏移 头4 尾7
public static String obfuscationPath(String str) {
/*if(NoUiUtils.fieldencode){
String btw_str = str.substring(1,str.length()-1);
String head = change(str.charAt(0),4);
String tail = change(str.charAt(str.length()-1),7);
return head + btw_str + tail;
}
return str;
}
//根据偏移量转换字符
public static String change(char ch,int offset){
int before = ch;
int after;
//a-z
if(ch >=97 && ch <= 122){
if(before+offset <= 122){
after = before+offset;
}else{
after = (before+offset)%122+96;
}
return String.valueOf((char)after);
}
//A-Z
else if(ch >=65 && ch <= 90){
if(before+offset <= 90){
after = before+offset;
}else{
after = (before+offset)%90+64;
}
return String.valueOf((char)after);
}
//0-9
else if(ch >=48 && ch <= 57){
if(before+offset <= 57){
after = before+offset;
}else{
after = (before+offset)%57+47;
}
return String.valueOf((char)after);
}
return String.valueOf(ch);
}
public static String transParamsToString(String[] params)
{
StringBuilder sb = new StringBuilder();
for(String str:params)
{
sb.append(str);
sb.append(',');
}
if(sb.charAt(sb.length() - 1) == ',')
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
public static void copyValueToParamsArr(String[] paramsKey,String[] params,String key,String value)
{
for (int i = 0; i < paramsKey.length; i++) {
if (paramsKey[i].equals(key)) {
params[i] = value;
break;
}
}
}
}*/
return str;
}
//根据偏移量转换字符
public static String change(char ch, int offset) {
int before = ch;
int after;
//a-z
if (ch >= 97 && ch <= 122) {
if (before + offset <= 122) {
after = before + offset;
} else {
after = (before + offset) % 122 + 96;
}
return String.valueOf((char) after);
}
//A-Z
else if (ch >= 65 && ch <= 90) {
if (before + offset <= 90) {
after = before + offset;
} else {
after = (before + offset) % 90 + 64;
}
return String.valueOf((char) after);
}
//0-9
else if (ch >= 48 && ch <= 57) {
if (before + offset <= 57) {
after = before + offset;
} else {
after = (before + offset) % 57 + 47;
}
return String.valueOf((char) after);
}
return String.valueOf(ch);
}
public static String transParamsToString(String[] params) {
StringBuilder sb = new StringBuilder();
for (String str : params) {
sb.append(str);
sb.append(',');
}
if (sb.charAt(sb.length() - 1) == ',')
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
public static void copyValueToParamsArr(String[] paramsKey, String[] params, String key, String value) {
for (int i = 0; i < paramsKey.length; i++) {
if (paramsKey[i].equals(key)) {
params[i] = value;
break;
}
}
}
}
......@@ -42,7 +42,7 @@
</service>
<service class="org.sss.util.ContainerUtils">
<!-- <property name="cacheClassName" value="org.sss.presentation.noui.cache.Ehcache.EhcacheCache" class="java.lang.String" /> -->
<property name="cacheClassName" value="org.sss.presentation.noui.cache.Ehcache.EhcacheCache" class="java.lang.String" />
<!-- 交易DAT文件是否采用压缩 -->
<property name="isCompressed" value="false" class="boolean"/>
</service>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment