qinchaoyue 4 minggu lalu
induk
melakukan
fffcd60026

+ 2 - 2
SnapshotWinFormsApp/Application/GriderApplication.cs

@@ -20,11 +20,11 @@ namespace SnapshotWinFormsApp.Application;
 [Description("导入网格员")]
 public class GriderApplication : ImportApplicationBase<Flow03_PushContent, Citizen, int>, IImportApplication
 {
-    private readonly IBaseRepository<Citizen> _userRepo;
+    private readonly ITargetRepository<Citizen> _userRepo;
 
     public GriderApplication(CreateInstanceInDto inDto) : base(inDto)
     {
-        _userRepo = new BaseRepository<Citizen>(inDto);
+        _userRepo = new TargetRepository<Citizen>(inDto);
     }
 
     public override ISugarQueryable<Flow03_PushContent> GetSourceList()

+ 13 - 16
SnapshotWinFormsApp/Application/Interfaces/ImportApplicationBase.cs

@@ -1,16 +1,18 @@
-using Mapster;
+using Abp.Json;
+using Mapster;
 using SnapshotWinFormsApp.Application.Dtos;
 using SnapshotWinFormsApp.Entities.NewHotline;
 using SnapshotWinFormsApp.Entities.OldHotline;
 using SnapshotWinFormsApp.Repository;
 using SnapshotWinFormsApp.Repository.Interfaces;
+using SnapshotWinFormsApp.Tools;
 using SqlSugar;
 using System.Reflection;
 
 namespace SnapshotWinFormsApp.Application.Interfaces;
 public class ImportApplicationBase<TSource, TEntity, TKey> : ImportApplicationBase<TSource, TEntity, TKey, TSource>
     where TSource : OldBaseEntity<TKey>, new()
-    where TEntity : Entity, new()
+    where TEntity : OldIdEntity, new()
 {
     public ImportApplicationBase(CreateInstanceInDto inDto) : base(inDto)
     {
@@ -19,20 +21,18 @@ public class ImportApplicationBase<TSource, TEntity, TKey> : ImportApplicationBa
 
 public class ImportApplicationBase<TSource, TEntity, TKey, TMix> : IImportApplication
     where TSource : OldBaseEntity<TKey>, new()
-    where TEntity : Entity, new()
+    where TEntity : OldIdEntity, new()
     where TMix : OldBaseEntity<TKey>, new()
 {
-    public readonly IRepository<TMix, TKey> _sourceRepo;
-    public readonly IBaseRepository<TEntity> _targetRepo;
-    public readonly IBaseRepository<OldDataId> _oldDataIdRepo;
+    public readonly ISourceRepository<TMix, TKey> _sourceRepo;
+    public readonly ITargetRepository<TEntity> _targetRepo;
     public readonly SqlSugarClient _sugarClient;
     public readonly CreateInstanceInDto _instance;
     public ImportApplicationBase(CreateInstanceInDto inDto)
     {
         _instance = inDto;
-        _sourceRepo = new Repository<TMix, TKey>(inDto);
-        _targetRepo = new BaseRepository<TEntity>(inDto);
-        _oldDataIdRepo = new BaseRepository<OldDataId>(inDto);
+        _sourceRepo = new SourceRepository<TMix, TKey>(inDto);
+        _targetRepo = new TargetRepository<TEntity>(inDto);
     }
 
     public async Task ImportAsync(Action<string> log, CancellationToken token)
@@ -50,12 +50,10 @@ public class ImportApplicationBase<TSource, TEntity, TKey, TMix> : IImportApplic
             var has = await HasOldDataAsync(tableName, item, token);
             if (has) continue;
             var target = await GetTargetAsync(item, token);
+            target.OldId = item.Id.ToString();
 
-            await _targetRepo.db.Ado.BeginTranAsync();
             target.Id = _targetRepo.InsertBulk(target, i + 1 == items.Count);
-            _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}");
+            log($"{i + 1}/{items.Count} 插入数据: {item.Id} {target.Id} {target.ToJson().Substring(0, 100)}");
             await InsertAfterAsync(log, item, target, token);
         }
     }
@@ -80,7 +78,7 @@ public class ImportApplicationBase<TSource, TEntity, TKey, TMix> : IImportApplic
     /// <returns></returns>
     public virtual ISugarQueryable<TMix> GetSourceList(CreateInstanceInDto inDto)
     {
-        return _sourceRepo.Queryable();
+        return _sourceRepo.Queryable().Where(m => m.CreationTime >= inDto.StartTime && m.CreationTime <= inDto.EndTime);
     }
 
     /// <summary>
@@ -111,7 +109,6 @@ public class ImportApplicationBase<TSource, TEntity, TKey, TMix> : IImportApplic
     /// <returns></returns>
     public virtual async Task<bool> HasOldDataAsync(string tableName, TMix item, CancellationToken token)
     {
-        return await _oldDataIdRepo.Queryable().AnyAsync(m => m.TableName == tableName && item.Id.ToString() == m.OldId, token);
+        return await _targetRepo.Queryable().AnyAsync(m => item.Id.ToString() == m.OldId, token);
     }
-
 }

