package com.changhong.epc.count.service.system.func; import com.changhong.epc.bean.count.MasterInfo; import com.changhong.epc.bean.count.func.FunNameKey; import com.changhong.epc.bean.count.func.FunctionInfo; import com.changhong.epc.bean.count.func.annotation.MyFunc; import com.changhong.epc.count.service.count.model.UnitInfo; import com.changhong.epc.count.service.system.func.set.aggregate.*; import com.changhong.epc.count.service.system.func.set.basic.CeilIntegerFuntion; import com.changhong.epc.count.service.system.func.set.basic.FloorIntegerFuntion; import com.changhong.epc.count.service.system.func.set.basic.RoundIntegerFuntion; import com.changhong.epc.count.service.system.func.set.date.*; import com.changhong.epc.count.service.system.func.set.norm.GetValDouble; import com.changhong.epc.count.service.system.func.set.norm.GetValString; import com.changhong.epc.count.service.system.func.set.norm.MasterParam; import com.changhong.epc.count.service.system.func.set.util.CurrencyAmount; import com.googlecode.aviator.AviatorEvaluator; import com.iemsoft.framework.cloud.core.tools.MsgTool; import org.springframework.stereotype.Component; import org.springframework.ui.ModelMap; import java.lang.reflect.Field; import java.util.*; /** * 函数注册 * @author wangZX * */ @Component public class FunRegister { /** * 注册说有函数 */ static{ AviatorEvaluator.addFunction(new DateFuntion()); AviatorEvaluator.addFunction(new FirstUnitFuntion()); AviatorEvaluator.addFunction(new GetCpnVal()); AviatorEvaluator.addFunction(new LastUnitFuntion()); AviatorEvaluator.addFunction(new UnitSumStr()); AviatorEvaluator.addFunction(new CeilIntegerFuntion()); AviatorEvaluator.addFunction(new FloorIntegerFuntion()); AviatorEvaluator.addFunction(new RoundIntegerFuntion()); AviatorEvaluator.addFunction(new GetDateAddHour()); AviatorEvaluator.addFunction(new GetDayFuntion()); AviatorEvaluator.addFunction(new GetHourFuntion()); AviatorEvaluator.addFunction(new GetMonthFuntion()); AviatorEvaluator.addFunction(new GetYearFuntion()); AviatorEvaluator.addFunction(new NowDate()); AviatorEvaluator.addFunction(new GetValString()); AviatorEvaluator.addFunction(new GetValDouble()); AviatorEvaluator.addFunction(new MasterParam()); AviatorEvaluator.addFunction(new CountFuntion()); AviatorEvaluator.addFunction(new CurrencyAmount()); } public static void main(String... args){ System.out.println(AviatorEvaluator.execute("(first('From_site_land')==last('To_site_land') && getDate(first('FromDate'), 'yyyy-MM-dd')==getDate(last('ToDate'), 'yyyy-MM-dd') && last('LeaveDate')==\"\")||(first('From_site_land')==last('To_site_land') && getDate(first('FromDate'), 'yyyy-MM-dd')==getDate(last('LeaveDate'), 'yyyy-MM-dd')&&last('LeaveDate')!=\"\")" // System.out.println(AviatorEvaluator.execute("first('From_site_land')==last('To_site_land')" , new ModelMap( "ALL_JOURNEY", Arrays.asList( new UnitInfo(){ { setUnitInfo( new HashSet<>(Arrays.asList( new MasterInfo("F000073", "", "1", "From_site_land") , new MasterInfo("F000073", "", "2", "To_site_land") , new MasterInfo("", "", "2019-03-06 08:39", "FromDate") , new MasterInfo("", "", "2019-03-06 09:15:00", "ToDate") , new MasterInfo("", "", "2019-03-06 16:39", "LeaveDate") )) ); } } , new UnitInfo(){ { setUnitInfo( new HashSet<>(Arrays.asList( new MasterInfo("F000073", "", "2", "From_site_land") , new MasterInfo("F000073", "", "1", "To_site_land") , new MasterInfo("", "", "2019-03-06 16:39", "FromDate") , new MasterInfo("", "", "2019-03-06 17:15:00", "ToDate") , new MasterInfo("", "", "", "LeaveDate") )) ); } } ) ))); } /** * 返回所有函数 * @return */ public Map> getFuncList(){ Map> funcs = new HashMap<>(); Field[] typeName = FunNameKey.class.getDeclaredFields(); MyFunc temp = null; for (Field field : typeName) { temp = field.getDeclaredAnnotation(MyFunc.class); if(temp != null && temp.isShow()){ List funInfos = funcs.get(temp.group().toString()); if(funInfos == null){ funInfos = new ArrayList<>(); funcs.put(temp.group().toString(), funInfos); } String val; try { val = Objects.toString(field.get(new FunNameKey(){}), ""); } catch (IllegalAccessException e) { val = ""; } FunctionInfo myFunc = new FunctionInfo(); myFunc.setFormat(MsgTool.get(temp.format())); myFunc.setShowFormat(val + MsgTool.get(temp.formatShow())); myFunc.setGroup(temp.group().getFuncGroupName().getName()); myFunc.setInfo(MsgTool.get(temp.info())); funInfos.add(myFunc); } } return funcs; } }