qinchaoyue 4 周之前
父节点
当前提交
a1f804571d

+ 2 - 33
SnapshotWinFormsApp/Application/CommunityInfoApplication.cs

@@ -16,40 +16,9 @@ using System.Threading.Tasks;
 namespace SnapshotWinFormsApp.Application;
 
 [Description("导入社区信息")]
-public class CommunityInfoApplication : IImportApplication
+public class CommunityInfoApplication :  ImportApplicationBase<SSP_AreaEntity, CommunityInfo, int>, IImportApplication
 {
-    private readonly IBaseRepository<CommunityInfo> _communityInfoRepo;
-    private readonly IRepository<SSP_AreaEntity, int> _areaRepo;
-    public CommunityInfoApplication(CreateInstanceInDto inDto)
+    public CommunityInfoApplication(CreateInstanceInDto inDto) : base(inDto)
     {
-        _communityInfoRepo = new BaseRepository<CommunityInfo>(inDto);
-        _areaRepo = new Repository<SSP_AreaEntity, int>(inDto);
-    }
-
-    public async Task ImportAsync(Action<string> log, CancellationToken token)
-    {
-        try
-        {
-            log($"正在查询旧数据...");
-            var items = await _areaRepo.GetAllAsync(token);
-
-            log($"共查询到{items.Count}条数据");
-            for (int i = 0;i < items.Count;i++)
-            {
-                var item = items[i];
-                var communitInfo = item.Adapt<CommunityInfo>();
-                var has = await _communityInfoRepo.Queryable()
-                    .AnyAsync(m => m.UniqueKey == communitInfo.UniqueKey, token);
-                if (has) continue;
-
-                await _communityInfoRepo.InsertAsync(communitInfo, token);
-                log($"{i}/{items.Count} 插入数据: {communitInfo.Id} {communitInfo.Name}");
-            }
-        }
-        catch (Exception e)
-        {
-            var msg = e.Message;
-            log($"导入数据异常: {e.Message}");
-        }
     }
 }

+ 57 - 0
SnapshotWinFormsApp/Application/GriderApplication.cs

@@ -0,0 +1,57 @@
+using DataTransmission.Enum;
+using SnapshotWinFormsApp.Application.Dtos;
+using SnapshotWinFormsApp.Application.Interfaces;
+using SnapshotWinFormsApp.Entities.NewHotline;
+using SnapshotWinFormsApp.Entities.OldHotline;
+using SnapshotWinFormsApp.Repository;
+using SnapshotWinFormsApp.Repository.Enum;
+using SnapshotWinFormsApp.Repository.Interfaces;
+using SnapshotWinFormsApp.Tools;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SnapshotWinFormsApp.Application;
+
+[Description("导入网格员")]
+public class GriderApplication : ImportApplicationBase<Flow03_PushContent, Citizen, int>, IImportApplication
+{
+    private readonly IBaseRepository<Citizen> _userRepo;
+
+    public GriderApplication(CreateInstanceInDto inDto) : base(inDto)
+    {
+        _userRepo = new BaseRepository<Citizen>(inDto);
+    }
+
+    public override ISugarQueryable<Flow03_PushContent> GetSourceList()
+    {
+        return _sourceRepo.Queryable()
+            .Where(m => m.MemberMobile != null && m.MemberName != null)
+            .GroupBy(m => new { m.MemberName, m.MemberMobile });
+    }
+
+    public override async Task<bool> HasOldDataAsync(string tableName, Flow03_PushContent item, CancellationToken token)
+    {
+        var userId = await _userRepo.Queryable()
+            .Where(m => m.PhoneNumber == item.MemberMobile)
+            .Select(m => m.Id)
+            .FirstAsync(token);
+        return userId.IsNullOrEmpty();
+    }
+
+    public override async Task<Citizen> GetTargetAsync(Flow03_PushContent source, CancellationToken token)
+    {
+        var userInfo = new Citizen
+        {
+            PhoneNumber = source.MemberMobile.Replace("\t", ""),
+            Name = source.MemberName.Replace("\t", ""),
+            CitizenType = EReadPackUserType.Guider,
+            IdentityType = EIdentityType.Citizen
+        };
+        return await Task.FromResult(userInfo);
+    }
+}

