using AutoFixture;
using Hotline.Api.Controllers;
using Hotline.Application.Identity;
using Hotline.Application.Snapshot.Contracts;
using Hotline.Caching.Interfaces;
using Hotline.File;
using Hotline.Identity.Accounts;
using Hotline.Identity.Roles;
using Hotline.Orders;
using Hotline.Repository.SqlSugar.Extensions;
using Hotline.Repository.SqlSugar.Snapshot;
using Hotline.Settings;
using Hotline.Share.Dtos.Article;
using Hotline.Share.Dtos.Snapshot;
using Hotline.Share.Enums;
using Hotline.Share.Enums.Order;
using Hotline.Share.Enums.Snapshot;
using Hotline.Share.Enums.ThirdAccount;
using Hotline.Share.Enums.User;
using Hotline.Share.Tools;
using Hotline.Snapshot;
using Hotline.Snapshot.IRepository;
using Hotline.Tests.Mock;
using Hotline.ThirdAccountDomainServices;
using Hotline.ThirdAccountDomainServices.Interfaces;
using Hotline.Users;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using XF.Domain.Authentications;
using XF.Domain.Cache;
using XF.Domain.Repository;
using XF.Utility.EnumExtensions;

namespace Hotline.Tests.Application;
public class SnapshotApplicationTest : TestBase
{
    private readonly ISnapshotApplication _snapshotApplication;
    private readonly IIdentityAppService _identityAppService;
    private readonly IRepository<RedPackRecord> _redPackRecordRepository;
    private readonly IIndustryApplication _industryApplication;
    private readonly IIndustryRepository _industryRepository;
    private readonly IFileRepository _fileRepository;
    private readonly OrderServiceMock _orderServiceMock;
    private readonly IInviteCodeRecordRepository _inviteCodeRecordRepository;
    private readonly IOrderRepository _orderRepository;
    private readonly IOrderSnapshotRepository _orderSnapshotRepository;
    private readonly ISessionContext _sessionContext;
    private readonly IGuiderSystemService _guiderSystemService;
    private readonly ISystemSettingCacheManager _systemSettingCacheManager;
    private readonly ICommunityInfoRepository _communityInfoRepository;
    private readonly IIndustryLogRepository _industryLogRepository;
    private readonly IRedPackApplication _redPackApplication;
    private readonly IOrderSnapshotApplication _orderSnapshotApplication;
    private readonly ICitizenRepository _citizenRepository;