+ 6 - 6
SnapshotWinFormsApp/Application/InviteLogApplication.cs

@@ -22,17 +22,17 @@ 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 readonly ITargetRepository<InviteCode> _newInviteCodeRepo;
+    private readonly ITargetRepository<InviteCodeRecord> _newInviteLogRepo;
+    private readonly ITargetRepository<Citizen> _userInfoRepo;
+    private readonly ITargetRepository<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);
+        _newInviteCodeRepo = new TargetRepository<InviteCode>(inDto);
+        _thirdAccountRepo = new TargetRepository<ThirdAccount>(inDto);
         invities = _newInviteCodeRepo.GetAll();
         thirdAccounts = _thirdAccountRepo.GetAll();
     }

+ 14 - 14
SnapshotWinFormsApp/Application/OrderSnapshotApplication.cs

@@ -25,32 +25,32 @@ namespace SnapshotWinFormsApp.Application;
 [Description("随手拍工单")]
 public class OrderSnapshotApplication : IImportApplication
 {
-    private readonly IBaseRepository<OrderSnapshot> _orderSnapshotRepo;
-    private readonly IRepository<Flow03_SearchEntity, int> _oldOrderRepo;
+    private readonly ITargetRepository<OrderSnapshot> _orderSnapshotRepo;
+    private readonly ISourceRepository<Flow03_SearchEntity, int> _oldOrderRepo;
     private readonly DbSqlServer _dbSqlServer;
     private Config config = new Config();
-    private readonly IBaseRepository<SnapshotUserInfo> _snapshotUserInfoRepo;
-    private readonly IBaseRepository<Industry> _industryRepo;
+    private readonly ITargetRepository<Citizen> _snapshotUserInfoRepo;
+    private readonly ITargetRepository<Industry> _industryRepo;
     private readonly List<Industry> industries;
-    private readonly IBaseRepository<CommunityInfo> _communityInfoRepo;
+    private readonly ITargetRepository<CommunityInfo> _communityInfoRepo;
     private readonly List<CommunityInfo> communityInfos;
-    private readonly IBaseRepository<Entities.NewHotline.User> _userRepo;
+    private readonly ITargetRepository<Entities.NewHotline.User> _userRepo;
     private readonly List<Entities.NewHotline.User> _users;
-    private readonly IBaseRepository<SystemDicData> _systemDicDataRepo;
+    private readonly ITargetRepository<SystemDicData> _systemDicDataRepo;
     private readonly List<SystemDicData> snapshotOrderLabels;
     public OrderSnapshotApplication(CreateInstanceInDto inDto)
     {
         _dbSqlServer = inDto.DbSqlServer;
-        _orderSnapshotRepo = new BaseRepository<OrderSnapshot>(inDto);
-        _oldOrderRepo = new Repository<Flow03_SearchEntity, int>(inDto);
-        _snapshotUserInfoRepo = new BaseRepository<SnapshotUserInfo>(inDto);
-        _industryRepo = new BaseRepository<Industry>(inDto);
+        _orderSnapshotRepo = new TargetRepository<OrderSnapshot>(inDto);
+        _oldOrderRepo = new SourceRepository<Flow03_SearchEntity, int>(inDto);
+        _snapshotUserInfoRepo = new TargetRepository<Citizen>(inDto);
+        _industryRepo = new TargetRepository<Industry>(inDto);
         industries = _industryRepo.Queryable().ToList();
-        _communityInfoRepo = new BaseRepository<CommunityInfo>(inDto);
+        _communityInfoRepo = new TargetRepository<CommunityInfo>(inDto);
         communityInfos = _communityInfoRepo.Queryable().ToList();
-        _userRepo = new BaseRepository<Entities.NewHotline.User>(inDto);
+        _userRepo = new TargetRepository<Entities.NewHotline.User>(inDto);
         _users = _userRepo.Queryable().ToList();
-        _systemDicDataRepo = new BaseRepository<SystemDicData>(inDto);
+        _systemDicDataRepo = new TargetRepository<SystemDicData>(inDto);
         snapshotOrderLabels = _systemDicDataRepo.Queryable().Where(m => m.DicTypeCode == "SnapshotOrderLabel").ToList();
 
         config.Name = "自贡市";

+ 13 - 7
SnapshotWinFormsApp/Application/PractitionerApplication.cs

@@ -1,24 +1,30 @@
-using DataTransmission.Enum;
+using Hotline.Settings;
+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 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 PractitionerApplication : ImportApplicationBase<SSP_AreaUserEntity, Practitioner, string>, IImportApplication
 {
+    private readonly ISelectRepository<SystemArea> _systemAreaRepo;
+    private IList<SystemArea> areas;
     public PractitionerApplication(CreateInstanceInDto inDto) : base(inDto)
     {
+        _systemAreaRepo = new SelectRepository<SystemArea>(inDto);
+        areas = _systemAreaRepo.GetAll();
+    }
+
+    public override async Task<Practitioner> GetTargetAsync(SSP_AreaUserEntity source, CancellationToken token)
+    {
+        var target = source.Adapt<Practitioner>();
+        target.SystemAreaId = areas.FirstOrDefault(m => m.AreaName == source.AreaName)?.Id ?? string.Empty;
+        return await Task.FromResult(target);
     }
 }

+ 4 - 4
SnapshotWinFormsApp/Application/SnapshotUserInfoApplication.cs

@@ -23,13 +23,13 @@ namespace SnapshotWinFormsApp.Application;
 [Description("导入用户信息")]
 public class SnapshotUserInfoApplication : ImportApplicationBase<WeChatUserEntity, Citizen, int>, IImportApplication
 {
-    private readonly IBaseRepository<ThirdAccount> _thirdAccountRepo;
-    private readonly IBaseRepository<Citizen> _userRepo;
+    private readonly ITargetRepository<ThirdAccount> _thirdAccountRepo;
+    private readonly ITargetRepository<Citizen> _userRepo;
 
     public SnapshotUserInfoApplication(CreateInstanceInDto inDto) : base(inDto)
     {
-        _thirdAccountRepo = new BaseRepository<ThirdAccount>(inDto);
-        _userRepo = new BaseRepository<Citizen>(inDto);
+        _thirdAccountRepo = new TargetRepository<ThirdAccount>(inDto);
+        _userRepo = new TargetRepository<Citizen>(inDto);
     }
 
     public override ISugarQueryable<WeChatUserEntity> GetSourceList()

+ 0 - 24
SnapshotWinFormsApp/Entities/NewHotline/OldDataId.cs

@@ -1,24 +0,0 @@
-using SqlSugar;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.IO.Pipes;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SnapshotWinFormsApp.Entities.NewHotline;
-
-[Description("老数据Id")]
-[SugarTable("old_data_id")]
-public class OldDataId : SoftDeleteEntity
-{
-    [Description("旧数据Id")]
-    public string OldId { get; set; }
-
-    [Description("表明")]
-    public string TableName { get; set; }
-
-    [Description("新数据Id")]
-    public string NewId { get; set; }
-}

+ 11 - 2
SnapshotWinFormsApp/Entities/NewHotline/Base.cs → SnapshotWinFormsApp/Entities/NewHotline/OldIdBase.cs

@@ -5,8 +5,17 @@ using DataTransmission.Entity;
 
 namespace SnapshotWinFormsApp.Entities.NewHotline
 {
+	public class OldIdEntity : Entity
+	{
+        /// <summary>
+        /// 旧系统的Id
+        /// </summary>
+        public string OldId { get; set; }
+    }
+
 	public class Entity
 	{
+
 		//private List<IAppNotification> _domainEvents = new();
 
 		public string Id { get; set; }
@@ -40,7 +49,7 @@ namespace SnapshotWinFormsApp.Entities.NewHotline
 	/// <summary>
 	/// 实体(带有创建时间)
 	/// </summary>
-	public abstract class CreationEntity : Entity, IHasCreationTime
+	public abstract class CreationEntity : OldIdEntity, IHasCreationTime
 	{
 		/// <summary>
 		/// 创建时间
@@ -52,7 +61,7 @@ namespace SnapshotWinFormsApp.Entities.NewHotline
 	/// <summary>
 	/// 实体(带有软删除)
 	/// </summary>
-	public abstract class SoftDeleteEntity : Entity, IHasDeletionTime, ISoftDelete
+	public abstract class SoftDeleteEntity : OldIdEntity, IHasDeletionTime, ISoftDelete
 	{
 		/// <summary>
 		/// 删除时间

+ 0 - 40
SnapshotWinFormsApp/Entities/NewHotline/SnapshotUserInfo.cs

@@ -1,40 +0,0 @@
-using SnapshotWinFormsApp.Repository.Enum;
-using SqlSugar;
-using System.ComponentModel;
-using System.ComponentModel.DataAnnotations.Schema;
-
-namespace SnapshotWinFormsApp.Entities.NewHotline;
-
-/// <summary>
-/// 网格员和普通随手拍人员信息
-/// </summary>
-[SugarTable("snapshot_user_info")]
-[Description("随手拍用户信息")]
-public class SnapshotUserInfo : CreationSoftDeleteEntity
-{
-    /// <summary>
-    /// 用户自己填的邀请码
-    /// </summary>
-    public string? InvitationCode { get; set; }
-
-    /// <summary>
-    /// 历史已经领取金额总和(单位:元)
-    /// </summary>
-    public double TotalAmount { get; set; }
-
-    /// <summary>
-    /// 用户类型
-    /// 注册时根据手机号码判断是否是 网格员
-    /// </summary>
-    public EReadPackUserType CitizenType { get; set; }
-
-    /// <summary>
-    /// 姓名
-    /// </summary>
-    public string? Name { get; set; }
-
-    /// <summary>
-    /// 电话号码
-    /// </summary>
-    public string? PhoneNumber { get; set; }
-}

+ 52 - 0
SnapshotWinFormsApp/Entities/NewHotline/SystemArea.cs

@@ -0,0 +1,52 @@
+using DataTransmission.Entity;
+using SqlSugar;
+
+namespace Hotline.Settings
+{
+    [SugarTable("system_area")]
+    public class SystemArea: CreationSoftDeleteEntity
+    {
+        /// <summary>
+        /// 区域名称
+        /// </summary>
+        public string AreaName { get; set; }
+
+        /// <summary>
+        /// 上级ID
+        /// </summary>
+        [SugarColumn(IsNullable = true)]
+        public string ParentId { get; set; }
+
+        /// <summary>
+        /// 简称
+        /// </summary>
+        public string AreaNameAbbreviation { get; set; }
+
+        /// <summary>
+        /// 是否可以修改
+        /// </summary>
+        [SugarColumn(DefaultValue = "f")]
+        public bool IsCanModify { get; set; }
+
+
+        [SugarColumn(IsIgnore = true)]
+        public List<SystemArea> Children { get; set; }
+
+    }
+
+    public static class AreaExtensions
+    {
+        /// <summary>
+        /// 获取最末级区域对应编码(最后2位)
+        /// </summary>
+        /// <param name="areaCode"></param>
+        /// <returns></returns>
+        /// <exception cref="UserFriendlyException"></exception>
+        public static string GetLastAreaCode(this string areaCode)
+        {
+            if (areaCode.Length < 6)
+                throw new Exception("非法区域编码");
+            return areaCode.Substring(areaCode.Length - 2, 2);
+        }
+    }
+}

+ 19 - 23
SnapshotWinFormsApp/MainForm.Designer.cs

@@ -51,20 +51,18 @@ partial class MainForm
         logTxt.Font = new Font("Courier New", 12F, FontStyle.Bold, GraphicsUnit.Point);
         logTxt.ForeColor = Color.LimeGreen;
         logTxt.Location = new Point(0, 0);
-        logTxt.Margin = new Padding(3, 4, 3, 4);
         logTxt.Multiline = true;
         logTxt.Name = "logTxt";
         logTxt.ScrollBars = ScrollBars.Vertical;
-        logTxt.Size = new Size(823, 701);
+        logTxt.Size = new Size(689, 526);
         logTxt.TabIndex = 1;
         // 
         // CancelBtn
         // 
         CancelBtn.Dock = DockStyle.Fill;
-        CancelBtn.Location = new Point(128, 482);
-        CancelBtn.Margin = new Padding(3, 4, 3, 4);
+        CancelBtn.Location = new Point(128, 362);
         CancelBtn.Name = "CancelBtn";
-        CancelBtn.Size = new Size(119, 215);
+        CancelBtn.Size = new Size(119, 161);
         CancelBtn.TabIndex = 0;
         CancelBtn.Text = "停止任务";
         CancelBtn.UseVisualStyleBackColor = true;
@@ -76,7 +74,6 @@ partial class MainForm
         splitContainer1.FixedPanel = FixedPanel.Panel1;
         splitContainer1.IsSplitterFixed = true;
         splitContainer1.Location = new Point(0, 0);
-        splitContainer1.Margin = new Padding(3, 4, 3, 4);
         splitContainer1.Name = "splitContainer1";
         // 
         // splitContainer1.Panel1
@@ -87,9 +84,8 @@ partial class MainForm
         // 
         splitContainer1.Panel2.Controls.Add(logTxt);
         splitContainer1.Panel2MinSize = 200;
-        splitContainer1.Size = new Size(1078, 701);
+        splitContainer1.Size = new Size(943, 526);
         splitContainer1.SplitterDistance = 250;
-        splitContainer1.SplitterWidth = 5;
         splitContainer1.TabIndex = 2;
         // 
         // tableLayoutPanel1
@@ -104,13 +100,12 @@ partial class MainForm
         tableLayoutPanel1.Controls.Add(endTimePicker, 1, 1);
         tableLayoutPanel1.Dock = DockStyle.Fill;
         tableLayoutPanel1.Location = new Point(0, 0);
-        tableLayoutPanel1.Margin = new Padding(3, 4, 3, 4);
         tableLayoutPanel1.Name = "tableLayoutPanel1";
         tableLayoutPanel1.RowCount = 3;
         tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 42.27848F));
         tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 57.72152F));
-        tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 222F));
-        tableLayoutPanel1.Size = new Size(250, 701);
+        tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 166F));
+        tableLayoutPanel1.Size = new Size(250, 526);
         tableLayoutPanel1.TabIndex = 1;
         // 
         // cityNameCbox
