LocationService.cs
6.87 KB
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
using FreeSql;
using HHECS.Application.Error;
using HHECS.BllModel;
using HHECS.Dal.Repository;
using HHECS.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace HHECS.Application.Service
{
public class LocationService : BaseService
{
private readonly LogService _logService = new LogService();
#region CRUD
public BllResult<List<Location>> GetPageLocations(Expression<Func<Location, bool>> exp, int pageIndex, int pageSize, out long totalCount)
{
try
{
return BllResultFactory.Success(new LocationRepository().Where(exp).Count(out totalCount).Page(pageIndex, pageSize).ToList());
}
catch (Exception ex)
{
totalCount = 0;
return BllResultFactory.Error<List<Location>>(ex.Message, ErrorCodeConst.DEZ0001.ToString());
}
}
/// <summary>
/// 批量删除货位
/// </summary>
/// <param name="codes"></param>
/// <returns></returns>
public BllResult DeleteLocations(List<string> codes)
{
try
{
//TaskEntityRepository taskEntityRepository = new TaskEntityRepository();
//var tasks = taskEntityRepository.Where(t => t.TaskStatus < (int)TaskEntityStatus.TaskCompleted).ToList();
//if (tasks.Count(t => codes.Exists(a => a == t.FromLocationCode) || codes.Exists(a => a == t.ToLocationCode)) > 0)
//{
// return BllResultFactory.Error($"所选库位中存在正在执行的任务,操作中止,请先完成任务再删除库位", ErrorCodeConst.Loc_E001.ToString());
//}
LocationRepository locationRepository = new LocationRepository();
return BllResultFactory.Success(locationRepository.Delete(t => codes.Contains(t.Code)));
}
catch (Exception ex)
{
return BllResultFactory.Error(ex.Message, ErrorCodeConst.DEZ0001.ToString());
}
}
public BllResult<List<Location>> GetAllLocations(Expression<Func<Location, bool>> exp)
{
try
{
return BllResultFactory.Success(new LocationRepository().Where(exp).ToList());
}
catch (Exception ex)
{
return BllResultFactory.Error<List<Location>>(ex.Message, ErrorCodeConst.DEZ0001.ToString());
}
}
public BllResult<Location> GetLocationCode(string type, string desctinationArea, string warehouseCode)
{
try
{
LocationRepository locationRepository = new LocationRepository();
var result = locationRepository.Where(a => a.Type == type && a.DestinationArea == desctinationArea && a.WarehouseCode == warehouseCode && a.ContainerCode == "").ToList();
if (result.Count == 0)
{
return BllResultFactory.Error<Location>($"无满足条件的库位数据", ErrorCodeConst.Loc_E002.ToString());
}
var locationCode = result.OrderByDescending(t => t.Column).FirstOrDefault();
if (locationCode == null)
{
return BllResultFactory.Error<Location>($"无满足条件的库位数据", ErrorCodeConst.Loc_E002.ToString());
}
return BllResultFactory.Success(locationCode);
}
catch (Exception ex)
{
return BllResultFactory.Error<Location>(ex.Message, ErrorCodeConst.DEZ0001.ToString());
}
}
/// <summary>
/// 获取所有库位 根据条件
/// </summary>
/// <param name="containerCode"></param>
/// <param name="row"></param>
/// <param name="column"></param>
/// <param name="layer"></param>
/// <param name="roadway"></param>
/// <param name="status"></param>
/// <param name="code"></param>
/// <param name="warehouseCode"></param>
/// <returns></returns>
public BllResult<List<Location>> GetAllLocations(string containerCode, string row, string column, string layer, string roadway, string status, string code, string warehouseCode)
{
try
{
Expression<Func<Location, bool>> exp = t => true;
if (!String.IsNullOrEmpty(containerCode))
{
exp = exp.And(t => t.ContainerCode.Contains(containerCode));
}
if (!String.IsNullOrEmpty(row))
{
exp = exp.And(t => t.Row.ToString() == row);
}
if (!String.IsNullOrEmpty(column))
{
exp = exp.And(t => t.Column.ToString() == column);
}
if (!String.IsNullOrEmpty(layer))
{
exp = exp.And(t => t.Layer.ToString() == layer);
}
if (!String.IsNullOrEmpty(roadway))
{
exp = exp.And(t => t.Roadway.ToString() == roadway);
}
if (!String.IsNullOrEmpty(status) && status != "all")
{
exp = exp.And(t => t.Status.ToString() == status);
}
if (!String.IsNullOrEmpty(code))
{
exp = exp.And(t => t.Code == code);
}
if (!String.IsNullOrEmpty(warehouseCode))
{
exp = exp.And(t => t.WarehouseCode == warehouseCode);
}
return BllResultFactory.Success(new LocationRepository().Where(exp).ToList());
}
catch (Exception ex)
{
return BllResultFactory.Error<List<Location>>(ex.Message, ErrorCodeConst.DEZ0001.ToString());
}
}
/// <summary>
/// 根据库位编码获取库位信息
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public BllResult<Location> GetLocationByCode(string code)
{
try
{
LocationRepository locationRepository = new LocationRepository();
var resut = locationRepository.Where(t => t.Code == code).First();
if (resut != null)
{
return BllResultFactory.Success(resut, "成功");
}
else
{
return BllResultFactory.Error<Location>("未查询到数据");
}
}
catch (Exception ex)
{
return BllResultFactory.Error<Location>(ex.Message, ErrorCodeConst.DEZ0001.ToString());
}
}
#endregion
}
}