+ 71 - 21
SnapshotWinFormsApp/Application/Interfaces/ImportApplicationBase.cs

@@ -1,32 +1,36 @@
-using DataTransmission.Enum;
-using Mapster;
+using Mapster;
 using SnapshotWinFormsApp.Application.Dtos;
 using SnapshotWinFormsApp.Entities.NewHotline;
 using SnapshotWinFormsApp.Entities.OldHotline;
 using SnapshotWinFormsApp.Repository;
 using SnapshotWinFormsApp.Repository.Interfaces;
 using SqlSugar;
-using System;
-using System.Collections.Generic;
-using System.Linq;
 using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace SnapshotWinFormsApp.Application.Interfaces;
-public class ImportApplicationBase<TSource, TEntity, TKey> : IImportApplication
+public class ImportApplicationBase<TSource, TEntity, TKey> : ImportApplicationBase<TSource, TEntity, TKey, TSource>
     where TSource : OldBaseEntity<TKey>, new()
-    where TEntity : Entity, new() 
+    where TEntity : Entity, new()
 {
-    private readonly IRepository<TSource, TKey> _sourceRepo;
-    private readonly IBaseRepository<TEntity> _targetRepo;
-    private readonly IBaseRepository<OldDataId> _oldDataIdRepo;
-    private readonly SqlSugarClient _sugarClient;
-    private readonly CreateInstanceInDto _instance;
+    public ImportApplicationBase(CreateInstanceInDto inDto) : base(inDto)
+    {
+    }
+}
+
+public class ImportApplicationBase<TSource, TEntity, TKey, TMix> : IImportApplication
+    where TSource : OldBaseEntity<TKey>, new()
+    where TEntity : Entity, new()
+    where TMix : OldBaseEntity<TKey>, new()
+{
+    public readonly IRepository<TMix, TKey> _sourceRepo;
+    public readonly IBaseRepository<TEntity> _targetRepo;
+    public readonly IBaseRepository<OldDataId> _oldDataIdRepo;
+    public readonly SqlSugarClient _sugarClient;
+    public readonly CreateInstanceInDto _instance;
     public ImportApplicationBase(CreateInstanceInDto inDto)
     {
         _instance = inDto;
-        _sourceRepo = new Repository<TSource, TKey>(inDto);
+        _sourceRepo = new Repository<TMix, TKey>(inDto);
         _targetRepo = new BaseRepository<TEntity>(inDto);
         _oldDataIdRepo = new BaseRepository<OldDataId>(inDto);
     }
@@ -35,6 +39,7 @@ public class ImportApplicationBase<TSource, TEntity, TKey> : IImportApplication
     {
         log($"正在查询旧数据...");
         var items = await GetSourceList(_instance).ToListAsync(token);
+        
         log($"共查询到{items.Count}条数据");
         var tableName = typeof(TSource).GetCustomAttribute<SugarTable>()?.TableName ?? throw new ArgumentNullException("老数据表名不能为空, 设置[SugarTable()]");
 
@@ -42,26 +47,71 @@ public class ImportApplicationBase<TSource, TEntity, TKey> : IImportApplication
         {
             await Task.Run(() => MainForm._pauseEvent.WaitHandle.WaitOne(), token);
             var item = items[i];
-            var has = HasOldData(tableName, item);
+            var has = await HasOldDataAsync(tableName, item, token);
             if (has) continue;
-            var target = item.Adapt<TEntity>();
+            var target = await GetTargetAsync(item, token);
 
             await _targetRepo.db.Ado.BeginTranAsync();
             target.Id = _targetRepo.InsertBulk(target, i + 1 == items.Count);
-            await _oldDataIdRepo.InsertAsync(new OldDataId { OldId = item.Id.ToString(), TableName = tableName, NewId = target.Id }, token);
+            _oldDataIdRepo.InsertBulk(new OldDataId { OldId = item.Id.ToString(), TableName = tableName, NewId = target.Id }, i + 1 == items.Count);
             await _targetRepo.db.Ado.CommitTranAsync();
             log($"{i}/{items.Count} 插入数据: {item.Id} {target.Id}");
+            await InsertAfterAsync(log, item, target, token);
         }
     }
 
-    public virtual ISugarQueryable<TSource> GetSourceList(CreateInstanceInDto inDto)
+    /// <summary>
+    /// 插入数据以后执行的动作
+    /// </summary>
+    /// <param name="item"></param>
+    /// <param name="target"></param>
+    /// <param name="token"></param>
+    /// <returns></returns>
+    /// <exception cref="NotImplementedException"></exception>
+    public virtual async Task InsertAfterAsync(Action<string> log, TMix item, TEntity target, CancellationToken token)
+    {
+        await Task.FromResult(0);
+    }
+
+    /// <summary>
+    /// 获取原始数据集合
+    /// </summary>
+    /// <param name="inDto"></param>
+    /// <returns></returns>
+    public virtual ISugarQueryable<TMix> GetSourceList(CreateInstanceInDto inDto)
     {
         return _sourceRepo.Queryable();
     }
 
-    public virtual bool HasOldData(string tableName, TSource item)
+    /// <summary>
+    /// 获取原始数据集合
+    /// </summary>
+    /// <returns></returns>
+    /// <exception cref="NotImplementedException"></exception>
+    public virtual ISugarQueryable<TMix> GetSourceList()
+    { 
+        throw new NotImplementedException();
+    }
+
+    /// <summary>
+    /// 根据原始数据获取目标数据
+    /// </summary>
+    /// <param name="source"></param>
+    /// <returns></returns>
+    public virtual async Task<TEntity> GetTargetAsync(TMix source, CancellationToken token)
+    {
+        return await Task.FromResult(source.Adapt<TEntity>());
+    }
+
+    /// <summary>
+    /// 验证是否已存在
+    /// </summary>
+    /// <param name="tableName"></param>
+    /// <param name="item"></param>
+    /// <returns></returns>
+    public virtual async Task<bool> HasOldDataAsync(string tableName, TMix item, CancellationToken token)
     {
-        return _oldDataIdRepo.Queryable().Any(m => m.TableName == tableName && item.Id.ToString() == m.OldId);
+        return await _oldDataIdRepo.Queryable().AnyAsync(m => m.TableName == tableName && item.Id.ToString() == m.OldId, token);
     }
 
 }

