From 62c7ae21f7b83f09598bafcfa0c745ab3c947141 Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Wed, 12 Oct 2022 01:41:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Epin=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sync/JDPopularizeSyncBusiness.cs | 32 +++++++++++++++++-- BBWY.Server.Model/Db/Shop/JdShopPin.cs | 22 +++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 BBWY.Server.Model/Db/Shop/JdShopPin.cs diff --git a/BBWY.Server.Business/Sync/JDPopularizeSyncBusiness.cs b/BBWY.Server.Business/Sync/JDPopularizeSyncBusiness.cs index ae0fea7f..a5c61242 100644 --- a/BBWY.Server.Business/Sync/JDPopularizeSyncBusiness.cs +++ b/BBWY.Server.Business/Sync/JDPopularizeSyncBusiness.cs @@ -65,7 +65,30 @@ namespace BBWY.Server.Business.Sync ShopId = shopId }); } - fsql.Insert(insertList).ExecuteAffrows(); + + #region 新增pin保存逻辑 + var pinList = jArray.Select(j => j.Value("pin")).Distinct().ToList(); + var dbPinList = fsql.Select().Where(p => p.ShopId == shopId).ToList(p => p.AccessPin); + var pinchajiList = pinList.Except(dbPinList).ToList(); + List insertJDShopPinList = null; + if (pinchajiList.Count() > 0) + { + insertJDShopPinList = pinchajiList.Select(pin => new JdShopPin() + { + Id = idGenerator.NewLong(), + AccessPin = pin, + CreateTime = DateTime.Now, + ShopId = shopId + }).ToList(); + } + #endregion + + fsql.Transaction(() => + { + if (insertJDShopPinList != null) + fsql.Insert(insertJDShopPinList).ExecuteAffrows(); + fsql.Insert(insertList).ExecuteAffrows(); + }); } private void SyncShopPopularizeRecord(ShopResponse shop, DateTime startDate, DateTime endDate, int pageIndex, out int currentCount) @@ -117,7 +140,12 @@ namespace BBWY.Server.Business.Sync private void DeleteOldData(IList shops, DateTime startDate, DateTime endDate) { var shopIds = shops.Select(s => Convert.ToInt64(s.ShopId)).ToList(); - fsql.Delete().Where(s => shopIds.Contains(s.ShopId.Value) && s.Date >= startDate && s.Date <= endDate).ExecuteAffrows(); + + fsql.Transaction(() => + { + fsql.Delete().Where(p => shopIds.Contains(p.ShopId.Value)).ExecuteAffrows(); + fsql.Delete().Where(s => shopIds.Contains(s.ShopId.Value) && s.Date >= startDate && s.Date <= endDate).ExecuteAffrows(); + }); } public void SyncAllShopPopularizeRecord() diff --git a/BBWY.Server.Model/Db/Shop/JdShopPin.cs b/BBWY.Server.Model/Db/Shop/JdShopPin.cs new file mode 100644 index 00000000..0a18a1e9 --- /dev/null +++ b/BBWY.Server.Model/Db/Shop/JdShopPin.cs @@ -0,0 +1,22 @@ +using FreeSql.DataAnnotations; +using System; + +namespace BBWY.Server.Model.Db +{ + + [ Table(Name = "jdshoppin", DisableSyncStructure = true)] + public partial class JdShopPin { + + [Column(StringLength = 100)] + public string AccessPin { get; set; } + + [Column(DbType = "datetime")] + public DateTime? CreateTime { get; set; } + + public long Id { get; set; } + + public long? ShopId { get; set; } + + } + +}