schangxiang@126.com
2025-09-17 ff43ddf18764629ff875478e4e47a7281cbd230a
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
using Admin.NET.Core.Service;
using Admin.NET.Application.Entity;
using Microsoft.AspNetCore.Http;
using System.Data;
using System.Web;
using System.Text;
using Admin.NET.Core;
 
namespace Admin.NET.Application;
/// <summary>
/// 库位视图服务
/// </summary>
[ApiDescriptionSettings(ApplicationConst.ReportCenterGroupName, Order = 100)]
public class WmsPlaceContainerInfoService : IDynamicApiController, ITransient
{
    private readonly SqlSugarRepository<v_wms_place_container_info> _rep;
    private readonly SqlSugarRepository<v_wms_location_view_details> _v_wms_location_view_detailsRep;
 
    public WmsPlaceContainerInfoService(SqlSugarRepository<v_wms_place_container_info> rep, SqlSugarRepository<v_wms_location_view_details> v_wms_location_view_detailsRep)
    {
        _rep = rep;
        _v_wms_location_view_detailsRep = v_wms_location_view_detailsRep;
    }
 
 
 
    /// <summary>
    /// 不分页查询库位视图
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "List")]
    [Description("WmsPlaceContainerInfo/List")]
    public async Task<InventoryByLocationOutput> List([FromQuery] WmsPlaceContainerInfoInput input)
    {
        var query = await CommonPageFilter(input).ToListAsync();
 
 
 
        InventoryByLocationOutput output = new InventoryByLocationOutput();
        int EmptyLocation = 0;//空库位数量
        int EmptyContainerLocation = 0;//空托数量
        int MaterialLocation = 0;//满托数量
        int LockedLocation = 0;// 锁定库位数量
        int DisableLocation = 0;//封存库位数量
 
 
        //分组
        var groups = query.GroupBy(x => new { x.WareLocationCode });
 
        foreach (var gg in groups)
        {     
            //判断状态,是空托,还是 满托,还是空库位
            var stocks = gg.ToList();
 
            //有物料(非RQ)的容器集合
            var materialContinerList = stocks.Where(x => !string.IsNullOrWhiteSpace(x.MaterialCode) && x.MaterialCode != ApplicationConst.DefaultContinerMaterialCode).ToList();
 
 
            //有货库位
            if (materialContinerList.Count() > 0)
            {
                //有货库位(物料)
                MaterialLocation++;
                foreach (var ss in stocks)
                {
                    ss.InventoryType = 2;
                }
            }else 
 
            //只有一条容器库位关系记录
            //空库位
            if (stocks.Count == 1 && string.IsNullOrEmpty(stocks.First().WareContainerCode) && string.IsNullOrEmpty(stocks.First().MaterialCode))
            {
                //空库位
                EmptyLocation++;
                foreach (var ss in stocks)
                {
                    ss.InventoryType = 0;
                }
            }
            else
            {  // 物料是容器的空容器(叠托)或容器没有物料
                EmptyContainerLocation++;
                foreach (var ss in stocks)
                {
                    ss.InventoryType = 1;
                }
            }
 
            var item = stocks.First();
 
            // ----------- ly0729 -库位状态-1显示 0隐藏
            if (input.InventoryType != null)
            {
                if (input.InventoryType == 0)
                {
                    item.ShowInventoryType = item.InventoryType == 0 ? "1" : "0";
                }
                else  if (input.InventoryType == 1) 
                {
                    item.ShowInventoryType = item.InventoryType == 1 ? "1" : "0";
 
                }
                else  if (input.InventoryType == 2) 
                {
                    item.ShowInventoryType = item.InventoryType == 2 ? "1" : "0";
                }
                else
                {
                    item.ShowInventoryType = "0";
                }
            }
            else
            {
                item.ShowInventoryType = "1";
            }
            // ----------- ly-库位状态-1显示 0隐藏
 
 
            if (item.Status == PlaceStatusEnum.封存)
            {
                DisableLocation++;
            }
            else if (item.Status == PlaceStatusEnum.锁定)
            {
                LockedLocation++;
            }
 
            if (output.Lanes != null)
            {
                var tempInventoryByLocationOutput = output.Lanes.Where(x => x.LaneCode == item.Lane).FirstOrDefault();
 
                if (tempInventoryByLocationOutput == null)
                {
                    List<RowLocation> rowLocations = new List<RowLocation>() { item };
                    List<Row> rows = new List<Row>() { new Row() { RowCode = item.Row, RowLocations = rowLocations } };
                    Lane lane = new Lane() { LaneCode = item.Lane, Rows = rows };
                    output.Lanes.Add(lane);
                }
                else
                {
                    var temp2 = output.Lanes.Where(x => x.LaneCode == item.Lane && x.Rows.Where(u => u.RowCode == item.Row).ToList().Count > 0).FirstOrDefault();
                    if (temp2 == null)
                    {
                        List<RowLocation> rowLocations = new List<RowLocation>() { item };
                        Row row = new Row() { RowCode = item.Row, RowLocations = rowLocations };
                        tempInventoryByLocationOutput.Rows.Add(row);
                    }
                    else
                    {
                        tempInventoryByLocationOutput.Rows.Where(u => u.RowCode == item.Row).FirstOrDefault().RowLocations.Add(item);
                    }
                }
            }
            else
            {
                List<RowLocation> rowLocations = new List<RowLocation>() { item };
                List<Row> rows = new List<Row>() { new Row() { RowCode = item.Row, RowLocations = rowLocations } };
                List<Lane> lanes = new List<Lane>() { new Lane() { LaneCode = item.Lane, Rows = rows } };
                output = new InventoryByLocationOutput() { Lanes = lanes };
            }
        }
        output.EmptyLocation = EmptyLocation;
        output.EmptyContainerLocation = EmptyContainerLocation;
        output.MaterialLocation = MaterialLocation;
        output.LockedLocation = LockedLocation;
        output.DisableLocation = DisableLocation;
        return output;
 
    }
 
 
 
    /// <summary>
    /// 不分页查询库位视图
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "Detail")]
    [Description("WmsPlaceContainerInfo/Detail")]
    public async Task<SqlSugarPagedList<v_wms_location_view_details>> Detail([FromQuery] WmsStockQuanInput input)
    {
 
        var query =  _v_wms_location_view_detailsRep.AsQueryable()
            .WhereIF(!string.IsNullOrWhiteSpace(input.PlaceCode), u => u.PlaceCode.Contains(input.PlaceCode.Trim()))
            .WhereIF(!string.IsNullOrWhiteSpace(input.ContainerCode), u => u.ContainerCode.Contains(input.ContainerCode.Trim()))
            .WhereIF(!string.IsNullOrWhiteSpace(input.MaterialCode), u => u.MaterialCode.Contains(input.MaterialCode.Trim()))
           .Select<v_wms_location_view_details>();
 
        return await query.OrderBuilder(input, "", "MaterialCode").ToPagedListAsync(input.Page, input.PageSize);
 
    }
 
 
 
 
    #region 私有方法
 
    /// <summary>
    /// 公共查询事务记录条件
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    private ISugarQueryable<RowLocation> CommonPageFilter(WmsPlaceContainerInfoInput input)
    {
        var query = _rep.AsQueryable()
            .WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
                u.WareLocationCode.Contains(input.SearchKey.Trim())
                || u.WareContainerCode.Contains(input.SearchKey.Trim())
                //|| u.Lane==input.Lane
                //|| u.Row==input.Row  
                )
           .WhereIF(!string.IsNullOrWhiteSpace(input.AreaCode), u => u.AreaCode.Contains(input.AreaCode.Trim()))
            .WhereIF(!string.IsNullOrWhiteSpace(input.WareContainerCode), u => u.WareContainerCode.Contains(input.WareContainerCode.Trim()))
            .WhereIF(!string.IsNullOrWhiteSpace(input.WareLocationCode), u => u.WareLocationCode.Contains(input.WareLocationCode.Trim()))
            .WhereIF(!string.IsNullOrWhiteSpace(input.WareLocationName), u => u.WareLocationName.Contains(input.WareLocationName.Trim()))
            .WhereIF(input.Lane.HasValue, u => u.Lane == input.Lane)
            .WhereIF(input.Row.HasValue, u => u.Row == input.Row)
            .WhereIF(input.Status.HasValue, u => u.Status == input.Status)
              .OrderBy(u => u.Lane).OrderBy(u => u.Row)
              .OrderBy(u => u.Column)
              .OrderBy(u => u.Layer)
            .Select<RowLocation>();
 
        return query;
    }
 
 
    #endregion
 
}