+ 8 - 73
SnapshotWinFormsApp/Application/InviteApplication.cs

@@ -14,83 +14,18 @@ using System.Configuration;
 namespace SnapshotWinFormsApp.Application;
 
 [Description("邀请码")]
-public class InviteApplication : IImportApplication
+public class InviteApplication : ImportApplicationBase<SSP_InviteEntity, InviteCode, int, OldInviteCodeRecord>, IImportApplication
 {
-    private readonly IRepository<SSP_InviteLogEntity, string> _inviteLogRepo;
-    private readonly IRepository<SSP_InviteEntity, int> _inviteRepo;
-    private readonly IBaseRepository<InviteCode> _newInviteCodeRepo;
-    private readonly IBaseRepository<InviteCodeRecord> _newInviteLogRepo;
-    private readonly IBaseRepository<SnapshotUserInfo> _userInfoRepo;
-    private readonly IBaseRepository<ThirdAccount> _thirdAccountRepo;
-    public InviteApplication(CreateInstanceInDto inDto)
+    public InviteApplication(CreateInstanceInDto inDto) : base(inDto)
     {
-        _inviteLogRepo = new Repository<SSP_InviteLogEntity, string>(inDto);
-        _inviteRepo = new Repository<SSP_InviteEntity, int>(inDto);
-        _newInviteCodeRepo = new BaseRepository<InviteCode>(inDto);
-        _newInviteLogRepo = new BaseRepository<InviteCodeRecord>(inDto);
-        _userInfoRepo = new BaseRepository<SnapshotUserInfo>(inDto);
-        _thirdAccountRepo = new BaseRepository<ThirdAccount>(inDto);
     }
 
-    public async Task ImportAsync(Action<string> log, CancellationToken token)
+    public override async Task<InviteCode> GetTargetAsync(OldInviteCodeRecord source, CancellationToken token)
     {
-        log($"正在查询旧数据...");
-        var items = await _inviteRepo.GetAllAsync(token);
-        log($"共查询到{items.Count}条数据");
-
-        for (int i = 0;i < items.Count;i++)
-        {
-            var inviteCode = items[i].Adapt<InviteCode>();
-            var has = await _newInviteCodeRepo.Queryable().AnyAsync(m => m.OrgName == inviteCode.OrgName, token);
-            if (has) continue;
-            var url = ConfigurationManager.AppSettings["ZiGongFile"] + inviteCode.QRCodeUrl;
-            var fileContent = await new FileTools().GetNetworkFileAsync(url, token);
-            inviteCode.QRCodeUrl = fileContent.Path;
-            await _newInviteCodeRepo.InsertAsync(inviteCode, token);
-            log($"{i + 1}/{items.Count} 插入数据: {inviteCode.Id} {inviteCode.OrgName}");
-        }
-
-        await ImportInivteLogAsync(log, token);
-    }
-
-    private async Task ImportInivteLogAsync(Action<string> log, CancellationToken token)
-    {
-        log($"正在查询旧数据...");
-        var items = await _inviteLogRepo.Queryable()
-            .LeftJoin<SSP_InviteEntity>((log, invite) => log.SSPI_CodeID == invite.SIC_Byte)
-            .LeftJoin<WeChatUserEntity>((log, invite, user) => user.WUR_Openid == log.SSPI_Openid)
-            .Select((log, invite, user) => new InviteCodeRecord
-            {
-                Id = log.Id,
-                Name = user.WUR_WebUserName,
-                OrgName = invite.SIC_BMName,
-                InviteCode = log.SSPI_Code,
-                WXOpenId = log.SSPI_Openid,
-                PhoneNumber = user.WUR_PhoneNum,
-            })
-            .ToListAsync(token);
-        log($"共查询到{items.Count}条数据");
-
-        var invities = await _newInviteCodeRepo.GetAllAsync(token);
-        var thirdAccounts = await _thirdAccountRepo.GetAllAsync(token);
-
-        for (int i = 0;i < items.Count;i++)
-        {
-            var inviteLog = items[i];
-            var has = await _newInviteLogRepo.Queryable().AnyAsync(m => m.Id == inviteLog.Id, token);
-            if (has) continue;
-            inviteLog.OrgId = invities.FirstOrDefault(m => m.OrgName == inviteLog.OrgName)?.Id;
-            await _newInviteLogRepo.InsertAsync(inviteLog, token);
-            log($"{i + 1}/{items.Count} 插入数据: {inviteLog.Id} {inviteLog.OrgName} {inviteLog.Name} {inviteLog.InviteCode}");
-            var userId = thirdAccounts
-                .Where(m => m.OpenId == inviteLog.WXOpenId).Select(m => m.ExternalId).FirstOrDefault();
-            if (userId.IsNullOrEmpty()) continue;
-
-            log($"更新用户邀请码: {userId} {inviteLog.InviteCode}");
-            await _userInfoRepo.Updateable()
-                .SetColumns(m => m.InvitationCode, inviteLog.InviteCode)
-                .Where(m => m.Id == userId)
-                .ExecuteCommandAsync(token);
-        }
+        var inviteCode = source.Adapt<InviteCode>();
+        var url = ConfigurationManager.AppSettings["ZiGongFile"] + inviteCode.QRCodeUrl;
+        var fileContent = await new FileTools().GetNetworkFileAsync(url, token);
+        inviteCode.QRCodeUrl = fileContent.Path;
+        return inviteCode;
     }
 }