@@ -118,18 +113,18 @@ partial class MainForm
         cityNameCbox.Dock = DockStyle.Fill;
         cityNameCbox.DropDownStyle = ComboBoxStyle.DropDownList;
         cityNameCbox.FormattingEnabled = true;
-        cityNameCbox.Location = new Point(3, 3);
+        cityNameCbox.Location = new Point(3, 2);
+        cityNameCbox.Margin = new Padding(3, 2, 3, 2);
         cityNameCbox.Name = "cityNameCbox";
-        cityNameCbox.Size = new Size(119, 28);
+        cityNameCbox.Size = new Size(119, 23);
         cityNameCbox.TabIndex = 1;
         // 
         // OkBtn
         // 
         OkBtn.Dock = DockStyle.Fill;
-        OkBtn.Location = new Point(3, 482);
-        OkBtn.Margin = new Padding(3, 4, 3, 4);
+        OkBtn.Location = new Point(3, 362);
         OkBtn.Name = "OkBtn";
-        OkBtn.Size = new Size(119, 215);
+        OkBtn.Size = new Size(119, 161);
         OkBtn.TabIndex = 0;
         OkBtn.Text = "开始导入";
         OkBtn.UseVisualStyleBackColor = true;
@@ -138,27 +133,28 @@ partial class MainForm
         // startTimePicker
         // 
         startTimePicker.Dock = DockStyle.Fill;
