using AngleSharp.Dom; using Mapster; using Masuit.Tools; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using SqlSugar; using System.Collections; using System.Collections.Generic; using System.Drawing.Printing; using System.Linq.Expressions; using System.Threading.Tasks; using WIDESEA_Cache; using WIDESEA_Common; using WIDESEA_Core; using WIDESEA_Model.Models; namespace WIDESEA_StorageBasicService; public class StockInfoService : ServiceBase, IStockInfoService { private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository; public StockInfoService(IStockInfoRepository BaseDal, ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository) : base(BaseDal) { _locationStatusChangeRecordRepository = locationStatusChangeRecordRepository; } /// /// 分页 /// /// /// 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 { } } Expression> locationStatus = null; Expression> floor = null; Expression> areaId = 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("floor")) { floor = x => x.LocationInfo.Floor.Contains(item.Value); } else if (item.Name.Contains("areaId")) { areaId = x => x.LocationInfo.AreaId== Convert.ToInt32(item.Value); } } //.IncludesAllFirstLayer() var data = BaseDal.Db.Queryable() .Includes(x => x.StockInfoDetails) .Includes(x => x.LocationInfo) .WhereIF(!wheres.IsNullOrEmpty(), wheres) .WhereIF(locationStatus != null, locationStatus) .WhereIF(floor != null, floor) .WhereIF(areaId != null, areaId) .OrderBy(orderByModels) .ToPageList(options.Page, options.Rows, ref totalCount); new PageGridData(totalCount, data); return new PageGridData(totalCount, data); } /// /// 批量删除 /// /// /// public override WebResponseContent DeleteData(object[] keys) { try { List stockInfos = new List(); List locationInfos = new List(); foreach (var item in keys) { var stock = BaseDal.QueryFirstNavAsync(x => x.Id == item.ObjToInt()).Result; var stockHty = stock.Adapt(); stockInfos.Add(stockHty); var location = SqlSugarHelper.DbWMS.Queryable().FirstAsync(x => x.LocationCode == stock.LocationCode).Result; var lastStatus = location.LocationStatus; location.LocationStatus = (int)LocationEnum.Free; locationInfos.Add(location); _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(location, lastStatus, (int)StatusChangeTypeEnum.ManualOperation, 0); } //var hty = BaseDal.Db.InsertNav(stockInfos) // .Include(x => x.StockInfoDetails) // .ExecuteCommand(); var isStockAdd = SqlSugarHelper.DbWMS.InsertNav(stockInfos).IncludesAllFirstLayer().ExecuteCommandAsync(); var locationd = SqlSugarHelper.DbWMS.Updateable(locationInfos).ExecuteCommandHasChange(); return base.DeleteData(keys); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } }