123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using Abp.Extensions;
- using DataTransmission.Enum;
- using Mapster;
- 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.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml.Linq;
- namespace SnapshotWinFormsApp.Application;
- [Description("微信用户和网格员")]
- public class SnapshotUserInfoApplication : ImportApplicationBase<WeChatUserEntity, Citizen>, IImportApplication
- {
- private readonly ITargetRepository<ThirdAccount> _thirdAccountRepo;
- private readonly ITargetRepository<Citizen> _userRepo;
- private readonly IList<Citizen> Users;
- private readonly IList<Flow03_PushContentDto> Guiders;
- private readonly IList<SSP_InviteLogEntity> InviteLogs;
- private readonly ITargetRepository<InviteCodeRecord> _inviteCodeRecordRepository;
- public SnapshotUserInfoApplication(CreateInstanceInDto inDto) : base(inDto)
- {
- _inviteCodeRecordRepository = new TargetRepository<InviteCodeRecord>(inDto);
- _thirdAccountRepo = new TargetRepository<ThirdAccount>(inDto);
- _userRepo = new TargetRepository<Citizen>(inDto);
- Users = _userRepo.GetAll();
- Guiders = new SourceRepository<Flow03_PushContent>(inDto).Queryable()
- .Where(m => m.MemberMobile != null && m.MemberName != null)
- .Select(m => new Flow03_PushContentDto(), true)
- .Distinct().ToList();
- InviteLogs = new SourceRepository<SSP_InviteLogEntity>(inDto).Queryable()
- .ToList();
- }
- public override async Task<Citizen> GetTargetAsync(WeChatUserEntity source, CancellationToken token)
- {
- var target = source.Adapt<Citizen>();
- target.InitId();
- target.OldId = source.Id;
- var guider = Guiders.Where(m => m.MemberMobile == target.PhoneNumber).FirstOrDefault();
- target.CitizenType = EReadPackUserType.Citizen;
- if (guider != null)
- {
- target.CitizenType = EReadPackUserType.Guider;
- target.LastModificationName = guider.MemberName;
- }
- var code = InviteLogs.Where(m => m.SSPI_Openid == source.WUR_Openid).FirstOrDefault();
- if (code != null)
- target.InvitationCode = code.SSPI_Code;
- return target;
- }
- public override ISugarQueryable<WeChatUserEntity> GetSourceList(string key = "")
- {
- return _sourceRepo.Queryable()
- .Where(m => m.WUR_UserType == "ssp")
- .WhereIF(_instance.Keyword.NotNullOrEmpty(), m => m.WUR_PhoneNum == _instance.Keyword)
- .WhereIF(key.NotNullOrEmpty(), m => m.WUR_Openid == key);
- }
- public override async Task<bool> HasOldDataAsync(WeChatUserEntity item, CancellationToken token)
- {
- var userId = Users
- .Where(m => m.PhoneNumber == item.WUR_PhoneNum)
- .Select(m => m.Id).FirstOrDefault();
- return userId.NotNullOrEmpty();
- }
- public override async Task<ThirdAccount> InsertAfterAsync(Action<string> log, WeChatUserEntity item, Citizen target, bool isEnd, CancellationToken token)
- {
- 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.InitId();
- thirdAccount.ExternalId = target.Id;
- if (thirdAccount.OpenId.IsNullOrEmpty())
- { log?.Invoke("openid为空"); return null; }
- thirdAccount.Id = _thirdAccountRepo.InsertBulk(thirdAccount, isEnd);
- return thirdAccount;
- }
- return null;
- }
- public async Task<IList<ThirdAccount>> InsertByOpenIdAsync(Action<string> log, string key, CancellationToken token)
- {
- var thirdAccountList = new List<ThirdAccount>();
- var oldUser = await GetSourceList(key).ToListAsync(token);
- for (int i = 0;i < oldUser.Count;i++)
- {
- var user = oldUser[i];
- var newUser = await GetTargetAsync(user, token);
- newUser.InitId();
- _targetRepo.InsertBulk(newUser, true);
- var th= await InsertAfterAsync(log, user, newUser, true, token);
- if (th != null) thirdAccountList.Add(th);
- }
- return thirdAccountList;
- }
- }
|