using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using DirectService.Tools;
using JLHHJSvr.BLL;
using JLHHJSvr.Com;
using JLHHJSvr.Com.Model;
using JLHHJSvr.Helper;
using JLHHJSvr.LJException;
using LJLib.DAL.SQL;
using LJLib.Net.SPI.Server;
using LJLib.SQLEX;

namespace JLHHJSvr.Excutor
{
    internal sealed class GetERPConfigureListExcutor : ExcutorBase<GetERPConfigureListRequest, GetERPConfigureListResponse>
    {
        protected override void ExcuteInternal(GetERPConfigureListRequest request, object state, GetERPConfigureListResponse 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 interfaceHelper = HelperBase.GetHelper<InterfaceHelper>(cmd);
                interfaceHelper.context = new HelperBase.Context() { tokendata = tokendata };

                var mattress = new u_mattress() { erp_configcodetype = request.configcodetype };

                // 匹配增行配置和增行清单
                if(request.isPz == 0)
                {
                    // 增行配置
                    interfaceHelper.MattressInterfaceFindERPPz(mattress, request.interfaceList);
                    rslt.interfaceList = request.interfaceList;
                } else
                {
                    // 增行清单
                    interfaceHelper.MattressInterfaceFindERPPrdPf(request.qdList);
                    rslt.qdList = request.qdList;
                }
            }
        }
    }
}
