lixiaojun
2024-01-08 b93f18e00ef41208a386993157ffd4f9dd0c8cce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
namespace Yw.DAL
{
    /// <summary>
    /// 运行分析配置
    /// </summary>
    public partial class RunAnalyConfigure : BaseDAL<Entity.RunAnalyConfigure>
    {
        /// <summary>
        /// 
        /// </summary>
        public override ConnectionConfig ConnectionConfig
        {
            get { return ConfigHelper.DefaultConnectionConfig; }
        }
 
        /// <summary>
        /// 设置
        /// </summary>
        public bool Set(List<Entity.RunAnalyConfigure> entityList)
        {
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                try
                {
                    db.BeginTran();
                    var ids = new List<long>();
                    if (entityList != null && entityList.Count > 0)
                    {
                        foreach (var entity in entityList)
                        {
                            if (entity.ID < 1)
                            {
                                entity.ID = db.Insertable(entity).ExecuteReturnSnowflakeId();
                                if (entity.ID < 1)
                                {
                                    db.RollbackTran();
                                    return false;
                                }
                            }
                            else
                            {
                                var bol = db.Updateable(entity).ExecuteCommandHasChange();
                                if (!bol)
                                {
                                    db.RollbackTran();
                                    return false;
                                }
                            }
                            ids.Add(entity.ID);
                        }
                    }
 
                    db.Deleteable<Entity.RunAnalyConfigure>().Where(x => !ids.Contains(x.ID)).ExecuteCommandHasChange();
                    db.CommitTran();
                    return true;
                }
                catch
                {
                    db.RollbackTran();
                    throw;
                }
            }
        }
 
    }
}