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

namespace JLHHJSvr.Excutor
{
    internal sealed class UnLockUserExcutor : ExcutorBase<UnLockUserRequest, UnLockUserResponse>
    {
        protected override void ExcuteInternal(UnLockUserRequest request, object state, UnLockUserResponse rslt)
        {
            var tokendata = BllHelper.GetToken(request.token);
            if (tokendata == null)
            {
                rslt.ErrMsg = "会话已经中断，请重新登录";
                return;
            }
            if (request.useridList == null || request.useridList.Count == 0)
            {
                rslt.ErrMsg = "至少提交一条需要解锁的记录";
                return;
            }

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

                using (cmd.Transaction = con.BeginTransaction())
                {
                    try
                    {
                        UserHelper.UnLock(cmd, request.useridList);
                        cmd.Transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        cmd.Transaction.Rollback();
                        rslt.ErrMsg = e.Message;
                    }
                }
            }
        }
    }
}
