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.Entity.Context; using WMS.Entity.SysEntity; using WMS.IDAL.ISysInterface; namespace WMS.DAL.SysInfrastructure { public class StorageLocatRepository : BaseRepository, IStorageLocatRepository { private static readonly SqlSugarScope Db = DataContext.Db; public StorageLocatRepository() : base(Db) { } /// /// 编辑储位信息 /// /// /// 状态 /// 标识 /// 存储环境 /// 操作人 /// public bool EditStorageLocat(int id, string status, string flag, string temperature, int userId) { try { var locate = GetOneById(id); if (locate == null) { throw new Exception($"为查询到id为{id}的储位信息"); } var com = new Common(); Db.BeginTran(); if (flag == "2" && locate.Depth == "01")//标识是损坏且深度是01时 需把深度为2的储位给屏蔽 { var locate2 = com.GetLocateNoDepth2(locate.WareHouseNo, locate.LocatNo); if (locate2.Flag == "0") { locate2.Flag = "1"; locate2.UpdateUser = userId; locate2.UpdateTime = DateTime.Now; var m = Edit(locate2); } } if (flag == "0" && locate.Depth == "02")//标识是正常且深度是02时 需判断深度为1的储位状态是否正常 { var locate1 = com.GetLocateNoDepth1(locate.WareHouseNo, locate.LocatNo); if (locate1.Flag == "2") { throw new Exception("需先修改深度为1的储位标识为不是损坏"); } } locate.Status = status; locate.Flag = flag; locate.Temperature = temperature; locate.UpdateUser = userId; locate.UpdateTime = DateTime.Now; var i = Edit(locate); Db.CommitTran(); return i > 0; } catch (Exception e) { Db.RollbackTran(); throw new Exception(e.Message); } } /// /// 编辑储位信息 /// /// /// 状态 /// 标识 /// 操作人 /// public bool EditStorageLocatList(List id, string status, string flag,string temperature, int userId) { try { var locateList = GetAllWhereAsync(m => id.Contains(m.Id)).ToList(); if (locateList.Count == 0) { throw new Exception($"为查询到id为{id}的储位信息"); } var com = new Common(); var i = 0; Db.BeginTran(); foreach (var locate in locateList) { if (flag == "2" && locate.Depth == "01")//标识是损坏且深度是01时 需把深度为2的储位给屏蔽 { var locate2 = com.GetLocateNoDepth2(locate.WareHouseNo, locate.LocatNo); if (locate2.Flag == "0" && !locateList.Contains(locate2)) { locate2.Flag = "1"; locate2.UpdateUser = userId; locate2.UpdateTime = DateTime.Now; var m = Edit(locate2); } } if (flag == "0" && locate.Depth == "02")//标识是正常且深度是02时 需判断深度为1的储位状态是否正常 { var locate1 = com.GetLocateNoDepth1(locate.WareHouseNo, locate.LocatNo); if (locate1.Flag == "2") { throw new Exception($"需先修改{locate1.LocatNo}的储位标识为不是损坏"); } } locate.Status = status; locate.Flag = flag; if (!string.IsNullOrEmpty(temperature)) { locate.Temperature = temperature; } locate.UpdateUser = userId; locate.UpdateTime = DateTime.Now; i = Edit(locate); } Db.CommitTran(); return i > 0; } catch (Exception e) { Db.RollbackTran(); throw new Exception(e.Message); } } /// /// 获取该仓库排数 /// /// 仓库号 /// public List GetStorageLocatRow(string wareHouseNo) { string str = "select Row from SysStorageLocat where IsDel = @isdel and WareHouseNo = @warehouseno group by Row order by Row"; if (wareHouseNo == "1") { var wareno = Db.Ado.SqlQuery("select TOP 1 WareHouseNo from SysWareHouse"); wareHouseNo = wareno[0]; } List maxrow = Db.Ado.SqlQuery(str, new { isdel = "0", //是否删除 warehouseno = wareHouseNo //仓库号 }); return maxrow; } /// /// 获取该仓库深度 /// /// 仓库号 /// public List GetDepth(string wareHouseNo) { string str = "select Depth from SysStorageLocat where IsDel = @isdel and WareHouseNo = @warehouseno group by Depth order by Depth"; if (wareHouseNo == "1") { var wareno = Db.Ado.SqlQuery("select TOP 1 WareHouseNo from SysWareHouse"); wareHouseNo = wareno[0]; } List depthlist = Db.Ado.SqlQuery(str, new { isdel = "0", //是否删除 warehouseno = wareHouseNo //仓库号 }); return depthlist; } } }