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 { 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.QueryFirstNavAsync(x => x.PalletCode == groupPlate.palletCode); if (!boxingInfo.IsNullOrEmpty()) { boxingInfo.StockStatus = (int)StockStateEmun.组盘撤销; DtBoxingInfo_Hty stockhty = boxingInfo.Adapt(); stockhty.ModifyDate = DateTime.Now; await _unitOfWorkManage.UseTranAsync(async () => { await BaseDal.Db.DeleteNav(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 }