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 GetResetWiptypeExcutor : ExcutorBase<GetResetWiptypeRequest, GetResetWiptypeResponse>
    {
        protected override void ExcuteInternal(GetResetWiptypeRequest request, object state, GetResetWiptypeResponse 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 qdList = request.qdList;
                foreach (var qdmx in qdList)
                {
                    var _bcpcompare = new u_bcpcompare() { pzname = qdmx.bj_pzname };
                    var _wip_type = "";
                    var _wrkgrpcode2 = "";
                    if (DbSqlHelper.SelectOne(cmd, _bcpcompare, "wip_type, wrkgrpcode2") == 1)
                    {
                        _wip_type = _bcpcompare.wip_type;
                        _wrkgrpcode2 = _bcpcompare.wrkgrpcode2;
                    }
                    qdmx.wip_type = _wip_type;
                    qdmx.wrkgrpcode2 = _wrkgrpcode2;
                }


                rslt.qdList = qdList;
            }
        }
    }
}
