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