using AngleSharp.Dom;
|
using Dm;
|
using Mapster;
|
using Masuit.Tools;
|
using NewLife.Reflection;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
using SqlSugar;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Drawing.Printing;
|
using System.Linq.Expressions;
|
using System.Threading.Tasks;
|
using System.Xml.Linq;
|
using WIDESEA_Cache;
|
using WIDESEA_Common;
|
using WIDESEA_Core;
|
using WIDESEA_Core.Enums;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_DTO;
|
using WIDESEA_DTO.Basic;
|
using WIDESEA_DTO.Stock;
|
using WIDESEA_DTO.WMS;
|
using WIDESEA_Model.Models;
|
using WIDESEA_StorageTaskRepository;
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
namespace WIDESEA_StorageBasicService;
|
|
public class StockInfoService : ServiceBase<DtStockInfo, IStockInfoRepository>, IStockInfoService
|
{
|
private readonly LogFactory LogFactory = new LogFactory();
|
private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository;
|
private readonly IUnitOfWorkManage _unitOfWorkManage;
|
private readonly IStockInfoDetailRepository _stockInfoDetailRepository;
|
private readonly IDt_TaskService _taskService;
|
private readonly ILocationInfoRepository _locationRepository;
|
private readonly IDt_TaskRepository _taskRepository;
|
private readonly IDt_Task_HtyRepository _task_HtyRepository;
|
|
public StockInfoService(IStockInfoRepository BaseDal,
|
ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository,
|
IUnitOfWorkManage unitOfWorkManage,
|
IStockInfoDetailRepository stockInfoDetailRepository,
|
IDt_TaskService taskService,
|
ILocationInfoRepository locationRepository,
|
IDt_TaskRepository taskRepository,
|
IDt_Task_HtyRepository task_HtyRepository) : base(BaseDal)
|
{
|
_locationStatusChangeRecordRepository = locationStatusChangeRecordRepository;
|
_unitOfWorkManage = unitOfWorkManage;
|
_stockInfoDetailRepository = stockInfoDetailRepository;
|
_taskService = taskService;
|
_locationRepository = locationRepository;
|
_taskRepository = taskRepository;
|
_task_HtyRepository = task_HtyRepository;
|
}
|
#region 方法重写
|
/// <summary>
|
/// 分页
|
/// </summary>
|
/// <param name="options"></param>
|
/// <returns></returns>
|
public override PageGridData<DtStockInfo> GetPageData(PageDataOptions options)
|
{
|
string wheres = ValidatePageOptions(options);
|
//获取排序字段
|
Dictionary<string, OrderByType> orderbyDic = GetPageDataSort(options, TProperties);
|
List<OrderByModel> orderByModels = new List<OrderByModel>();
|
foreach (var item in orderbyDic)
|
{
|
OrderByModel orderByModel = new()
|
{
|
FieldName = item.Key,
|
OrderByType = item.Value
|
};
|
orderByModels.Add(orderByModel);
|
}
|
|
|
int totalCount = 0;
|
List<SearchParameters> searchParametersList = new List<SearchParameters>();
|
if (!string.IsNullOrEmpty(options.Wheres))
|
{
|
try
|
{
|
searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
|
options.Filter = searchParametersList;
|
}
|
catch { }
|
}
|
|
Expression<Func<DtStockInfo, bool>> locationStatus = null;
|
Expression<Func<DtStockInfo, bool>> floor = null;
|
Expression<Func<DtStockInfo, bool>> areaId = null;
|
Expression<Func<DtStockInfo, bool>> materielCode = null;
|
Expression<Func<DtStockInfo, bool>> materielName = null;
|
Expression<Func<DtStockInfo, bool>> demandClassification = null;
|
foreach (var item in searchParametersList)
|
{
|
if (item.Name.Contains("locationStatus"))
|
{
|
locationStatus = x => x.LocationInfo.LocationStatus == Convert.ToInt32(item.Value);
|
}
|
else if (item.Name.Contains("areaId"))
|
{
|
areaId = x => x.LocationInfo.AreaId == Convert.ToInt32(item.Value);
|
}
|
else if (item.Name.Contains("materielCode"))
|
{
|
materielCode = x => x.StockInfoDetails.Any(d => d.MaterielCode.Contains(item.Value));
|
}
|
else if (item.Name.Contains("materielName"))
|
{
|
materielName = x => x.StockInfoDetails.Any(d => d.MaterielName.Contains(item.Value));
|
}
|
else if (item.Name.Contains("demandClassification"))
|
{
|
demandClassification = x => x.StockInfoDetails.Any(d => d.DemandClassification.Contains(item.Value));
|
}
|
}
|
//.IncludesAllFirstLayer()
|
var data = BaseDal.Db.Queryable<DtStockInfo>()
|
.Includes(x => x.StockInfoDetails)
|
.Includes(x => x.LocationInfo)
|
.WhereIF(!wheres.IsNullOrEmpty(), wheres)
|
.WhereIF(locationStatus != null, locationStatus)
|
.WhereIF(floor != null, floor)
|
.WhereIF(areaId != null, areaId)
|
.WhereIF(materielCode != null, materielCode)
|
.WhereIF(materielName != null, materielName)
|
.WhereIF(demandClassification != null, demandClassification)
|
.OrderBy(orderByModels)
|
.ToPageList(options.Page, options.Rows, ref totalCount);
|
new PageGridData<DtStockInfo>(totalCount, data);
|
return new PageGridData<DtStockInfo>(totalCount, data);
|
}
|
|
|
public List<T> DeserializeList<T>(List<Dictionary<string, object>> rawData)
|
{
|
if (rawData == null) return new List<T>();
|
var processedData = rawData.Select(dict =>
|
{
|
var newDict = new Dictionary<string, object>();
|
foreach (var kvp in dict)
|
{
|
var newKey = char.ToUpper(kvp.Key[0]) + kvp.Key.Substring(1);
|
newDict[newKey] = kvp.Value;
|
}
|
return newDict;
|
}).ToList();
|
var json = JsonSerializer.Serialize(processedData);
|
return JsonSerializer.Deserialize<List<T>>(json);
|
}
|
|
#endregion
|
|
#region 库存视图
|
public List<StockSelectViewDTO> GetStockSelectViews(GetStockSelectViewDto viewDto)
|
{
|
var stocks = BaseDal.Db.Queryable<DtStockInfo>()
|
.Includes(x => x.StockInfoDetails)
|
.Includes(x => x.LocationInfo)
|
.Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable)
|
.Where(x => x.StockInfoDetails.Any(d => d.MaterielCode == viewDto.materielCode && d.Quantity > 0 && d.Quantity > d.OutboundQuantity)).ToList().OrderBy(x => x.CreateDate);
|
|
List<DtLocationInfo> locationInfos = new List<DtLocationInfo>();
|
List<DtStockInfo> stockNew = new List<DtStockInfo>();
|
if (stocks != null || stocks.Count() > 0)
|
{
|
var locations = stocks.Select(s => s.LocationInfo).ToList();
|
stockNew = stocks.Where(s => s.LocationInfo != null && locationInfos.Contains(s.LocationInfo)).ToList();
|
}
|
|
var result = stockNew.Select(s => new StockSelectViewDTO
|
{
|
MaterielCode = s.StockInfoDetails
|
.FirstOrDefault(d => d.MaterielCode == viewDto.materielCode)?.MaterielCode ?? string.Empty,
|
|
MaterielName = s.StockInfoDetails
|
.FirstOrDefault(d => d.MaterielCode == viewDto.materielCode)?.MaterielName ?? string.Empty,
|
|
UseableQuantity = s.StockInfoDetails
|
.Where(d => d.MaterielCode == viewDto.materielCode && d.Quantity > 0 && d.Quantity > d.OutboundQuantity)
|
.Sum(d => (decimal?)d.Quantity - d.OutboundQuantity) ?? 0, // 处理空值情况
|
|
PalletCode = s.PalletCode ?? string.Empty,
|
LocationCode = s.LocationInfo?.LocationCode ?? string.Empty
|
}).ToList();
|
|
return result;
|
}
|
|
#endregion
|
|
|
}
|