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; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SnapshotWinFormsApp.Application; [Description("导入社区信息")] public class CommunityInfoApplication : IImportApplication { private readonly IBaseRepository _communityInfoRepo; private readonly IRepository _areaRepo; public CommunityInfoApplication(CreateInstanceInDto inDto) { _communityInfoRepo = new BaseRepository(inDto); _areaRepo = new Repository(inDto); } public async Task ImportAsync(Action 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(); 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}"); } } }