pblbackend/DOAN.Service/PBL/MESInteractionServcie.cs

187 lines
6.7 KiB
C#
Raw Normal View History

2024-11-13 15:53:15 +08:00
using DOAN.Infrastructure.PLC;
2024-11-01 11:35:11 +08:00
using DOAN.Model.PBL;
2024-11-13 15:53:15 +08:00
using DOAN.Model.PBL.Dto;
2024-11-01 11:35:11 +08:00
using DOAN.Service.PBL.IService;
2025-01-16 10:13:50 +08:00
using DOAN.ServiceCore.Signalr;
2024-11-13 15:53:15 +08:00
using Infrastructure.Attribute;
2024-11-01 11:35:11 +08:00
using Mapster;
2025-01-16 10:13:50 +08:00
using Microsoft.AspNetCore.SignalR;
2024-11-13 15:53:15 +08:00
using Newtonsoft.Json.Linq;
2024-11-01 11:35:11 +08:00
namespace DOAN.Service.PBL
{
/// <summary>
/// 料架表Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(IMESInteractionServcie), ServiceLifetime = LifeTime.Transient)]
public class MESInteractionServcie : BaseService<Storagelocation>, IMESInteractionServcie
{
2025-01-16 10:13:50 +08:00
private readonly IHubContext<PBLhub> notificationHubContext;
public MESInteractionServcie(IHubContext<PBLhub> _notificationHubContext) {
notificationHubContext= _notificationHubContext;
}
2024-11-13 15:53:15 +08:00
public bool TestPLc(string address, PLCTool pLCTool)
{
bool isSucesss = pLCTool.ReadBit(address);
return isSucesss;
2024-11-07 21:27:56 +08:00
2024-11-13 15:53:15 +08:00
}
2024-11-07 21:27:56 +08:00
2024-11-13 15:53:15 +08:00
/// <summary>
/// MES亮灯
/// </summary>
/// <param name="light"></param>
/// <param name="pLCTool"></param>
/// <returns></returns>
public bool MESLightUp(LightUpDto light, PLCTool pLCTool)
2024-11-01 11:35:11 +08:00
{
2024-11-13 15:53:15 +08:00
int result = 0;
2024-11-01 11:35:11 +08:00
// 1.记录MES交互记录
MES_Interation_Log item = light.Adapt<MES_Interation_Log>();
item.Id = XUEHUA;
2024-11-07 21:27:56 +08:00
item.CreatedTime = DateTime.Now;
2024-11-01 11:35:11 +08:00
Context.Insertable(item).ExecuteCommand();
2024-11-07 20:17:39 +08:00
// 2.根据总成零件号 ,版本 查询对应零件号,使得对应料架亮灯
2024-11-01 11:35:11 +08:00
2024-11-13 15:53:15 +08:00
// 同一个会有多个料架
2025-01-16 10:13:50 +08:00
//镜壳 料架层
2024-11-13 15:53:15 +08:00
List<Storagelocation> MirrorshellShelfList = Context.Queryable<Storagelocation>().Where(it => it.Partnumber ==
2025-01-16 10:13:50 +08:00
SqlFunc.Subqueryable<Billofmaterials>().Where(It => It.Productcode == light.AssemblyPartNumber).Select(it => it.MirrorshellCode)).ToList();
2024-11-01 11:35:11 +08:00
//镜体 料架
2024-11-13 15:53:15 +08:00
// Storagelocation MirrorshellBody = Context.Queryable<Storagelocation>().Where(it => it.Partnumber ==
// SqlFunc.Subqueryable<Billofmaterials>().Where(It => It.Productcode == light.AssemblyPartNumber && It.Version == light.Version).Select(it => it.MirrorbodyCode)).First();
2025-01-16 10:13:50 +08:00
if (MirrorshellShelfList != null && MirrorshellShelfList.Count() > 0)
2024-11-13 15:53:15 +08:00
{
2024-11-01 11:35:11 +08:00
2024-11-13 15:53:15 +08:00
foreach (var item1 in MirrorshellShelfList)
{
// 3.对应料架亮灯
2024-11-07 20:17:39 +08:00
2024-11-13 15:53:15 +08:00
//TODO PLC 交互
// 对应料架 亮灯字段
// 通知PLC
bool isSucesss = pLCTool.WriteBit(item1.PlcAddress, true);
if (isSucesss)
{
item1.IsLight = 1;
2024-11-01 11:35:11 +08:00
2024-11-13 15:53:15 +08:00
Context.Updateable(item1).ExecuteCommand();
2024-11-07 21:27:56 +08:00
2024-11-13 15:53:15 +08:00
}
2024-11-08 08:42:33 +08:00
2024-11-13 15:53:15 +08:00
//亮灯日志
Light_Log light_Log = new Light_Log();
light_Log.Id = XUEHUA;
light_Log.LightOperation = 1;
light_Log.ShelfCode = item1.RackCode;
light_Log.LayerNum = item1.LayerNum;
light_Log.Operationer = "PBL";
light_Log.CreatedTime = DateTime.Now;
light_Log.IsSuccess = isSucesss;
//Light_Log light_Log2 = new Light_Log();
//light_Log2.Id = XUEHUA;
//light_Log2.LightOperation = 1;
//light_Log2.ShelfCode = item1.RackCode;
//light_Log2.Operationer = "PBL";
//light_Log2.CreatedTime = DateTime.Now;
//light_Log2.IsSuccess = isSucesss;
//Context.Insertable(light_Log2).ExecuteCommand();
result += Context.Insertable(light_Log).ExecuteCommand();
}
2024-11-01 11:35:11 +08:00
}
2024-11-13 15:53:15 +08:00
else
{
2025-01-16 10:13:50 +08:00
// 发送socket 通知
string message=$"MES产品编号{light.AssemblyPartNumber}或者版本{light.Version},在PBL中找不到。请维护PBL料架信息";
notificationHubContext.Clients.All.SendAsync("PBL_bom_except", light);
2024-11-13 15:53:15 +08:00
return false;
}
2024-11-07 21:27:56 +08:00
return result > 0;
2024-11-01 11:35:11 +08:00
}
2024-11-08 08:42:33 +08:00
/// <summary>
2024-11-13 15:53:15 +08:00
/// MES灭灯
2024-11-08 08:42:33 +08:00
/// </summary>
/// <param name="scan_code"></param>
/// <returns></returns>
2024-11-13 15:53:15 +08:00
public bool MESLightDown(string scan_code, PLCTool pLCTool)
2024-11-01 11:35:11 +08:00
{
2024-11-13 15:53:15 +08:00
int result = 0;
2024-11-01 11:35:11 +08:00
// 1.记录MES交互记录
MES_Interation_Log item = new MES_Interation_Log();
item.Id = XUEHUA;
2024-11-07 21:27:56 +08:00
item.ScanCode = scan_code;
2024-11-01 11:35:11 +08:00
item.CreatedTime = DateTime.Now;
Context.Insertable(item).ExecuteCommand();
2024-11-13 15:53:15 +08:00
//2 找到对应的库存最大料架 灭灯
2025-01-16 10:13:50 +08:00
Storagelocation storagelocation = Context.Queryable<Storagelocation>().Where(it => it.Partnumber.Contains(scan_code)).OrderByDescending(it => it.PackageNum).First();
2024-11-13 15:53:15 +08:00
if (storagelocation != null)
{
2024-11-07 21:27:56 +08:00
2024-11-13 15:53:15 +08:00
// TODO PLC 交互
bool isSuccess = pLCTool.WriteBit(storagelocation.PlcAddress, false);
if (isSuccess)
{
storagelocation.IsLight = 0;
2024-11-14 18:24:10 +08:00
// storagelocation.PackageNum -= 1;
2025-01-16 10:13:50 +08:00
//if (storagelocation.PackageNum < 0)
//{
// storagelocation.PackageNum = 0;
//}
2024-11-13 15:53:15 +08:00
//3 扣减对应的库存
// 合并货架的id
2025-01-16 10:13:50 +08:00
int[] ids = { 1, 2, 3, 4, 5, 6, 7, 8 };
2024-11-13 15:53:15 +08:00
if (ids.Contains(storagelocation.Id))
{
Context.Updateable<Storagelocation>().SetColumns(it=>it.IsLight == 0).Where(it=>it.Partnumber == storagelocation.Partnumber).ExecuteCommand();
}
else
{
Context.Updateable(storagelocation).ExecuteCommand();
}
}
//灭灯日志
Light_Log light_Log = new Light_Log();
light_Log.Id = XUEHUA;
light_Log.LightOperation = 2;
light_Log.LayerNum = 1;
light_Log.ShelfCode = storagelocation.RackCode;
2024-11-07 21:27:56 +08:00
2024-11-13 15:53:15 +08:00
light_Log.IsSuccess = isSuccess;
light_Log.Operationer = "PBL";
light_Log.CreatedTime = DateTime.Now;
result += Context.Insertable(light_Log).ExecuteCommand();
2024-11-08 08:42:33 +08:00
}
2024-11-13 15:53:15 +08:00
else
2024-11-07 21:27:56 +08:00
{
2024-11-13 15:53:15 +08:00
return false;
2024-11-01 11:35:11 +08:00
}
2024-11-01 14:13:40 +08:00
return result > 0;
2024-11-01 11:35:11 +08:00
}
}
2024-11-13 15:53:15 +08:00
2024-11-01 11:35:11 +08:00
}