12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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<CommunityInfo> _communityInfoRepo;
- private readonly IRepository<SSP_AreaEntity, int> _areaRepo;
- public CommunityInfoApplication(CreateInstanceInDto 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}");
- }
- }
- }
|