using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using Model.ModelDto.SysDto; using Model.ModelVm.SysVm; using SqlSugar; using WMS.DAL; using WMS.Entity.BllAsnEntity; using WMS.Entity.Context; using WMS.Entity.DataEntity; using WMS.Entity.SysEntity; using WMS.IBLL.ISysServer; using WMS.IDAL.ISysInterface; namespace WMS.BLL.SysServer { public class StorageLocatServer : DbHelper, IStorageLocatServer { private static readonly SqlSugarScope Db = DataContext.Db; public IStorageLocatRepository LocatRst { get; set; } public StorageLocatServer(IStorageLocatRepository locatRst) : base(Db) { LocatRst = locatRst; } /// /// 查询储位信息 /// /// 仓库号 /// 巷道号 /// 区域号 /// 状态 /// 标志0:正常 1:屏蔽 2:损坏 屏蔽:储位不可存放货物,不影响内侧储位使用 损坏:内侧储位也不允许使用 /// 储位号 /// 排 /// 列 /// 层 /// /// /// /// public List GetStorageLocatList(string houseNo, string roadwayNo, string areaNo, string status, string flag, string locat, int? row, int? col, int? layer, int page, int limit, out int count) { try { Expression> item = Expressionable.Create() //创建表达式 .AndIF(!string.IsNullOrWhiteSpace(houseNo), it => it.WareHouseNo == houseNo) .AndIF(!string.IsNullOrWhiteSpace(roadwayNo), it => it.RoadwayNo == roadwayNo) .AndIF(!string.IsNullOrWhiteSpace(areaNo), it => it.AreaNo == areaNo) .AndIF(!string.IsNullOrWhiteSpace(status), it => it.Status == status) .AndIF(!string.IsNullOrWhiteSpace(flag), it => it.Flag == flag) .AndIF(!string.IsNullOrWhiteSpace(locat), it => it.LocatNo.Contains(locat.Trim())) .AndIF(row != null, it => it.Row == row) .AndIF(col != null, it => it.Column == col) .AndIF(layer != null, it => it.Layer == layer) .ToExpression();//注意 这一句 不能少 var data = LocatRst.GetAllByOrderPageAsync(item, limit, page, out int counts) .Includes(x => x.WareHouseInfo) .Includes(x => x.AreaInfo) .Includes(x => x.RoadwayInfo) .Includes(x => x.TemperatureInfo) .Includes(x => x.CreateUserInfo) .Includes(x => x.UpdateUserInfo).ToList(); count = counts; return data.Select(m => new LocatDto() { Id = m.Id, LocatNo = m.LocatNo, WareHouseNo = m.WareHouseNo, WareHouseName = m.WareHouseInfo == null ? "" : m.WareHouseInfo.WareHouseName, RoadwayNo = m.RoadwayNo, RoadwayName = m.RoadwayInfo == null ? "" : m.RoadwayInfo.RoadwayName, AreaNo = m.AreaNo, AreaName = m.AreaInfo == null ? "" : m.AreaInfo.AreaName, Status = m.Status, StatusName = GetStatus(m.Status), Flag = m.Flag, FlagName = GetFlag(m.Flag), Depth = m.Depth, Row = m.Row, Column = m.Column, Layer = m.Layer, Height = m.Height, Weight = m.Weight, AisleOne=m.AisleOne, AisleTwo=m.AisleTwo, TempName = m.TemperatureInfo == null ? "" : m.TemperatureInfo.DictName, CreateTime = m.CreateTime, CreateUserName = m.CreateUserInfo == null ? "" : m.CreateUserInfo.UserName, UpdateTime = m.UpdateTime, UpdateUserName = m.UpdateUserInfo == null ? "" : m.UpdateUserInfo.UserName }).ToList(); } catch (Exception e) { throw new Exception(e.Message); } } /// /// 查询单条储位信息 /// /// /// public SysStorageLocat GetStorageLocat(int id) { try { var data = LocatRst.GetOneById(id); return data; } catch (Exception e) { Console.WriteLine(e); throw; } } public bool EditStorageLocat(EditLocateVm model,string url ,int userId) { try { var bl = LocatRst.EditStorageLocat(model.Id, model.Status, model.Flag, model.Temperature,url, userId); return bl; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 添加储位信息(立体库)用于开发人员添加基础信息 /// /// 仓库号 /// 巷道号 /// 区域号 /// 排 /// 列 /// 层 /// 深度 /// 操作人 /// public async Task AddStorageLocat(string houseNo, string roadwayNo, string areaNo, int row, int col, int layer, string dept, int userId) { try { var q = 0; //R01 -01 -01 -02 //巷道–排-列-层 for (int r = 13; r <= row; r++)//排 { var r1 = "1"; if (r < 10) { r1 = "0" + r; } else { r1 = r.ToString(); } for (int l = 1; l <= layer; l++)//层 { var l1 = "1"; if (l < 10) { l1 = "0" + l; } else { l1 = l.ToString(); } for (int c = 1; c <= col; c++)//列 { var c1 = "1"; if (c < 10) { c1 = "0" + c; } else { c1 = c.ToString(); } var area = l <= 7 ? "A12" : "A11";//区域 for (int d = 1; d <= int.Parse(dept); d++) //深度 { var s = "0" + d;//深度 q += await LocatRst.AddAsync(new SysStorageLocat() { LocatNo = r1 + c1 + l1 + s, WareHouseNo = houseNo, RoadwayNo = roadwayNo, AreaNo = areaNo, Status = "0", Flag = "0", Depth = s, Row = r, Column = c, Layer = l, CreateUser = userId }); } } } } return q; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 添加储位信息(平库)用于开发人员添加基础信息 /// /// /// /// public async Task AddPkStorageLocat(AddLocateVm model, int userId) { try { var q = 0; List _list = new List(); // 列循环 for (int z = 1; z <= model.Col; z++) { var locatInfo = new SysStorageLocat() { // 区域+排+列+深度 LocatNo = model.AreaNo + model.Row.ToString().PadLeft(3, '0') + z.ToString().PadLeft(2, '0'), WareHouseNo = model.HouseNo, RoadwayNo = "", AreaNo = model.AreaNo, Status = "0", AisleOne = "", AisleTwo = "", Flag = "0", Depth = "1", Row = model.Row, Column = z, Layer = 1, CreateUser = userId }; _list.Add(locatInfo); } foreach (var item in _list) { //if (model.AisleNum > 0) //{ //if (item.LocatNo != _list[0].LocatNo) //{ // item.AisleOne = _list[0].LocatNo; //} if (model.AisleNum == 0) { if (item.LocatNo != _list[0].LocatNo) { item.AisleOne = _list[0].LocatNo; } } if (model.AisleNum == 1) { if (item.LocatNo != _list[model.Col-1].LocatNo) { item.AisleOne = _list[model.Col - 1].LocatNo; } } //} await LocatRst.AddAsync(item); } return _list.Count; } catch (Exception e) { throw new Exception(e.Message); } } public bool EditStorageLocatList(EditLocateListVm model,string url, int userId) { try { var bl = LocatRst.EditStorageLocatList(model.Id, model.Status, model.Flag, model.Temperature, url, userId); return bl; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 查询储位状态 /// /// /// public string GetStatus(string code) { if (string.IsNullOrWhiteSpace(code)) { return ""; } else { var str = ""; switch (code) { case "0": str = "空储位"; break; case "1": str = "有物品"; break; case "2": str = "入库中"; break; case "3": str = "出库中"; break; case "4": str = "移入中"; break; case "5": str = "移出中"; break; } return str; } } /// /// 查询储位标志 /// /// /// public string GetFlag(string code) { if (string.IsNullOrWhiteSpace(code)) { return ""; } else { var str = ""; switch (code) { case "0": str = "正常"; break; case "1": str = "屏蔽"; break; case "2": str = "损坏"; break; } return str; } } /// /// 获取储位信息 /// /// 仓库 /// 巷道号 /// 排 1 or 2 /// 深度 /// public List GetStorageLocatLists(string wareHouseNo, string roadway, string row, string depth) { try { var list = Db.Queryable().Where(m => m.IsDel == "0" && m.WareHouseNo == wareHouseNo && m.RoadwayNo == roadway && m.Row == int.Parse(row) && m.Depth == depth).ToList(); return list; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 获取最大层级 /// /// 仓库号 /// 仓库号 /// 仓库号 /// public int GetMaxLayer(string wareHouseNo, string roadway, string row) { try { var road = roadway.Substring(1, roadway.Length - 1); var num = int.Parse(road); var rows = (num - 1) * 2 + int.Parse(row);//排 var maxLayer = Db.Queryable().Where(m => m.IsDel == "0" && m.WareHouseNo == wareHouseNo && m.RoadwayNo == roadway && m.Row == int.Parse(row)).Max(m => m.Layer); return maxLayer; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 获取最大列数 /// /// 仓库号 /// 仓库号 /// 仓库号 /// public int GetColumn(string wareHouseNo, string roadway, string row) { try { var road = roadway.Substring(1, roadway.Length - 1); var num = int.Parse(road); var rows = (num - 1) * 2 + int.Parse(row);//排 var maxColumn = Db.Queryable().Where(m => m.IsDel == "0" && m.WareHouseNo == wareHouseNo && m.RoadwayNo == roadway && m.Row == int.Parse(row)).Max(m => m.Column); return maxColumn; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 获取该仓库排数 /// /// 仓库号 /// public List GetStorageLocatRow(string wareHouseNo) { List maxrow = LocatRst.GetStorageLocatRow(wareHouseNo); return maxrow; } /// /// 获取该仓库深度 /// /// 仓库号 /// public List GetDepth(string wareHouseNo) { List depthlist = LocatRst.GetDepth(wareHouseNo); return depthlist; } /// /// 根据排获取该仓库深度 /// /// 排 /// public List GetRowDepth(string row) { string str = $"select Depth from SysStorageLocat where IsDel = '0' and WareHouseNo = 'W01' and Row = {row} group by Depth order by Depth"; List depthlist = Db.Ado.SqlQuery(str); return depthlist; } /// /// 获取库位占比(圆) /// /// 仓库号 /// public List GetStorageProportion(string wareHouseNo) { try { string str = $"select status,count(Status) statusnum,'{wareHouseNo}' as WareHouseNo from SysStorageLocat where IsDel = '0' and WareHouseNo = @warehouseno and Flag = '0' group by Status order by Status"; List getLocateVms = Db.Ado.SqlQuery(str, new { warehouseno = wareHouseNo //仓库号 }); str = $"select 6 as Status,COUNT(*) statusnum,'{wareHouseNo}' as WareHouseNo from SysStorageLocat where IsDel = '0' and WareHouseNo = '{wareHouseNo}' and Flag != '0'"; GetLocateVm getLocateVm = Db.Ado.SqlQuerySingle(str); getLocateVms.Add(getLocateVm); int a = 0; //0:空储位 int b = 0; //1:有物品 int c = 0; //2:入库中 int d = 0; //3:出库中 int e = 0; //4:移入中 int f = 0; //5:移出中 int g = 0; //6:损坏\屏蔽 foreach (var item in getLocateVms) { //0:空储位 if (item.Status == "0") { a = 1; //0:空储位 continue; } //1:有物品 if (item.Status == "1") { b = 1; //1:有物品 continue; } //2:入库中 if (item.Status == "2") { c = 1; //2:入库中 continue; } //3:出库中 if (item.Status == "3") { d = 1; //3:出库中 continue; } //4:移入中 if (item.Status == "4") { e = 1; //4:移入中 continue; } //5:移出中 if (item.Status == "5") { f = 1; //5:移出中 continue; } //6:损坏\屏蔽 if (item.Status == "6") { g = 1; //6:损坏\屏蔽 continue; } } //0:空储位 if (a == 0) { getLocateVm = new GetLocateVm(); getLocateVm.WareHouseNo = wareHouseNo; //仓库号 getLocateVm.StatusNum = "0"; getLocateVm.Status = "0"; getLocateVms.Add(getLocateVm); } //1:有物品 if (b == 0) { getLocateVm = new GetLocateVm(); getLocateVm.WareHouseNo = wareHouseNo; //仓库号 getLocateVm.StatusNum = "0"; getLocateVm.Status = "1"; getLocateVms.Add(getLocateVm); } //2:入库中 if (c == 0) { getLocateVm = new GetLocateVm(); getLocateVm.WareHouseNo = wareHouseNo; //仓库号 getLocateVm.StatusNum = "0"; getLocateVm.Status = "2"; getLocateVms.Add(getLocateVm); } //3:出库中 if (d == 0) { getLocateVm = new GetLocateVm(); getLocateVm.WareHouseNo = wareHouseNo; //仓库号 getLocateVm.StatusNum = "0"; getLocateVm.Status = "3"; getLocateVms.Add(getLocateVm); } //4:移入中 if (e == 0) { getLocateVm = new GetLocateVm(); getLocateVm.WareHouseNo = wareHouseNo; //仓库号 getLocateVm.StatusNum = "0"; getLocateVm.Status = "4"; getLocateVms.Add(getLocateVm); } //5:移出中 if (f == 0) { getLocateVm = new GetLocateVm(); getLocateVm.WareHouseNo = wareHouseNo; //仓库号 getLocateVm.StatusNum = "0"; getLocateVm.Status = "5"; getLocateVms.Add(getLocateVm); } //6:损坏\屏蔽 if (g == 0) { getLocateVm = new GetLocateVm(); getLocateVm.WareHouseNo = wareHouseNo; //仓库号 getLocateVm.StatusNum = "0"; getLocateVm.Status = "6"; getLocateVms.Add(getLocateVm); } return getLocateVms; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 获取库位占比(柱) /// /// 仓库号 /// 巷道号 /// public List GetStorageProportion1(string wareHouseNo, string roadwayNo) { try { //根据仓库号以及巷道号获取储位各状态数据 string str = "select Row,Status,COUNT(Status) StatusNum from SysStorageLocat where WareHouseNo = @warehouseno and RoadwayNo = @roadwayno group by Row,Status order by Row,Status"; List getLocateVms = Db.Ado.SqlQuery(str, new { warehouseno = wareHouseNo, //仓库号 roadwayno = roadwayNo //巷道号 }); getLocateVms[0].WareHouseNo = wareHouseNo; getLocateVms[0].RoadwayNo = roadwayNo; return getLocateVms; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 获取仓库巷道 /// /// 仓库号 /// public List GetRoadwayList(string wareHouseNo) { try { string str = "select RoadwayNo,RoadwayName,WareHouseNo from SysStorageRoadway where IsDel = @isdel"; if (!string.IsNullOrWhiteSpace(wareHouseNo)) { str += " and WareHouseNo = @warehouseno"; } List roadway = Db.Ado.SqlQuery(str, new { isdel = "0", //是否删除 warehouseno = wareHouseNo //仓库号 }); return roadway; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 根据储位地址获取储位上的托盘和物品信息 /// /// /// public LocateInfoVm GetLocateInfo(string locatNo) { try { LocateInfoVm model = new LocateInfoVm(); //储位信息 SysStorageLocat storageLocat = Db.Queryable().First(w => w.LocatNo == locatNo && w.IsDel == "0"); if (storageLocat == null) { throw new Exception("未找到对应储位"); } //有物品、出库中数据源(库存明细表) if (storageLocat.Status == "1" || storageLocat.Status == "3" || storageLocat.Status == "5") { //库存明细 List stockDetailList = Db.Queryable().Where(w => w.LocatNo == locatNo && w.IsDel == "0").ToList(); if (stockDetailList == null || stockDetailList.Count <= 0) { throw new Exception("未找到对应的库存明细信息"); } model.LocatNo = locatNo; model.Status = storageLocat.Status; model.PalletNo = stockDetailList[0].PalletNo; List goodsList = new List(); foreach (var item in stockDetailList) { LocateGoodsInfoVm goodsModel = new LocateGoodsInfoVm(); goodsModel.SkuNo = item.SkuNo; goodsModel.SkuName = item.SkuName; goodsModel.LotNo = item.LotNo; goodsModel.Qty = item.Qty; goodsModel.Standard = item.Standard; goodsModel.ExpirationTime = item.ExpirationTime; goodsModel.InspectStatus = item.InspectStatus; goodsList.Add(goodsModel); } model.GoodsInfoList = goodsList; } //入库中数据源(托盘绑定表) else if (storageLocat.Status == "2") { //托盘绑定信息 List palletBindList = Db.Queryable() .Where(w => w.LocatNo == locatNo && w.IsDel == "0" && w.Status == "1").ToList(); if (palletBindList == null || palletBindList.Count <= 0) { throw new Exception("未找到对应的托盘绑定信息"); } model.LocatNo = locatNo; model.Status = storageLocat.Status; model.PalletNo = palletBindList[0].PalletNo; List goodsList = new List(); foreach (var item in palletBindList) { //入库单明细 BllArrivalNoticeDetail noticeDetail = Db.Queryable().First(w => w.Id == item.ASNDetailNo); if (noticeDetail == null) { throw new Exception("未找到对应的入库单明细信息"); } LocateGoodsInfoVm goodsModel = new LocateGoodsInfoVm(); goodsModel.SkuNo = noticeDetail.SkuNo; goodsModel.SkuName = noticeDetail.SkuName; goodsModel.LotNo = noticeDetail.LotNo; goodsModel.Qty = noticeDetail.Qty; goodsList.Add(goodsModel); } model.GoodsInfoList = goodsList; } else { model.LocatNo = locatNo; model.Status = storageLocat.Status; } //储位状态 switch (model.Status) { case "0": model.Status = "空储位"; break; case "1": model.Status = "有物品"; break; case "2": model.Status = "入库中"; break; case "3": model.Status = "出库中"; break; case "4": model.Status = "移入中"; break; case "5": model.Status = "移出中"; break; default: model.Status = ""; break; } return model; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 获取低储位巷道信息及剩余储位数量 /// /// public List GetAvailabilityRoadry() { try { string str = "SELECT *, (SELECT COUNT(*) FROM SysStorageLocat WHERE IsDel = '0' and Status = '0' and Flag = '0' and RoadwayNo = SysStorageRoadway.RoadwayNo) AS countSum FROM SysStorageRoadway where IsDel = '0' "; var list = Db.Ado.SqlQuery(str); list = list.Where(a => a.countSum <= a.Availability).ToList(); return list; } catch (Exception ex) { throw ex; } } /// /// 根据想到获取排 /// /// 巷道 /// public List ByRoadwayGetRow(string roadwayNo) { string str = $"select Row from SysStorageLocat where IsDel = '0' and WareHouseNo = 'W01' and RoadwayNo = '{roadwayNo}' group by Row order by Row"; List row = Db.Ado.SqlQuery(str); return row; } #region 平库图例 /// /// 获取储位信息(平库图例) /// /// 仓库 /// 排 /// public List GetFlatLibraryLegend(string wareHouseNo, string row) { try { var area = Db.Queryable().Where(m => m.IsDel == "0" && m.Status == "0" && m.WareHouseNo == wareHouseNo).ToList(); var areaStr = new List(); if (row == "3") { areaStr = area.Where(m => m.AreaName.Contains("3楼")).Select(m => m.AreaNo).ToList(); } else if (row == "4") { areaStr = area.Where(m => m.AreaName.Contains("4楼")).Select(m => m.AreaNo).ToList(); } var list = Db.Queryable().Where(m => m.IsDel == "0" && m.WareHouseNo == wareHouseNo && areaStr.Contains(m.AreaNo)).ToList(); return list; } catch (Exception e) { throw new Exception(e.Message); } } #endregion } }