wxw
2025-05-12 c7c2f7aa20427204944ba80a2704232b2f281582
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Model.ModelDto.SysDto;
using SqlSugar;
using WMS.Entity.Context;
using WMS.Entity.SysEntity;
using WMS.IDAL.ISysInterface;
 
namespace WMS.DAL.SysInfrastructure
{
    public class StorageLocatRepository : BaseRepository<SysStorageLocat>, IStorageLocatRepository
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        public StorageLocatRepository() : base(Db)
        {
        }
 
        /// <summary>
        /// 编辑储位信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status">状态</param>
        /// <param name="flag">标识</param>
        /// <param name="temperature">存储环境</param>
        /// <param name="userId">操作人</param>
        /// <returns></returns>
        public bool EditStorageLocat(int id, string status, string flag, string temperature, int userId)
        {
            try
            {
                var locate = GetOneById(id);
                if (locate == null)
                {
                    throw new Exception($"为查询到id为{id}的储位信息");
                }
 
                var com = new Common();
                Db.BeginTran();
                if (flag == "2" && locate.Depth == "01")//标识是损坏且深度是01时 需把深度为2的储位给屏蔽
                {
                    var locate2 = com.GetLocateNoDepth2(locate.WareHouseNo, locate.LocatNo);
                    if (locate2.Flag == "0")
                    {
                        locate2.Flag = "1";
                        locate2.UpdateUser = userId;
                        locate2.UpdateTime = DateTime.Now;
                        var m = Edit(locate2);
                    }
 
                }
 
                if (flag == "0" && locate.Depth == "02")//标识是正常且深度是02时 需判断深度为1的储位状态是否正常
                {
                    var locate1 = com.GetLocateNoDepth1(locate.WareHouseNo, locate.LocatNo);
 
                    if (locate1.Flag == "2")
                    {
                        throw new Exception("需先修改深度为1的储位标识为不是损坏");
                    }
                }
 
                locate.Status = status;
                locate.Flag = flag;
                locate.Temperature = temperature;
                locate.UpdateUser = userId;
                locate.UpdateTime = DateTime.Now;
                var i = Edit(locate);
                Db.CommitTran();
                return i > 0;
 
            }
            catch (Exception e)
            {
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 编辑储位信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status">状态</param>
        /// <param name="flag">标识</param> 
        /// <param name="userId">操作人</param>
        /// <returns></returns>
        public bool EditStorageLocatList(List<int> id, string status, string flag, int userId)
        {
            try
            {
                var locateList = GetAllWhereAsync(m => id.Contains(m.Id)).ToList();
                if (locateList.Count == 0)
                {
                    throw new Exception($"为查询到id为{id}的储位信息");
                }
 
                var com = new Common();
                var i = 0;
                Db.BeginTran();
                foreach (var locate in locateList)
                {
                    if (flag == "2" && locate.Depth == "01")//标识是损坏且深度是01时 需把深度为2的储位给屏蔽
                    {
                        var locate2 = com.GetLocateNoDepth2(locate.WareHouseNo, locate.LocatNo);
                        if (locate2.Flag == "0" && !locateList.Contains(locate2))
                        {
                            locate2.Flag = "1";
                            locate2.UpdateUser = userId;
                            locate2.UpdateTime = DateTime.Now;
                            var m = Edit(locate2);
                        }
 
                    }
                    if (flag == "0" && locate.Depth == "02")//标识是正常且深度是02时 需判断深度为1的储位状态是否正常
                    {
                        var locate1 = com.GetLocateNoDepth1(locate.WareHouseNo, locate.LocatNo);
 
                        if (locate1.Flag == "2")
                        {
                            throw new Exception($"需先修改{locate1.LocatNo}的储位标识为不是损坏");
                        }
                    }
 
                    locate.Status = status;
                    locate.Flag = flag;
                    locate.UpdateUser = userId;
                    locate.UpdateTime = DateTime.Now;
                    i = Edit(locate);
                }
 
                Db.CommitTran();
                return i > 0;
 
            }
            catch (Exception e)
            {
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 获取储位信息
        /// </summary>
        /// <param name="wareHouseNo">仓库</param>
        /// <param name="row">排</param>
        /// <returns></returns>
        public List<SysStorageLocat> GetStorageLocatLists(string wareHouseNo, string row)
        {
            string str = "select * from SysStorageLocat where IsDel = @isdel and Row = @row and WareHouseNo = @warehouseno";
            if (wareHouseNo == "1")
            {
                var wareno = Db.Ado.SqlQuery<string>("select TOP 1 WareHouseNo from SysWareHouse");
                wareHouseNo = wareno[0];
            }
            List<SysStorageLocat> list = Db.Ado.SqlQuery<SysStorageLocat>(str, new
            {
                isdel = "0", //是否删除
                warehouseno = wareHouseNo, //仓库
                row, //排
            });
            return list;
        }
 
        /// <summary>
        /// 获取最大层级
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <returns></returns>
        public int GetMaxLayer(string wareHouseNo)
        {
            string str = "select max(Layer) MaxLayer from SysStorageLocat where IsDel = @isdel and WareHouseNo = @warehouseno";
            if (wareHouseNo == "1")
            {
                var wareno = Db.Ado.SqlQuery<string>("select TOP 1 WareHouseNo from SysWareHouse");
                wareHouseNo = wareno[0];
            }
            int MaxLayer = Db.Ado.SqlQuerySingle<int>(str, new
            {
                isdel = "0", //是否删除
                warehouseno = wareHouseNo //仓库号
            });
            return MaxLayer;
        }
 
        /// <summary>
        /// 获取该仓库排数
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <returns></returns>
        public List<int> GetStorageLocatRow(string wareHouseNo)
        {
            string str = "select Row from SysStorageLocat where IsDel = @isdel and WareHouseNo = @warehouseno group by Row order by Row";
            if (wareHouseNo == "1")
            {
                var wareno = Db.Ado.SqlQuery<string>("select TOP 1 WareHouseNo from SysWareHouse");
                wareHouseNo = wareno[0];
            }
            List<int> maxrow = Db.Ado.SqlQuery<int>(str, new
            {
                isdel = "0", //是否删除
                warehouseno = wareHouseNo //仓库号
            });
            return maxrow;
        }
 
        /// <summary>
        /// 获取该仓库深度
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <returns></returns>
        public List<string> GetDepth(string wareHouseNo)
        {
            string str = "select Depth from SysStorageLocat where IsDel = @isdel and WareHouseNo = @warehouseno group by Depth order by Depth";
            if (wareHouseNo == "1")
            {
                var wareno = Db.Ado.SqlQuery<string>("select TOP 1 WareHouseNo from SysWareHouse");
                wareHouseNo = wareno[0];
            }
            List<string> depthlist = Db.Ado.SqlQuery<string>(str, new
            {
                isdel = "0", //是否删除
                warehouseno = wareHouseNo //仓库号
            });
            return depthlist;
        }
    }
}