package com.changhong.epc.count.service.tool;
|
|
import com.changhong.epc.bean.count.MasterInfo;
|
import com.changhong.epc.count.service.count.model.UnitInfo;
|
import com.changhong.epc.bean.count.MeInfo;
|
import com.changhong.epc.count.service.system.model.SystemFunContextType;
|
import com.googlecode.aviator.runtime.type.AviatorObject;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
import com.iemsoft.framework.cloud.core.tools.StringUtil;
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
import java.util.Map;
|
import java.util.Objects;
|
|
/**
|
* 系统函数工具类
|
*/
|
public class SystemFunTool {
|
|
/**
|
* 获得函数参数值
|
* @param arg1
|
* @param env
|
* @return
|
*/
|
public static Object getVal(AviatorObject arg1, Map<String, Object> env){
|
if(arg1 == null){
|
return null;
|
}
|
return arg1.getValue(env);
|
}
|
|
/**
|
* 比较两个值大小
|
* @param arg1
|
* @param arg2
|
* @param env
|
* @return
|
*/
|
public static int compareTo(AviatorObject arg1, AviatorObject arg2, Map<String, Object> env){
|
Object val1 = getVal(arg1, env);
|
Object val2 = getVal(arg2, env);
|
if(val1 == null && val2 != null){
|
return 1;
|
}
|
if(val2 == null && val1 != null){
|
return -1;
|
}
|
if(val1 == null && val2 == null){
|
return 0;
|
}
|
if(isNumber(val1) && isNumber(val2)){
|
return new Double(getNumber(val1).doubleValue() - getNumber(val2).doubleValue()).intValue();
|
}else{
|
return Objects.toString(val1, "").compareTo(Objects.toString(val2, ""));
|
}
|
}
|
|
/**
|
* 获得数值类型参数
|
* @param arg1
|
* @param env
|
* @return
|
*/
|
public static Number getNumberVal(AviatorObject arg1, Map<String, Object> env){
|
Object val = getVal(arg1, env);
|
if(val instanceof MeInfo){
|
return getNumber(((MeInfo) val).getMeValue());
|
}else {
|
return getNumber(val);
|
}
|
}
|
|
/**
|
* 获得字符类型参数
|
* @param arg1
|
* @param env
|
* @return
|
*/
|
public static String getStringVal(AviatorObject arg1, Map<String, Object> env){
|
return getStringVal(arg1, env, getJourney(env));
|
}
|
|
public static String getStringVal(AviatorObject arg1, Map<String, Object> env, UnitInfo unitInfo){
|
Object val = getVal(arg1, env);
|
// 引用主数据占位
|
if(val instanceof MeInfo){
|
MeInfo meInfo = ((MeInfo) val);
|
if(StringUtil.isBlank(meInfo.getMeValue())){
|
return Objects.toString(getJourneyValByMdCode(unitInfo, meInfo.getMdCode()), "");
|
}else{
|
return Objects.toString(meInfo.getMeValue(), "");
|
}
|
}
|
// 常量 控件别名、主数据 占位
|
if(val instanceof String){
|
String strVal = Objects.toString(val, "");
|
Object v = getJourneyValByFromKey(unitInfo, strVal);
|
if(ObjectUtil.notEmpty(v)){
|
return Objects.toString(v, "");
|
}
|
v = getJourneyValByMdCode(unitInfo, strVal);
|
if(ObjectUtil.notEmpty(v)){
|
return Objects.toString(v, "");
|
}
|
}
|
// 常量值
|
return Objects.toString(val, "");
|
}
|
|
/**
|
* 获得当前行程信息
|
* @param env
|
* @return
|
*/
|
public static UnitInfo getJourney(Map<String, Object> env) {
|
UnitInfo j = (UnitInfo) env.get(SystemFunContextType.JOURNEY.toString());
|
return j;
|
}
|
|
public static Object getJourneyValByMdCode(UnitInfo unitInfo, String mdCode){
|
if(unitInfo == null){
|
return null;
|
}
|
MasterInfo master = null;
|
for(MasterInfo masterInfo : unitInfo.getUnitInfoMdJoinAll()){
|
if(Objects.equals(masterInfo.getMdCode(), mdCode)){
|
master = masterInfo;
|
}
|
}
|
if(master == null){
|
return null;
|
}
|
return master.getMeVal();
|
}
|
|
public static Object getJourneyValByFromKey(UnitInfo unitInfo, String fromKey){
|
if(unitInfo == null){
|
return null;
|
}
|
for (MasterInfo masterInfo: unitInfo.getUnitInfo()) {
|
if(Objects.equals(masterInfo.getAlias(), fromKey)){
|
return masterInfo.getMeVal();
|
}
|
}
|
return null;
|
}
|
|
/**
|
* 获得自定义类型参数
|
* @param arg1
|
* @param env
|
* @return
|
*/
|
public static MeInfo getMeInfoVal(AviatorObject arg1, Map<String, Object> env){
|
Object val = getVal(arg1, env);
|
if(val instanceof MeInfo){
|
return (MeInfo) val;
|
}else{
|
return null;
|
}
|
}
|
|
public static <T> T getMeInfoProp(AviatorObject arg1, Map<String, Object> env, MeInfoFunction<T> meInfoFunction){
|
Object val = getVal(arg1, env);
|
if(val instanceof MeInfo){
|
return meInfoFunction.getProp((MeInfo) val);
|
}else{
|
return null;
|
}
|
}
|
|
@FunctionalInterface
|
public interface MeInfoFunction<T>{
|
T getProp(MeInfo meInfo);
|
}
|
|
/**
|
* 返回数值类型
|
* @param val
|
* @return
|
*/
|
public static Number getNumber(Object val){
|
if(val instanceof Number){
|
return (Number) val;
|
}
|
String strVal = Objects.toString(val, "");
|
if(NumberUtils.isNumber(strVal)){
|
return NumberUtils.createNumber(strVal);
|
}
|
return new Integer(0);
|
}
|
|
/**
|
* 是否是数值类型
|
* @param val
|
* @return
|
*/
|
public static boolean isNumber(Object val){
|
return NumberUtils.isNumber(Objects.toString(val, ""));
|
}
|
|
/**
|
* 获取表单控件值
|
*/
|
public static MasterInfo getNumberObject(UnitInfo unitInfo){
|
if(unitInfo == null){
|
return null;
|
}
|
for (MasterInfo masterInfo: unitInfo.getUnitInfo()) {
|
if(masterInfo.getAlias().indexOf("number_")==0){
|
return masterInfo;
|
}
|
}
|
return null;
|
}
|
}
|