bklLiudl
2025-04-07 4e8f58cb41c7b6d570fd1979d80f74ab8a4d00c2
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
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.SysEntity;
using WMS.IBLL.ISysServer;
using WMS.IDAL.ISysInterface;
 
namespace WMS.BLL.SysServer
{
    public class StorageRoadwayServer: IStorageRoadwayServer
    {
        public IStorageRoadwayRepository RoadwayRst { get; set; }
        public StorageRoadwayServer(IStorageRoadwayRepository roadwayRst)
        {
            RoadwayRst = roadwayRst;
        }
 
        /// <summary>
        /// 查询巷道信息
        /// </summary>
        /// <param name="houseNo">仓库号</param>
        /// <param name="roadwayName">巷道名称</param>
        /// <param name="status">状态</param>
        /// <param name="type">类型</param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public List<RoadwayDto> GetStorageRoadwayList(string houseNo, string roadwayName, string status, string type, int page, int limit,out int count)
        {
            try
            {
                Expression<Func<SysStorageRoadway, bool>> item = Expressionable.Create<SysStorageRoadway>() //创建表达式
                   .AndIF(!string.IsNullOrWhiteSpace(houseNo), it => it.WareHouseNo.Contains(houseNo.Trim()))
                   .AndIF(!string.IsNullOrWhiteSpace(roadwayName), it => it.RoadwayName.Contains(roadwayName.Trim()))
                   .AndIF(!string.IsNullOrWhiteSpace(status), it => it.Status == status)
                   .AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
                   .ToExpression();//注意 这一句 不能少
 
                var data = RoadwayRst.GetAllByOrderPageAsync(item, limit, page,out int counts)
                    .Includes(x => x.WareHouseInfo)
                    .Includes(x => x.TemperatureInfo)
                    .Includes(x => x.CreateUserInfo)
                    .Includes(x => x.UpdateUserInfo).ToList();
                count = counts;
                return data.Select(m => new RoadwayDto()
                {
                    Id = m.Id,
                    RoadwayNo = m.RoadwayNo,
                    RoadwayName = m.RoadwayName,
                    WareHouseNo = m.WareHouseNo,
                    WareHouseName = m.WareHouseInfo == null ? "" : m.WareHouseInfo.WareHouseName,
                    AreaNo = m.AreaNo,
                    Priority = m.Priority,
                    Status = m.Status,
                    Type = m.Type,
                    TypeName = GetType(m.Type),
                    TemperatureName = m.TemperatureInfo == null ? "" : m.TemperatureInfo.DictName,
                    CreateTime = m.CreateTime,
                    CreateUserName = m.CreateUserInfo == null ? "" : m.CreateUserInfo.RealName,
                    UpdateTime = m.UpdateTime,
                    UpdateUserName = m.UpdateUserInfo == null ? "" : m.UpdateUserInfo.RealName
                }).ToList();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 查询单条巷道信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SysStorageRoadway GetStorageRoadway(int id)
        {
            try
            {
                var data = RoadwayRst.GetOneById(id);
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 获取巷道信息(根据仓库号)
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <returns></returns>
        public List<SysStorageRoadway> GetStorageRoadwayByHouseNo(string wareHouseNo)
        {
            try
            {
                var data = RoadwayRst.GetAllAsync().ToList();
                if (!string.IsNullOrWhiteSpace(wareHouseNo))
                {
                    data = data.Where(m => m.WareHouseNo == wareHouseNo).ToList();
                }
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 编辑巷道信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="roadwayNo"></param>
        /// <param name="roadwayName"></param>
        /// <param name="houseNo"></param>
        /// <param name="areaNo"></param>
        /// <param name="status"></param>
        /// <param name="priority"></param>
        /// <param name="type"></param>
        /// <param name="temp"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool EditStorageRoadway(int id, string roadwayName, int priority, string type, string temp, int userId)
        {
            try
            {
                var roadway = RoadwayRst.GetOneById(id);
                if (roadway == null)
                {
                    throw new Exception("为查询到当前巷道信息");
                }
                //判断除当前id信息以外是否含有编号和名称
                var bol = RoadwayRst.GetAllAsync().Any(m => m.Id != id && m.RoadwayNo== roadway.RoadwayNo && m.RoadwayName == roadwayName.Trim());
                if (bol)
                {
                    throw new Exception("当前巷道号或巷道名称已存在");
                }
 
                roadway.RoadwayName = roadwayName;
                roadway.Priority = priority;
                roadway.Type = type;
                roadway.Temperature = temp;
                roadway.UpdateUser = userId;
                roadway.UpdateTime = DateTime.Now;
                var num = RoadwayRst.Edit(roadway);
                if (num > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 编辑巷道状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status">状态</param>
        /// <param name="userId">操作人</param>
        /// <returns></returns>
        public bool EditStorageRoadwayStatus(int id, string status, int userId)
        {
            try
            {
                var area = RoadwayRst.GetOneById(id);
                if (area == null)
                {
                    throw new Exception("为查询到当前区域信息");
                }
 
                area.Status = status;
                area.UpdateUser = userId;
                area.UpdateTime = DateTime.Now;
                var num = RoadwayRst.EditStorageRoadwayStatus(area);
                if (num > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 查询巷道类别
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public string GetType(string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return "";
            }
            else
            {
                var str = "";
                switch (code)
                {
                    case "1":
                        str = "成品区";
                        break;
                    case "2":
                        str = "原料区";
                        break;
                    case "3":
                        str = "包材区";
                        break;
                    case "4":
                        str = "空托区";
                        break;
                    case "5":
                        str = "耗材区";
                        break;
                }
                return str;
            }
        }
    }
}