using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Model.InterFaceModel;
|
using Model.ModelDto.SysDto;
|
using Model.ModelVm.SysVm;
|
using Newtonsoft.Json;
|
using SqlSugar;
|
using Utility.Tools;
|
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,string url, int userId)
|
{
|
try
|
{
|
var locate = GetOneById(id);
|
if (locate == null)
|
{
|
throw new Exception($"为查询到id为{id}的储位信息");
|
}
|
|
var com = new Common();
|
Db.BeginTran();
|
//修改储位集合
|
List<WcsLocat> outDtoList = new List<WcsLocat>();
|
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);
|
|
WcsLocat locatEntry = new WcsLocat();
|
locatEntry.LocatNo = locate2.LocatNo;
|
locatEntry.Status = locate2.Status;
|
locatEntry.Flag = locate2.Status;
|
|
outDtoList.Add(locatEntry);
|
}
|
|
}
|
|
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);
|
|
if (i > 0)
|
{
|
WcsLocat locatEntry2 = new WcsLocat();
|
locatEntry2.LocatNo = locate.LocatNo;
|
locatEntry2.Status = locate.Status;
|
locatEntry2.Flag = locate.Status;
|
|
outDtoList.Add(locatEntry2);
|
|
// 正式运行程序放开
|
//var jsonData = JsonConvert.SerializeObject(outDtoList);
|
//string response = "";
|
|
//try
|
//{
|
// response = HttpHelper.DoPost(url, jsonData, "下发给WCS同步储位信息", "WCS");
|
// //解析返回数据
|
// var wcsModel = JsonConvert.DeserializeObject<WcsModel>(response);
|
// if (wcsModel.StatusCode == -1)
|
// {
|
// throw new Exception(wcsModel.Msg);
|
// }
|
//}
|
//catch (Exception ex)
|
//{
|
// throw new Exception(ex.Message);
|
//}
|
}
|
|
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,string temperature,string url ,int userId)
|
{
|
try
|
{
|
var locateList = GetAllWhere(m => id.Contains(m.Id)).ToList();
|
if (locateList.Count == 0)
|
{
|
throw new Exception($"为查询到id为{id}的储位信息");
|
}
|
|
var com = new Common();
|
var i = 0;
|
Db.BeginTran();
|
//修改储位集合
|
List<WcsLocat> outDtoList = new List<WcsLocat>();
|
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);
|
|
WcsLocat locatEntry = new WcsLocat();
|
locatEntry.LocatNo = locate2.LocatNo;
|
locatEntry.Status = locate2.Status;
|
locatEntry.Flag = locate2.Status;
|
|
outDtoList.Add(locatEntry);
|
}
|
|
}
|
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);
|
|
WcsLocat locatEntry2 = new WcsLocat();
|
locatEntry2.LocatNo = locate.LocatNo;
|
locatEntry2.Status = locate.Status;
|
locatEntry2.Flag = locate.Status;
|
|
outDtoList.Add(locatEntry2);
|
}
|
if (i > 0)
|
{
|
// 正式运行程序放开
|
//var jsonData = JsonConvert.SerializeObject(outDtoList);
|
//string response = "";
|
|
//try
|
//{
|
// response = HttpHelper.DoPost(url, jsonData, "下发给WCS出库命令", "WCS");
|
// //解析返回数据
|
// var wcsModel = JsonConvert.DeserializeObject<WcsModel>(response);
|
// if (wcsModel.StatusCode == -1)
|
// {
|
// throw new Exception(wcsModel.Msg);
|
// }
|
//}
|
//catch (Exception ex)
|
//{
|
// throw new Exception(ex.Message);
|
//}
|
}
|
Db.CommitTran();
|
return i > 0;
|
|
}
|
catch (Exception e)
|
{
|
Db.RollbackTran();
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <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;
|
}
|
|
|
|
}
|
}
|