lixiaojun
2025-02-13 bfd1b73be85fd66ee37031eadcd4d09e7dafb52f
Service/HStation.Service.Assets.Core/05-service/04-FourLink/03-AssetsFourCoefficient/AssetsFourlinkCoefficient.cs
@@ -3,21 +3,21 @@
    /// <summary>
    ///
    /// </summary>
    public partial class AssetsFourlinkCoefficient
    public partial class AssetsFourlinkFactor
    {
        #region Cache
        //获取缓存
        private static List<Model.AssetsFourlinkCoefficient> GetCache()
        private static List<Model.AssetsFourlinkFactor> GetCache()
        {
            var all = AssetsFourlinkCoefficientCacheHelper.GetSet(() =>
            var all = AssetsFourlinkFactorCacheHelper.GetSet(() =>
            {
                var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkCoefficient>();
                var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkFactor>();
                var entity_list = dal.GetAll();
                var model_list = Entity2Models(entity_list);
                if (model_list == null)
                {
                    model_list = new List<Model.AssetsFourlinkCoefficient>();
                    model_list = new List<Model.AssetsFourlinkFactor>();
                }
                return model_list;
            }, Yw.Service.ConfigHelper.CacheKeepTime, Yw.Service.ConfigHelper.CacheRandomTime);
@@ -27,7 +27,7 @@
        //通过 ID 更新缓存
        private static void UpdateCache(long ID)
        {
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkCoefficient>();
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkFactor>();
            var entity_ds = dal.GetByID(ID);
            var model_ds = Entity2Model(entity_ds);
            var all = GetCache();
@@ -40,7 +40,7 @@
            {
                model.Reset(model_ds);
            }
            AssetsFourlinkSeriesCacheHelper.Trigger();
            AssetsFourlinkFactorCacheHelper.Trigger();
        }
        //通过 Ids 更新缓存
@@ -50,7 +50,7 @@
            {
                return;
            }
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkCoefficient>();
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkFactor>();
            var entity_list = dal.GetByIds(Ids);
            var model_list = Entity2Models(entity_list);
            var all = GetCache();
@@ -59,7 +59,7 @@
            {
                all.AddRange(model_list);
            }
            AssetsFourlinkSeriesCacheHelper.Trigger();
            AssetsFourlinkFactorCacheHelper.Trigger();
        }
        //移除缓存
@@ -67,7 +67,7 @@
        {
            var all = GetCache();
            all.RemoveAll(x => x.ID == ID);
            AssetsFourlinkSeriesCacheHelper.Trigger();
            AssetsFourlinkFactorCacheHelper.Trigger();
        }
        //移除所有缓存
@@ -75,7 +75,7 @@
        {
            var all = GetCache();
            all.Clear();
            AssetsFourlinkSeriesCacheHelper.Trigger();
            AssetsFourlinkFactorCacheHelper.Trigger();
        }
        /// <summary>
@@ -83,7 +83,7 @@
        /// </summary>
        public static void PublishCache(string key)
        {
            AssetsFourlinkSeriesCacheHelper.Publish(key);
            AssetsFourlinkFactorCacheHelper.Publish(key);
        }
        #endregion Cache
@@ -93,16 +93,16 @@
        /// <summary>
        /// 获取所有
        /// </summary>
        public List<Model.AssetsFourlinkCoefficient> GetAll()
        public List<Model.AssetsFourlinkFactor> GetAll()
        {
            var all = GetCache();
            return all;
            return all?.OrderBy(x => x.SortCode).ToList();
        }
        /// <summary>
        /// 通过 ID 获取
        /// </summary>
        public Model.AssetsFourlinkCoefficient GetByID(long ID)
        public Model.AssetsFourlinkFactor GetByID(long ID)
        {
            var all = GetAll();
            return all.Find(x => x.ID == ID);
@@ -111,14 +111,27 @@
        /// <summary>
        /// 通过 ID 获取
        /// </summary>
        public List<Model.AssetsFourlinkCoefficient> GetByIds(List<long> Ids)
        public List<Model.AssetsFourlinkFactor> GetByIds(List<long> Ids)
        {
            if (Ids == null || Ids.Count < 1)
            {
                return default;
            }
            var all = GetAll();
            return all.Where(x => Ids.Contains(x.ID)).ToList();
            return all.Where(x => Ids.Contains(x.ID))?.OrderBy(x => x.SortCode).ToList();
        }
        /// <summary>
        /// 获取最大排序码
        /// </summary>
        public int GetMaxSortCode()
        {
            var all = GetAll();
            if (all == null || all.Count < 1)
            {
                return 0;
            }
            return all.Max(x => x.SortCode);
        }
        #endregion Query
@@ -128,13 +141,13 @@
        /// <summary>
        /// 插入一条数据
        /// </summary>
        public long Insert(Model.AssetsFourlinkCoefficient model)
        public long Insert(Model.AssetsFourlinkFactor model)
        {
            if (model == null)
            {
                return default;
            }
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkCoefficient>();
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkFactor>();
            var entity = Model2Entity(model);
            var id = dal.Insert(entity);
            if (id > 0)
@@ -147,13 +160,13 @@
        /// <summary>
        /// 插入多条
        /// </summary>
        public bool Inserts(List<Model.AssetsFourlinkCoefficient> list)
        public bool Inserts(List<Model.AssetsFourlinkFactor> list)
        {
            if (list == null || list.Count < 1)
            {
                return false;
            }
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkCoefficient>();
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkFactor>();
            var entity_list = Model2Entities(list);
            var ids = dal.InsertsR(entity_list);
            if (ids != null && ids.Count > 0)
@@ -171,14 +184,14 @@
        /// <summary>
        /// 更新一条
        /// </summary>
        public bool Update(Model.AssetsFourlinkCoefficient model)
        public bool Update(Model.AssetsFourlinkFactor model)
        {
            if (model == null)
            {
                return false;
            }
            var entity = Model2Entity(model);
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkCoefficient>();
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkFactor>();
            var bol = dal.Update(entity);
            if (bol)
            {
@@ -190,7 +203,7 @@
        /// <summary>
        /// 批量更新
        /// </summary>
        public bool Updates(List<Model.AssetsFourlinkCoefficient> list)
        public bool Updates(List<Model.AssetsFourlinkFactor> list)
        {
            if (list == null || list.Count < 1)
            {
@@ -201,11 +214,51 @@
                return false;
            }
            var entity_list = Model2Entities(list);
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkCoefficient>();
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkFactor>();
            var bol = dal.Updates(entity_list);
            if (bol)
            {
                UpdateCache(list.Select(x => x.ID).ToList());
            }
            return bol;
        }
        /// <summary>
        /// 更新排序码
        /// </summary>
        public bool UpdateSortCode(long ID, int SortCode)
        {
            if (ID < 1)
            {
                return false;
            }
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkFactor>();
            var bol = dal.UpdateSortCode(ID, SortCode);
            if (bol)
            {
                UpdateCache(ID);
            }
            return bol;
        }
        /// <summary>
        /// 更新排序
        /// </summary>
        public bool UpdateSorter(List<Yw.Model.Sorter> sorters)
        {
            if (sorters == null || sorters.Count < 1)
            {
                return false;
            }
            if (sorters.Exists(x => x.ID < 1))
            {
                return false;
            }
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkFactor>();
            var bol = dal.UpdateSorter(sorters.ToEntityList());
            if (bol)
            {
                UpdateCache(sorters.Select(x => x.ID).ToList());
            }
            return bol;
        }
@@ -220,22 +273,11 @@
        public bool DeleteByID(long ID, out string Msg)
        {
            Msg = string.Empty;
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkCoefficient>();
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkFactor>();
            var bol = dal.DeleteByID(ID);
            if (bol)
            {
                RemoveCache(ID);
            }
            return bol;
        }
        public bool DeleteAll()
        {
            var dal = DALCreateHelper.CreateDAL<HStation.DAL.IAssetsFourlinkCoefficient>();
            var bol = dal.DeleteAll();
            if (bol)
            {
                RemoveAllCache();
            }
            return bol;
        }