From e0738c0754dd80a3b8d972f03d84b0611fd8254c Mon Sep 17 00:00:00 2001 From: ningshuxia <ningshuxia0927@outlook.com> Date: 星期二, 22 十一月 2022 16:43:54 +0800 Subject: [PATCH] Merge branch 'master' of http://47.103.154.90:83/r/IStation/Service.V4.1 --- Application/IStation.Application.Product/iot_payment_record/dto/IotPaymentRecordDto.cs | 75 ++++ Model/IStation.Model.Product/iot/IotPaymentRecord.cs | 104 ++++++ Transfer/IStation.Transfer.Expert_SDC800/TransferHelper.cs | 2 Service/IStation.Service.Product/iot/iot_payment_record/IotPaymentRecord_Instance.cs | 66 ++++ Application/IStation.Application.Product/iot_payment_record/IotPaymentRecord_Controller.cs | 204 ++++++++++++ Application/IStation.Application.Product/config/Mapper.cs | 10 DAL/IStation.DAL.Product/iot/IotPaymentRecord.cs | 64 ++++ Application/IStation.Application.Product/iot_payment_record/dto/AddIotPaymentRecordInput.cs | 50 +++ Application/IStation.Application.Product/iot_payment_record/dto/UpdateIotPaymentRecordInput.cs | 54 +++ Service/IStation.Service.Product/iot/iot_payment_record/IotPaymentRecord.cs | 254 +++++++++++++++ Service/IStation.Service.Product/iot/iot_payment_record/cache/IotPaymentRecordCacheHelper.cs | 71 ++++ 11 files changed, 953 insertions(+), 1 deletions(-) diff --git a/Application/IStation.Application.Product/config/Mapper.cs b/Application/IStation.Application.Product/config/Mapper.cs index 39a2c7c..95eb33a 100644 --- a/Application/IStation.Application.Product/config/Mapper.cs +++ b/Application/IStation.Application.Product/config/Mapper.cs @@ -258,6 +258,16 @@ #endregion + #region 鐗╄仈鍗$即璐硅褰� + + config.ForType<AddIotPaymentRecordInput, Model.IotPaymentRecord>(); + + config.ForType<UpdateIotPaymentRecordInput, Model.IotPaymentRecord>(); + + config.ForType<Model.IotPaymentRecord, IotPaymentRecordDto>(); + + #endregion + } } } \ No newline at end of file diff --git a/Application/IStation.Application.Product/iot_payment_record/IotPaymentRecord_Controller.cs b/Application/IStation.Application.Product/iot_payment_record/IotPaymentRecord_Controller.cs new file mode 100644 index 0000000..a78dcfe --- /dev/null +++ b/Application/IStation.Application.Product/iot_payment_record/IotPaymentRecord_Controller.cs @@ -0,0 +1,204 @@ +锘縰sing Microsoft.AspNetCore.Mvc; +using System.Net; +using System.Net.Http.Headers; +using Microsoft.Extensions.Hosting.Internal; +using Microsoft.AspNetCore.Http.Extensions; +using IStation.Untity; +using Furion.DynamicApiController; +using System.ComponentModel.DataAnnotations; +using Mapster; + + +namespace IStation.Application +{ + /// <summary> + /// IotPaymentRecord + /// </summary> + [Route("Product/IotPaymentRecord")] + [ApiDescriptionSettings("Product", Name = "鐗╄仈鍗$即璐硅褰�", Order = 1000)] + public class IotPaymentRecord_Controller : IDynamicApiController + { + private readonly Service.IotPaymentRecord _service = new Service.IotPaymentRecord(); + + #region Query + + /// <summary> + /// 閫氳繃 CorpID 鑾峰彇 + /// </summary> + [Route("GetByCorpID@V1.0")] + [HttpGet] + public List<IotPaymentRecordDto> GetByCorpID([FromQuery][Required] CorpIDInput input) + { + var list = _service.GetByCorpID(input.CorpID); + var vm_list = list?.Select(x => x.Adapt<Model.IotPaymentRecord, IotPaymentRecordDto>()).ToList(); + return vm_list; + } + + /// <summary> + /// 閫氳繃 ID 鑾峰彇 + /// </summary> + [Route("GetByID@V1.0")] + [HttpGet] + public IotPaymentRecordDto GetByID([FromQuery][Required] IDUnderCorpInput input) + { + var model = _service.GetByID(input.CorpID, input.ID); + return model?.Adapt<Model.IotPaymentRecord, IotPaymentRecordDto>(); + } + + /// <summary> + /// 閫氳繃 Ids 鑾峰彇 + /// </summary> + [Route("GetByIds@V1.0")] + [HttpGet] + public List<IotPaymentRecordDto> GetByIds([FromQuery][Required] IdsUnderCorpInput input) + { + var ids = LongListHelper.ToList(input.Ids); + var list = _service.GetByIds(input.CorpID, ids); + var vm_list = list?.Select(x => x.Adapt<Model.IotPaymentRecord, IotPaymentRecordDto>()).ToList(); + return vm_list; + } + + /// <summary> + /// 閫氳繃 ProductID 鑾峰彇 + /// </summary> + [Route("GetByProductID@V1.0")] + [HttpGet] + public List<IotPaymentRecordDto> GetByProductID([FromQuery] ProductIDUnderCorpInput input) + { + var list = _service.GetByProductID(input.CorpID, input.ProductID); + var vmList = list?.Select(x => new IotPaymentRecordDto(x)).ToList(); + return vmList; + } + + /// <summary> + /// 閫氳繃 ProductIds 鑾峰彇 + /// </summary> + [Route("GetByProductIds@V1.0")] + [HttpGet] + public List<IotPaymentRecordDto> GetByProductIds([FromQuery] ProductIdsUnderCorpInput input) + { + var productIds = LongListHelper.ToList(input.ProductIds); + var list = _service.GetByProductIds(input.CorpID, productIds); + var vmList = list?.Select(x => new IotPaymentRecordDto(x)).ToList(); + return vmList; + } + + /// <summary> + /// 閫氳繃 BelongType and BelongID鑾峰彇 + /// </summary> + [Route("GetByBelongTypeAndBelongID@V1.0")] + [HttpGet] + public List<IotPaymentRecordDto> GetByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input) + { + var list = _service.GetByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + var vmList = list?.Select(x => new IotPaymentRecordDto(x)).ToList(); + return vmList; + } + + #endregion + + #region Insert + + /// <summary> + /// 鎻掑叆涓�鏉� + /// </summary> + [Route("Insert@V1.0")] + [HttpPost] + public long Insert(AddIotPaymentRecordInput input) + { + if (input == null) + return default; + var model = input.Adapt<AddIotPaymentRecordInput, Model.IotPaymentRecord>(); + var id = _service.Insert(model); + return id; + } + + /// <summary> + /// 鎻掑叆澶氭潯 + /// </summary> + [Route("Inserts@V1.0")] + [HttpPost] + public bool Inserts(List<AddIotPaymentRecordInput> inputList) + { + if (inputList == null || inputList.Count < 1) + return false; + var list = inputList.Select(x => x.Adapt<AddIotPaymentRecordInput, Model.IotPaymentRecord>()).ToList(); + var bol = _service.Inserts(list); + return bol; + } + + #endregion + + #region Update + + /// <summary> + /// 鏇存柊涓�鏉� + /// </summary> + [Route("Update@V1.0")] + [HttpPut] + public bool Update(UpdateIotPaymentRecordInput input) + { + if (input == null) + return false; + var model = _service.GetByID(input.CorpID, input.ID); + if (model == null) + return false; + var rhs = new Model.IotPaymentRecord(model); + input.Adapt(rhs); + var bol = _service.Update(rhs); + return bol; + } + + /// <summary> + /// 鏇存柊澶氭潯 + /// </summary> + [Route("Updates@V1.0")] + [HttpPut] + public bool Updates(List<UpdateIotPaymentRecordInput> inputList) + { + if (inputList == null || inputList.Count() < 1) + { + return false; + } + var corpIds = inputList.Select(x => x.CorpID).Distinct().ToList(); + if (corpIds.Count > 1) + return false; + var modelList = _service.GetByIds(corpIds[0], inputList.Select(x => x.ID).ToList()); + if (modelList == null || modelList.Count < 1) + return false; + var rhsList = new List<Model.IotPaymentRecord>(); + modelList.ForEach(x => { + var input = inputList.Find(t => t.ID == x.ID); + if (input != null) + { + var rhs = new Model.IotPaymentRecord(x); + input.Adapt(rhs); + rhsList.Add(rhs); + } + }); + if (rhsList.Count < 1) + return false; + var bol = _service.Updates(rhsList); + return bol; + } + + #endregion + + #region Delete + + /// <summary> + /// 鍒犻櫎 + /// </summary> + [Route("DeleteByID@V1.0")] + [HttpDelete] + public DeleteReasonOutput DeleteByID([FromQuery][Required] IDUnderCorpInput input) + { + var bol = _service.DeleteByID(input.CorpID, input.ID, out string Msg); + return new DeleteReasonOutput() { Success = bol, Reason = Msg }; + } + + #endregion + + + } +} diff --git a/Application/IStation.Application.Product/iot_payment_record/dto/AddIotPaymentRecordInput.cs b/Application/IStation.Application.Product/iot_payment_record/dto/AddIotPaymentRecordInput.cs new file mode 100644 index 0000000..a7d14e0 --- /dev/null +++ b/Application/IStation.Application.Product/iot_payment_record/dto/AddIotPaymentRecordInput.cs @@ -0,0 +1,50 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Application +{ + /// <summary> + /// 娣诲姞鐗╄仈鍗$即璐硅褰� + /// </summary> + public class AddIotPaymentRecordInput + { + + /// <summary> + /// 瀹㈡埛鏍囪瘑 + /// </summary> + public long CorpID { get; set; } + + /// <summary> + /// 璁惧鏍囪瘑 + /// </summary> + public long ProductID { get; set; } + + /// <summary> + /// 缂磋垂浜� + /// </summary> + public string PayerName { get; set; } + + /// <summary> + /// 缂磋垂鏃堕棿 + /// </summary> + public DateTime PaymentTime { get; set; } + + /// <summary> + /// 鏈夋晥澶╂暟 + /// </summary> + public int ValidDays { get; set; } + + /// <summary> + /// 鏈夋晥棰濆害 + /// </summary> + public double LimitValue { get; set; } + + /// <summary> + /// 璇存槑 + /// </summary> + public string Description { get; set; } + } +} diff --git a/Application/IStation.Application.Product/iot_payment_record/dto/IotPaymentRecordDto.cs b/Application/IStation.Application.Product/iot_payment_record/dto/IotPaymentRecordDto.cs new file mode 100644 index 0000000..6bd885f --- /dev/null +++ b/Application/IStation.Application.Product/iot_payment_record/dto/IotPaymentRecordDto.cs @@ -0,0 +1,75 @@ +锘縰sing IStation.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Application +{ + /// <summary> + /// + /// </summary> + public class IotPaymentRecordDto + { + /// <summary> + /// + /// </summary> + public IotPaymentRecordDto() { } + + /// <summary> + /// + /// </summary> + public IotPaymentRecordDto(Model.IotPaymentRecord rhs) + { + this.ID = rhs.ID; + this.CorpID = rhs.CorpID; + this.ProductID = rhs.ProductID; + this.PayerName = rhs.PayerName; + this.PaymentTime = rhs.PaymentTime; + this.ValidDays = rhs.ValidDays; + this.LimitValue = rhs.LimitValue; + this.Description = rhs.Description; + } + + /// <summary> + /// 鏍囪瘑 + /// </summary> + public long ID { get; set; } + + /// <summary> + /// 瀹㈡埛鏍囪瘑 + /// </summary> + public long CorpID { get; set; } + + /// <summary> + /// 璁惧鏍囪瘑 + /// </summary> + public long ProductID { get; set; } + + /// <summary> + /// 缂磋垂浜� + /// </summary> + public string PayerName { get; set; } + + /// <summary> + /// 缂磋垂鏃堕棿 + /// </summary> + public DateTime PaymentTime { get; set; } + + /// <summary> + /// 鏈夋晥澶╂暟 + /// </summary> + public int ValidDays { get; set; } + + /// <summary> + /// 鏈夋晥棰濆害 + /// </summary> + public double LimitValue { get; set; } + + /// <summary> + /// 璇存槑 + /// </summary> + public string Description { get; set; } + } +} diff --git a/Application/IStation.Application.Product/iot_payment_record/dto/UpdateIotPaymentRecordInput.cs b/Application/IStation.Application.Product/iot_payment_record/dto/UpdateIotPaymentRecordInput.cs new file mode 100644 index 0000000..a06ec30 --- /dev/null +++ b/Application/IStation.Application.Product/iot_payment_record/dto/UpdateIotPaymentRecordInput.cs @@ -0,0 +1,54 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Application +{ + /// <summary> + /// + /// </summary> + public class UpdateIotPaymentRecordInput + { + /// <summary> + /// 鏍囪瘑 + /// </summary> + public long ID { get; set; } + + /// <summary> + /// 瀹㈡埛鏍囪瘑 + /// </summary> + public long CorpID { get; set; } + + /// <summary> + /// 璁惧鏍囪瘑 + /// </summary> + public long ProductID { get; set; } + + /// <summary> + /// 缂磋垂浜� + /// </summary> + public string PayerName { get; set; } + + /// <summary> + /// 缂磋垂鏃堕棿 + /// </summary> + public DateTime PaymentTime { get; set; } + + /// <summary> + /// 鏈夋晥澶╂暟 + /// </summary> + public int ValidDays { get; set; } + + /// <summary> + /// 鏈夋晥棰濆害 + /// </summary> + public double LimitValue { get; set; } + + /// <summary> + /// 璇存槑 + /// </summary> + public string Description { get; set; } + } +} diff --git a/DAL/IStation.DAL.Product/iot/IotPaymentRecord.cs b/DAL/IStation.DAL.Product/iot/IotPaymentRecord.cs new file mode 100644 index 0000000..fee746c --- /dev/null +++ b/DAL/IStation.DAL.Product/iot/IotPaymentRecord.cs @@ -0,0 +1,64 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; + + +namespace IStation.DAL +{ + /// <summary> + /// 鐗╄仈鍗$即璐硅褰� + /// </summary> + public partial class IotPaymentRecord : CorpDAL<Entity.IotPaymentRecord> + { + /// <summary> + /// + /// </summary> + public override ConnectionConfig ConnectionConfig + { + get { return ConfigHelper.DefaultConnectionConfig; } + } + + /// <summary> + /// 閫氳繃 ProductID 鑾峰彇 + /// </summary> + public List<Entity.IotPaymentRecord> GetByProductID(long CorpID, long ProductID) + { + using (var db = new SqlSugarClient(ConnectionConfig)) + { + return db.Queryable<Entity.IotPaymentRecord>().Where(x => x.CorpID == CorpID && x.ProductID == ProductID).ToList(); + } + } + + /// <summary> + /// 閫氳繃 ProductIds 鑾峰彇 + /// </summary> + public List<Entity.IotPaymentRecord> GetByProductIds(long CorpID, List<long> ProductIds) + { + if (ProductIds == null || ProductIds.Count < 1) + return default; + using (var db = new SqlSugarClient(ConnectionConfig)) + { + return db.Queryable<Entity.IotPaymentRecord>().Where(x => x.CorpID == CorpID && ProductIds.Contains(x.ProductID)).ToList(); + } + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇 + /// </summary> + public List<Entity.IotPaymentRecord> GetByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID) + { + using (var db = new SqlSugarClient(ConnectionConfig)) + { + return db.Queryable<Entity.IotPaymentRecord, Entity.Product>((x, y) => x.ProductID == y.ID) + .Where((x, y) => y.CorpID == CorpID && y.BelongType == BelongType && y.BelongID == BelongID) + .Select(x => x).ToList(); + } + } + + + } +} \ No newline at end of file diff --git a/Model/IStation.Model.Product/iot/IotPaymentRecord.cs b/Model/IStation.Model.Product/iot/IotPaymentRecord.cs new file mode 100644 index 0000000..d9b6fb9 --- /dev/null +++ b/Model/IStation.Model.Product/iot/IotPaymentRecord.cs @@ -0,0 +1,104 @@ +锘縰sing System; +using System.Text; +using System.Collections.Generic; +using System.Data; +using System.Runtime.Serialization; +using System.ComponentModel.DataAnnotations; + +namespace IStation.Model +{ + /// <summary> + /// 鐗╄仈鍗$即璐硅褰� + /// </summary> + public partial class IotPaymentRecord : System.ICloneable + { + /// <summary> + /// + /// </summary> + public IotPaymentRecord() { } + + /// <summary> + /// + /// </summary> + public IotPaymentRecord(IotPaymentRecord rhs) + { + this.ID = rhs.ID; + this.CorpID = rhs.CorpID; + this.ProductID = rhs.ProductID; + this.PayerName = rhs.PayerName; + this.PaymentTime = rhs.PaymentTime; + this.ValidDays = rhs.ValidDays; + this.LimitValue = rhs.LimitValue; + this.Description = rhs.Description; + } + + /// <summary> + /// + /// </summary> + public void Reset(IotPaymentRecord rhs) + { + this.ID = rhs.ID; + this.CorpID = rhs.CorpID; + this.ProductID = rhs.ProductID; + this.PayerName = rhs.PayerName; + this.PaymentTime = rhs.PaymentTime; + this.ValidDays = rhs.ValidDays; + this.LimitValue = rhs.LimitValue; + this.Description = rhs.Description; + } + + /// <summary> + /// 鏍囪瘑 + /// </summary> + public long ID { get; set; } + + /// <summary> + /// 瀹㈡埛鏍囪瘑 + /// </summary> + public long CorpID { get; set; } + + /// <summary> + /// 璁惧鏍囪瘑 + /// </summary> + public long ProductID { get; set; } + + /// <summary> + /// 缂磋垂浜� + /// </summary> + public string PayerName { get; set; } + + /// <summary> + /// 缂磋垂鏃堕棿 + /// </summary> + public DateTime PaymentTime { get; set; } + + /// <summary> + /// 鏈夋晥澶╂暟 + /// </summary> + public int ValidDays { get; set; } + + /// <summary> + /// 鏈夋晥棰濆害 + /// </summary> + public double LimitValue { get; set; } + + /// <summary> + /// 璇存槑 + /// </summary> + public string Description { get; set; } + + /// <summary> + /// + /// </summary> + public IotPaymentRecord Clone() + { + return (IotPaymentRecord)this.MemberwiseClone(); + } + + object ICloneable.Clone() + { + return this.MemberwiseClone(); + } + } + +} \ No newline at end of file diff --git a/Service/IStation.Service.Product/iot/iot_payment_record/IotPaymentRecord.cs b/Service/IStation.Service.Product/iot/iot_payment_record/IotPaymentRecord.cs new file mode 100644 index 0000000..ad7ddfe --- /dev/null +++ b/Service/IStation.Service.Product/iot/iot_payment_record/IotPaymentRecord.cs @@ -0,0 +1,254 @@ +锘縰sing AutoMapper; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Service +{ + /// <summary> + /// 鐗╄仈鍗$即璐硅褰� + /// </summary> + public partial class IotPaymentRecord + { + #region Cache + + //閫氳繃 CorpID 鑾峰彇缂撳瓨 + private List<Model.IotPaymentRecord> GetCorpCache(long CorpID) + { + return IotPaymentRecordCacheHelper.GetSet(CorpID, () => + { + var dal = new DAL.IotPaymentRecord(); + var entity_list = dal.GetByCorpID(CorpID); + var model_list = Entity2Models(entity_list); + if (model_list == null) + { + model_list = new List<Model.IotPaymentRecord>(); + } + return model_list; + }, ConfigHelper.CacheKeepTime, ConfigHelper.CacheRandomTime); + } + + //閫氳繃 ID 鏇存柊缂撳瓨 + internal void UpdateCorpCache(long CorpID, long ID) + { + var dal = new DAL.IotPaymentRecord(); + var entity_ds = dal.GetByID(CorpID, ID); + var model_ds = Entity2Model(entity_ds); + var all = GetCorpCache(CorpID); + var model = all.Find(x => x.ID == ID); + if (model == null) + { + all.Add(model_ds); + } + else + { + model.Reset(model_ds); + } + } + + //閫氳繃 Ids 鏇存柊缂撳瓨 + private void UpdateCorpCache(long CorpID, List<long> Ids) + { + if (Ids == null || Ids.Count() < 1) + return; + var dal = new DAL.IotPaymentRecord(); + var entity_list = dal.GetByIds(CorpID, Ids); + var model_list = Entity2Models(entity_list); + var all = GetCorpCache(CorpID); + all.RemoveAll(x => Ids.Contains(x.ID)); + if (model_list != null && model_list.Count > 0) + { + all.AddRange(model_list); + } + } + + //绉婚櫎缂撳瓨 + private void RemoveCorpCache(long CorpID, long ID) + { + var all = GetCorpCache(CorpID); + all.RemoveAll(x => x.ID == ID); + } + + #endregion + + #region Query + + /// <summary> + /// 閫氳繃 CorpID 鑾峰彇 + /// </summary> + public List<Model.IotPaymentRecord> GetByCorpID(long CorpID) + { + var all = GetCorpCache(CorpID); + return all.OrderBy(x=>x.PaymentTime).ToList(); + } + + /// <summary> + /// 閫氳繃 ID 鑾峰彇 + /// </summary> + public Model.IotPaymentRecord GetByID(long CorpID, long ID) + { + var all = GetByCorpID(CorpID); + return all.Find(x => x.ID == ID); + } + + /// <summary> + /// 閫氳繃 Ids鑾峰彇 + /// </summary> + public List<Model.IotPaymentRecord> GetByIds(long CorpID, List<long> Ids) + { + if (Ids == null || Ids.Count() < 1) + return default; + var all = GetByCorpID(CorpID); + return all.Where(x => Ids.Contains(x.ID)).OrderBy(x=>x.PaymentTime).ToList(); + } + + /// <summary> + /// 閫氳繃 ProductID 鑾峰彇 + /// </summary> + public List<Model.IotPaymentRecord> GetByProductID(long CorpID, long ProductID) + { + var all = GetByCorpID(CorpID); + return all.Where(x => x.ProductID == ProductID).OrderBy(x => x.PaymentTime).ToList(); + } + + /// <summary> + /// 閫氳繃 ProductIds 鑾峰彇 + /// </summary> + public List<Model.IotPaymentRecord> GetByProductIds(long CorpID, List<long> ProductIds) + { + if (ProductIds == null || ProductIds.Count < 1) + return default; + var all=GetByCorpID(CorpID); + return all.Where(x => ProductIds.Contains(x.ProductID)).OrderBy(x => x.PaymentTime).ToList(); + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇 + /// </summary> + public List<Model.IotPaymentRecord> GetByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID) + { + var productList = new Product().GetByBelongTypeAndBelongID(CorpID,BelongType,BelongID); + if (productList == null || productList.Count < 1) + return default; + var all = GetByCorpID(CorpID); + var list = (from x in all join y in productList on x.ProductID equals y.ID orderby x.PaymentTime select x).ToList(); + return list; + } + + #endregion + + #region Insert + + /// <summary> + /// 鎻掑叆涓�鏉℃暟鎹� + /// </summary> + public long Insert(Model.IotPaymentRecord model) + { + if (model == null) + return default; + if (model.CorpID < 1) + return default; + + var dal = new DAL.IotPaymentRecord(); + var entity = Model2Entity(model); + var id = dal.Insert(entity); + if (id > 0) + { + UpdateCorpCache(model.CorpID, id); + } + return id; + } + + /// <summary> + /// 鎻掑叆澶氭潯 + /// </summary> + public bool Inserts(IEnumerable<Model.IotPaymentRecord> list) + { + if (list == null || list.Count() < 1) + return default; + var corpIds = list.Select(x => x.CorpID).Distinct().ToList(); + if (corpIds.Count != 1 || corpIds[0] < 1) + return default; + var dal = new DAL.IotPaymentRecord(); + var entity_list = Model2Entities(list.ToList()); + var ids = dal.InsertsR(entity_list); + if (ids != null && ids.Count > 0) + { + UpdateCorpCache(corpIds[0], ids); + return true; ; + } + return default; + } + + #endregion + + #region Update + + /// <summary> + /// 鏇存柊涓�鏉� + /// </summary> + public bool Update(Model.IotPaymentRecord model) + { + if (model == null) + return default; + if (model.CorpID < 1) + return default; + if (model.ID < 1) + return default; + var dal = new DAL.IotPaymentRecord(); + var entity = Model2Entity(model); + var bol = dal.Update(entity); + if (bol) + { + UpdateCorpCache(model.CorpID, model.ID); + } + return bol; + } + + /// <summary> + /// 鎵归噺鏇存柊 + /// </summary> + public bool Updates(List<Model.IotPaymentRecord> list) + { + if (list == null || list.Count() < 1) + return default; + var corpIds = list.Select(x => x.CorpID).Distinct().ToList(); + if (corpIds.Count != 1 || corpIds[0] < 1) + return default; + if (list.ToList().Exists(x => x.ID < 1)) + return default; + var dal = new DAL.IotPaymentRecord(); + var entity_list = Model2Entities(list.ToList()); + var bol = dal.Updates(entity_list); + if (bol) + { + UpdateCorpCache(corpIds[0], list.Select(x => x.ID).ToList()); + } + return bol; + } + + #endregion + + + #region Delete + + /// <summary> + /// 閫氳繃 ID 鍒犻櫎 + /// </summary> + public bool DeleteByID(long CorpID, long ID, out string Msg) + { + Msg = string.Empty; + var dal = new DAL.IotPaymentRecord(); + var bol = dal.DeleteByID(CorpID, ID); + if (bol) + { + RemoveCorpCache(CorpID, ID); + } + return bol; + } + + #endregion + } +} \ No newline at end of file diff --git a/Service/IStation.Service.Product/iot/iot_payment_record/IotPaymentRecord_Instance.cs b/Service/IStation.Service.Product/iot/iot_payment_record/IotPaymentRecord_Instance.cs new file mode 100644 index 0000000..4507e89 --- /dev/null +++ b/Service/IStation.Service.Product/iot/iot_payment_record/IotPaymentRecord_Instance.cs @@ -0,0 +1,66 @@ +锘縰sing AutoMapper; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Service +{ + /// <summary> + /// + /// </summary> + public partial class IotPaymentRecord + { + + //Entity to GetModel + private Model.IotPaymentRecord Entity2Model(Entity.IotPaymentRecord entity) + { + if (entity == null) + return default; + var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.IotPaymentRecord, Model.IotPaymentRecord>()).CreateMapper(); + var model = mapper.Map<Entity.IotPaymentRecord, Model.IotPaymentRecord>(entity); + return model; + } + //Entities to GetModels + private List<Model.IotPaymentRecord> Entity2Models(List<Entity.IotPaymentRecord> entities) + { + if (entities == null || entities.Count() < 1) + return default; + var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.IotPaymentRecord, Model.IotPaymentRecord>()).CreateMapper(); + var models = mapper.Map<List<Entity.IotPaymentRecord>, List<Model.IotPaymentRecord>>(entities); + return models; + } + + //Model to Entity + private Entity.IotPaymentRecord Model2Entity(Model.IotPaymentRecord model) + { + if (model == null) + return default; + var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.IotPaymentRecord, Entity.IotPaymentRecord>()).CreateMapper(); + var entity = mapper.Map<Model.IotPaymentRecord, Entity.IotPaymentRecord>(model); + return entity; + } + + //Models to Entities + private List<Entity.IotPaymentRecord> Model2Entities(List<Model.IotPaymentRecord> models) + { + if (models == null || models.Count < 1) + return default; + var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.IotPaymentRecord, Entity.IotPaymentRecord>()).CreateMapper(); + var entities = mapper.Map<List<Model.IotPaymentRecord>, List<Entity.IotPaymentRecord>>(models); + return entities; + } + + //Model to Entity + private void Model2Entity(Model.IotPaymentRecord model, Entity.IotPaymentRecord entity) + { + if (model == null || entity == null) + return; + var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.IotPaymentRecord, Entity.IotPaymentRecord>()).CreateMapper(); + mapper.Map(model, entity); + } + + + } +} diff --git a/Service/IStation.Service.Product/iot/iot_payment_record/cache/IotPaymentRecordCacheHelper.cs b/Service/IStation.Service.Product/iot/iot_payment_record/cache/IotPaymentRecordCacheHelper.cs new file mode 100644 index 0000000..2fb0423 --- /dev/null +++ b/Service/IStation.Service.Product/iot/iot_payment_record/cache/IotPaymentRecordCacheHelper.cs @@ -0,0 +1,71 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Service +{ + /// <summary> + /// IotPaymentRecord缂撳瓨杈呭姪绫� + /// </summary> + internal class IotPaymentRecordCacheHelper + { + private const string _contentKey = "IotPaymentRecordListKey"; + + private static string GetCacheKey(long CorpID) + { + var contentKey = string.Format("{0}-{1}", _contentKey, CorpID); + return CacheHelper.GetCacheKey(contentKey); + } + + /// <summary> + /// 璁剧疆缂撳瓨 + /// </summary> + public static void Set(long CorpID, List<Model.IotPaymentRecord> list, int Minites = 30, int RandomSeconds = 0) + { + var cacheKey = GetCacheKey(CorpID); + MemoryCacheHelper.Set(cacheKey, list, Minites * 60 + RandomSeconds); + } + + /// <summary> + /// 鑾峰彇缂撳瓨 + /// </summary> + public static List<Model.IotPaymentRecord> Get(long CorpID) + { + var cacheKey = GetCacheKey(CorpID); + return MemoryCacheHelper.Get<List<Model.IotPaymentRecord>>(cacheKey); + } + + /// <summary> + /// 鑾峰彇璁剧疆缂撳瓨 + /// </summary> + public static List<Model.IotPaymentRecord> GetSet(long CorpID, Func<List<Model.IotPaymentRecord>> func, int Minites = 30, int RandomSeconds = 0) + { + var cacheKey = GetCacheKey(CorpID); + return MemoryCacheHelper.GetSet(cacheKey, func, Minites * 60 + RandomSeconds); + } + + /// <summary> + /// 绉婚櫎缂撳瓨 + /// </summary> + public static void Remove(long CorpID) + { + var cacheKey = GetCacheKey(CorpID); + MemoryCacheHelper.Remove(cacheKey); + } + + /// <summary> + /// 鍏ㄩ儴绉婚櫎 + /// </summary> + public static void RemoveAll() + { + MemoryCacheHelper.Remove((key) => + { + return key.Contains(CacheHelper.GetCacheKey(_contentKey)); + }); + } + + + } +} \ No newline at end of file diff --git a/Transfer/IStation.Transfer.Expert_SDC800/TransferHelper.cs b/Transfer/IStation.Transfer.Expert_SDC800/TransferHelper.cs index 09cb849..e52277c 100644 --- a/Transfer/IStation.Transfer.Expert_SDC800/TransferHelper.cs +++ b/Transfer/IStation.Transfer.Expert_SDC800/TransferHelper.cs @@ -34,7 +34,7 @@ { var list = DataHelper.GetRecordList(model); var result = BulkInsert(list); - LogHelper.Info($"{model.IP}:涓婁紶{result}锛�"); + LogHelper.Info($"{model.IP}:涓婁紶{result}锛岄噰鏍风偣鏁�:{model.Len}锛�"); } } }); -- Gitblit v1.9.3