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
|
|
}
|