using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using JLHHJSvr.BLL;
using JLHHJSvr.Com;
using JLHHJSvr.Com.Model;
using JLHHJSvr.DBA.DBModle;
using JLHHJSvr.LJFramework.Tools;
using LJLib.DAL.SQL;
using LJLib.Net.SPI.Server;

namespace JLHHJSvr.Excutor
{
    internal sealed class GetFormulaComputeExcutor : ExcutorBase<GetFormulaComputeRequest, GetFormulaComputeResponse>
    {
        protected override void ExcuteInternal(GetFormulaComputeRequest request, object state, GetFormulaComputeResponse rslt)
        {
            var tokendata = BllHelper.GetToken(request.token);
            if (tokendata == null)
            {
                rslt.ErrMsg = "会话已经中断，请重新登录";
                return;
            }
            using (var con = new SqlConnection(GlobalVar.ConnectionString))
            using (var cmd = con.CreateCommand())
            {
                con.Open();

                rslt.values = new List<decimal>();
                try {
                    foreach(var iformula in request.formulas)
                    {
                        var res = LJExprParser.Parse(iformula);
                        rslt.values.Add(res.Result.DecimalValue);
                    }
                }
                catch (Exception ex)
                {
                    rslt.ErrMsg = ex.ToString();
                }
            }
        }
    }
}