    public SnapshotApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, ISnapshotApplication snapshotApplication, IIdentityAppService identityAppService, IRepository<RedPackRecord> redPackRecordRepository, IIndustryApplication industryApplication, IIndustryRepository industryRepository, IFileRepository fileRepository, OrderServiceMock orderServiceMock, IOrderRepository orderRepository, IOrderSnapshotRepository orderSnapshotRepository, IThirdIdentiyService thirdService, IThirdAccountRepository thirdAccount, ISessionContext sessionContext, IGuiderSystemService guiderSystemService, ISystemSettingCacheManager systemSettingCacheManager, ICommunityInfoRepository communityInfoRepository, IIndustryLogRepository industryLogRepository, IRedPackApplication redPackApplication, IOrderSnapshotApplication orderSnapshotApplication, ITypedCache<SystemSetting> cacheSettingData, ThirdAccounSupplierFactory thirdAccountDomainFactory, ICitizenRepository citizenRepository, IServiceProvider serviceProvider, IInviteCodeRecordRepository inviteCodeRecordRepository) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdService, thirdAccount, cacheSettingData, thirdAccountDomainFactory, serviceProvider)
    {
        _snapshotApplication = snapshotApplication;
        _identityAppService = identityAppService;
        _redPackRecordRepository = redPackRecordRepository;
        _industryApplication = industryApplication;
        _industryRepository = industryRepository;
        _fileRepository = fileRepository;
        _orderServiceMock = orderServiceMock;
        _orderRepository = orderRepository;
        _orderSnapshotRepository = orderSnapshotRepository;
        SetWeiXin();
        _sessionContext = sessionContext;
        _guiderSystemService = guiderSystemService;
        _systemSettingCacheManager = systemSettingCacheManager;
        _communityInfoRepository = communityInfoRepository;
        _industryLogRepository = industryLogRepository;
        _redPackApplication = redPackApplication;
        _orderSnapshotApplication = orderSnapshotApplication;
        _citizenRepository = citizenRepository;
        _inviteCodeRecordRepository = inviteCodeRecordRepository;
    }

    /// <summary>
    /// 随手拍公开集合
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task GetOrderSnapshotPublishItemsAsync()
    {
        var items = await _orderSnapshotApplication.GetOrderSnapshotPublishItems(new GetOrderSnapshotPublishItemsInDto()).ToPageListAsync(0, 10);
        items.NotNullOrEmpty().ShouldBeTrue();
        items = await _orderSnapshotApplication.GetOrderSnapshotPublishItems(new GetOrderSnapshotPublishItemsInDto
        {
            OrderStatus = EOrderStatus.Filed
        }).ToPageListAsync(0, 10);
        items.NotNullOrEmpty().ShouldBeTrue();
        items = await _orderSnapshotApplication.GetOrderSnapshotPublishItems(new GetOrderSnapshotPublishItemsInDto
        {
            IsPublished = true
        }).ToPageListAsync(0, 10);
        items.NotNullOrEmpty().ShouldBeTrue();
        var signItems = await _orderSnapshotApplication.GetSignOrderSnapshotItems(new SignOrderSnapshotItemsInDto()).ToListAsync();
    }

    [Fact]
    public async Task GetHomePage_Test()
    {
        var result = await _snapshotApplication.GetHomePageAsync();
        result.Industrys.Any().ShouldBe(true, "首页数据为空");
        result.Industrys.First().DisplayOrder.ShouldBe(1, "排序异常");
    }

    [Fact]
    public async Task GetBulletionPopup_Test()
    {
        var item = await _snapshotApplication.GetBulletionPopupAsync(CancellationToken.None);
        //item.ShouldNotBeNull();
    }


    /// <summary>
    /// 添加随手拍公告
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task AddBulletin_Test()
    {
        var industry = await _industryRepository.Queryable()
            .Where(m => m.BulletinTypeGuideId != null && m.BulletinTypeGuideName != null)
            .OrderBy(m => m.DisplayOrder)
            .FirstAsync();
        if (industry == null)
        {
            return;
        }
        var inDto = new AddSnapshotBulletinInDto
        {
            Title = "单元测试" + DateTime.Now.ToLongDateTimeString(),
            Content = "测试内容" + DateTime.Now.ToLongDateTimeString(),
            BulletinTypeId = industry.BulletinTypeGuideId!,
            BulletinTypeName = industry.BulletinTypeGuideName!
        };
        var bulletinId = await _snapshotApplication.AddBulletinAsync(inDto);
        inDto = new AddSnapshotBulletinInDto
        {
            Title = "单元测试" + DateTime.Now.ToLongDateTimeString(),
            Content = "测试内容" + DateTime.Now.ToLongDateTimeString(),
            BulletinTypeId = industry.BulletinTypePublicityId!,
            BulletinTypeName = industry.BulletinTypePublicityName!
        };
        bulletinId = await _snapshotApplication.AddBulletinAsync(inDto);
        await _snapshotApplication.AuditBulletinAsync(new ExamineBulletinDto { Id = bulletinId, IsPass = true, Reason = "测试审核通过" });

        var items = await _snapshotApplication.GetBulletinsAsync(new BulletinInDto { IndustryId = industry.Id }, CancellationToken.None);
        items.Count.ShouldNotBe(0, "公告数量为0");
    }

    /// <summary>
    /// 获取公开工单集合
    /// 发布到公开工单
    /// 审核通过公开工单
    /// 获取特提参数
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task PublishOrder_Test()
    {
        var industry = await _industryRepository.Queryable()
            .Where(m => m.Name == "电气焊作业申报")
            .OrderBy(m => m.DisplayOrder)
            .FirstAsync();

        var order = _orderServiceMock.CreateSnapshotOrder(SetWeiXin)
            .办理到一级部门(SetZuoXi)
            .办理到二级部门(Set一级部门)
            .办理一级部门汇总(Set二级部门)
            .办理到归档(Set一级部门)
            .GetCreateResult();
        SetZuoXi();
        var auditDetail = await _orderSnapshotApplication.GetOrderSnapshotPublishDetailAsync(order.Id);
        var orderEntity = await _orderRepository.GetAsync(order.Id);
        var orderSnapshot = await _orderSnapshotRepository.GetAsync(order.Id);
        var inDto = new AddSnapshotOrderPublishInDto
        {
            ArrangeContent = auditDetail.Content,
            ArrangeOpinion = auditDetail.FileOpinion,
            ArrangeTitle = auditDetail.Title,
            OrderId = auditDetail.Id,
            ArrangeAddress = auditDetail.FullAddress,
            HandleTime = DateTime.Now
        };
        var auditId = await _orderSnapshotApplication.AddOrderPublishAsync(inDto, CancellationToken.None);
        var items = await _snapshotApplication.GetOrderPublishAsync(new OrderPublishInDto { IndustryId = industry.Id }, CancellationToken.None);
        items.Any(m => m.No == order.No).ShouldBeFalse();
        await _orderSnapshotApplication.UpdateOrderSnapshotPublishStatusAsync(new UpdateOrderSnapshotPublishStatusInDto { Id = auditId, Status = EOrderSnapshotPublishStatus.Agree });

        items = await _snapshotApplication.GetOrderPublishAsync(new OrderPublishInDto
        {
            IndustryId = industry.Id
        }, CancellationToken.None);
        items.Any(m => m.No == order.No).ShouldBeTrue();

        var orderPublishDetail = await _snapshotApplication.GetOrderPublishDetailAsync(items.OrderByDescending(m => m.HandleTime).First().Id, CancellationToken.None);
        orderPublishDetail.ShouldNotBeNull();
        orderPublishDetail.Workflow.Any(m => m.Name.IsNullOrEmpty()).ShouldBeFalse();
        await _snapshotApplication.AddRedPardAsync(order.Id, CancellationToken.None);
        var guiderItems = await _redPackApplication
            .GetRedPackGuiderAuditItems(new SnapshotOrderGuiderAuditItemsInDto(null, null, -1))
            .ToListAsync();
        guiderItems.Count.ShouldNotBe(0);
    }

    [Fact]
    public async Task GetBulletins_Test()
    {
        var whly = await _industryRepository.GetAsync(m => m.Name == "文化旅游");
        if (whly == null)
        {
            var temp = await _industryRepository.Queryable().Where(m => m.IndustryType == EIndustryType.Clue).FirstAsync();
            temp.Id = null;
            temp.Name = "文化旅游";
            temp.IndustryType = EIndustryType.Clue;
            await _industryRepository.AddAsync(temp);
        }

        var homePage = await _snapshotApplication.GetHomePageAsync();
        var inDto = new BulletinInDto
        {
            IndustryId = homePage.Industrys.First(m => m.Name == "文化旅游").Id,
        };
        var items = await _snapshotApplication.GetBulletinsAsync(inDto, CancellationToken.None);
        items.ShouldNotBeNull();
        items.Any().ShouldBe(true, "公告数据为空");
        items.Any(m => m.Title.IsNullOrEmpty()).ShouldBe(false, "标题错误");
        items.Any(m => m.Content.IsNullOrEmpty()).ShouldBe(false, "内容错误");
        items.Any(m => m.Id.IsNullOrEmpty()).ShouldBe(false, "Id错误");
    }

    /// <summary>
    /// 获取小程序个人中心
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task GetSnapshotUserInfo_Test()
    {
        //await _identityAppService.GetThredTokenAsync(new ThirdTokenInDto() { ThirdType = EThirdType.Test}, CancellationToken.None);
        var result = await _snapshotApplication.GetSnapshotUserInfoAsync(CancellationToken.None);
        result.ShouldNotBeNull();
        result.PhoneNumber.ShouldNotBeNullOrEmpty();
        result.PhoneNumberMask.Contains("***").ShouldBeTrue();
    }

    /// <summary>
    /// 根据OpenId刷新token
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task RefreshTokenAsync()
    {
        var token = await _identityAppService.GetThirdTokenAsync(new ThirdTokenInDto { ThirdType = EThirdType.Test, LoginCode = "测试生成的OpenId" }, CancellationToken.None);
        var newToken = await _identityAppService.RefreshTokenAsync(token["openId"].ToString(), CancellationToken.None);
        newToken.ShouldNotBeNull();
        newToken["openId"].ShouldBe(token["openId"].ToString());
        newToken["phoneNumber"].ToString().ShouldNotBeNullOrEmpty();
    }

    /// <summary>
    /// 请求第三方token
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task GetThirdToken_Test()
    {
        var result = await _identityAppService.GetThirdTokenAsync(new ThirdTokenInDto { AppType = EAppType.Snapshot, ThirdType = EThirdType.Test,   LoginCode = "测试生成的OpenId" }, CancellationToken.None);
        result["phoneNumber"].ToString().ShouldNotBeNullOrEmpty();
    }

    [Fact]
    public async Task SnapshotOrder_Test()
    {
        var dto = new OrderInDto();
        var page = await _snapshotApplication.GetSnapshotOrdersAsync(dto, CancellationToken.None);
        page.Count.ShouldNotBe(0);
        page.FirstOrDefault()?.IndustryName.ShouldNotBeNullOrEmpty();
        page.FirstOrDefault()?.OrderNo.ShouldNotBeNullOrEmpty();
        page.FirstOrDefault()?.StatusText.ShouldNotBeNullOrEmpty();
        page.FirstOrDefault()?.Area.ShouldNotBeNullOrEmpty();
        var key = page.FirstOrDefault()?.Title.Substring(0, 1);
        dto.KeyWords = key;
        page = await _snapshotApplication.GetSnapshotOrdersAsync(dto, CancellationToken.None);
        page.Count.ShouldNotBe(0);
    }

    [Theory]
    [InlineData(EOrderQueryStatus.All, 3)]
    [InlineData(EOrderQueryStatus.Reply, 2)]
    [InlineData(EOrderQueryStatus.NoReply, 1)]
    [InlineData(EOrderQueryStatus.Appraise, 1)]
    public async Task SnapshotOrderStatus_Test(EOrderQueryStatus status, int count)
    {
        var dto = new OrderInDto { Status = status };
        var page = await _snapshotApplication.GetSnapshotOrdersAsync(dto, CancellationToken.None);
        page.Count.ShouldNotBe(0, $"状态:{status.GetDescription()} 数据为空");
    }

    /// <summary>
    /// 获取工单详情
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task GetSnapshotOrderDetail_Test()
    {
        var page = await _snapshotApplication.GetSnapshotOrdersAsync(new OrderInDto(), CancellationToken.None);
        var id = page.First().Id;
        var detail = await _snapshotApplication.GetSnapshotOrderDetailAsync(id, CancellationToken.None);
        detail.Id.ShouldBe(id);
        detail.Title.ShouldNotBeNullOrEmpty();
        detail.Opinion.ShouldNotBeNullOrEmpty();
        detail.Content.ShouldNotBeNullOrEmpty();
    }

    [Fact]
    public async Task GetPointsItems_Test()
    {
        SetWeiXin();
        var items = await _snapshotApplication.GetPointItemsAsync(new PointItemsInDto(), CancellationToken.None);
        items.ShouldNotBeNull();
        var total = await _snapshotApplication.GetPointsTotalAsync(new PointItemsInDto(), CancellationToken.None);
        total.ShouldNotBe(0);
    }

    /// <summary>
    /// 红包列表记录
    /// </summary>
    /// <param name="count"></param>
    /// <param name="exp"></param>
    /// <returns></returns>
    [Theory]
    [InlineData(2, 2)]
    [InlineData(12, 12)]
    public async Task GetRedPackDateAsync(int count, int exp)
    {
        var items = await _snapshotApplication.GetRedPackDateAsync(new RedPackDateInDto { }, CancellationToken.None);
    }

    /// <summary>
    /// 红包总额
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task GetRedPackReceivedTotal_Test()
    {
        var amount = await _snapshotApplication.GetRedPackReceivedTotalAsync(CancellationToken.None);
    }

    /// <summary>
    /// 添加志愿者上报信息
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task AddVolunteerReport_Test()
    {
        await _snapshotApplication.AddVolunteerAsync(new AddVolunteerInDto { Name = _sessionContext.UserName, PhoneNumber = _sessionContext.Phone }, CancellationToken.None);
        var inDto = _fixture.Create<AddVolunteerReportInDto>();
        inDto.JobType = "电焊";
        inDto.PhoneNumber = "13999989" + DateTime.Now.ToString("ss");
        inDto.Name = "单元测试" + DateTime.Now.ToString("ss");
        foreach (var item in inDto.Files)
        {
            item.FileName = DateTime.Now.ToShortTimeString() + "文件.doc";
        }

        var result = await _snapshotApplication.AddVolunteerReportAsync(inDto, CancellationToken.None);
        result.Id.ShouldNotBeNull();
    }

    /// <summary>
    /// 保存用户邀请码
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task SaveInvitationCode_Test()
    {
        var code = new Random().Next(100, 200).ToString();
        await _inviteCodeRecordRepository.RemoveAsync(m => m.InviteCode == code);
        try
        {
            await _citizenRepository.Updateable()
                .SetColumns(m => m.InvitationCode, null)
                .Where(m => m.Id == _sessionContext.UserId)
                .ExecuteCommandAsync();
            await _snapshotApplication.SaveInvitationCodeAsync(new SaveInvitationCodeInDto { InvitationCode = code });
            var userInfo = await _citizenRepository.GetAsync(_sessionContext.UserId);
            userInfo.ShouldNotBeNull();
            userInfo!.InvitationCode.ShouldBe(code);
        }
        catch (Exception e)
        {
            var msg = e.Message;
            throw;
        }
    }

    /// <summary>
    /// 获取志愿者集合
    /// 获取志愿者详情
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task GetPractitionerItems_Test()
    {
        var items = await _snapshotApplication.GetPractitionerItemsAsync(new PractitionerItemInDto { AreaId = "510399" }, CancellationToken.None);
        items.Count.ShouldNotBe(0);

        var item = await _snapshotApplication.GetPractitionerDetailAsync(items.First().Id, CancellationToken.None);
        item.Street.ShouldNotBeNullOrEmpty();
        item.Name.ShouldNotBeNullOrEmpty();
        item.SystemAreaName.ShouldNotBeNullOrEmpty();
        item.SystemAreaName.ShouldNotBeNullOrEmpty();
        item.Gender.ShouldNotBe(EGender.Unknown);
        item.GenderTxt.ShouldNotBeNullOrEmpty();
        item.PhoneNumber.ShouldNotBeNullOrEmpty();
    }

    /// <summary>
    /// 统计红包数据
    /// </summary>
    /// <param name="status"></param>
    /// <returns></returns>
    [Theory]
    [InlineData(ERedPackPickupStatus.Unreceived)]
    [InlineData(ERedPackPickupStatus.Received)]
    public async Task GetRedPacksAsync(ERedPackPickupStatus status)
    {
        try
        {
            var page = await _snapshotApplication.GetRedPacksAsync(new RedPacksInDto { Status = status }, CancellationToken.None);
            page.ShouldNotBeNull();
        }
        catch (Exception e)
        {
            var msg = e.Message;
            throw;
        }        
        //page.Count.ShouldNotBe(0, "数据不应该为空");
    }

    [Fact]
    public async Task GetBulletinsDetail_Test()
    {
        var detail = await _snapshotApplication.GetBulletinsDetailAsync("08dc788f-20f4-4bf1-83d3-b5a8a4f395b0");
        //detail.Id.ShouldNotBeNullOrEmpty();
        //detail.Title.ShouldNotBeNullOrEmpty();
        //detail.Content.ShouldNotBeNullOrEmpty();
    }

    /// <summary>
    /// 测试行业
    /// 测试添加数据是否和获取的数据一致
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task Industry_Test()
    {
        SetZuoXi();
        var industry = new AddIndustryDto
        {
            Name = "测试行业",
            TitleSuffix = "测试标题",
            ApproveOrgId = "测试审批部门Id",
            ApproveOrgName = "测试审批部门名字",
            AcceptType = "测试受理类型",
            AcceptTypeCode = "测试受理类型代码",
            CitizenReadPackAmount = 100,
            GuiderReadPackAmount = 200,
            IsEnable = true,
            Files = new List<IndustryFileDto>
            {
                new IndustryFileDto
                {
                    Name = "测试文件" + DateTime.Now.ToShortDateString(),
                    Path = "测试文件地址" + DateTime.Now.ToShortTimeString(),
                    FileName ="测试文件" + DateTime.Now.ToShortDateString()  + ".doc",
                    AdditionId = DateTime.Now.ToLongDateString()
                }
            },
            ArgeePoints = 3,
            ExtraDeductedPoints = 2,
            RefusePoints = 1,
            ReportPoints = 4,
            IsPoints = false
        };
        var industryId = await _industryApplication.AddIndustryAsync(industry, CancellationToken.None);
        var pageDto = await _snapshotApplication.GetIndustryBaseAsync(industryId, CancellationToken.None);
        var industryOut = await _industryApplication.GetIndustryDetailAsync(industryId, CancellationToken.None);
        try
        {
            industryOut.ArgeePoints.Value.ShouldBe(industry.ArgeePoints.Value);
            industryOut.ExtraDeductedPoints.Value.ShouldBe(industry.ExtraDeductedPoints.Value);
            industryOut.RefusePoints.Value.ShouldBe(industry.RefusePoints.Value);
            industryOut.ReportPoints.Value.ShouldBe(industry.ReportPoints.Value);
            industryOut.IsPoints.ShouldBe(industry.IsPoints);
            pageDto.ShouldNotBeNull();
            pageDto.Files.ShouldNotBeNull();
            foreach (var file in pageDto.Files)
            {
                file.Id.ShouldNotBeNullOrEmpty();
                file.Name.ShouldNotBeNullOrEmpty();
                file.Path.ShouldNotBeNullOrEmpty();
                file.FileName.ShouldNotBeNullOrEmpty();
                file.AdditionId.ShouldNotBeNullOrEmpty();
                file.Key.ShouldBe(industryId);
            }
            pageDto.Workplace.ShouldNotBeNull();
            pageDto.WorkplaceName.ShouldNotBeNull();
        }
        catch (Exception e)
        {
            // ignore
        }
        finally
        {
            await _industryRepository.Removeable().Where(m => m.Id == industryId).ExecuteCommandAsync();
            await _fileRepository.Removeable().Where(m => m.Id == pageDto.Files.First().Id).ExecuteCommandAsync();
        }
    }

    /// <summary>
    /// 上报线索
    /// 推送网格员
    /// 网格员回复
    /// </summary>
    /// <returns></returns>
    [Fact]
    public async Task Snapshot_Test()
    {
        SetSettingCache(SettingConstants.OvertimeBack, "4");
        var order = _orderServiceMock.CreateSnapshotOrder(SetWeiXin, "安全隐患")
            .办理到网格员(SetZuoXi)
            .GetCreateResult();
        await _snapshotApplication.PostOrderGuiderSystemAsync(order.Id, CancellationToken.None);
        var orderSnapshot = await _orderSnapshotRepository.GetAsync(order.Id);
        orderSnapshot.IndustryName = "修改行业名称";
        await _orderSnapshotRepository.UpdateAsync(orderSnapshot);
        var industryLog = await _industryLogRepository.Queryable()
            .Where(m => m.OrderId == order.Id)
            .FirstAsync();
        industryLog.ShouldNotBeNull();
        industryLog.IndustryName.ShouldBe("修改行业名称");
        await _orderSnapshotRepository.Updateable()
            .SetColumns(m => m.IndustryName, industryLog.OldIndustryName)
            .Where(m => m.Id == order.Id)
            .ExecuteCommandAsync();
        orderSnapshot = await _orderSnapshotRepository.GetAsync(order.Id);
        var replyDto = new GuiderSystemInDto
        {
            ReplyCode = order.No,
            AppealNumber = orderSnapshot.NetworkENumber,
            ReplyDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"),
            ReplyUserName = "18181552753@zgsg",
            ReplyBMName = "瓦市村村民委员会",
            ReplyResultType = "2",
            ReplyISTrue = "1",
            IsRepeat = "0",
            IsHiddenDanger = "1",
            MemberName = "许利洪",
            MemberMobile = "18181552753",
            ReplyContent = "到现场查实，存在安全隐患",
            OrgId = "4828",
            OrgName = "瓦市村民委员会" + DateTime.Now.ToString("ss"),
            OrgFullName = "四川省/自贡市/沿滩区/永安镇/瓦市村村民委员会" + DateTime.Now.ToString("ss"),
            DepartmentNo = "510311106206",
            ParentOrgId = "4821",
            ReplyFileList = new List<string>
            {
                "http://10.0.188.11:1234/tqOssManager/getObjectByUri/sichuan/scgrid/jpg/2024/12/5/095020318625.jpg"
            }
        };
        await _snapshotApplication.SaveGuiderSystemReplyAsync(replyDto, CancellationToken.None);
        var orderReply = await _orderSnapshotRepository.GetByNetworkENumberAsync(replyDto.AppealNumber);
        orderReply.IsDanger.ShouldBe(true);
        orderReply.MemberMobile.ShouldBe(replyDto.MemberMobile);
        orderReply.MemberName.ShouldBe(replyDto.MemberName);
        orderReply.NetworkRemark.ShouldBe(replyDto.ReplyContent);
        orderReply.ReplyDate.Value.ToString("yyyy-MM-dd hh:mm:ss").ShouldBe(replyDto.ReplyDate);
        var community = await _communityInfoRepository.GetAsync(replyDto.OrgId);
        community.ShouldNotBeNull();
        community.Name.ShouldBe(replyDto.OrgName);
        community.FullName.ShouldBe(replyDto.OrgFullName);
    }
}