+ 78 - 0
SnapshotWinFormsApp/Application/InviteLogApplication.cs

@@ -0,0 +1,78 @@
+using Abp.Collections.Extensions;
+using Hotline.Snapshot;
+using Mapster;
+using Newtonsoft.Json.Linq;
+using SnapshotWinFormsApp.Application.Dtos;
+using SnapshotWinFormsApp.Application.Interfaces;
+using SnapshotWinFormsApp.Entities.NewHotline;
+using SnapshotWinFormsApp.Entities.OldHotline;
+using SnapshotWinFormsApp.Repository;
+using SnapshotWinFormsApp.Repository.Interfaces;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Linq.Dynamic.Core.Tokenizer;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SnapshotWinFormsApp.Application;
+
+[Description("邀请码记录")]
+public class InviteLogApplication : ImportApplicationBase<SSP_InviteLogEntity, InviteCodeRecord, string, OldInviteLogEntity>, IImportApplication
+{
+    private readonly IBaseRepository<InviteCode> _newInviteCodeRepo;
+    private readonly IBaseRepository<InviteCodeRecord> _newInviteLogRepo;
+    private readonly IBaseRepository<SnapshotUserInfo> _userInfoRepo;
+    private readonly IBaseRepository<ThirdAccount> _thirdAccountRepo;
+    private IList<InviteCode> invities;
+    private IList<ThirdAccount> thirdAccounts;
+
+    public InviteLogApplication(CreateInstanceInDto inDto) : base(inDto)
+    {
+        _newInviteCodeRepo = new BaseRepository<InviteCode>(inDto);
+        _thirdAccountRepo = new BaseRepository<ThirdAccount>(inDto);
+        invities = _newInviteCodeRepo.GetAll();
+        thirdAccounts = _thirdAccountRepo.GetAll();
+    }
+
+    public override ISugarQueryable<OldInviteLogEntity> GetSourceList(CreateInstanceInDto inDto)
+    {
+        return _sugarClient.Queryable<SSP_InviteLogEntity>()
+            .LeftJoin<SSP_InviteEntity>((log, invite) => log.SSPI_CodeID == invite.SIC_Byte)
+            .LeftJoin<WeChatUserEntity>((log, invite, user) => user.WUR_Openid == log.SSPI_Openid)
+            .Select((log, invite, user) => new OldInviteLogEntity
+            {
+                Id = log.Id,
+                Name = user.WUR_WebUserName,
+                OrgName = invite.SIC_BMName,
+                InviteCode = log.SSPI_Code,
+                WXOpenId = log.SSPI_Openid,
+                PhoneNumber = user.WUR_PhoneNum,
+            });
+    }
+
+    public override async Task<bool> HasOldDataAsync(string tableName, OldInviteLogEntity item, CancellationToken token)
+    {
+        return await _newInviteLogRepo.Queryable().AnyAsync(m => m.Id == item.Id, token);
+    }
+
+    public override async Task<InviteCodeRecord> GetTargetAsync(OldInviteLogEntity source, CancellationToken token)
+    {
+        var target = source.Adapt<InviteCodeRecord>();
+        target.OrgId = invities.FirstOrDefault(m => m.OrgName == source.OrgName)?.Id ?? string.Empty;
+        return await Task.FromResult(target);
+    }
+
+    public override async Task InsertAfterAsync(Action<string> log,  OldInviteLogEntity item, InviteCodeRecord target, CancellationToken token)
+    {
+        var userId = thirdAccounts.Where(m => m.OpenId == item.WXOpenId).Select(m => m.ExternalId).FirstOrDefault();
+        if (userId.IsNullOrEmpty()) return;
+
+        await _userInfoRepo.Updateable()
+                 .SetColumns(m => m.InvitationCode, item.InviteCode)
+                 .Where(m => m.Id == userId)
+                 .ExecuteCommandAsync(token);
+    }
+}

