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 SqlSugar;
|
using WMS.Entity.Context;
|
using WMS.Entity.SysEntity;
|
using WMS.IDAL.ISysInterface;
|
|
namespace WMS.DAL.SysInfrastructure
|
{
|
public class StorageLocatRepository : BaseRepository<SysStorageLocat>, IStorageLocatRepository
|
{
|
private static readonly SqlSugarScope Db = DataContext.Db;
|
public StorageLocatRepository() : base(Db)
|
{
|
}
|
|
/// <summary>
|
/// 编辑储位信息
|
/// </summary>
|
/// <param name="id"></param>
|
/// <param name="status">状态</param>
|
/// <param name="flag">标识</param>
|
/// <param name="temperature">存储环境</param>
|
/// <param name="userId">操作人</param>
|
/// <returns></returns>
|
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);
|
}
|
}
|
/// <summary>
|
/// 编辑储位信息
|
/// </summary>
|
/// <param name="id"></param>
|
/// <param name="status">状态</param>
|
/// <param name="flag">标识</param>
|
/// <param name="userId">操作人</param>
|
/// <returns></returns>
|
public bool EditStorageLocatList(List<int> id, string status, string flag, 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;
|
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);
|
}
|
}
|
|
/// <summary>
|
/// 获取储位信息
|
/// </summary>
|
/// <param name="wareHouseNo">仓库</param>
|
/// <param name="row">排</param>
|
/// <returns></returns>
|
public List<SysStorageLocat> GetStorageLocatLists(string wareHouseNo, string row)
|
{
|
string str = "select * from SysStorageLocat where IsDel = @isdel and Row = @row and WareHouseNo = @warehouseno";
|
if (wareHouseNo == "1")
|
{
|
var wareno = Db.Ado.SqlQuery<string>("select TOP 1 WareHouseNo from SysWareHouse");
|
wareHouseNo = wareno[0];
|
}
|
List<SysStorageLocat> list = Db.Ado.SqlQuery<SysStorageLocat>(str, new
|
{
|
isdel = "0", //是否删除
|
warehouseno = wareHouseNo, //仓库
|
row, //排
|
});
|
return list;
|
}
|
|
/// <summary>
|
/// 获取最大层级
|
/// </summary>
|
/// <param name="wareHouseNo">仓库号</param>
|
/// <returns></returns>
|
public int GetMaxLayer(string wareHouseNo)
|
{
|
string str = "select max(Layer) MaxLayer from SysStorageLocat where IsDel = @isdel and WareHouseNo = @warehouseno";
|
if (wareHouseNo == "1")
|
{
|
var wareno = Db.Ado.SqlQuery<string>("select TOP 1 WareHouseNo from SysWareHouse");
|
wareHouseNo = wareno[0];
|
}
|
int MaxLayer = Db.Ado.SqlQuerySingle<int>(str, new
|
{
|
isdel = "0", //是否删除
|
warehouseno = wareHouseNo //仓库号
|
});
|
return MaxLayer;
|
}
|
|
/// <summary>
|
/// 获取该仓库排数
|
/// </summary>
|
/// <param name="wareHouseNo">仓库号</param>
|
/// <returns></returns>
|
public List<int> 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<string>("select TOP 1 WareHouseNo from SysWareHouse");
|
wareHouseNo = wareno[0];
|
}
|
List<int> maxrow = Db.Ado.SqlQuery<int>(str, new
|
{
|
isdel = "0", //是否删除
|
warehouseno = wareHouseNo //仓库号
|
});
|
return maxrow;
|
}
|
|
/// <summary>
|
/// 获取该仓库深度
|
/// </summary>
|
/// <param name="wareHouseNo">仓库号</param>
|
/// <returns></returns>
|
public List<string> 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<string>("select TOP 1 WareHouseNo from SysWareHouse");
|
wareHouseNo = wareno[0];
|
}
|
List<string> depthlist = Db.Ado.SqlQuery<string>(str, new
|
{
|
isdel = "0", //是否删除
|
warehouseno = wareHouseNo //仓库号
|
});
|
return depthlist;
|
}
|
}
|
}
|