tangxu
2024-01-09 ddc2780231ea76be74fadb7486401a3d0d17b101
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
67
68
69
70
71
72
73
namespace Yw.DAL
{
    /// <summary>
    ///  
    /// </summary>
    public partial class HealthDeterioration : BaseDAL_Sorter<Entity.HealthDeterioration>
    {
        /// <summary>
        /// 
        /// </summary>
        public override ConnectionConfig ConnectionConfig
        {
            get { return ConfigHelper.DefaultConnectionConfig; }
 
        }
 
        /// <summary>
        /// 设置
        /// </summary>
        public bool Set(List<Entity.HealthDeterioration> list)
        {
            if (list == null || list.Count < 1)
                return false;
            var deductionList = list.Select(x => x.Deduction).Distinct().ToList();
            if (deductionList.Count != list.Count)
                return false;
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                try
                {
                    db.BeginTran();
 
                    //删除
                    var ids = list.Where(x => x.ID > 0).Select(x => x.ID).Distinct().ToList();
                    db.Deleteable<Entity.HealthDeterioration>().Where(x => !ids.Contains(x.ID)).ExecuteCommand();
 
                    foreach (var item in list)
                    {
                        if (item.ID < 1)
                        {
                            var id = db.Insertable(item).ExecuteReturnSnowflakeId();
                            if (id < 1)
                            {
                                db.RollbackTran();
                                return false;
                            }
                        }
                        else
                        {
                            var bol = db.Updateable(item).ExecuteCommandHasChange();
                            if (!bol)
                            {
                                db.RollbackTran();
                                return false;
                            }
                        }
                    }
                    db.CommitTran();
                    return true;
                }
                catch
                {
                    db.RollbackTran();
                    return false;
                }
            }
        }
 
 
 
 
    }
}