-        startTimePicker.Location = new Point(3, 205);
+        startTimePicker.Location = new Point(3, 154);
+        startTimePicker.Margin = new Padding(3, 2, 3, 2);
         startTimePicker.Name = "startTimePicker";
-        startTimePicker.Size = new Size(119, 27);
+        startTimePicker.Size = new Size(119, 23);
         startTimePicker.TabIndex = 2;
         // 
         // endTimePicker
         // 
         endTimePicker.Dock = DockStyle.Fill;
-        endTimePicker.Location = new Point(128, 205);
+        endTimePicker.Location = new Point(128, 154);
+        endTimePicker.Margin = new Padding(3, 2, 3, 2);
         endTimePicker.Name = "endTimePicker";
-        endTimePicker.Size = new Size(119, 27);
+        endTimePicker.Size = new Size(119, 23);
         endTimePicker.TabIndex = 3;
         // 
         // MainForm
         // 
         AcceptButton = OkBtn;
-        AutoScaleDimensions = new SizeF(8F, 20F);
+        AutoScaleDimensions = new SizeF(7F, 15F);
         AutoScaleMode = AutoScaleMode.Font;
-        ClientSize = new Size(1078, 701);
+        ClientSize = new Size(943, 526);
         Controls.Add(splitContainer1);
