using System;
using DirectService.Tools;
using JLHHJSvr.BLL;
using JLHHJSvr.Com;
using JLHHJSvr.Helper;
using LJLib.DAL.SQL;
using LJLib.Net.SPI.Server;
using LJLib.SQLEX;

namespace JLHHJSvr.Excutor
{
    internal sealed class DeleteSysPostMessageExcutor : ExcutorBase<DeleteSysPostMessageRequest, DeleteSysPostMessageResponse>
    {
        protected override void ExcuteInternal(DeleteSysPostMessageRequest request, object state, DeleteSysPostMessageResponse 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 baseHelper = HelperBase.GetHelper<BasicInfoHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });

                using (cmd.Transaction = con.BeginTransaction())
                {
                    try
                    {
                        baseHelper.DeleteSysPostMessage(request.postid);
                        cmd.Transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        rslt.ErrMsg = e.Message;
                        cmd.Transaction?.Rollback();
                    }
                }
            }
        }
    }
}