+ 24 - 80
SnapshotWinFormsApp/Application/SnapshotUserInfoApplication.cs

@@ -8,6 +8,7 @@ using SnapshotWinFormsApp.Entities.OldHotline;
 using SnapshotWinFormsApp.Repository;
 using SnapshotWinFormsApp.Repository.Enum;
 using SnapshotWinFormsApp.Repository.Interfaces;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -20,101 +21,44 @@ using System.Xml.Linq;
 namespace SnapshotWinFormsApp.Application;
 
 [Description("导入用户信息")]
-public class SnapshotUserInfoApplication : IImportApplication
+public class SnapshotUserInfoApplication : ImportApplicationBase<WeChatUserEntity, Citizen, int>, IImportApplication
 {
     private readonly IBaseRepository<ThirdAccount> _thirdAccountRepo;
-    private readonly IRepository<WeChatUserEntity, int> _weChatRepo;
-    private readonly IRepository<WeChatFollowUserEntity, int> _weChatFlowRepo;
     private readonly IBaseRepository<Citizen> _userRepo;
-    private readonly IRepository<Flow03_PushContent, int> _pushContentRepo;
 
-    public SnapshotUserInfoApplication(CreateInstanceInDto inDto)
+    public SnapshotUserInfoApplication(CreateInstanceInDto inDto) : base(inDto)
     {
         _thirdAccountRepo = new BaseRepository<ThirdAccount>(inDto);
-        _weChatRepo = new Repository<WeChatUserEntity, int>(inDto);
-        _weChatFlowRepo = new Repository<WeChatFollowUserEntity, int>(inDto);
         _userRepo = new BaseRepository<Citizen>(inDto);
-        _pushContentRepo = new Repository<Flow03_PushContent, int>(inDto);
     }
 
-    public async Task ImportAsync(Action<string> log, CancellationToken token)
+    public override ISugarQueryable<WeChatUserEntity> GetSourceList()
     {
-        await ImportSnapshotUserInfoAsync(log, token);
-        log($"正在查询旧数据...");
-        var guiderOldItems = await _pushContentRepo.Queryable()
-            .Where(m => m.MemberMobile != null && m.MemberName != null)
-            .GroupBy(m => new { m.MemberName, m.MemberMobile })
-            .Select(m => new { m.MemberName, m.MemberMobile })
-            .ToListAsync(token);
+        return _sourceRepo.Queryable()
+            .Where(m => m.WUR_UserType == "ssp");
+    }
 
-        log($"共查询到{guiderOldItems.Count}条数据");
-        for (int i = 0;i < guiderOldItems.Count;i++)
-        {
-            var item = guiderOldItems[i];
-            if (token.IsCancellationRequested)
-            {
-                log("任务已取消");
-                return;
-            }
-            var userId = await _userRepo.Queryable()
-                .Where(m => m.PhoneNumber == item.MemberMobile)
-                .Select(m => m.Id)
-                .FirstAsync(token);
-            if (userId.IsNullOrEmpty())
-            {
-                var userInfo = new Citizen
-                {
-                    PhoneNumber = item.MemberMobile.Replace("\t", ""),
-                    Name = item.MemberName.Replace("\t", ""),
-                };
-                userInfo.CitizenType = EReadPackUserType.Guider;
-                userInfo.IdentityType = EIdentityType.Citizen;
-                userId = await _userRepo.InsertAsync(userInfo, token);
-                log($"{i}/{guiderOldItems.Count} 插入用户信息: {userId}, {userInfo.Name}, {userInfo.PhoneNumber}");
-            }
-        }
+    public override async Task<bool> HasOldDataAsync(string tableName, WeChatUserEntity item, CancellationToken token)
+    {
+        var userId = await _userRepo.Queryable()
+            .Where(m => m.PhoneNumber == item.WUR_PhoneNum)
+            .Select(m => m.Id)
+            .FirstAsync(token);
+        return userId.IsNullOrEmpty();
     }
 
-    public async Task ImportSnapshotUserInfoAsync(Action<string> log, CancellationToken token)
+    public override async Task InsertAfterAsync(Action<string> log, WeChatUserEntity item, Citizen target, CancellationToken token)
     {
-        log($"正在查询旧数据...");
-        var items = await _weChatRepo.Queryable()
-            .Where(m => m.WUR_UserType == "ssp")
-            .ToListAsync(token);
-        log($"共查询到{items.Count}条数据");
-        var totalCount = items.Count;
-        var index = 0;
-        foreach (var item in items)
+        var thirdId = await _thirdAccountRepo.Queryable()
+            .Where(m => m.OpenId == item.WUR_Openid && m.UnIonId == item.WUR_unionid)
+            .Select(m => m.Id)
+            .FirstAsync(token);
+        if (thirdId.IsNullOrEmpty())
         {
-            index++;
-            if (token.IsCancellationRequested)
-            {
-                log("任务已取消");
-                return;
-            }
-            var userId = await _userRepo.Queryable()
-                .Where(m => m.PhoneNumber == item.WUR_PhoneNum)
-                .Select(m => m.Id)
-                .FirstAsync(token);
-            if (userId.IsNullOrEmpty())
-            {
-                var userInfo = item.Adapt<Citizen>();
-                userInfo.CitizenType = EReadPackUserType.Citizen;
-                userInfo.IdentityType = EIdentityType.Citizen;
-                userId = await _userRepo.InsertAsync(userInfo, token);
-                log($"{index}/{totalCount} 插入用户信息: {userId}, {userInfo.Name}, {userInfo.PhoneNumber}");
-            }
-            var thirdId = await _thirdAccountRepo.Queryable()
-                .Where(m => m.OpenId == item.WUR_Openid && m.UnIonId == item.WUR_unionid)
-                .Select(m => m.Id)
-                .FirstAsync(token);
-            if (thirdId.IsNullOrEmpty())
-            {
-                var thirdAccount = item.Adapt<ThirdAccount>();
-                thirdAccount.ExternalId = userId;
-                thirdAccount.Id = await _thirdAccountRepo.InsertAsync(thirdAccount, token);
-                log($"{index}/{totalCount} 插入第三方账号信息: {thirdAccount.Id}, {thirdAccount.OpenId}, {thirdAccount.UserName}, {thirdAccount.PhoneNumber}, {thirdAccount.ExternalId}");
-            }
+            var thirdAccount = item.Adapt<ThirdAccount>();
+            thirdAccount.ExternalId = target.Id;
+            thirdAccount.Id = await _thirdAccountRepo.InsertAsync(thirdAccount, token);
+            log($"插入第三方账号信息: {thirdAccount.Id}, {thirdAccount.OpenId}, {thirdAccount.UserName}, {thirdAccount.PhoneNumber}, {thirdAccount.ExternalId}");
         }
     }
 }

