添加报警窗口
出库流程调试、优化
This commit is contained in:
@ -12,5 +12,7 @@ namespace WCS.BLL.Config
|
||||
public class JsConfig
|
||||
{
|
||||
public List<string> ModuleCodePatterns { get; set; }
|
||||
|
||||
public bool IsSameMatCodeOut { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WCS.Model.ApiModel.Stocktaking;
|
||||
|
||||
namespace WCS.BLL.DbModels
|
||||
{
|
||||
@ -61,12 +62,4 @@ namespace WCS.BLL.DbModels
|
||||
public bool IsSelected { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public enum StocktakingOrderStatus
|
||||
{
|
||||
未盘点 = 0,
|
||||
部分盘点 = 1,
|
||||
盘点完成 = 2,
|
||||
已提交 = 3
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,10 @@ namespace WCS.BLL.HardWare
|
||||
/// </summary>
|
||||
public interface IShelfBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 货架是否处于报警中
|
||||
/// </summary>
|
||||
public bool IsWarning { get; set; }
|
||||
/// <summary>
|
||||
/// 货架ID 数据库中那个
|
||||
/// </summary>
|
||||
@ -39,7 +43,7 @@ namespace WCS.BLL.HardWare
|
||||
/// <summary>
|
||||
/// 货架当前模式
|
||||
/// </summary>
|
||||
public Mode CurentMode { get; set; }
|
||||
public Mode CurrentMode { get; set; }
|
||||
|
||||
public MatInfoResponse InStoreData { get; set; }
|
||||
|
||||
|
@ -42,7 +42,7 @@ namespace WCS.BLL.HardWare
|
||||
data[5] = (byte)lightBuzzerStatus;
|
||||
|
||||
//Only For Debug
|
||||
data[5] = (byte)LightBuzzerStatus.关闭;
|
||||
//data[5] = (byte)LightBuzzerStatus.关闭;
|
||||
|
||||
data[4] = time;//灯短亮一次的时间
|
||||
data[6] = time;//蜂鸣器持续鸣叫的时间
|
||||
|
@ -14,7 +14,7 @@ namespace WCS.BLL.HardWare
|
||||
public string ShelfCode { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public int RowCounts { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public int ColumnCounts { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public Mode CurentMode { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public Mode CurrentMode { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public string ModulesStr { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public string GroupName { get; set; }
|
||||
public MatInfoResponse InStoreData { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
@ -24,6 +24,7 @@ namespace WCS.BLL.HardWare
|
||||
public List<int> ModuleIds { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public string ClientIp { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public List<string> ExceptionMessages { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public bool IsWarning { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public void GoInInstore(string IPAdress)
|
||||
{
|
||||
|
@ -6,12 +6,14 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TouchSocket.Core;
|
||||
using TouchSocket.Sockets;
|
||||
using WCS.BLL.Config;
|
||||
using WCS.BLL.DbModels;
|
||||
using WCS.BLL.Manager;
|
||||
using WCS.DAL;
|
||||
using WCS.DAL.Db;
|
||||
using WCS.DAL.DbModels;
|
||||
using WCS.Model;
|
||||
using WCS.Model.WebSocketModel;
|
||||
using static System.Formats.Asn1.AsnWriter;
|
||||
|
||||
namespace WCS.BLL.HardWare
|
||||
@ -27,7 +29,7 @@ namespace WCS.BLL.HardWare
|
||||
ShelfCode = shelfInfo.ShelfCode;
|
||||
RowCounts = shelfInfo.Rowcounts;
|
||||
ColumnCounts = shelfInfo.Columncounts;
|
||||
CurentMode = shelfInfo.CurrentMode;
|
||||
CurrentMode = shelfInfo.CurrentMode;
|
||||
ClientIp = shelfInfo.ClientIp;
|
||||
LightId = shelfInfo.LightId;
|
||||
WarningLight = new WarningLight() { LightId = shelfInfo.LightId };
|
||||
@ -96,18 +98,39 @@ namespace WCS.BLL.HardWare
|
||||
//TcpCleint.Connect();
|
||||
}
|
||||
|
||||
|
||||
public int ShelfId { get; set; }
|
||||
public string ShelfCode { get; set; }
|
||||
public int RowCounts { get; set; }
|
||||
public int ColumnCounts { get; set; }
|
||||
public Mode CurentMode { get; set; }
|
||||
public Mode CurrentMode { get; set; }
|
||||
public string ModulesStr { get; set; }//当前货架所有模组的Str
|
||||
public string GroupName { get; set; }
|
||||
public List<SmartShelfModule> Modules { get; set; } = new List<SmartShelfModule>();
|
||||
public TCPClient TcpCleint { get { return TCPClientManager.GetTCPClientByIPHost(ClientIp); } }
|
||||
|
||||
public int LightId { get; set; }
|
||||
public bool IsWarning { get; set; } = false;
|
||||
public WarningLight WarningLight { get; set; }
|
||||
public void ClearWarning()
|
||||
{
|
||||
if (this.CurrentMode == Mode.入库模式)
|
||||
{
|
||||
WarningLight.BlueLight(TcpCleint);
|
||||
}
|
||||
else if (this.CurrentMode == Mode.出库模式)
|
||||
{
|
||||
WarningLight.GreenLight(TcpCleint);
|
||||
}
|
||||
else if (this.CurrentMode == Mode.盘点模式)
|
||||
{
|
||||
WarningLight.GreenLight(TcpCleint);
|
||||
}
|
||||
else
|
||||
{
|
||||
WarningLight.CloseLight(TcpCleint);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 自检异常、未响应对应模式的异常
|
||||
/// </summary>
|
||||
@ -136,19 +159,19 @@ namespace WCS.BLL.HardWare
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.CurentMode == Mode.入库模式)
|
||||
if (this.CurrentMode == Mode.入库模式)
|
||||
{
|
||||
CurrentCom = IPAddress;
|
||||
return;
|
||||
}
|
||||
//判断当前模式是否为待机模式
|
||||
else if (this.CurentMode != Mode.待机模式)
|
||||
else if (this.CurrentMode != Mode.待机模式)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.CurentMode = Mode.入库模式;
|
||||
this.CurrentMode = Mode.入库模式;
|
||||
}
|
||||
//清空错误
|
||||
ExceptionMessages.Clear();
|
||||
@ -195,15 +218,20 @@ namespace WCS.BLL.HardWare
|
||||
|
||||
if (notInstoreList.Count > 0)
|
||||
{
|
||||
|
||||
|
||||
foreach (var item in notInstoreList)
|
||||
{
|
||||
ExceptionMessages.Add($"模组{item.ModuleCode}未进入入库模式!");
|
||||
}
|
||||
//通信校验
|
||||
|
||||
IsWarning = true;
|
||||
WarningLight.WaringLightAlwaysRed(TcpCleint);
|
||||
}
|
||||
|
||||
//警示灯亮起
|
||||
WarningLight.BlueLight(TcpCleint);
|
||||
//没有报警才亮蓝灯
|
||||
if(!IsWarning)
|
||||
WarningLight.BlueLight(TcpCleint);
|
||||
//绑定当前进入入库PDA/WCS前端的IP
|
||||
CurrentCom = IPAddress;
|
||||
//返回成功
|
||||
@ -219,13 +247,13 @@ namespace WCS.BLL.HardWare
|
||||
public void GoOutInstore()
|
||||
{
|
||||
//当前货架是否为入库模式
|
||||
if (CurentMode != Mode.入库模式)
|
||||
if (CurrentMode != Mode.入库模式)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.CurentMode = Mode.待机模式;
|
||||
this.CurrentMode = Mode.待机模式;
|
||||
}
|
||||
|
||||
//清空错误
|
||||
@ -262,7 +290,7 @@ namespace WCS.BLL.HardWare
|
||||
.ToList();
|
||||
if (list.Count > 0)
|
||||
{
|
||||
CurentMode = Mode.待机模式;
|
||||
CurrentMode = Mode.待机模式;
|
||||
foreach (var item in list)
|
||||
{
|
||||
ExceptionMessages.Add($"模组{item.ModuleCode}未成功退出入库模式!");
|
||||
@ -275,11 +303,11 @@ namespace WCS.BLL.HardWare
|
||||
public void GoInOutstore(List<OutOrderMatDetail> MatDetails, OutOrder outOrder)
|
||||
{
|
||||
//第一步:设置货架当前模式
|
||||
if (CurentMode != Mode.待机模式)
|
||||
if (CurrentMode != Mode.待机模式)
|
||||
{
|
||||
Modules.ForEach(t => { t.Reset(TcpCleint); });
|
||||
}
|
||||
CurentMode = Mode.出库模式;
|
||||
CurrentMode = Mode.出库模式;
|
||||
|
||||
//第二步:货架添加需要出的SN 出库的领料单号
|
||||
//移除货架所有现有待出库的MatSN
|
||||
@ -292,12 +320,13 @@ namespace WCS.BLL.HardWare
|
||||
////第三步:对应的模组进入出库模式
|
||||
var boardIds = MatDetails.Select(t => t.StoreInfo.BoardId)
|
||||
.Distinct()
|
||||
.OrderBy(t => t)
|
||||
.ToList();
|
||||
var outModules = Modules.Where(t => boardIds.Contains(t.BoardId)).ToList();
|
||||
outModules.ForEach(t =>
|
||||
{
|
||||
var outMatSns = MatDetails.Where(t => t.StoreInfo.ModuleId == t.Id)
|
||||
.Select(t => t.MatSN)
|
||||
var outMatSns = MatDetails.Where(mat => mat.StoreInfo.BoardId == t.BoardId)
|
||||
.Select(mat => mat.MatSN)
|
||||
.ToList();
|
||||
t.GoInOutStoreMode(TcpCleint, outMatSns);
|
||||
});
|
||||
@ -307,7 +336,7 @@ namespace WCS.BLL.HardWare
|
||||
|
||||
public void GoInStocktaking()
|
||||
{
|
||||
this.CurentMode = Mode.盘点模式;
|
||||
this.CurrentMode = Mode.盘点模式;
|
||||
}
|
||||
|
||||
public void GoOutOutstore()
|
||||
@ -319,14 +348,14 @@ namespace WCS.BLL.HardWare
|
||||
{
|
||||
module.GoOutOutStoreMode(TcpCleint);
|
||||
}
|
||||
CurrentOutOrder = null;
|
||||
CurrentOutStoreMatSNs.Clear();
|
||||
this.CurentMode = Mode.待机模式;
|
||||
WarningLight.CloseLight(TcpCleint);
|
||||
this.CurrentMode = Mode.待机模式;
|
||||
}
|
||||
|
||||
public void GoOutStocktaking()
|
||||
{
|
||||
this.CurentMode = Mode.待机模式;
|
||||
this.CurrentMode = Mode.待机模式;
|
||||
}
|
||||
|
||||
void IShelfBase.Reset()
|
||||
@ -390,7 +419,7 @@ namespace WCS.BLL.HardWare
|
||||
default:
|
||||
;
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
Logs.Write("协议处理5");
|
||||
}
|
||||
@ -407,7 +436,6 @@ namespace WCS.BLL.HardWare
|
||||
.FirstOrDefault();
|
||||
if (module == null)
|
||||
{
|
||||
//TO DO 报错
|
||||
return;
|
||||
}
|
||||
else
|
||||
@ -421,7 +449,6 @@ namespace WCS.BLL.HardWare
|
||||
var module = this.Modules.Where(t => t.BoardId == boardId).FirstOrDefault();
|
||||
if (module == null)
|
||||
{
|
||||
//TO DO 报错
|
||||
return;
|
||||
}
|
||||
else
|
||||
@ -467,47 +494,63 @@ namespace WCS.BLL.HardWare
|
||||
ExceptionMessages.Add($"{storeInfo.StoreCode}物料{storeInfo.CurrentMatSn}丢失,库存数据已删除,请重新扫码后入库");
|
||||
#endregion
|
||||
|
||||
#region 【后台】丢失的数据处理
|
||||
Task.Run(() =>
|
||||
//#region 【后台】丢失的数据处理
|
||||
//Task.Run(() =>
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// DbHelp.db.BeginTran();
|
||||
// //库位表字段清空
|
||||
// storeInfo.CurrentMatSn = string.Empty;
|
||||
// DbHelp.db.Updateable(storeInfo).ExecuteCommand();
|
||||
|
||||
// //库存表记录删除、插入出入记录
|
||||
// var inventoryDetail = DbHelp.db.Queryable<InventoryDetail>().Where(t => t.StoreId == storeInfo.Id).First();
|
||||
// if (inventoryDetail != null)
|
||||
// {
|
||||
// var inOutRecord = new InOutRecord()
|
||||
// {
|
||||
// StoreCode = storeInfo.StoreCode,
|
||||
// StoreId = storeInfo.Id,
|
||||
// StoreInfo = storeInfo,
|
||||
|
||||
// MatSN = inventoryDetail.MatSN,
|
||||
// MatCode = inventoryDetail.MatCode,
|
||||
// MatName = inventoryDetail.MatName,
|
||||
// MatBatch = inventoryDetail.MatBatch,
|
||||
// MatQty = inventoryDetail.MatQty,
|
||||
// MatSpec = inventoryDetail.MatSpec,
|
||||
// MatCustomer = inventoryDetail.MatCustomer,
|
||||
// MatSupplier = inventoryDetail.MatSupplier,
|
||||
|
||||
// Direction = DirectionEnum.丢失,
|
||||
// };
|
||||
// DbHelp.db.Insertable(inOutRecord).ExecuteCommand();
|
||||
// DbHelp.db.Deleteable(inventoryDetail).ExecuteCommand();
|
||||
// }
|
||||
// DbHelp.db.CommitTran();
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// DbHelp.db.RollbackTran();
|
||||
// }
|
||||
//});
|
||||
//#endregion
|
||||
#region 不处理、WebSocket通知前台
|
||||
var exceptionMessage = storeInfo.StoreCode + $"进入入库自检发现物料{storeInfo.CurrentMatSn}丢失,请确认是否删除?";
|
||||
var warningModel = new WebSocketMessageModel()
|
||||
{
|
||||
try
|
||||
{
|
||||
DbHelp.db.BeginTran();
|
||||
//库位表字段清空
|
||||
storeInfo.CurrentMatSn = string.Empty;
|
||||
DbHelp.db.Updateable(storeInfo).ExecuteCommand();
|
||||
|
||||
//库存表记录删除、插入出入记录
|
||||
var inventoryDetail = DbHelp.db.Queryable<InventoryDetail>().Where(t => t.StoreId == storeInfo.Id).First();
|
||||
if (inventoryDetail != null)
|
||||
{
|
||||
var inOutRecord = new InOutRecord()
|
||||
{
|
||||
StoreCode = storeInfo.StoreCode,
|
||||
StoreId = storeInfo.Id,
|
||||
StoreInfo = storeInfo,
|
||||
|
||||
MatSN = inventoryDetail.MatSN,
|
||||
MatCode = inventoryDetail.MatCode,
|
||||
MatName = inventoryDetail.MatName,
|
||||
MatBatch = inventoryDetail.MatBatch,
|
||||
MatQty = inventoryDetail.MatQty,
|
||||
MatSpec = inventoryDetail.MatSpec,
|
||||
MatCustomer = inventoryDetail.MatCustomer,
|
||||
MatSupplier = inventoryDetail.MatSupplier,
|
||||
|
||||
Direction = DirectionEnum.丢失,
|
||||
};
|
||||
DbHelp.db.Insertable(inOutRecord).ExecuteCommand();
|
||||
DbHelp.db.Deleteable(inventoryDetail).ExecuteCommand();
|
||||
}
|
||||
DbHelp.db.CommitTran();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DbHelp.db.RollbackTran();
|
||||
}
|
||||
});
|
||||
WarningType = WarningTypeEnum.入库自检丢失,
|
||||
StoreId = storeInfo.Id,
|
||||
StoreCode = storeInfo.StoreCode,
|
||||
ModuleId = module.ModuleId,
|
||||
ModuleCode = module.ModuleCode,
|
||||
ShelfCode = ShelfCode,
|
||||
ShelfId = ShelfId,
|
||||
WarningMessage = exceptionMessage,
|
||||
ClientIp = "127.0.0.1"
|
||||
};
|
||||
WarningManager.SendWarning(warningModel);
|
||||
#endregion
|
||||
|
||||
WarningLight.WaringLightAlwaysRed(TcpCleint);
|
||||
@ -526,6 +569,24 @@ namespace WCS.BLL.HardWare
|
||||
#region 缓存记录异常信息
|
||||
ExceptionMessages.Add($"库位{storeInfo.StoreCode}:存在物料未扫描上架");
|
||||
#endregion
|
||||
|
||||
#region 不处理、WebSocket通知前台
|
||||
var exceptionMessage = $"进入入库自检发现库位{storeInfo.StoreCode}存在物料未扫描上架,请拿下后点击【确认】消除报警";
|
||||
var warningModel = new WebSocketMessageModel()
|
||||
{
|
||||
WarningType = WarningTypeEnum.入库自检未扫描上架,
|
||||
StoreId = storeInfo.Id,
|
||||
StoreCode = storeInfo.StoreCode,
|
||||
ModuleId = module.ModuleId,
|
||||
ModuleCode = module.ModuleCode,
|
||||
ShelfCode = ShelfCode,
|
||||
ShelfId = ShelfId,
|
||||
WarningMessage = exceptionMessage,
|
||||
ClientIp = "127.0.0.1"
|
||||
};
|
||||
WarningManager.SendWarning(warningModel);
|
||||
#endregion
|
||||
|
||||
WarningLight.WaringLightAlwaysRed(TcpCleint);
|
||||
}
|
||||
else
|
||||
@ -596,7 +657,20 @@ namespace WCS.BLL.HardWare
|
||||
{
|
||||
Logs.Write("协议处理5.5");
|
||||
var exceptionMessage = storeInfo.StoreCode + "入库过程中存在物料未扫描上架!";
|
||||
WebSoceketManager.TrySendMessage("127.0.0.1", exceptionMessage);
|
||||
var warningModel = new WebSocketMessageModel()
|
||||
{
|
||||
WarningType = WarningTypeEnum.入库中未扫描上架,
|
||||
StoreId = storeInfo.Id,
|
||||
StoreCode = storeInfo.StoreCode,
|
||||
ModuleId = module.ModuleId,
|
||||
ModuleCode = module.ModuleCode,
|
||||
ShelfCode = ShelfCode,
|
||||
ShelfId = ShelfId,
|
||||
WarningMessage = storeInfo.StoreCode + "入库过程中存在物料未扫描上架!",
|
||||
ClientIp = "127.0.0.1"
|
||||
};
|
||||
WarningManager.SendWarning(warningModel);
|
||||
|
||||
Logs.Write("协议处理5.4");
|
||||
module.ComfirmErrInstore(TcpCleint);
|
||||
WarningLight.WaringLightAlwaysRed(TcpCleint);
|
||||
@ -608,8 +682,6 @@ namespace WCS.BLL.HardWare
|
||||
{
|
||||
module.ComfirmErrInstore(TcpCleint);
|
||||
WarningLight.WaringLightBlueEnd(TcpCleint);
|
||||
//ComfirmErrInstoreByIp(shelfStatus.ClientIp, boardIds);
|
||||
//WaringLightBlueEnd(shelfStatus.ClientIp, shelfStatus.LightId);
|
||||
//TO DO Logs.Write($"[{guid}]该位置已放置物料!");
|
||||
return;
|
||||
}
|
||||
@ -703,11 +775,11 @@ namespace WCS.BLL.HardWare
|
||||
{
|
||||
Logs.Write("协议处理5.1");
|
||||
lightNumber = (int)data[TcpCleint.PreFixLength + 4];
|
||||
var store = DbHelp.db.Queryable<StoreInfo>()
|
||||
var storeInfo = DbHelp.db.Queryable<StoreInfo>()
|
||||
.Where(t => t.BoardId == boardId && t.LightNumber == lightNumber)
|
||||
.First();
|
||||
Logs.Write("协议处理5.2");
|
||||
if (store == null)
|
||||
if (storeInfo == null)
|
||||
{
|
||||
//TO DO 库位未找到
|
||||
return;
|
||||
@ -718,9 +790,30 @@ namespace WCS.BLL.HardWare
|
||||
{
|
||||
case 0x00:
|
||||
{
|
||||
Logs.Write("协议处理5.4");
|
||||
var exceptionMessage = store.StoreCode + "恢复正常!";
|
||||
WebSoceketManager.TrySendMessage("127.0.0.1", exceptionMessage);
|
||||
var warnings = WarningManager.Warnings.Where(t => t.IsWarning = true)
|
||||
.Where(t => t.ShelfId == ShelfId && t.StoreId == storeInfo.Id)
|
||||
.ToList();
|
||||
|
||||
var exceptionMessage = storeInfo.StoreCode + "恢复正常!";
|
||||
var warningModel = new WebSocketMessageModel()
|
||||
{
|
||||
IsWarning = false,
|
||||
WarningType = WarningTypeEnum.恢复正常,
|
||||
StoreId = storeInfo.Id,
|
||||
StoreCode = storeInfo.StoreCode,
|
||||
ShelfCode = ShelfCode,
|
||||
ShelfId = ShelfId,
|
||||
WarningMessage = exceptionMessage,
|
||||
ClientIp = "127.0.0.1",
|
||||
SolvedGuids = warnings.Select(t => t.Guid).ToList(),
|
||||
};
|
||||
WarningManager.SendWarning(warningModel);
|
||||
//自动消除本地缓存的报警
|
||||
warnings.ForEach(warning =>
|
||||
{
|
||||
WarningManager.ClearWarning(warning, SolveTypeEnum.忽略);
|
||||
});
|
||||
|
||||
ProcessingExceptions.RemoveAll(t => t.BoardId == boardId);
|
||||
Logs.Write("协议处理5.5");
|
||||
}
|
||||
@ -728,13 +821,27 @@ namespace WCS.BLL.HardWare
|
||||
case 0x01:
|
||||
{
|
||||
Logs.Write("协议处理5.4");
|
||||
var exceptionMessage = store.StoreCode + "入库过程中存在物料未扫描上架!";
|
||||
WebSoceketManager.TrySendMessage("127.0.0.1", exceptionMessage);
|
||||
var exceptionMessage = storeInfo.StoreCode + "入库过程中存在物料未扫描上架!";
|
||||
//WebSoceketManager.TrySendMessage("127.0.0.1", exceptionMessage);
|
||||
var warningModel = new WebSocketMessageModel()
|
||||
{
|
||||
WarningType = WarningTypeEnum.入库中未扫描上架,
|
||||
StoreId = storeInfo.Id,
|
||||
StoreCode = storeInfo.StoreCode,
|
||||
//ModuleId = module.ModuleId,
|
||||
//ModuleCode = module.ModuleCode,
|
||||
ShelfCode = ShelfCode,
|
||||
ShelfId = ShelfId,
|
||||
WarningMessage = exceptionMessage,
|
||||
ClientIp = "127.0.0.1"
|
||||
};
|
||||
WarningManager.SendWarning(warningModel);
|
||||
|
||||
ProcessingExceptions.Add(new ProcessingExceptionType()
|
||||
{
|
||||
BoardId = boardId,
|
||||
LightNumber = lightNumber,
|
||||
ExceptionMessage = store.StoreCode + "入库过程中存在物料未扫描上架!"
|
||||
ExceptionMessage = storeInfo.StoreCode + "入库过程中存在物料未扫描上架!"
|
||||
});
|
||||
Logs.Write("协议处理5.5");
|
||||
}
|
||||
@ -742,13 +849,27 @@ namespace WCS.BLL.HardWare
|
||||
case 0x02:
|
||||
{
|
||||
Logs.Write("协议处理5.4");
|
||||
var exceptionMessage = store.StoreCode + "物料被取出!";
|
||||
WebSoceketManager.TrySendMessage("127.0.0.1", exceptionMessage);
|
||||
var exceptionMessage = storeInfo.StoreCode + "物料被取出!";
|
||||
//WebSoceketManager.TrySendMessage("127.0.0.1", exceptionMessage);
|
||||
var warningModel = new WebSocketMessageModel()
|
||||
{
|
||||
WarningType = WarningTypeEnum.入库中异常取出,
|
||||
StoreId = storeInfo.Id,
|
||||
StoreCode = storeInfo.StoreCode,
|
||||
//ModuleId = module.ModuleId,
|
||||
//ModuleCode = module.ModuleCode,
|
||||
ShelfCode = ShelfCode,
|
||||
ShelfId = ShelfId,
|
||||
WarningMessage = exceptionMessage,
|
||||
ClientIp = "127.0.0.1"
|
||||
};
|
||||
WarningManager.SendWarning(warningModel);
|
||||
|
||||
ProcessingExceptions.Add(new ProcessingExceptionType()
|
||||
{
|
||||
BoardId = boardId,
|
||||
LightNumber = lightNumber,
|
||||
ExceptionMessage = store.StoreCode + "入库过程中物料丢失!"
|
||||
ExceptionMessage = storeInfo.StoreCode + "入库过程中物料丢失!"
|
||||
});
|
||||
Logs.Write("协议处理5.5");
|
||||
}
|
||||
@ -906,7 +1027,7 @@ namespace WCS.BLL.HardWare
|
||||
|
||||
public void OutstoreReturnProcess(byte[] data, int boardId, int lightNumber)
|
||||
{
|
||||
if (CurentMode != Mode.出库模式)
|
||||
if (CurrentMode != Mode.出库模式)
|
||||
{
|
||||
//TO DO 未在出库模式 要报错
|
||||
Logs.Write($"出库错误:{ShelfCode}该货架模式不是出库模式或盘点模式!");
|
||||
@ -1003,7 +1124,7 @@ namespace WCS.BLL.HardWare
|
||||
x.IsSended = true;
|
||||
});
|
||||
//TO DO 发料需求表增加数量
|
||||
|
||||
|
||||
//保存数据
|
||||
DbHelp.db.Deleteable(inventoryDetail).ExecuteCommand();
|
||||
DbHelp.db.Insertable(inOutRecord).ExecuteCommand();
|
||||
@ -1016,16 +1137,23 @@ namespace WCS.BLL.HardWare
|
||||
|
||||
//确认本次出库
|
||||
module.ComfirmOutstore(TcpCleint, data[TcpCleint.PreFixLength + 3]);
|
||||
|
||||
//通知前台刷新
|
||||
Task.Run(() =>
|
||||
{
|
||||
//给信号通知出库页面更新页面的状态
|
||||
var messageMode = new WebSocketMessageModel()
|
||||
{
|
||||
IsWarning = false,
|
||||
ClientIp = "127.0.0.1",
|
||||
WarningType = WarningTypeEnum.通知刷新出库
|
||||
};
|
||||
WarningManager.SendWarning(messageMode);
|
||||
});
|
||||
|
||||
//当前柜子是否还存在未出库的
|
||||
CurrentOutStoreMatSNs.RemoveAll(t => t == matSN);//删除本次已出的物料SN
|
||||
|
||||
|
||||
var isExsistOut = CurrentOutStoreMatSNs.Any();
|
||||
|
||||
//本批次出库已完成
|
||||
if (!isExsistOut)
|
||||
{
|
||||
@ -1033,8 +1161,97 @@ namespace WCS.BLL.HardWare
|
||||
GoOutOutstore();
|
||||
WarningLight.CloseLight(TcpCleint);
|
||||
var currentPickBillNumber = CurrentOutOrder.OrderNumber;
|
||||
//OrderNumber = string.Empty;
|
||||
CurrentOutOrder = null;
|
||||
}
|
||||
|
||||
//看是否是分批次出库的情况 分批次亮灯
|
||||
if (LocalFile.Config.IsSameMatCodeOut)
|
||||
{
|
||||
#region 触发下一批次的精准发料
|
||||
//查一下是否是当前发料单最后一个货架(在出库模式 同一个发料单下)
|
||||
var isLastShelf = ShelfManager.Shelves
|
||||
.Where(t => t.OrderNumber == OrderNumber)
|
||||
.Where(t => t.CurrentMode == Mode.出库模式)
|
||||
.Any();
|
||||
if (!isLastShelf)
|
||||
{
|
||||
Logs.Write($"发料单{OrderNumber},最后一个出库货架,触发精准发料机制!查询是否还存在待出库物料");
|
||||
var outOrder = DbHelp.db.Queryable<OutOrder>()
|
||||
.Where(t => t.OrderNumber == OrderNumber)
|
||||
.First();
|
||||
if (outOrder != null)
|
||||
{
|
||||
var outOrderMatDetails = DbHelp.db.Queryable<OutOrderMatDetail>()
|
||||
.Where(t => t.OrderId == outOrder.Id)
|
||||
.Where(t => t.IsSended == false)
|
||||
.Includes(t => t.StoreInfo)
|
||||
.ToList();
|
||||
|
||||
if (outOrderMatDetails != null && outOrderMatDetails.Count > 0)
|
||||
{
|
||||
//存在待出库 然后之前又没亮灯的情况 => 精准发料分批次亮灯
|
||||
Logs.Write($"发料单{OrderNumber},还有物料未出!");
|
||||
var outOrderDetailCount = outOrderMatDetails.GroupBy(t => t.MatCode)
|
||||
.Select(o => new { count = o.Count(), bb = o })
|
||||
.Where(o => o.count >= 2)
|
||||
.OrderByDescending(o => o.count)
|
||||
.ToList();
|
||||
//相同物料存在盘数超过2的情况,亮下一个盘数多的物料
|
||||
if (outOrderDetailCount.Count > 0)
|
||||
{
|
||||
var matCode = outOrderDetailCount.First().bb.Key;
|
||||
outOrderMatDetails = outOrderMatDetails.Where(t => t.MatCode == matCode)
|
||||
.ToList();
|
||||
Logs.Write($"发料单{OrderNumber},本次亮灯物料{matCode}!");
|
||||
}
|
||||
//相同物料不存在盘数超过n的情况,剩余物料全部亮灯
|
||||
else
|
||||
{
|
||||
//剩余物料全出
|
||||
Logs.Write($"发料单{OrderNumber},剩余物料灯全亮!");
|
||||
}
|
||||
|
||||
var shelfIds = outOrderMatDetails.Select(t => t.StoreInfo.ShelfId)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
var shelfs = ShelfManager.Shelves.Where(t => shelfIds.Contains(t.ShelfId)).ToList(); ;
|
||||
|
||||
var otherModeShelfs = shelfs.Where(t => t.CurrentMode != HardWare.Mode.待机模式).ToList();
|
||||
if (otherModeShelfs != null && otherModeShelfs.Count > 0)
|
||||
{
|
||||
otherModeShelfs.ForEach(t =>
|
||||
{
|
||||
t.Reset();
|
||||
});
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
//对应的货架对应位置 进入出库模式 亮灯
|
||||
shelfs.ForEach(shelf =>
|
||||
{
|
||||
var matDetails = outOrderMatDetails.Where(t => t.StoreInfo.ShelfCode == shelf.ShelfCode)
|
||||
|
||||
.Distinct()
|
||||
.ToList();
|
||||
shelf.GoInOutstore(matDetails, outOrder);
|
||||
shelf.OrderNumber = outOrder.OrderNumber;
|
||||
});
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Logs.Write($"发料单{OrderNumber},当前物料已发完!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logs.Write($"发料单{OrderNumber},OutOrder为null,肯定是有问题");
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -1071,10 +1288,10 @@ namespace WCS.BLL.HardWare
|
||||
public void OutstoreExceptionReturnProcess(byte[] data, int boardId, int lightNumber)
|
||||
{
|
||||
lightNumber = (int)data[TcpCleint.PreFixLength + 4];
|
||||
var store = DbHelp.db.Queryable<StoreInfo>()
|
||||
var storeInfo = DbHelp.db.Queryable<StoreInfo>()
|
||||
.Where(t => t.BoardId == boardId && t.LightNumber == lightNumber)
|
||||
.First();
|
||||
if (store == null)
|
||||
if (storeInfo == null)
|
||||
{
|
||||
//TO DO 库位未找到
|
||||
return;
|
||||
@ -1084,32 +1301,82 @@ namespace WCS.BLL.HardWare
|
||||
{
|
||||
case 0x00:
|
||||
{
|
||||
var exceptionMessage = store.StoreCode + "恢复正常!";
|
||||
WebSoceketManager.TrySendMessage("127.0.0.1", exceptionMessage);
|
||||
//对应的异常
|
||||
var warnings = WarningManager.Warnings.Where(t => t.IsWarning = true)
|
||||
.Where(t => t.ShelfId == ShelfId && t.StoreId == storeInfo.Id)
|
||||
.ToList();
|
||||
|
||||
var exceptionMessage = storeInfo.StoreCode + "恢复正常!";
|
||||
var warningModel = new WebSocketMessageModel()
|
||||
{
|
||||
IsWarning = false,
|
||||
WarningType = WarningTypeEnum.恢复正常,
|
||||
StoreId = storeInfo.Id,
|
||||
StoreCode = storeInfo.StoreCode,
|
||||
ShelfCode = ShelfCode,
|
||||
ShelfId = ShelfId,
|
||||
WarningMessage = exceptionMessage,
|
||||
ClientIp = "127.0.0.1",
|
||||
SolvedGuids = warnings.Select(t => t.Guid).ToList(),
|
||||
};
|
||||
WarningManager.SendWarning(warningModel);
|
||||
//自动消除本地缓存的报警
|
||||
warnings.ForEach(warning =>
|
||||
{
|
||||
WarningManager.ClearWarning(warning, SolveTypeEnum.忽略);
|
||||
});
|
||||
ProcessingExceptions.RemoveAll(t => t.BoardId == boardId);
|
||||
}
|
||||
break;
|
||||
case 0x01:
|
||||
{
|
||||
var exceptionMessage = store.StoreCode + "出库过程中存在物料上架!";
|
||||
WebSoceketManager.TrySendMessage("127.0.0.1", exceptionMessage);
|
||||
var exceptionMessage = storeInfo.StoreCode + "出库过程中存在物料上架!";
|
||||
//WebSoceketManager.TrySendMessage("127.0.0.1", exceptionMessage);
|
||||
var warningModel = new WebSocketMessageModel()
|
||||
{
|
||||
WarningType = WarningTypeEnum.出库中未扫描上架,
|
||||
StoreId = storeInfo.Id,
|
||||
StoreCode = storeInfo.StoreCode,
|
||||
//ModuleId = module.ModuleId,
|
||||
//ModuleCode = module.ModuleCode,
|
||||
ShelfCode = ShelfCode,
|
||||
ShelfId = ShelfId,
|
||||
WarningMessage = exceptionMessage,
|
||||
ClientIp = "127.0.0.1"
|
||||
};
|
||||
WarningManager.SendWarning(warningModel);
|
||||
|
||||
ProcessingExceptions.Add(new ProcessingExceptionType()
|
||||
{
|
||||
BoardId = boardId,
|
||||
LightNumber = lightNumber,
|
||||
ExceptionMessage = store.StoreCode + "出库过程中存在物料上架!"
|
||||
ExceptionMessage = storeInfo.StoreCode + "出库过程中存在物料上架!"
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 0x02:
|
||||
{
|
||||
var exceptionMessage = store.StoreCode + "物料被取出!";
|
||||
WebSoceketManager.TrySendMessage("127.0.0.1", exceptionMessage);
|
||||
var exceptionMessage = storeInfo.StoreCode + "物料被取出!";
|
||||
//WebSoceketManager.TrySendMessage("127.0.0.1", exceptionMessage);
|
||||
var warningModel = new WebSocketMessageModel()
|
||||
{
|
||||
WarningType = WarningTypeEnum.出库中丢失,
|
||||
StoreId = storeInfo.Id,
|
||||
StoreCode = storeInfo.StoreCode,
|
||||
//ModuleId = module.ModuleId,
|
||||
//ModuleCode = module.ModuleCode,
|
||||
ShelfCode = ShelfCode,
|
||||
ShelfId = ShelfId,
|
||||
WarningMessage = exceptionMessage,
|
||||
ClientIp = "127.0.0.1"
|
||||
};
|
||||
WarningManager.SendWarning(warningModel);
|
||||
|
||||
ProcessingExceptions.Add(new ProcessingExceptionType()
|
||||
{
|
||||
BoardId = boardId,
|
||||
LightNumber = lightNumber,
|
||||
ExceptionMessage = store.StoreCode + "出库过程中物料被异常取出!"
|
||||
ExceptionMessage = storeInfo.StoreCode + "出库过程中物料被异常取出!"
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
@ -57,6 +57,8 @@ namespace WCS.BLL.HardWare
|
||||
public bool IsEnable { get; set; }
|
||||
public Mode CurrentMode { get; set; }
|
||||
|
||||
public List<string> CurrentOutSns { get; set; }
|
||||
|
||||
public void SetCurrentMode()
|
||||
{
|
||||
|
||||
@ -160,6 +162,7 @@ namespace WCS.BLL.HardWare
|
||||
/// <param name="tcpClient"></param>
|
||||
public void GoInOutStoreMode(TCPClient tcpClient, List<string> outSns)
|
||||
{
|
||||
CurrentOutSns = outSns;
|
||||
var storeInfos = DbHelp.db.Queryable<StoreInfo>()
|
||||
.Where(t => t.BoardId == BoardId)
|
||||
.OrderBy(t => t.LightNumber)
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -24,14 +25,10 @@ namespace WCS.BLL.Manager
|
||||
foreach (var ip in ips)
|
||||
{
|
||||
var tcpCleint = new TCPClient(ip, "192.168.9.183:20003");
|
||||
|
||||
|
||||
//var tcpCleint = new TCPClient("192.168.0.183:20002", "192.168.0.183:20003");
|
||||
//配置断线重连
|
||||
|
||||
tcpCleint.tcpClient.Received += (client, e) =>
|
||||
{
|
||||
|
||||
|
||||
var clientIpHost = client.IP + ":" + client.Port;
|
||||
var TcpCleint = TCPClientManager.GetTCPClientByIPHost(clientIpHost);
|
||||
if (TcpCleint == null)
|
||||
@ -108,6 +105,30 @@ namespace WCS.BLL.Manager
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitStatus()
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
Thread.Sleep(1000);
|
||||
//给所有板子发复位
|
||||
TCPClients.ForEach(tcpClient =>
|
||||
{
|
||||
//板子复位
|
||||
new SmartShelfModule() { BoardId = 2047 }.Reset(tcpClient);
|
||||
//报警灯复位
|
||||
new WarningLight().CloseLight(tcpClient);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Write($"启动时复位异常,{ex.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
public static TCPClient GetTCPClientByIPHost(string IpHost)
|
||||
{
|
||||
return TCPClients.Where(t => t.RemoteIPHost == IpHost).FirstOrDefault();
|
||||
|
239
WCS.BLL/Manager/WarningManager.cs
Normal file
239
WCS.BLL/Manager/WarningManager.cs
Normal file
@ -0,0 +1,239 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.OscarClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WCS.BLL.DbModels;
|
||||
using WCS.BLL.HardWare;
|
||||
using WCS.DAL.Db;
|
||||
using WCS.DAL.DbModels;
|
||||
using WCS.Model.WebSocketModel;
|
||||
|
||||
namespace WCS.BLL.Manager
|
||||
{
|
||||
/// <summary>
|
||||
/// 报警信息
|
||||
/// </summary>
|
||||
public static class WarningManager
|
||||
{
|
||||
public static object flag = new object();
|
||||
public static void StartWarningMessageThread()
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var noReceivedWarningMessage = Warnings.Where(t => t.ClientIsReceived == false && t.LastSendTime < DateTime.Now.AddSeconds(-5))
|
||||
.ToList();
|
||||
foreach (var warning in noReceivedWarningMessage)
|
||||
{
|
||||
WebSoceketManager.TrySendMessage(warning.ClientIp, JsonConvert.SerializeObject(warning));
|
||||
warning.LastSendTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
Thread.Sleep(5000);
|
||||
}
|
||||
});
|
||||
}
|
||||
public static List<WebSocketMessageModel> Warnings { get; set; } = new List<WebSocketMessageModel>();
|
||||
public static void SendWarning(WebSocketMessageModel warning)
|
||||
{
|
||||
lock (flag)
|
||||
{
|
||||
Warnings.Add(warning);
|
||||
WebSoceketManager.TrySendMessage(warning.ClientIp, JsonConvert.SerializeObject(warning));
|
||||
warning.LastSendTime = DateTime.Now;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void ClearWarning(WebSocketMessageModel warning, SolveTypeEnum solveType)
|
||||
{
|
||||
try
|
||||
{
|
||||
var shelfIsWarning = true;
|
||||
var warningInManager = Warnings.Where(t => t.Guid == warning.Guid).FirstOrDefault();
|
||||
if (warningInManager != null)
|
||||
{
|
||||
if (solveType == SolveTypeEnum.处理)
|
||||
{
|
||||
//TODO 对应报警处理对应的数据
|
||||
switch (warningInManager.WarningType)
|
||||
{
|
||||
case WarningTypeEnum.入库自检丢失:
|
||||
SolveLoss(warningInManager);
|
||||
break;
|
||||
case WarningTypeEnum.入库自检未扫描上架:
|
||||
SolveNoScan(warningInManager);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//消除报警缓存信息
|
||||
lock (flag)
|
||||
{
|
||||
Warnings.Remove(warningInManager);
|
||||
}
|
||||
}
|
||||
|
||||
//货架是否还存在报警信息
|
||||
shelfIsWarning = Warnings.Where(t => t.ShelfId == warning.ShelfId)
|
||||
.Any();
|
||||
|
||||
//对应货架如果不存在报警信息了 指示灯回到对应的状态
|
||||
if (!shelfIsWarning)
|
||||
{
|
||||
var shelf = ShelfManager.Shelves.Where(t => t.ShelfId == warning.ShelfId)
|
||||
.FirstOrDefault();
|
||||
if (shelf != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var smartShelf = shelf as SmartShelf;
|
||||
smartShelf?.ClearWarning();
|
||||
smartShelf.IsWarning = false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 重新发指令进入对应模式
|
||||
GoInRightMode(warning);
|
||||
#endregion
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logs.Write($"消除报警信息失败:发生异常" + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveMessage(WebSocketMessageModel warning)
|
||||
{
|
||||
var warningInManager = Warnings.Where(t => t.Guid == warning.Guid).FirstOrDefault();
|
||||
lock (flag)
|
||||
{
|
||||
Warnings.Remove(warningInManager);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region 报警消除的处理
|
||||
public static void SolveNoScan(WebSocketMessageModel warning)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void SolveLoss(WebSocketMessageModel warning)
|
||||
{
|
||||
#region 【后台】丢失的数据处理
|
||||
|
||||
try
|
||||
{
|
||||
//获取库位
|
||||
var storeInfo = DbHelp.db.Queryable<StoreInfo>()
|
||||
.Where(t => t.Id == warning.StoreId)
|
||||
.First();
|
||||
if (storeInfo != null)
|
||||
{
|
||||
DbHelp.db.BeginTran();
|
||||
//库位表字段清空
|
||||
storeInfo.CurrentMatSn = string.Empty;
|
||||
DbHelp.db.Updateable(storeInfo).ExecuteCommand();
|
||||
|
||||
//库存表记录删除、插入出入记录
|
||||
var inventoryDetail = DbHelp.db.Queryable<InventoryDetail>().Where(t => t.StoreId == storeInfo.Id).First();
|
||||
if (inventoryDetail != null)
|
||||
{
|
||||
var inOutRecord = new InOutRecord()
|
||||
{
|
||||
StoreCode = storeInfo.StoreCode,
|
||||
StoreId = storeInfo.Id,
|
||||
StoreInfo = storeInfo,
|
||||
|
||||
MatSN = inventoryDetail.MatSN,
|
||||
MatCode = inventoryDetail.MatCode,
|
||||
MatName = inventoryDetail.MatName,
|
||||
MatBatch = inventoryDetail.MatBatch,
|
||||
MatQty = inventoryDetail.MatQty,
|
||||
MatSpec = inventoryDetail.MatSpec,
|
||||
MatCustomer = inventoryDetail.MatCustomer,
|
||||
MatSupplier = inventoryDetail.MatSupplier,
|
||||
|
||||
Direction = DirectionEnum.丢失,
|
||||
};
|
||||
DbHelp.db.Insertable(inOutRecord).ExecuteCommand();
|
||||
DbHelp.db.Deleteable(inventoryDetail).ExecuteCommand();
|
||||
}
|
||||
DbHelp.db.CommitTran();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DbHelp.db.RollbackTran();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static void GoInRightMode(WebSocketMessageModel warning)
|
||||
{
|
||||
try
|
||||
{
|
||||
//模组还存在其他异常 暂时不进入对应模式
|
||||
var moduleOtherError = WarningManager.Warnings.Where(t => t.ShelfId == warning.ShelfId && t.ModuleId == warning.ModuleId).Any();
|
||||
if (moduleOtherError)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var shelf = ShelfManager.Shelves.Where(t => t.ShelfId == warning.ShelfId)
|
||||
.FirstOrDefault();
|
||||
if (shelf != null)
|
||||
{
|
||||
var smartShelf = shelf as SmartShelf;
|
||||
if (smartShelf != null)
|
||||
{
|
||||
var module = smartShelf.Modules.Where(t => t.ModuleId == warning.ModuleId).FirstOrDefault();
|
||||
if (module != null)
|
||||
{
|
||||
switch (smartShelf.CurrentMode)
|
||||
{
|
||||
case Mode.入库模式:
|
||||
module.GoInInstoreMode(smartShelf.TcpCleint);
|
||||
smartShelf.WarningLight.BlueLight(smartShelf.TcpCleint);
|
||||
break;
|
||||
case Mode.出库模式:
|
||||
module.GoInOutStoreMode(smartShelf.TcpCleint, module.CurrentOutSns);
|
||||
smartShelf.WarningLight.GreenLight(smartShelf.TcpCleint);
|
||||
break;
|
||||
case Mode.待机模式:
|
||||
module.Reset(smartShelf.TcpCleint);
|
||||
smartShelf.WarningLight.CloseLight(smartShelf.TcpCleint);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logs.Write("重置模组状态异常" + e.Message);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
@ -12,6 +12,8 @@ namespace WCS.BLL.Manager
|
||||
public static class WebSoceketManager
|
||||
{
|
||||
public static HttpService service;
|
||||
|
||||
public static object flag = new object();
|
||||
public static void InitWebSocket()
|
||||
{
|
||||
service = new HttpService();
|
||||
@ -40,7 +42,10 @@ namespace WCS.BLL.Manager
|
||||
var clients = service.GetClients().Where(t => t.IP == IpAddress).ToList();
|
||||
foreach (var client in clients)
|
||||
{
|
||||
client.WebSocket.SendAsync(Message);
|
||||
lock (client)
|
||||
{
|
||||
client.WebSocket.Send(Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TouchSocket.Core;
|
||||
using TouchSocket.Http.WebSockets;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using WCS.Model.WebSocketModel;
|
||||
|
||||
namespace WCS.BLL.Manager
|
||||
{
|
||||
@ -30,12 +33,30 @@ namespace WCS.BLL.Manager
|
||||
|
||||
if (!client.Client.IsClient)
|
||||
{
|
||||
var clients = WebSoceketManager.service.GetClients().ToList();
|
||||
clients.ForEach(t =>
|
||||
try
|
||||
{
|
||||
t.WebSocket.Send("我已收到");
|
||||
});
|
||||
client.Send("我已收到");
|
||||
var message = e.DataFrame.ToText();
|
||||
var warning = JsonConvert.DeserializeObject<WebSocketMessageModel>(message);
|
||||
if (warning.IsWarning == false)
|
||||
{
|
||||
WarningManager.RemoveMessage(warning);
|
||||
return;
|
||||
}
|
||||
if (warning != null)
|
||||
{
|
||||
//收到这个表示客户端已成功收到消息并提示给前端 避免一直发
|
||||
var warningInManager = WarningManager.Warnings.Where(t => t.Guid == warning.Guid).FirstOrDefault();
|
||||
if (warningInManager != null)
|
||||
{
|
||||
|
||||
warningInManager.ClientIsReceived = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
return;
|
||||
|
||||
|
18
WCS.BLL/Services/IService/IWarningService.cs
Normal file
18
WCS.BLL/Services/IService/IWarningService.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WCS.Model;
|
||||
using WCS.Model.WebSocketModel;
|
||||
|
||||
namespace WCS.BLL.Services.IService
|
||||
{
|
||||
/// <summary>
|
||||
/// 处理、查询报警使用的服务
|
||||
/// </summary>
|
||||
public interface IWarningService
|
||||
{
|
||||
public Task<ResponseCommon<object>> SolveWarning(SolveWarningRequest request);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Runtime;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
@ -10,9 +11,12 @@ using WCS.BLL.DbModels;
|
||||
using WCS.BLL.HardWare;
|
||||
using WCS.BLL.Manager;
|
||||
using WCS.BLL.Services.IService;
|
||||
using WCS.BLL.Tool;
|
||||
using WCS.BLL.Tool.Api.ApiModel;
|
||||
using WCS.DAL.Db;
|
||||
using WCS.Model;
|
||||
using WCS.Model.ApiModel.MatBaseInfo;
|
||||
using static Dm.net.buffer.ByteArrayBuffer;
|
||||
|
||||
namespace WCS.BLL.Services.Service
|
||||
{
|
||||
@ -63,7 +67,7 @@ namespace WCS.BLL.Services.Service
|
||||
//已找到模组对应货架
|
||||
shelf.GoInInstore(request.IpAdress);
|
||||
|
||||
if (shelf.CurentMode == Mode.入库模式)
|
||||
if (shelf.CurrentMode == Mode.入库模式)
|
||||
//成功进入入库模式
|
||||
return new ShelfGoInInstoreResponse()
|
||||
{
|
||||
@ -129,12 +133,12 @@ namespace WCS.BLL.Services.Service
|
||||
};
|
||||
}
|
||||
//判断当前是否是入库模式
|
||||
if (shelf.CurentMode != Mode.入库模式)
|
||||
if (shelf.CurrentMode != Mode.入库模式)
|
||||
{
|
||||
return new ResponseCommon<MatInfo>()
|
||||
{
|
||||
Code = 201,
|
||||
Message = $"操作失败:货架[{request.ShelfCode}]不在入库模式!\r\n当前为{shelf.CurentMode}",
|
||||
Message = $"操作失败:货架[{request.ShelfCode}]不在入库模式!\r\n当前为{shelf.CurrentMode}",
|
||||
};
|
||||
}
|
||||
//判断物料是否已入库
|
||||
@ -149,9 +153,92 @@ namespace WCS.BLL.Services.Service
|
||||
}
|
||||
#region 获取物料数据 //调用接口或者直接查询数据库
|
||||
//TODO做成配置 调用接口
|
||||
if (1 != 1)
|
||||
if (1 == 1)
|
||||
{
|
||||
#region 调用Mes接口获取物料信息
|
||||
try
|
||||
{
|
||||
var body = new
|
||||
{
|
||||
materialBar = request.MatSn
|
||||
};
|
||||
//var Result = ApiHelp.GetDataFromHttp<ResponseCommon<List<queryByBarResponse>>>("http://192.168.2.23:9213/integrate/instock/queryBybar", body, "POST");
|
||||
var Result = new ResponseCommon<List<queryByBarResponse>>()
|
||||
{
|
||||
Code = 200,
|
||||
Data = new List<queryByBarResponse>() {new queryByBarResponse()
|
||||
{
|
||||
materialBar = request.MatSn,
|
||||
materialCode = "111222",
|
||||
materialName = "电阻",
|
||||
materialQty = 1000,
|
||||
}
|
||||
}
|
||||
};
|
||||
//查询到物料信息
|
||||
if (Result != null && Result.Code == 200 && Result.Data != null && Result.Data.Count > 0)
|
||||
{
|
||||
var data = Result.Data.First();
|
||||
shelf.InStoreData = new MatInfoResponse()
|
||||
{
|
||||
materialBar = data.materialBar,
|
||||
materialCode = data.materialCode,
|
||||
materialName = data.materialName,
|
||||
materialQty = data.materialQty,
|
||||
materialSpec = data.materialSpec,
|
||||
batchNo = data.batchNo,
|
||||
supplier = "",
|
||||
customer = data.materialBar,
|
||||
|
||||
InstoreUser = request.UserName
|
||||
};
|
||||
|
||||
var matInfo = new MatInfo()
|
||||
{
|
||||
MatSn = data.materialBar,
|
||||
MatCode = data.materialCode,
|
||||
MatName = data.materialName,
|
||||
MatBatch = data.batchNo,
|
||||
MatQty = (int)data.materialQty,
|
||||
MatSpec = data.materialSpec,
|
||||
MatSupplier = "",
|
||||
MatCustomer = "",
|
||||
};
|
||||
|
||||
return new ResponseCommon<MatInfo>()
|
||||
{
|
||||
Code = 200,
|
||||
Data = matInfo,
|
||||
Message = "success"
|
||||
};
|
||||
}
|
||||
else if (Result != null && Result.Code == 200 && Result.Data == null)
|
||||
{
|
||||
//Mes系统中未获取到物料信息
|
||||
return new ResponseCommon<MatInfo>()
|
||||
{
|
||||
Code = 201,
|
||||
Message = $"操作失败:调用Mes接口未获取到物料信息!",
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ResponseCommon<MatInfo>()
|
||||
{
|
||||
Code = 201,
|
||||
Message = $"操作失败:调用Mes接口失败!",
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new ResponseCommon<MatInfo>()
|
||||
{
|
||||
Code = 300,
|
||||
Message = $"操作失败:调用Mes接口发生异常{e.Message}",
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
//查询数据库
|
||||
else
|
||||
@ -207,12 +294,12 @@ namespace WCS.BLL.Services.Service
|
||||
}
|
||||
|
||||
//判断当前是否是入库模式
|
||||
if (shelf.CurentMode != Mode.入库模式)
|
||||
if (shelf.CurrentMode != Mode.入库模式)
|
||||
{
|
||||
return new ResponseCommon()
|
||||
{
|
||||
Code = 201,
|
||||
Message = $"货架[{request.ShelfCode}]已退出入库模式!\r\n当前为{shelf.CurentMode}",
|
||||
Message = $"货架[{request.ShelfCode}]已退出入库模式!\r\n当前为{shelf.CurrentMode}",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TouchSocket.Sockets;
|
||||
using WCS.BLL.Config;
|
||||
using WCS.BLL.DbModels;
|
||||
using WCS.BLL.Manager;
|
||||
using WCS.BLL.Services.IService;
|
||||
@ -403,78 +404,112 @@ namespace WCS.BLL.Services.Service
|
||||
|
||||
public async Task<ResponseBase> GoInOutstore(GetOutOrderDetailRequest request)
|
||||
{
|
||||
//获取出库单
|
||||
var order = await DbHelp.db.Queryable<OutOrder>()
|
||||
.WhereIF(request.OrderId != 0, t => t.Id == request.OrderId)
|
||||
.WhereIF(!string.IsNullOrEmpty(request.OrderNumber), t => t.OrderNumber == request.OrderNumber)
|
||||
.FirstAsync();
|
||||
if (order == null)
|
||||
try
|
||||
{
|
||||
return new ResponseCommon()
|
||||
//获取出库单
|
||||
var order = await DbHelp.db.Queryable<OutOrder>()
|
||||
.WhereIF(request.OrderId != 0, t => t.Id == request.OrderId)
|
||||
.WhereIF(!string.IsNullOrEmpty(request.OrderNumber), t => t.OrderNumber == request.OrderNumber)
|
||||
.FirstAsync();
|
||||
if (order == null)
|
||||
{
|
||||
Code = 201,
|
||||
Message = $"不存在对应的出库单据{request.OrderNumber}!",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
//如果是按物料编码出库 需要计算物料明细、并进行物料锁定
|
||||
if (order.SyncType == SyncTypeEnum.ByMatCode)
|
||||
{
|
||||
var result = CaculateOutOrderMatDetails(order);
|
||||
if (result.Code != 200)
|
||||
{
|
||||
return result;
|
||||
return new ResponseCommon()
|
||||
{
|
||||
Code = 201,
|
||||
Message = $"不存在对应的出库单据{request.OrderNumber}!",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//获取需要出库的物料明细
|
||||
var outOrderMatDetails = DbHelp.db.Queryable<OutOrderMatDetail>()
|
||||
.Where(t => t.OrderId == order.Id)
|
||||
.Where(t => t.IsSended == false)
|
||||
.Includes(t => t.StoreInfo)
|
||||
.ToList();
|
||||
if (outOrderMatDetails == null || outOrderMatDetails.Count == 0)
|
||||
{
|
||||
return new ResponseCommon()
|
||||
//如果是按物料编码出库 需要计算物料明细、并进行物料锁定
|
||||
if (order.SyncType == SyncTypeEnum.ByMatCode)
|
||||
{
|
||||
Code = 201,
|
||||
Message = $"出库单据{request.OrderNumber}物料已全部出库!",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
//按货架分组 按物料找到对应的货架
|
||||
var shelfIds = outOrderMatDetails.Select(t => t.StoreInfo.ShelfId)
|
||||
.Distinct()
|
||||
var result = CaculateOutOrderMatDetails(order);
|
||||
if (result.Code != 200)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//获取需要出库的物料明细
|
||||
var outOrderMatDetails = DbHelp.db.Queryable<OutOrderMatDetail>()
|
||||
.Where(t => t.OrderId == order.Id)
|
||||
.Where(t => t.IsSended == false)
|
||||
.Includes(t => t.StoreInfo)
|
||||
.ToList();
|
||||
if (outOrderMatDetails == null || outOrderMatDetails.Count == 0)
|
||||
{
|
||||
return new ResponseCommon()
|
||||
{
|
||||
Code = 201,
|
||||
Message = $"出库单据{request.OrderNumber}物料已全部出库!",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
//按货架分组 按物料找到对应的货架
|
||||
var shelfIds = outOrderMatDetails.Select(t => t.StoreInfo.ShelfId)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
var shelfs = ShelfManager.Shelves.Where(t => shelfIds.Contains(t.ShelfId)).ToList(); ;
|
||||
|
||||
var outherModeShelfs = shelfs.Where(t => t.CurrentMode != HardWare.Mode.待机模式).Select(t => t.ShelfCode).ToList();
|
||||
if (outherModeShelfs != null && outherModeShelfs.Count > 0)
|
||||
{
|
||||
return new ResponseCommon()
|
||||
{
|
||||
Code = 201,
|
||||
Message = $"进入出库模式失败:货架{string.Join("", outherModeShelfs)}不在待机模式",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
//看是否是分批次出库的情况 分批次亮灯
|
||||
if (LocalFile.Config.IsSameMatCodeOut)
|
||||
{
|
||||
var outOrderDetailCount = outOrderMatDetails.GroupBy(t => t.MatCode)
|
||||
.Select(o => new { count = o.Count(), bb = o })
|
||||
.Where(o => o.count >= 2)
|
||||
.OrderByDescending(o => o.count)
|
||||
.ToList();
|
||||
var shelfs = ShelfManager.Shelves.Where(t => shelfIds.Contains(t.ShelfId)).ToList(); ;
|
||||
//相同物料存在盘数超过2的情况,亮下一个盘数多的物料
|
||||
if (outOrderDetailCount.Count > 0)
|
||||
{
|
||||
var matCode = outOrderDetailCount.First().bb.Key;
|
||||
outOrderMatDetails = outOrderMatDetails.Where(t => t.MatCode == matCode)
|
||||
.ToList();
|
||||
Logs.Write($"发料单{order.OrderNumber},本次亮灯物料{matCode}!");
|
||||
}
|
||||
//相同物料不存在盘数超过n的情况,剩余物料全部亮灯
|
||||
else
|
||||
{
|
||||
//剩余物料全出
|
||||
Logs.Write($"发料单{order.OrderNumber},剩余物料灯全亮!");
|
||||
}
|
||||
}
|
||||
|
||||
var outherModeShelfs = shelfs.Where(t => t.CurentMode != HardWare.Mode.待机模式).Select(t => t.ShelfCode).ToList();
|
||||
if (outherModeShelfs != null && outherModeShelfs.Count > 0)
|
||||
{
|
||||
return new ResponseCommon()
|
||||
{
|
||||
Code = 201,
|
||||
Message = $"进入出库模式失败:货架{string.Join("", outherModeShelfs)}不在待机模式",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
//对应的货架对应位置 进入出库模式 亮灯
|
||||
shelfs.ForEach(shelf =>
|
||||
//对应的货架对应位置 进入出库模式 亮灯
|
||||
shelfs.ForEach(shelf =>
|
||||
{
|
||||
var matDetails = outOrderMatDetails.Where(t => t.StoreInfo.ShelfCode == shelf.ShelfCode)
|
||||
|
||||
.Distinct()
|
||||
.ToList();
|
||||
shelf.GoInOutstore(matDetails, order);
|
||||
shelf.OrderNumber = order.OrderNumber;
|
||||
});
|
||||
|
||||
//返回
|
||||
return new ResponseCommon()
|
||||
//返回
|
||||
return new ResponseCommon()
|
||||
{
|
||||
Code = 200,
|
||||
Message = "Success",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Code = 200,
|
||||
Message = "Success",
|
||||
Data = null
|
||||
};
|
||||
await GoInOutstore(request);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
private ResponseBase CaculateOutOrderMatDetails(OutOrder order)
|
||||
@ -657,7 +692,8 @@ namespace WCS.BLL.Services.Service
|
||||
});
|
||||
|
||||
//解锁物料 删除物料明细
|
||||
CancelOutOrderMatDetails(order);
|
||||
if (order.SyncType == SyncTypeEnum.ByMatCode)
|
||||
CancelOutOrderMatDetails(order);
|
||||
|
||||
return new ResponseCommon()
|
||||
{
|
||||
|
@ -312,21 +312,22 @@ namespace WCS.BLL.Services.Service
|
||||
{
|
||||
|
||||
var recordsQueryable = DbHelp.db.Queryable<StockTakingOrder>()
|
||||
.WhereIF(!string.IsNullOrEmpty(request.StocktakingOrderNumber), t => t.StocktakingOrderNumber.Contains(request.StocktakingOrderNumber));
|
||||
.WhereIF(!string.IsNullOrEmpty(request.StocktakingOrderNumber), t => t.StocktakingOrderNumber.Contains(request.StocktakingOrderNumber))
|
||||
.WhereIF(!string.IsNullOrEmpty(request.StocktakingOrderSource), t => t.StocktakingOrderSource!=null && t.StocktakingOrderSource.Contains(request.StocktakingOrderSource));
|
||||
|
||||
switch (request.StocktakingOrderStatus)
|
||||
{
|
||||
case Model.ApiModel.Stocktaking.StocktakingOrderStatus.未盘点:
|
||||
recordsQueryable = recordsQueryable.Where(t => t.StocktakingOrderStatus == DbModels.StocktakingOrderStatus.未盘点);
|
||||
recordsQueryable = recordsQueryable.Where(t => t.StocktakingOrderStatus == StocktakingOrderStatus.未盘点);
|
||||
break;
|
||||
case Model.ApiModel.Stocktaking.StocktakingOrderStatus.部分盘点:
|
||||
recordsQueryable = recordsQueryable.Where(t => t.StocktakingOrderStatus == DbModels.StocktakingOrderStatus.部分盘点);
|
||||
recordsQueryable = recordsQueryable.Where(t => t.StocktakingOrderStatus == StocktakingOrderStatus.部分盘点);
|
||||
break;
|
||||
case Model.ApiModel.Stocktaking.StocktakingOrderStatus.已提交:
|
||||
recordsQueryable = recordsQueryable.Where(t => t.StocktakingOrderStatus == DbModels.StocktakingOrderStatus.已提交);
|
||||
recordsQueryable = recordsQueryable.Where(t => t.StocktakingOrderStatus == StocktakingOrderStatus.已提交);
|
||||
break;
|
||||
case Model.ApiModel.Stocktaking.StocktakingOrderStatus.盘点完成:
|
||||
recordsQueryable = recordsQueryable.Where(t => t.StocktakingOrderStatus == DbModels.StocktakingOrderStatus.盘点完成);
|
||||
recordsQueryable = recordsQueryable.Where(t => t.StocktakingOrderStatus == StocktakingOrderStatus.盘点完成);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -530,7 +531,7 @@ namespace WCS.BLL.Services.Service
|
||||
#endregion
|
||||
|
||||
#region 查询当前盘点盘已启动的货架
|
||||
var shelfs = ShelfManager.Shelves.Where(t => t.CurentMode == HardWare.Mode.盘点模式 && t.OrderNumber == order.StocktakingOrderNumber).ToList();
|
||||
var shelfs = ShelfManager.Shelves.Where(t => t.CurrentMode == HardWare.Mode.盘点模式 && t.OrderNumber == order.StocktakingOrderNumber).ToList();
|
||||
shelfs.ForEach(t =>
|
||||
{
|
||||
t.GoOutStocktaking();
|
||||
@ -674,7 +675,7 @@ namespace WCS.BLL.Services.Service
|
||||
#endregion
|
||||
|
||||
#region 判断单据状态
|
||||
if (order.StocktakingOrderStatus != DbModels.StocktakingOrderStatus.已提交)
|
||||
if (order.StocktakingOrderStatus != StocktakingOrderStatus.已提交)
|
||||
{
|
||||
return new ResponseCommon()
|
||||
{
|
||||
@ -682,7 +683,7 @@ namespace WCS.BLL.Services.Service
|
||||
Message = $"单据已提交,请勿重复提交!",
|
||||
};
|
||||
}
|
||||
else if (order.StocktakingOrderStatus != DbModels.StocktakingOrderStatus.盘点完成)
|
||||
else if (order.StocktakingOrderStatus != StocktakingOrderStatus.盘点完成)
|
||||
{
|
||||
return new ResponseCommon()
|
||||
{
|
||||
|
51
WCS.BLL/Services/Service/WarningService.cs
Normal file
51
WCS.BLL/Services/Service/WarningService.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using TouchSocket.Core;
|
||||
using WCS.BLL.Manager;
|
||||
using WCS.BLL.Services.IService;
|
||||
using WCS.DAL;
|
||||
using WCS.DAL.Db.AuthDb;
|
||||
using WCS.Model;
|
||||
using WCS.Model.ApiModel;
|
||||
using WCS.Model.ApiModel.User;
|
||||
using WCS.Model.WebSocketModel;
|
||||
|
||||
namespace WCS.BLL.Services.Service
|
||||
{
|
||||
public class WarningService : IWarningService
|
||||
{
|
||||
public async Task<ResponseCommon<object>> SolveWarning(SolveWarningRequest request)
|
||||
{
|
||||
//获取对应的报警
|
||||
var warning = WarningManager.Warnings
|
||||
.Where(t => t.Guid == request.Guid)
|
||||
.FirstOrDefault();
|
||||
if (warning != null)
|
||||
{
|
||||
WarningManager.ClearWarning(warning, request.SolveType);
|
||||
}
|
||||
//判断一下是否还存在对应报警
|
||||
warning = WarningManager.Warnings
|
||||
.Where(t => t.Guid == request.Guid)
|
||||
.FirstOrDefault();
|
||||
if (warning == null)
|
||||
return new ResponseCommon<object>()
|
||||
{
|
||||
Code = 200,
|
||||
Message = "报警解除成功!"
|
||||
};
|
||||
else
|
||||
{
|
||||
return new ResponseCommon<object>()
|
||||
{
|
||||
Code = 201,
|
||||
Message = "报警解除失败!请重试!"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -3,15 +3,18 @@ using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using WCS.BLL.Tool.Api.Models;
|
||||
using WCS.BLL;
|
||||
using WCS.Model;
|
||||
|
||||
namespace WCS.BLL.Tool.Api
|
||||
namespace WCS.BLL.Tool
|
||||
{
|
||||
public static class ApiHelp
|
||||
{
|
||||
@ -19,57 +22,57 @@ namespace WCS.BLL.Tool.Api
|
||||
static ApiHelp()
|
||||
{
|
||||
httpClient = new HttpClient();
|
||||
httpClient.Timeout = TimeSpan.FromSeconds(5);
|
||||
httpClient.DefaultRequestHeaders.Add("User-Agent", "Chrome/95.0.4638.69 Safari/537.36");
|
||||
//ServicePointManager.Expect100Continue = false;
|
||||
httpClient.Timeout = TimeSpan.FromSeconds(10);
|
||||
httpClient.DefaultRequestHeaders.Add("UserModel-Agent", "Chrome/95.0.4638.69 Safari/537.36");
|
||||
ServicePointManager.Expect100Continue = false;
|
||||
}
|
||||
|
||||
public static ApiResult Get(string uri, object? query = null, object? body = null)
|
||||
public static async Task<ResponseBase> Get(string uri, object? query = null, object? body = null)
|
||||
{
|
||||
return Send(HttpMethod.Get, uri, query, body);
|
||||
return await Send(HttpMethod.Get, uri, query, body);
|
||||
}
|
||||
|
||||
public static ApiResult Get(IEnumerable<object> uri, object? query = null, object? body = null)
|
||||
public static async Task<ResponseBase> Get(IEnumerable<object> uri, object? query = null, object? body = null)
|
||||
{
|
||||
return Send(HttpMethod.Get, uri, query, body);
|
||||
return await Send(HttpMethod.Get, uri, query, body);
|
||||
}
|
||||
|
||||
public static ApiResult<T> Get<T>(string uri, object? query = null, object? body = null)
|
||||
public static async Task<T> Get<T>(string uri, object? query = null, object? body = null)
|
||||
{
|
||||
return Send<T>(HttpMethod.Get, uri, query, body);
|
||||
return await Send<T>(HttpMethod.Get, uri, query, body);
|
||||
}
|
||||
|
||||
public static ApiResult<T> Get<T>(IEnumerable<object> uri, object? query = null, object? body = null)
|
||||
public static async Task<T> Get<T>(IEnumerable<object> uri, object? query = null, object? body = null)
|
||||
{
|
||||
return Send<T>(HttpMethod.Get, uri, query, body);
|
||||
return await Send<T>(HttpMethod.Get, uri, query, body);
|
||||
}
|
||||
|
||||
public static ApiResult Post(string uri, object? body = null, object? query = null)
|
||||
public static async Task<ResponseBase> Post(string uri, object? body = null, object? query = null)
|
||||
{
|
||||
return Send(HttpMethod.Post, uri, query, body);
|
||||
return await Send(HttpMethod.Post, uri, query, body);
|
||||
}
|
||||
|
||||
public static ApiResult Post(IEnumerable<object> uri, object? body = null, object? query = null)
|
||||
public static async Task<ResponseBase> Post(IEnumerable<object> uri, object? body = null, object? query = null)
|
||||
{
|
||||
return Send(HttpMethod.Post, uri, query, body);
|
||||
return await Send(HttpMethod.Post, uri, query, body);
|
||||
}
|
||||
|
||||
public static ApiResult<T> Post<T>(string uri, object? body = null, object? query = null)
|
||||
public static async Task<T> Post<T>(string uri, object? body = null, object? query = null)
|
||||
{
|
||||
return Send<T>(HttpMethod.Post, uri, query, body);
|
||||
return await Send<T>(HttpMethod.Post, uri, query, body);
|
||||
}
|
||||
|
||||
public static ApiResult<T> Post<T>(IEnumerable<object> uri, object? body = null, object? query = null)
|
||||
public static async Task<T> Post<T>(IEnumerable<object> uri, object? body = null, object? query = null)
|
||||
{
|
||||
return Send<T>(HttpMethod.Post, uri, query, body);
|
||||
return await Send<T>(HttpMethod.Post, uri, query, body);
|
||||
}
|
||||
|
||||
public static ApiResult Send(HttpMethod method, string uri, object? query = null, object? body = null)
|
||||
public static async Task<ResponseBase> Send(HttpMethod method, string uri, object? query = null, object? body = null)
|
||||
{
|
||||
return Send(method, new string[] { uri }, query, body);
|
||||
return await Send(method, new string[] { uri }, query, body);
|
||||
}
|
||||
|
||||
public static ApiResult Send(HttpMethod method, IEnumerable<object> uri, object? query = null, object? body = null)
|
||||
public static async Task<ResponseBase> Send(HttpMethod method, IEnumerable<object> uri, object? query = null, object? body = null)
|
||||
{
|
||||
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, "".AppendPathSegments(uri).SetQueryParams(query));
|
||||
|
||||
@ -79,35 +82,44 @@ namespace WCS.BLL.Tool.Api
|
||||
httpRequestMessage.Content = content;
|
||||
}
|
||||
|
||||
var re = httpClient.SendAsync(httpRequestMessage).Result;
|
||||
var re = await httpClient.SendAsync(httpRequestMessage);
|
||||
if (!re.IsSuccessStatusCode)
|
||||
return new ApiResult() { Code = ((int)re.StatusCode).ToString() };
|
||||
return new ResponseBase() { Code = (int)re.StatusCode };
|
||||
|
||||
var con = re.Content.ReadAsStringAsync().Result;
|
||||
return JsonConvert.DeserializeObject<ApiResult>(con) ?? new ApiResult();
|
||||
var con = await re.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<ResponseBase>(con) ?? new ResponseBase();
|
||||
}
|
||||
|
||||
public static ApiResult<T> Send<T>(HttpMethod method, string uri, object? query = null, object? body = null)
|
||||
public static async Task<T> Send<T>(HttpMethod method, string uri, object? query = null, object? body = null)
|
||||
{
|
||||
return Send<T>(method, new string[] { uri }, query, body);
|
||||
return await Send<T>(method, new string[] { uri }, query, body);
|
||||
}
|
||||
|
||||
public static ApiResult<T> Send<T>(HttpMethod method, IEnumerable<object> uri, object? query = null, object? body = null)
|
||||
public static async Task<T> Send<T>(HttpMethod method, IEnumerable<object> uri, object? query = null, object? body = null)
|
||||
{
|
||||
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, "".AppendPathSegments(uri).SetQueryParams(query));
|
||||
|
||||
if (body != null)
|
||||
try
|
||||
{
|
||||
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
||||
httpRequestMessage.Content = content;
|
||||
var url = "".AppendPathSegments(uri).SetQueryParams(query);
|
||||
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, url);
|
||||
|
||||
if (body != null)
|
||||
{
|
||||
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
||||
httpRequestMessage.Content = content;
|
||||
}
|
||||
|
||||
var re = await httpClient.SendAsync(httpRequestMessage);
|
||||
if (!re.IsSuccessStatusCode)
|
||||
return default(T);
|
||||
|
||||
var con = await re.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<T>(con) ?? default(T); ;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
var re = httpClient.SendAsync(httpRequestMessage).Result;
|
||||
if (!re.IsSuccessStatusCode)
|
||||
return new ApiResult<T>() { Code = ((int)re.StatusCode).ToString() };
|
||||
|
||||
var con = re.Content.ReadAsStringAsync().Result;
|
||||
return JsonConvert.DeserializeObject<ApiResult<T>>(con) ?? new ApiResult<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -118,17 +130,18 @@ namespace WCS.BLL.Tool.Api
|
||||
/// <returns>地址</returns>
|
||||
public static string AppendPathSegments(this string url, IEnumerable<object> segments)
|
||||
{
|
||||
string urlStr = url;
|
||||
string urlStr = url.Trim();
|
||||
foreach (var segment in segments)
|
||||
{
|
||||
var val = segment?.ToString();
|
||||
var val = segment?.ToString()?.Trim() ?? "";
|
||||
if (string.IsNullOrWhiteSpace(val))
|
||||
continue;
|
||||
|
||||
if (urlStr.EndsWith("/"))
|
||||
urlStr = urlStr.Substring(0, urlStr.Length - 1);
|
||||
|
||||
urlStr += val!.StartsWith("/") ? val : $"/{val}";
|
||||
if (val.Length > 0)
|
||||
urlStr += string.IsNullOrEmpty(urlStr) || val.StartsWith("/") ? val : $"/{val}";
|
||||
}
|
||||
return urlStr;
|
||||
}
|
||||
@ -178,5 +191,126 @@ namespace WCS.BLL.Tool.Api
|
||||
|
||||
return urlStr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Post方式下载Excel文件
|
||||
/// </summary>
|
||||
/// <param name="localFilePath">文件保存的路径</param>
|
||||
/// <param name="method"></param>
|
||||
/// <param name="requestUrl"></param>
|
||||
/// <param name="body"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task PostDownloadFileAsync(string localFilePath, HttpMethod method, string requestUrl, object? body = null)
|
||||
{
|
||||
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, requestUrl);
|
||||
if (body != null)
|
||||
{
|
||||
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
||||
httpRequestMessage.Content = content;
|
||||
}
|
||||
using (var response = await httpClient.SendAsync(httpRequestMessage))
|
||||
{
|
||||
response.EnsureSuccessStatusCode(); // 确保请求成功
|
||||
|
||||
// 获取内容头中的文件名(如果需要的话)
|
||||
//var contentDisposition = ContentDispositionHeaderValue.Parse(response.Content.Headers.ContentDisposition.ToString());
|
||||
//string filename = contentDisposition.FileName.Trim('"'); // 去除引号
|
||||
var filename = string.Empty;
|
||||
// 如果提供的本地文件路径没有文件名,则使用从响应头中获取的文件名
|
||||
if (Path.GetFileName(localFilePath) == string.Empty)
|
||||
{
|
||||
localFilePath = Path.Combine(Path.GetDirectoryName(localFilePath), filename);
|
||||
}
|
||||
// 写入文件
|
||||
using (var fileStream = new FileStream(localFilePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true))
|
||||
{
|
||||
await response.Content.CopyToAsync(fileStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Post方式导入Excel文件
|
||||
/// </summary>
|
||||
/// <param name="localFilePath">文件保存的路径</param>
|
||||
/// <param name="method"></param>
|
||||
/// <param name="requestUrl"></param>
|
||||
/// <param name="body"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<T> PostImportFileAsync<T>(string localFilePath, HttpMethod method, string requestUrl, string userName, string deviceType)
|
||||
{
|
||||
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, requestUrl);
|
||||
|
||||
using (var content = new MultipartFormDataContent())
|
||||
{
|
||||
var fileContent = new StreamContent(new FileStream(localFilePath, FileMode.Open, FileAccess.Read));
|
||||
fileContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("multipart/form-data");
|
||||
content.Add(fileContent, "excelFile", Path.GetFileName(localFilePath));
|
||||
|
||||
var userNameContent = new StringContent(userName);
|
||||
userNameContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("multipart/form-data");
|
||||
content.Add(userNameContent, "userName");
|
||||
|
||||
var deviceTypeContent = new StringContent(deviceType);
|
||||
deviceTypeContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("multipart/form-data");
|
||||
content.Add(deviceTypeContent, "deviceType");
|
||||
|
||||
httpRequestMessage.Content = content;
|
||||
using (var response = await httpClient.SendAsync(httpRequestMessage))
|
||||
{
|
||||
response.EnsureSuccessStatusCode(); // 确保请求成功
|
||||
var filename = string.Empty;
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return default(T);
|
||||
|
||||
var con = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<T>(con) ?? default(T); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static T GetDataFromHttp<T>(string url, object dataObj, string httpMethod, bool isSaveLog = false)
|
||||
{
|
||||
Guid guid = Guid.NewGuid();
|
||||
var data = JsonConvert.SerializeObject(dataObj);
|
||||
try
|
||||
{
|
||||
if (isSaveLog)
|
||||
Logs.Write($"【{guid}】开始请求调用接口 url:{url} 请求方式:{httpMethod} 数据:{data}", LogsType.Api);
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.Method = httpMethod;
|
||||
request.ContentType = "application/json";
|
||||
request.Timeout = 10000;
|
||||
|
||||
if (!string.IsNullOrEmpty(data))
|
||||
{
|
||||
string strContent = data; //参数data
|
||||
using (StreamWriter dataStream = new StreamWriter(request.GetRequestStream()))
|
||||
{
|
||||
dataStream.Write(strContent);
|
||||
dataStream.Close();
|
||||
}
|
||||
}
|
||||
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
string encoding = response.ContentEncoding;
|
||||
if (encoding == null || encoding.Length < 1)
|
||||
{
|
||||
encoding = "UTF-8"; //默认编码
|
||||
}
|
||||
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
|
||||
string retString = reader.ReadToEnd();
|
||||
if (isSaveLog)
|
||||
Logs.Write($"【{guid}】请求调用接口结束 返回数据为{retString}", LogsType.Api);
|
||||
return JsonConvert.DeserializeObject<T>(retString);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Write($"【{guid}】请求调用遇到异常 异常信息为{ex.Message}");
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
29
WCS.BLL/Tool/Api/ApiModel/queryByBarResponse.cs
Normal file
29
WCS.BLL/Tool/Api/ApiModel/queryByBarResponse.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WCS.BLL.Tool.Api.ApiModel
|
||||
{
|
||||
public class queryByBarResponse
|
||||
{
|
||||
public string materialBar { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string materialCode { get; set; }
|
||||
/// <summary>
|
||||
/// 有源蜂鸣器
|
||||
/// </summary>
|
||||
public string materialName { get; set; }
|
||||
/// <summary>
|
||||
/// TMB09A03/5X9电压3V
|
||||
/// </summary>
|
||||
public string materialSpec { get; set; }
|
||||
|
||||
public double materialQty { get; set; }
|
||||
|
||||
public string batchNo { get; set; }
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WCS.BLL.Tool.Api.Models
|
||||
{
|
||||
public class ApiResult
|
||||
{
|
||||
public string Code { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
|
||||
public class ApiResult<T> : ApiResult
|
||||
{
|
||||
public T Data { get; set; }
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ namespace WCS.BLL
|
||||
/// 数据库错误
|
||||
/// </summary>
|
||||
DbErr,
|
||||
Api
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user