-        Margin = new Padding(3, 4, 3, 4);
         Name = "MainForm";
         StartPosition = FormStartPosition.CenterScreen;
         Text = "随手拍数据导入";

+ 4 - 0
SnapshotWinFormsApp/MainForm.cs

@@ -107,10 +107,14 @@ public partial class MainForm : Form
             {
                 await Task.WhenAll(tasks);
                 AddLog("所有任务完成");
+                OkBtn.Text = "开始";
+                _startButtonStatus = EButtonStatusType.Start;
             }
             catch (OperationCanceledException)
             {
                 AddLog("任务已取消");
+                OkBtn.Text = "开始";
+                _startButtonStatus = EButtonStatusType.Start;
             }
             return;
         }

+ 26 - 3
SnapshotWinFormsApp/Repository/Interfaces/IRepository.cs → SnapshotWinFormsApp/Repository/Interfaces/ISourceRepository.cs

@@ -1,4 +1,6 @@
-using SnapshotWinFormsApp.Entities.NewHotline;
+using DataTransmission.Entity;
+using Hotline.Settings;
+using SnapshotWinFormsApp.Entities.NewHotline;
 using SnapshotWinFormsApp.Entities.OldHotline;
 using SqlSugar;
 using System;
@@ -10,7 +12,12 @@ using System.Threading.Tasks;
 
 namespace SnapshotWinFormsApp.Repository.Interfaces;
 