+ 2 - 1
SnapshotWinFormsApp/Entities/NewHotline/InviteCodeRecord.cs

@@ -1,4 +1,5 @@
-using SqlSugar;
+using SnapshotWinFormsApp.Entities.OldHotline;
+using SqlSugar;
 using System.ComponentModel;
 
 namespace SnapshotWinFormsApp.Entities.NewHotline;

+ 11 - 0
SnapshotWinFormsApp/Entities/OldHotline/OldInviteCodeRecord.cs

@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SnapshotWinFormsApp.Entities.OldHotline;
+
+public class OldInviteCodeRecord : OldBaseEntity<int>
+{
+}

+ 1 - 1
SnapshotWinFormsApp/Entities/OldHotline/SSP_AreaEntity.cs

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
 namespace SnapshotWinFormsApp.Entities.OldHotline;
 
 [SugarTable("ZG_CityHotline_Ver3.dbo.SSP_Area")]
-public class SSP_AreaEntity :OldBaseEntity<int>
+public class SSP_AreaEntity : OldBaseEntity<int>
 {
     [SugarColumn(ColumnName = "S_ID")]
     public override int Id {get;set;}

+ 39 - 0
SnapshotWinFormsApp/Entities/OldHotline/SSP_InviteLogEntity.cs

@@ -20,3 +20,42 @@ public class SSP_InviteLogEntity: OldBaseEntity<string>
     public string SSPI_CodeID { get; set; }
     public int SSPI_Type { get; set; }
 }
