using System.Data.SqlClient;
using DirectService.Tools;
using JLHHJSvr.BLL;
using JLHHJSvr.Com;
using JLHHJSvr.Com.Model;
using JLHHJSvr.Helper;
using JLHHJSvr.LJFramework.Tools;
using LJLib.Net.SPI.Server;
using LJLib.SQLEX;
using Newtonsoft.Json.Linq;

namespace JLHHJSvr.Excutor
{
    internal sealed class GetERPMtrlTypeListExcutor : ExcutorBase<GetERPMtrlTypeListRequest, GetERPMtrlTypeListResponse>
    {
        protected override void ExcuteInternal(GetERPMtrlTypeListRequest request, object state, GetERPMtrlTypeListResponse rslt)
        {
            var tokendata = BllHelper.GetToken(request.token);
            if (tokendata == null)
            {
                rslt.ErrMsg = "会话已经中断，请重新登录";
                return;
            }

            using (var con = GlobalVar.ConnectionString.NewSqlConnection())
            using (var cmd = con.CreateCommand())
            {
                con.Open();

                var cusion = new menuRecursion();

                var erpHelper = HelperBase.GetHelper<ERPHelper>(null);

                //var _params = new JObject();
                //_params.Add("parentid", request.parentid);
                //_params.Add("RecurionType", request.RecurionType);

                var list = erpHelper.GetERPMtrltype(cmd);

                var pk = new PkName()
                {
                    MainField = "mtrltypeid",
                    MainName = "mtrltype",
                    ParentField = "parentid"
                };

                ListEx.GetRecursions(list, pk, out var resultList);

                rslt.reList = resultList;
            }
        }
    }
}