-public interface IRepository<T, TKey> where T : OldBaseEntity<TKey>, new()
+/// <summary>
+/// 操作老系统的仓储
+/// </summary>
+/// <typeparam name="T"></typeparam>
+/// <typeparam name="TKey"></typeparam>
+public interface ISourceRepository<T, TKey> where T : OldBaseEntity<TKey>, new()
 {
     ISugarQueryable<T> Queryable();
     T GetById(int id);
@@ -18,7 +25,23 @@ public interface IRepository<T, TKey> where T : OldBaseEntity<TKey>, new()
     DataTable GetDataTable(string sql, List<SugarParameter> parameters = null);
 }
 
-public interface IBaseRepository<T> where T : Entity, new()
+/// <summary>
+/// 操作新系统, 但是不需要插入数据的仓储
+/// </summary>
+/// <typeparam name="T"></typeparam>
+public interface ISelectRepository<T> where T : DataTransmission.Entity.Entity, new()
+{
+    ISugarQueryable<T> Queryable();
+    T GetById(string id);
+    Task<List<T>> GetAllAsync(CancellationToken token);
+    IList<T> GetAll();
+}
+
+/// <summary>
+/// 操作新系统插入的仓储
+/// </summary>
+/// <typeparam name="T"></typeparam>
+public interface ITargetRepository<T> where T : OldIdEntity, new()
 {
     SqlSugarClient db { get; }
     ISugarQueryable<T> Queryable();

+ 43 - 0
SnapshotWinFormsApp/Repository/SelectRepository.cs

@@ -0,0 +1,43 @@
+using SnapshotWinFormsApp.Application.Dtos;
+using SnapshotWinFormsApp.Repository.Interfaces;
+using SqlSugar;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SnapshotWinFormsApp.Repository;
+
+public class SelectRepository<T> : ISelectRepository<T>
+     where T : DataTransmission.Entity.Entity, new()
+{
+    private readonly SqlSugarClient _db;
+
+    public SelectRepository(CreateInstanceInDto inDto)
+    {
+        var context = inDto.DbSqlServer;
+        _db = context.DbItems.GetValueOrDefault(inDto.Key + "PGSQLDB");
+    }
+
+    public IList<T> GetAll()
+    {
+        return _db.Queryable<T>().ToList();
+    }
+
+    public async Task<List<T>> GetAllAsync(CancellationToken token)
+    {
+        return await _db.Queryable<T>().ToListAsync(token);
+    }
+
+    public T GetById(string id)
+    {
+        return _db.Queryable<T>().Where(m => m.Id == id).First();
+    }
+
+    public ISugarQueryable<T> Queryable()
+    {
+        return _db.Queryable<T>();
+    }
+}

+ 2 - 2
SnapshotWinFormsApp/Repository/Repository.cs → SnapshotWinFormsApp/Repository/SourceRepository.cs

@@ -11,11 +11,11 @@ using System.Threading.Tasks;
 
 namespace SnapshotWinFormsApp.Repository;
 
-public class Repository<T, TKey> : IRepository<T, TKey> where T : OldBaseEntity<TKey>, new()
+public class SourceRepository<T, TKey> : ISourceRepository<T, TKey> where T : OldBaseEntity<TKey>, new()
 {
     public SqlSugarClient _db { get; }
 
-    public Repository(CreateInstanceInDto inDto)
+    public SourceRepository(CreateInstanceInDto inDto)
     {
         var context = inDto.DbSqlServer;
         _db = context.DbItems.GetValueOrDefault(inDto.Key + "SQLServerDB");

+ 2 - 2
SnapshotWinFormsApp/Repository/BaseRepository.cs → SnapshotWinFormsApp/Repository/TargetRepository.cs

@@ -29,14 +29,14 @@ public class ConcurrentQueueRepository<TEntity> where TEntity : Entity, new()
 }
 
 
-public class BaseRepository<T> : IBaseRepository<T> where T : Entity, new()
+public class TargetRepository<T> : ITargetRepository<T> where T : OldIdEntity, new()
 {
     private readonly SqlSugarClient _db;
     public readonly ConcurrentQueueRepository<T> _queue;
 
     public SqlSugarClient db => this._db;
 
-    public BaseRepository(CreateInstanceInDto inDto)
+    public TargetRepository(CreateInstanceInDto inDto)
     {
         var context = inDto.DbSqlServer;
         _db = context.DbItems.GetValueOrDefault(inDto.Key + "PGSQLDB");

+ 2 - 0
SnapshotWinFormsApp/Tools/MapsterConfig.cs

@@ -15,6 +15,8 @@ public static class MapsterConfig
         TypeAdapterConfig<SSP_AreaUserEntity, Practitioner>.NewConfig()
             .Map(m => m.CreationTime, n => n.InsertTime.ObjToDate())
             .Map(m => m.PhoneNumber, n => n.Tel)
+            .Map(m => m.Street, n => n.AreaTown)
+            .Map(m => m.SystemAreaName, n => n.AreaName)
             .Map(m => m.Gender, n => n.Sex.Trim() == "男" ? EGender.Male : EGender.Female);
 
         TypeAdapterConfig<WeChatUserEntity, ThirdAccount>.NewConfig()

+ 5 - 0
SnapshotWinFormsApp/Tools/MyExtensions.cs

@@ -10,6 +10,11 @@ namespace SnapshotWinFormsApp.Tools;
 
 public static class MyExtensions
 {
+    public static string ToJson(this object obj)
+    {
+        return obj == null ? default(string) : JsonConvert.SerializeObject(obj);
+    }
+
     public static bool IsNullOrEmpty(this string? str)
     {
         return string.IsNullOrEmpty(str);