+
+public class OldInviteLogEntity : OldBaseEntity<string>
+{
+    /// <summary>
+    /// 部门Id
+    /// </summary>
+    [SugarColumn(ColumnDescription = "部门Id")]
+    public string OrgId { get; set; }
+
+    /// <summary>
+    /// 部门名称
+    /// </summary>
+    [SugarColumn(ColumnDescription = "部门名称")]
+    public string OrgName { get; set; }
+
+    /// <summary>
+    /// 邀请码
+    /// </summary>
+    [SugarColumn(ColumnDescription = "邀请码")]
+    public string InviteCode { get; set; }
+
+    /// <summary>
+    /// 微信OpenId
+    /// </summary>
+    [SugarColumn(ColumnDescription = "微信OpenId")]
+    public string WXOpenId { get; set; }
+
+    /// <summary>
+    /// 电话
+    /// </summary>
+    [SugarColumn(ColumnDescription = "电话")]
+    public string PhoneNumber { get; set; }
+
+    /// <summary>
+    /// 姓名
+    /// </summary>
+    [SugarColumn(ColumnDescription = "姓名")]
+    public string? Name { get; set; }
+}

+ 12 - 4
SnapshotWinFormsApp/Repository/BaseRepository.cs

@@ -20,8 +20,10 @@ public class ConcurrentQueueRepository<TEntity> where TEntity : Entity, new()
     public void Insert(TEntity entity, ISqlSugarClient sugarClient, bool isEnd)
     {
         _queue.Enqueue(entity);
-        if (_queue.Count != 1000 && isEnd == false) return;
-        sugarClient.Fastest<TEntity>().BulkCopy(_queue.ToList());
+        if (_queue.Count != 100 && isEnd == false) return;
+        sugarClient.Ado.BeginTran();
+        sugarClient.Insertable(_queue.ToList()).ExecuteCommand();
+        sugarClient.Ado.CommitTran();
         _queue.Clear();
     }
 }
