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, 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 GetPageData(PageDataOptions options) { string wheres = ValidatePageOptions(options); //获取排序字段 Dictionary orderbyDic = GetPageDataSort(options, TProperties); List orderByModels = new List(); foreach (var item in orderbyDic) { OrderByModel orderByModel = new() { FieldName = item.Key, OrderByType = item.Value }; orderByModels.Add(orderByModel); } int totalCount = 0; List searchParametersList = new List(); if (!string.IsNullOrEmpty(options.Wheres)) { try { searchParametersList = options.Wheres.DeserializeObject>(); options.Filter = searchParametersList; } catch { } } var data = BaseDal.Db.Queryable() .Includes(x => x.BoxingInfoDetails) .WhereIF(!wheres.IsNullOrEmpty(), wheres) .OrderBy(orderByModels) .ToPageList(options.Page, options.Rows, ref totalCount); new PageGridData(totalCount, data); return new PageGridData(totalCount, data); } #region 组盘 public async Task AddGroupPlateAsync(GroupPlate groupPlate) { WebResponseContent content = new WebResponseContent(); try { var boxingInfo = BaseDal.QueryFirst(x=>x.PalletCode == groupPlate.palletCode); if(boxingInfo != null) { return content.Error($"托盘号【{groupPlate.palletCode}】存在组盘信息"); } var newBoxingInfo = new DtBoxingInfo { PalletCode = groupPlate.palletCode, MaterielName = groupPlate.group, StockStatus = (int)StockStateEmun.组盘暂存, IsFull = groupPlate.IsFull, Remark = string.Empty }; await BaseDal.AddDataAsync(newBoxingInfo); return content.OK("组盘成功"); } catch (Exception ex) { return content.Error(ex.Message); } } #endregion #region 解盘 public async Task DeleteGroupPlateAsync(GroupPlate groupPlate) { WebResponseContent content = new WebResponseContent(); try { if (groupPlate == null || groupPlate.palletCode.IsNullOrEmpty()) { return content.Error("参数错误"); } var boxingInfo = await BaseDal.QueryFirstAsync(x => x.PalletCode == groupPlate.palletCode); if (!boxingInfo.IsNullOrEmpty()) { DtBoxingInfo_Hty boxinghty = boxingInfo.Adapt(); boxinghty.ModifyDate = DateTime.Now; boxinghty.StockStatus = (int)StockStateEmun.组盘撤销; await _unitOfWorkManage.UseTranAsync(async () => { await BaseDal.Db.Deleteable(x => x.Id == boxingInfo.Id).ExecuteCommandAsync(); await AddBoxingHtyAsync(boxinghty); }); content.OK("解盘成功"); } else { content.Error("未找到组盘数据"); } return content; } catch (Exception ex) { return content.Error(ex.Message); } } private async Task AddBoxingHtyAsync(DtBoxingInfo_Hty stockhty) { var isStockAdd = await SqlSugarHelper.DbWMS.InsertNav(stockhty).Include(x=>x.BoxingInfoDetails).ExecuteCommandAsync(); if (!isStockAdd) { throw new Exception("组盘历史信息添加失败"); } } #endregion }