123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using Abp.Collections.Extensions;
- using Hotline.Snapshot;
- using Mapster;
- using SnapshotWinFormsApp.Application.Dtos;
- using SnapshotWinFormsApp.Application.Interfaces;
- using SnapshotWinFormsApp.Entities.NewHotline;
- using SnapshotWinFormsApp.Entities.OldHotline;
- using SnapshotWinFormsApp.Repository;
- using SnapshotWinFormsApp.Repository.Interfaces;
- using SnapshotWinFormsApp.Tools;
- using System.ComponentModel;
- using System.Configuration;
- namespace SnapshotWinFormsApp.Application;
- [Description("邀请码")]
- public class InviteApplication : 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)
- {
- _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)
- {
- 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);
- }
- }
- }
|