using HslCommunication.WebSocket;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Common.CommonEnum;
|
using WIDESEA_Common.LocationEnum;
|
using WIDESEA_Common.StockEnum;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Const;
|
using WIDESEA_Core.DB;
|
using WIDESEA_Core.Enums;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_Core.Seed;
|
using WIDESEA_Core.Utilities;
|
using WIDESEA_DTO.Basic;
|
using WIDESEA_IBasicRepository;
|
using WIDESEA_IBasicService;
|
using WIDESEA_IStockRepository;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_BasicService
|
{
|
public partial class LocationInfoService : ServiceBase<Dt_LocationInfo, ILocationInfoRepository>, ILocationInfoService
|
{
|
private readonly IUnitOfWorkManage _unitOfWorkManage;
|
private readonly IBasicRepository _basicRepository;
|
private readonly IStockInfoRepository _stockInfoRepository;
|
private readonly IProStockInfoRepository _proStockInfoRepository;
|
public ILocationInfoRepository Repository => BaseDal;
|
|
public LocationInfoService(ILocationInfoRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IBasicRepository basicRepository, IStockInfoRepository stockInfoRepository, IProStockInfoRepository proStockInfoRepository) : base(BaseDal)
|
{
|
_unitOfWorkManage = unitOfWorkManage;
|
_basicRepository = basicRepository;
|
_stockInfoRepository = stockInfoRepository;
|
_proStockInfoRepository = proStockInfoRepository;
|
}
|
|
/// <summary>
|
/// 查询货位对应的RFID及库存信息
|
/// </summary>
|
/// <param name="locationCodes"></param>
|
/// <returns></returns>
|
public WebResponseContent GetRfid(string[] locationCodes, int warehouseId = 0)
|
{
|
try
|
{
|
// 参数验证
|
if (locationCodes == null || locationCodes.Length == 0)
|
{
|
return WebResponseContent.Instance.Error("货位编号不能为空");
|
}
|
|
if (warehouseId == 1)
|
{
|
// 查询原料库Dt_StockInfo表,获取RFID及库存信息
|
var rawMaterialRfidList = _stockInfoRepository.QueryData()
|
.Where(x => locationCodes.Contains(x.LocationCode))
|
.Select(x => new {
|
locationCode = x.LocationCode,
|
rfidCode = x.RfidCode,
|
paperRoll = x.MaterielName, // 纸卷名称
|
width = x.MaterielWide, // 门幅(幅宽)
|
barcode = x.PalletCode, // 纸卷条码
|
status = x.StockStatus, // 状态
|
inDate = x.CreateDate // 入库时间(创建时间)
|
})
|
.ToList();
|
|
// 返回结果
|
return WebResponseContent.Instance.OK(data: rawMaterialRfidList);
|
}
|
|
if (warehouseId == 2)
|
{
|
// 替换原有的 .Select(x => new { ... Detail = x.proStockInfoDetails?.FirstOrDefault() ... }) 代码块
|
var finishedProductRfidList = _proStockInfoRepository.Db.Queryable<Dt_ProStockInfo>()
|
.Includes(x => x.proStockInfoDetails)
|
.Where(x => locationCodes.Contains(x.LocationCode))
|
.ToList()
|
.Select(x => new
|
{
|
locationCode = x.LocationCode,
|
rfidCode = x.PalletCode,
|
paperRoll = (x.proStockInfoDetails != null && x.proStockInfoDetails.Count > 0) ? x.proStockInfoDetails[0].ProductName : string.Empty,
|
productName = (x.proStockInfoDetails != null && x.proStockInfoDetails.Count > 0) ? x.proStockInfoDetails[0].ProductName : string.Empty,
|
width = (x.proStockInfoDetails != null && x.proStockInfoDetails.Count > 0) ? x.proStockInfoDetails[0].StockQty : 0,
|
quantity = (x.proStockInfoDetails != null && x.proStockInfoDetails.Count > 0) ? x.proStockInfoDetails[0].StockQty : 0,
|
barcode = x.PalletCode,
|
status = x.StockStatus,
|
inDate = x.CreateDate
|
})
|
.ToList();
|
|
// 返回结果
|
return WebResponseContent.Instance.OK(data: finishedProductRfidList);
|
}
|
// 如果没有匹配的仓库ID,返回空列表
|
return WebResponseContent.Instance.OK(data: new List<object>());
|
}
|
catch (Exception ex)
|
{
|
Console.WriteLine($"GetRfid 异常: {ex.Message}");
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 批量启用货位
|
/// </summary>
|
/// <param name="keys">货位主键数组</param>
|
/// <returns></returns>
|
public WebResponseContent LocationEnableStatus(int[] keys)
|
{
|
List<Dt_LocationInfo> locationInfos = Repository.QueryData(x => keys.Contains(x.Id));
|
locationInfos.ForEach(x =>
|
{
|
x.EnableStatus = EnableStatusEnum.Normal.ObjToInt();
|
});
|
Repository.UpdateData(locationInfos);
|
|
return WebResponseContent.Instance.OK();
|
}
|
|
/// <summary>
|
/// 批量禁用货位
|
/// </summary>
|
/// <param name="keys">货位主键数组</param>
|
/// <returns></returns>
|
public WebResponseContent LocationDisableStatus(int[] keys)
|
{
|
List<Dt_LocationInfo> locationInfos = Repository.QueryData(x => keys.Contains(x.Id));
|
locationInfos.ForEach(x =>
|
{
|
x.EnableStatus = EnableStatusEnum.Disable.ObjToInt();
|
});
|
Repository.UpdateData(locationInfos);
|
|
return WebResponseContent.Instance.OK();
|
}
|
|
/// <summary>
|
/// 单个启用货位
|
/// </summary>
|
/// <param name="key">货位主键</param>
|
/// <returns></returns>
|
public WebResponseContent LocationEnableStatus(int key)
|
{
|
return LocationEnableStatus(new int[] { key });
|
}
|
|
/// <summary>
|
/// 单个禁用货位
|
/// </summary>
|
/// <param name="key">货位主键</param>
|
/// <returns></returns>
|
public WebResponseContent LocationDisableStatus(int key)
|
{
|
return LocationDisableStatus(new int[] { key });
|
}
|
/// <summary>
|
/// 初始化货位
|
/// </summary>
|
/// <param name="initializationLocationDTO"></param>
|
/// <returns></returns>
|
public WebResponseContent InitializationLocation(InitializationLocationDTO initializationLocationDTO)
|
{
|
try
|
{
|
(bool, string, object?) result = ModelValidate.ValidateModelData(initializationLocationDTO);
|
if (!result.Item1) return WebResponseContent.Instance.Error(result.Item2);
|
|
int depth = initializationLocationDTO.Depth;
|
List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
|
for (int i = 0; i < initializationLocationDTO.MaxRow; i++)
|
{
|
if ((i + 1) % initializationLocationDTO.MaxRow == 1)
|
{
|
depth = initializationLocationDTO.Depth;
|
}
|
else if ((i + 1) % initializationLocationDTO.MaxRow == initializationLocationDTO.Depth + 1)
|
{
|
depth = 1;
|
}
|
else if ((i + 1) % initializationLocationDTO.MaxRow > 1 && (i + 1) % initializationLocationDTO.MaxRow <= initializationLocationDTO.Depth)
|
{
|
depth -= 1;
|
}
|
else
|
{
|
depth += 1;
|
}
|
for (int j = 0; j < initializationLocationDTO.MaxColumn; j++)
|
{
|
for (int k = 0; k < initializationLocationDTO.MaxLayer; k++)
|
{
|
Dt_LocationInfo locationInfo = new Dt_LocationInfo()
|
{
|
WarehouseId = 0,
|
Columns = j + 1,
|
EnableStatus = EnableStatusEnum.Normal.ObjToInt(),
|
Layer = k + 1,
|
LocationStatus = LocationStatusEnum.Free.ObjToInt(),
|
LocationType = LocationTypeEnum.Undefined.ObjToInt(),
|
RoadwayNo = $"{initializationLocationDTO.Roadway.ToString()}",
|
Row = i + 1,
|
Depth = depth,
|
};
|
locationInfo.LocationCode = $"{locationInfo.RoadwayNo}-{locationInfo.Row.ToString().PadLeft(3, '0')}-{locationInfo.Columns.ToString().PadLeft(3, '0')}-{locationInfo.Layer.ToString().PadLeft(3, '0')}-{locationInfo.Depth.ToString().PadLeft(2, '0')}";
|
locationInfo.LocationName = $"{locationInfo.RoadwayNo}巷道{locationInfo.Row.ToString().PadLeft(3, '0')}行{locationInfo.Columns.ToString().PadLeft(3, '0')}列{locationInfo.Layer.ToString().PadLeft(3, '0')}层{locationInfo.Depth.ToString().PadLeft(2, '0')}深";
|
locationInfos.Add(locationInfo);
|
}
|
}
|
}
|
BaseDal.AddData(locationInfos);
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
}
|
}
|