lixiaojun
2024-07-17 a60f3ee45a6b86de936d19a122acdfb30570a867
Yw.Service.Run.Core/04-dal/03-sqlite/RunAnalyConfigure.cs
@@ -14,20 +14,98 @@
        }
        /// <summary>
        ///
        /// </summary>
        public Entity.RunAnalyConfigure GetByObjectTypeAndObjectID(string ObjectType, long ObjectID)
        {
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.RunAnalyConfigure>()
                        .Where(x => x.ObjectType == ObjectType && x.ObjectID == ObjectID)
                        .First();
            }
        }
        /// <summary>
        ///
        /// </summary>
        public long InsertOrUpdate(Entity.RunAnalyConfigurePure pure)
        {
            if (pure == null)
            {
                return default;
            }
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                try
                {
                    db.BeginTran();
                    var entity = db.Queryable<Entity.RunAnalyConfigure>()
                        .Where(x => x.ObjectType == pure.ObjectType && x.ObjectID == pure.ObjectID)
                        .First();
                    if (entity == null)
                    {
                        entity = new Entity.RunAnalyConfigure(pure);
                    }
                    else
                    {
                        entity.Reset(pure);
                    }
                    if (entity.ID < 1)
                    {
                        entity.ID = db.Insertable(entity).ExecuteReturnSnowflakeId();
                        if (entity.ID < 1)
                        {
                            db.RollbackTran();
                            return default;
                        }
                    }
                    else
                    {
                        var bol = db.Updateable(entity).ExecuteCommandHasChange();
                        if (!bol)
                        {
                            db.RollbackTran();
                            return default;
                        }
                    }
                    return entity.ID;
                }
                catch
                {
                    db.RollbackTran();
                    throw;
                }
            }
        }
        /// <summary>
        /// 设置
        /// </summary>
        public bool Set(List<Entity.RunAnalyConfigure> entityList)
        public bool Set(List<Entity.RunAnalyConfigurePure> pureList)
        {
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                try
                {
                    db.BeginTran();
                    var ids = new List<long>();
                    if (entityList != null && entityList.Count > 0)
                    if (pureList != null && pureList.Count > 0)
                    {
                        foreach (var entity in entityList)
                        foreach (var pure in pureList)
                        {
                            var entity = db.Queryable<Entity.RunAnalyConfigure>()
                                .Where(x => x.ObjectType == pure.ObjectType && x.ObjectID == pure.ObjectID)
                                .First();
                            if (entity == null)
                            {
                                entity = new Entity.RunAnalyConfigure(pure);
                            }
                            else
                            {
                                entity.Reset(pure);
                            }
                            if (entity.ID < 1)
                            {
                                entity.ID = db.Insertable(entity).ExecuteReturnSnowflakeId();
@@ -46,11 +124,9 @@
                                    return false;
                                }
                            }
                            ids.Add(entity.ID);
                        }
                    }
                    db.Deleteable<Entity.RunAnalyConfigure>().Where(x => !ids.Contains(x.ID)).ExecuteCommandHasChange();
                    db.CommitTran();
                    return true;
                }
@@ -62,5 +138,18 @@
            }
        }
        /// <summary>
        /// 通过 ObjectType 和 ObjectID 删除
        /// </summary>
        public bool DeleteByObjectTypeAndObjectID(string ObjectType, long ObjectID)
        {
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Deleteable<Entity.RunAnalyConfigure>()
                    .Where(x => x.ObjectType == ObjectType && x.ObjectID == ObjectID)
                    .ExecuteCommandHasChange();
            }
        }
    }
}