using SqlSugar; using SqlSugar.Extensions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEAWCS_Common.LocationEnum; using WIDESEAWCS_Common.StockEnum; using WIDESEAWCS_Core.BaseRepository; using WIDESEAWCS_Core.Enums; using WIDESEAWCS_DTO.Stock; using WIDESEAWCS_IBasicRepository; using WIDESEAWCS_IStockRepository; using WIDESEAWCS_Model.Models; namespace WIDESEA_StockRepository { public class StockInfoRepository : RepositoryBase, IStockInfoRepository { public StockInfoRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage) { } public List GetAllStockViews() { ISugarQueryable sugarQueryable = Db.Queryable(); ISugarQueryable sugarQueryable1 = Db.Queryable(); return sugarQueryable.InnerJoin(sugarQueryable1, (a, b) => a.LocationCode == b.LocationCode).Select((a, b) => new StockViewDTO { AreaId = a.AreaId, LocationCode = b.LocationCode, Column = a.Column, CreateDate = b.CreateDate, Creater = b.Creater, Depth = a.Depth, EnalbeStatus = a.EnableStatus, IsFull = b.IsFull, Layer = a.Layer, LocationName = a.LocationName, LocationStatus = a.LocationStatus, LocationType = a.LocationType, Modifier = b.Modifier, ModifyDate = b.ModifyDate, PalletCode = b.PalletCode, StockRemark = b.Remark, RoadwayNo = a.RoadwayNo, Row = a.Row, StockId = b.Id, StockStatus = b.StockStatus, Details = b.Details, }).Includes(x => x.Details).ToList(); } public Dt_StockInfo GetStockInfo(string palletCode) { return Db.Queryable().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First(); } public List GetStockInfos(string materielCode) { return Db.Queryable().Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode)).ToList(); //ISugarQueryable sugarQueryable = Db.Queryable(); //ISugarQueryable sugarQueryable1 = Db.Queryable().Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode)); //return sugarQueryable.InnerJoin(sugarQueryable1, (a, b) => a.LocationCode == b.LocationCode).Select((a, b) => b).Includes(x => x.Details).ToList(); } public List GetStockInfos(string materielCode, List locationCodes) { return Db.Queryable().Where(x => locationCodes.Contains(x.LocationCode)).Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode)).ToList(); //ISugarQueryable sugarQueryable = Db.Queryable().Where(x => locationCodes.Contains(x.LocationCode)); //ISugarQueryable sugarQueryable1 = Db.Queryable().Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode)); //return sugarQueryable.InnerJoin(sugarQueryable1, (a, b) => a.LocationCode == b.LocationCode).Select((a, b) => b).OrderBy(a => a.CreateDate).Includes(a => a.Details).ToList(); } public List GetStockInfosByIds(List ids) { return Db.Queryable().Where(x => ids.Contains(x.Id)).Includes(x => x.Details).ToList(); } public List GetStockInfosByPalletCodes(List palletCodes) { return Db.Queryable().Where(x => palletCodes.Contains(x.PalletCode)).Includes(x => x.Details).ToList(); } public List GetStockInfosExclude(string materielCode, List palletCodes) { return Db.Queryable().Where(x => !palletCodes.Contains(x.PalletCode)).Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode)).ToList(); } public bool UpdateDataWithDetail(Dt_StockInfo stockInfo) { return Db.UpdateNav(stockInfo).Include(x => x.Details).ExecuteCommand(); } public Dt_StockInfo GetPalletStockInfo(string roadwayNo) { //ISugarQueryable locationCodes = Db.Queryable().Where(x => x.RoadwayNo == roadwayNo && x.LocationStatus == LocationStatusEnum.Pallet.ObjToInt() && (x.EnalbeStatus == LocationEnalbeStatusEnum.OnlyOut.ObjToInt() || LocationEnalbeStatusEnum.Normal.ObjToInt() == x.EnalbeStatus)).Select(x => x.LocationCode); //return Db.Queryable().Where(x => x.StockStatus == StockStatusEmun.已入库.ObjToInt() && SqlFunc.Subqueryable().Where(v => v.LocationCode == x.LocationCode && v.RoadwayNo == roadwayNo && v.LocationStatus == LocationStatusEnum.Pallet.ObjToInt() && (v.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt() || EnableStatusEnum.Normal.ObjToInt() == v.EnableStatus)).Any()).OrderBy(x => x.ModifyDate).First(); return null; } } }