bklLiudl
2024-05-25 484e5129e4c9a671c5660a556a24bd306f1fdd9b
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
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 StorageAreaServer: IStorageAreaServer
    {
        public IStorageAreaRepository AreaRst { get; set; }
        public StorageAreaServer(IStorageAreaRepository areaRst)
        {
            AreaRst = areaRst;
        }
 
        /// <summary>
        /// 获取库区域信息
        /// </summary>
        /// <param name="areaName">区域名称</param>
        /// <param name="wareHouseNo">仓库编号</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<AreaDto> GetStorageAreaList(string areaName, string wareHouseNo, string status, string type,int page, int limit,out int count)
        {
            try
            {
                //创建表达式
                Expression<Func<SysStorageArea, bool>> item = Expressionable.Create<SysStorageArea>()
                    .AndIF(!string.IsNullOrWhiteSpace(areaName), it => it.AreaName.Contains(areaName.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(wareHouseNo), it => it.WareHouseNo == wareHouseNo)
                    .AndIF(!string.IsNullOrWhiteSpace(status), it => it.Status == status)
                    .AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
                    .ToExpression();//注意 这一句 不能少
 
                
                var data = AreaRst.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 AreaDto()
                {
                    Id = m.Id,
                    AreaNo = m.AreaNo,
                    AreaName = m.AreaName,
                    WareHouseNo = m.WareHouseNo,
                    WareHouseName = m.WareHouseInfo == null ? "" : m.WareHouseInfo.WareHouseName,
                    RoadwayNo = m.RoadwayNo,
                    Status = m.Status,
                    Priority = m.Priority,
                    Type = m.Type,
                    TypeName = GetTypeName(m.Type),//类别名称
                    Temp = m.Temperature,
                    TempName = 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">ID</param>
        /// <returns></returns>
        public SysStorageArea GetStorageArea(int id)
        {
            try
            {
                var data = AreaRst.GetOneById(id);
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 获取区域信息(根据仓库号)
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <returns></returns>
        public List<SysStorageArea> GetStorageAreaByHouseNo(string wareHouseNo)
        {
            try
            {
                var data = AreaRst.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">ID</param>
        /// <param name="name">区域名称</param>
        /// <param name="priority">优先级</param>
        /// <param name="type">类别</param>
        /// <param name="temp">存储环境</param>
        /// <param name="userId">操作人</param>
        /// <returns>是否成功</returns>
        public bool EditStorageArea(int id, string name, int priority, string type, string temp, int userId)
        {
            try
            {
                //判断除当前id信息以外是否含有编号和名称
                var bol = AreaRst.GetAllAsync()
                    .Any(m => m.Id != id && m.AreaName == name.Trim());
                if (bol)
                {
                    throw new Exception("当前区域号或区域名称已存在");
                }
 
                var area = AreaRst.GetOneById(id);
                if (area == null)
                {
                    throw new Exception("为查询到当前区域信息");
                }
 
                area.AreaName = name;
                area.Priority = priority;
                area.Type = type;
                area.Temperature = temp;
                area.UpdateUser = userId;
                area.UpdateTime = DateTime.Now;
                var num = AreaRst.Edit(area);
                if (num > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
 
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 修改区域状态
        /// </summary>
        /// <param name="id">Id</param>
        /// <param name="status">状态 0 启用 1停用</param>
        /// <param name="userId">操作人ID</param>
        /// <returns></returns>
        public bool EditStorageAreaStatus(int id,string status,int userId)
        {
            try
            {
                var area = AreaRst.GetOneById(id);
                if (area == null)
                {
                    throw new Exception("为查询到当前区域信息");
                }
 
                area.Status = status;
                area.UpdateUser = userId;
                area.UpdateTime = DateTime.Now;
                var num = AreaRst.EditStorageAreaStatus(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 GetTypeName(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;
                    default:
                        str = "";
                        break;
                }
 
                return str;
            }
        }
    }
 
}