using Mapster;
|
using Masuit.Tools;
|
using Masuit.Tools.Models;
|
using SqlSugar;
|
using System.ComponentModel.DataAnnotations;
|
using System.Linq.Expressions;
|
using System.Threading.Tasks;
|
using WIDESEA_Common;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_DTO.Basic;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_StorageBasicService;
|
|
public class BoxingInfoService : ServiceBase<DtBoxingInfo, IBoxingInfoRepository>, IBoxingInfoService
|
{
|
private readonly IUnitOfWorkManage _unitOfWorkManage;
|
private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository;
|
private readonly IBoxingInfoDetailRepository _boxingInfoDetailRepository;
|
public BoxingInfoService(IBoxingInfoRepository BaseDal,IUnitOfWorkManage unitOfWorkManage, ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository,IBoxingInfoDetailRepository boxingInfoDetailRepository) : base(BaseDal)
|
{
|
_unitOfWorkManage = unitOfWorkManage;
|
_locationStatusChangeRecordRepository = locationStatusChangeRecordRepository;
|
_boxingInfoDetailRepository = boxingInfoDetailRepository;
|
}
|
public override PageGridData<DtBoxingInfo> 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 { }
|
}
|
var data = BaseDal.Db.Queryable<DtBoxingInfo>()
|
.Includes(x => x.BoxingInfoDetails)
|
.WhereIF(!wheres.IsNullOrEmpty(), wheres)
|
.OrderBy(orderByModels)
|
.ToPageList(options.Page, options.Rows, ref totalCount);
|
new PageGridData<DtBoxingInfo>(totalCount, data);
|
return new PageGridData<DtBoxingInfo>(totalCount, data);
|
}
|
|
#region 组盘
|
|
public async Task<WebResponseContent> AddGroupPlateAsync(GroupPlate groupPlate)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
|
return content.OK("组盘成功");
|
}
|
catch (Exception ex)
|
{
|
return content.Error(ex.Message);
|
}
|
}
|
|
|
|
#endregion
|
|
#region 解盘
|
public async Task<WebResponseContent> DeleteGroupPlateAsync(GroupPlate groupPlate)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
if (groupPlate == null || groupPlate.palletCode.IsNullOrEmpty())
|
{
|
return content.Error("参数错误");
|
}
|
var boxingInfo = await BaseDal.QueryFirstNavAsync(x => x.PalletCode == groupPlate.palletCode);
|
if (!boxingInfo.IsNullOrEmpty())
|
{
|
boxingInfo.StockStatus = (int)StockStateEmun.组盘撤销;
|
DtBoxingInfo_Hty stockhty = boxingInfo.Adapt<DtBoxingInfo_Hty>();
|
stockhty.ModifyDate = DateTime.Now;
|
await _unitOfWorkManage.UseTranAsync(async () =>
|
{
|
await BaseDal.Db.DeleteNav<DtBoxingInfo>(x => x.Id == boxingInfo.Id)
|
.Include(x => x.BoxingInfoDetails)
|
.ExecuteCommandAsync();
|
await AddStockHtyAsync(stockhty);
|
});
|
content.OK("解盘成功");
|
}
|
else
|
{
|
content.Error("未找到组盘数据");
|
}
|
return content;
|
}
|
catch (Exception ex)
|
{
|
return content.Error(ex.Message);
|
}
|
}
|
private async Task AddStockHtyAsync(DtBoxingInfo_Hty stockhty)
|
{
|
var isStockAdd = await SqlSugarHelper.DbWMS.InsertNav(stockhty).Include(x=>x.BoxingInfoDetails).ExecuteCommandAsync();
|
if (!isStockAdd)
|
{
|
throw new Exception("组盘历史信息添加失败");
|
}
|
}
|
#endregion
|
}
|