duheng
2024-11-17 a2a57963e160a319276c5c8499f16c9809056e4c
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using Yw.DAL.PostgreSql;
 
namespace HStation.DAL.PostgreSql
{
    /// <summary>
    ///
    /// </summary>
    public partial class AssetsPumpMain : BaseDAL_Paras_Flags_TagName_Sorter<Entity.AssetsPumpMain>, IAssetsPumpMain
    {
        /// <summary>
        ///
        /// </summary>
        public override ConnectionConfig ConnectionConfig
        {
            get { return Assets.ConfigHelper.PostgreSqlConnectionConfig; }
        }
 
        //删除拓展
        public bool DeleteEx(long ID)
        {
            if (ID <= 0)
            {
                return default;
            }
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                try
                {
                    db.BeginTran();
                    var main = db.Queryable<Entity.AssetsPumpMain>().ToList().Find(x => x.ID == ID);
                    var result = db.Deleteable(main).ExecuteCommand() > 0;
                    if (!result)
                    {
                        db.RollbackTran();
                        return default;
                    }
                    else
                    {
                        var map = db.Queryable<Entity.AssetsPumpGroupAndMainMapping>().ToList().Find(x => x.MainID == ID);
                        if (map != null)
                        {
                            var mapresult = db.Deleteable(map).ExecuteCommand() > 0;
                            if (!mapresult)
                            {
                                db.RollbackTran();
                                return default;
                            }
                        }
                    }
                    db.CommitTran();
                    return true;
                }
                catch (Exception ex)
                {
                    db.RollbackTran();
                    throw;
                }
            }
        }
 
        //插入拓展
        public long InsertsEx(Entity.AssetsPumpMain AssetsPumpMain, Entity.AssetsPumpGroupAndMainMapping AssetsPumpGroupAndMainMap)
        {
            if (AssetsPumpMain == null)
            {
                return default;
            }
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                try
                {
                    db.BeginTran();
                    var result = db.Insertable(AssetsPumpMain).ExecuteReturnSnowflakeId();
                    if (result < 0)
                    {
                        db.RollbackTran();
                        return default;
                    }
                    else
                    {
                        if (AssetsPumpGroupAndMainMap != null)
                        {
                            AssetsPumpGroupAndMainMap.MainID = result;
                            var mapresult = db.Insertable(AssetsPumpGroupAndMainMap).ExecuteReturnSnowflakeId();
                            if (mapresult < 0)
                            {
                                db.RollbackTran();
                                return default;
                            }
                        }
                    }
                    db.CommitTran();
                    return result;
                }
                catch (Exception ex)
                {
                    db.RollbackTran();
                    throw;
                }
            }
        }
    }
}