bklLiudl
3 天以前 0fb06f822b3574c3e8ba40331cba15ce1693ce07
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Model.InterFaceModel;
using Model.ModelDto.SysDto;
using Model.ModelVm.SysVm;
using Newtonsoft.Json;
using SqlSugar;
using Utility.Tools;
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="areaNo">所属区域</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 areaNo,string status, string flag, string temperature,string url, int userId)
        {
            try
            {
                var locate = GetOneById(id);
                if (locate == null)
                {
                    throw new Exception($"为查询到id为{id}的储位信息");
                }
 
                var com = new Common();
                Db.BeginTran();
                //修改储位集合
                List<WcsLocat> outDtoList = new List<WcsLocat>();
                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;
                        locate2.AreaNo = areaNo;
                        var m = Edit(locate2);
 
                        WcsLocat locatEntry = new WcsLocat();
                        locatEntry.LocatNo = locate2.LocatNo;
                        locatEntry.Status = locate2.Status;
                        locatEntry.Flag = locate2.Status;
 
                        outDtoList.Add(locatEntry);
                    }
 
                }
 
                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.AreaNo = areaNo;
                locate.UpdateUser = userId;
                locate.UpdateTime = DateTime.Now;
                var i = Edit(locate);
 
                if (i > 0)
                {
                    WcsLocat locatEntry2 = new WcsLocat();
                    locatEntry2.LocatNo = locate.LocatNo;
                    locatEntry2.Status = locate.Status;
                    locatEntry2.Flag = locate.Status;
 
                    outDtoList.Add(locatEntry2);
 
                    // 正式运行程序放开
                    //var jsonData = JsonConvert.SerializeObject(outDtoList);
                    //string response = "";
 
                    //try
                    //{
                    //    response = HttpHelper.DoPost(url, jsonData, "下发给WCS同步储位信息", "WCS");
                    //    //解析返回数据 
                    //    var wcsModel = JsonConvert.DeserializeObject<WcsModel>(response);
                    //    if (wcsModel.StatusCode == -1)
                    //    {
                    //        throw new Exception(wcsModel.Msg);
                    //    }
                    //}
                    //catch (Exception ex)
                    //{
                    //    throw new Exception(ex.Message);
                    //}
                }
 
                Db.CommitTran();
                return i > 0;
            }
            catch (Exception e)
            {
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 编辑储位信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="areaNo">所属区域</param>
        /// <param name="status">状态</param>
        /// <param name="flag">标识</param> 
        /// <param name="userId">操作人</param>
        /// <returns></returns>
        public bool EditStorageLocatList(List<int> id,string areaNo, string status, string flag,string temperature,string url ,int userId)
        {
            try
            {
                var locateList = GetAllWhere(m => id.Contains(m.Id)).ToList();
                if (locateList.Count == 0)
                {
                    throw new Exception($"为查询到id为{id}的储位信息");
                }
 
                var com = new Common();
                var i = 0;
                Db.BeginTran();
                //修改储位集合
                List<WcsLocat> outDtoList = new List<WcsLocat>();
                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;
                            locate2.AreaNo = areaNo;
                            var m = Edit(locate2);
 
                            WcsLocat locatEntry = new WcsLocat();
                            locatEntry.LocatNo = locate2.LocatNo;
                            locatEntry.Status = locate2.Status;
                            locatEntry.Flag = locate2.Status;
 
                            outDtoList.Add(locatEntry);
                        }
 
                    }
                    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;
                    if (!string.IsNullOrEmpty(temperature))
                    {
                        locate.Temperature = temperature;
                    }                    
                    locate.UpdateUser = userId;
                    locate.UpdateTime = DateTime.Now;
                    locate.AreaNo = areaNo;
                    i = Edit(locate);
 
                    WcsLocat locatEntry2 = new WcsLocat();
                    locatEntry2.LocatNo = locate.LocatNo;
                    locatEntry2.Status = locate.Status;
                    locatEntry2.Flag = locate.Status;
 
                    outDtoList.Add(locatEntry2);
                }
                if (i > 0)
                {
                    // 正式运行程序放开
                    //var jsonData = JsonConvert.SerializeObject(outDtoList);
                    //string response = "";
 
                    //try
                    //{
                    //    response = HttpHelper.DoPost(url, jsonData, "下发给WCS出库命令", "WCS");
                    //    //解析返回数据 
                    //    var wcsModel = JsonConvert.DeserializeObject<WcsModel>(response);
                    //    if (wcsModel.StatusCode == -1)
                    //    {
                    //        throw new Exception(wcsModel.Msg);
                    //    }
                    //}
                    //catch (Exception ex)
                    //{
                    //    throw new Exception(ex.Message);
                    //}
                }
                Db.CommitTran();
                return i > 0;
 
            }
            catch (Exception e)
            {
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
        
        /// <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;
        }
         
         
         
    }
}