@@ -41,9 +43,9 @@ public class BaseRepository<T> : IBaseRepository<T> where T : Entity, new()
         _queue = new ConcurrentQueueRepository<T>();
     }
 
-    public async Task<List<T>> GetAllAsync(CancellationToken token)
+    public async Task<IList<T>> GetAllAsync(CancellationToken token)
     {
-        return _db.Queryable<T>().ToList();
+        return await _db.Queryable<T>().ToListAsync(token);
     }
 
     public T GetById(int id)
@@ -87,4 +89,10 @@ public class BaseRepository<T> : IBaseRepository<T> where T : Entity, new()
         _queue.Insert(entity,_db, isEnd);
         return entity.Id;
     }
+
+    public IList<T> GetAll()
+    {
+        return _db.Queryable<T>().ToList();
+
+    }
 }

+ 2 - 1
SnapshotWinFormsApp/Repository/Interfaces/IRepository.cs

@@ -23,11 +23,12 @@ public interface IBaseRepository<T> where T : Entity, new()
     SqlSugarClient db { get; }
     ISugarQueryable<T> Queryable();
     T GetById(int id);
-    Task<List<T>> GetAllAsync(CancellationToken token);
+    Task<IList<T>> GetAllAsync(CancellationToken token);
     Task<string> InsertAsync(T entity, CancellationToken token);
     string InsertBulk(T entity, bool isEnd);
     void Update(T entity);
     IUpdateable<T> Updateable();
     Task<int> ExecuteSqlAsync(string sql);
     DataTable GetDataTable(string sql);
+    IList<T> GetAll();
 }