public override FuncCalcResult CalcFuncValue() { FuncCalcResult result; try { //var whereDic = GetWhere(); //string sql1 = "select sum(coalesce(amount, 0)) from invo_bill where (invo_bill.invo_state <> '2' or invo_bill.invo_state is null) and(invo_bill.split_flag = '' or invo_bill.split_flag is null or invo_bill.split_flag = '0') and invo_bill.inputtype = '1' and invo_bill.bill_type = '0' and " + whereDic["where1"]; //string sql2 = "select sum(coalesce(invo_split.amount,0)) from invo_bill,invo_split where (invo_bill.invo_state<>'2' or invo_bill.invo_state is null) and invo_bill.split_flag='1' and invo_bill.id=invo_split.inv_id and invo_bill.inputtype='1' and invo_bill.bill_type='0' and " + whereDic["where1"]; var sqlDic = GetSqls(); GitReportFuncDac funcDac = new GitReportFuncDac(); var d_cost1 = funcDac.QueryForDecimal(sqlDic["sql1"]); var d_cost2 = funcDac.QueryForDecimal(sqlDic["sql2"]); result = new FuncCalcResult(); result.Status = EnumFuncActionStatus.Success; result.Value = Convert.ToString(d_cost1 + d_cost2); } catch (Exception ex) { result = new FuncCalcResult(); result.Status = EnumFuncActionStatus.Failure; result.Fault = new FuncFault { FaultCode = "-1", Faultstring = "error", Detail = ex.Message }; } return(result); }
public override FuncCalcResult CalcFuncValue() { FuncCalcResult result = new FuncCalcResult(); result.Status = EnumFuncActionStatus.Success; result.Value = "48.50"; return(result); }
//报表格式有可能会产生变化 internal static FuncCalcResult GetFuncValue(FuncInfo func) { if (func == null) { throw new FuncException("要进行计算的函数为空"); } FuncCalcResult calcResult = null; //本次计算KEY string taskId = FuncCalcTask.GetTaskId(); if (string.IsNullOrEmpty(taskId)) { throw new FuncException("函数计算任务的taskId不能为空"); } var funcInfoMateData = FuncCache.GetFuncInfoMetaData(func.Name); if (funcInfoMateData == null) { //计算结果 calcResult = new FuncCalcResult { Status = EnumFuncActionStatus.Failure }; calcResult.Fault = FaultBuilder.Fault("错误", func.Name + "没有注册函数信息"); return(calcResult); } //没有缓存则计算 var refInfo = FuncConfigure.GetFuncRefInfo(func); if (refInfo == null) { //计算结果 calcResult = new FuncCalcResult { Status = EnumFuncActionStatus.Failure }; calcResult.Fault = FaultBuilder.Fault("错误", func.Name + "没有注册函数实现类信息"); return(calcResult); } try { //反射调用 var assembly = Assembly.Load(refInfo.AssemblyName); var clazz = assembly.GetType(refInfo.ClassName); //使用新封装的接口,所有的参数都是通过request取 var calcObject = Activator.CreateInstance(clazz) as IFunction; if (calcObject == null) { //计算结果 calcResult = new FuncCalcResult { Status = EnumFuncActionStatus.Failure }; calcResult.Fault = FaultBuilder.Fault("错误", func.Name + "没有实现接口IFuncCalc"); return(calcResult); } if (calcObject != null) { calcObject.Func = func; var funcInfo = calcObject.PreHandle(); //返回预处理结果,主要是参数的处理 var cache = FuncCache.GetFunc(taskId, funcInfo); if (cache != null) { //已经有值,表示已经缓存,则直接取数 return(cache.CalcResult); } else { var funcCalc = calcObject as IFuncCalc; var result = funcCalc.GetValue(); //同时加入到缓存中,对象是否要clone funcInfo.CalcResult = result; FuncCache.AddFunc(taskId, funcInfo); return(result); } } } catch (Exception ex) { //计算结果 calcResult = new FuncCalcResult { Status = EnumFuncActionStatus.Failure }; calcResult.Fault = FaultBuilder.Fault("错误", func.Name + "反射调用异常"); } return(calcResult); }