修改
This commit is contained in:
87
DOAN.Service/PBL/AlarmLogService.cs
Normal file
87
DOAN.Service/PBL/AlarmLogService.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Extensions;
|
||||
using DOAN.Model.PBL.Dto;
|
||||
using DOAN.Model.PBL;
|
||||
using DOAN.Repository;
|
||||
using DOAN.Service.PBL.IPBLService;
|
||||
|
||||
namespace DOAN.Service.PBL
|
||||
{
|
||||
/// <summary>
|
||||
/// 库存报警日志Service业务层处理
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(IAlarmLogService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class AlarmLogService : BaseService<AlarmLog>, IAlarmLogService
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询库存报警日志列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<AlarmLogDto> GetList(AlarmLogQueryDto parm)
|
||||
{
|
||||
var predicate = QueryExp(parm);
|
||||
|
||||
var response = Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.ToPage<AlarmLog, AlarmLogDto>(parm);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取详情
|
||||
/// </summary>
|
||||
/// <param name="Id"></param>
|
||||
/// <returns></returns>
|
||||
public AlarmLog GetInfo(string Id)
|
||||
{
|
||||
var response = Queryable()
|
||||
.Where(x => x.Id == Id)
|
||||
.First();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加库存报警日志
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public AlarmLog AddAlarmLog(AlarmLog model)
|
||||
{
|
||||
return Insertable(model).ExecuteReturnEntity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改库存报警日志
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateAlarmLog(AlarmLog model)
|
||||
{
|
||||
return Update(model, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询导出表达式
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
private static Expressionable<AlarmLog> QueryExp(AlarmLogQueryDto parm)
|
||||
{
|
||||
var predicate = Expressionable.Create<AlarmLog>()
|
||||
.AndIF(!string.IsNullOrEmpty(parm.Name),it =>it.Name.Contains(parm.Name))
|
||||
.AndIF(!string.IsNullOrEmpty(parm.Code), it => it.Code.Contains(parm.Code))
|
||||
.AndIF(parm.Type > -1, it => it.Type == parm.Type)
|
||||
.AndIF(parm.Status > -1, it => it.Status == parm.Status)
|
||||
.AndIF(parm.StoragelocationId > -1, it => it.StoragelocationId == parm.StoragelocationId)
|
||||
.AndIF(parm.StartTime.HasValue, it => it.ActionTime >= parm.StartTime)
|
||||
.AndIF(parm.EndTime.HasValue, it => it.ActionTime <= parm.EndTime)
|
||||
;
|
||||
|
||||
return predicate;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,7 +142,8 @@ public class BigScreenService : BaseService<Storagelocation>, IBigScreenService
|
||||
AlarmNum = layer.AlarmNum ?? 2, // 确认默认值
|
||||
PackageNum = layer.PackageNum ?? 0,
|
||||
IsLight = layer.IsLight == 1,
|
||||
IsFeedingMaterial = (layer.PackageNum ?? 0) <= (layer.AlarmNum ?? 2) && layer.IsLackAlarm == 1
|
||||
// IsFeedingMaterial = (layer.PackageNum ?? 0) < (layer.AlarmNum ?? 2) && layer.IsLackAlarm == 1
|
||||
IsFeedingMaterial = CalculateIsOneLayerNumFeedingMaterial(layer)
|
||||
}).ToArray();
|
||||
var rackDto = new BigScreenDto
|
||||
{
|
||||
@@ -150,7 +151,8 @@ public class BigScreenService : BaseService<Storagelocation>, IBigScreenService
|
||||
RackCode = group.Key,
|
||||
IsLight = layers.Any(l => l.IsLight == 1),
|
||||
IsInUse = layers.Any(l => l.IsLackAlarm == 1),
|
||||
IsFeedingMaterial = layers.Any(l => (l.PackageNum ?? 0) <= (l.AlarmNum ?? 2) && l.IsLackAlarm == 1),
|
||||
// IsFeedingMaterial = layers.Any(l => (l.PackageNum ?? 0) < (l.AlarmNum ?? 2) && l.IsLackAlarm == 1),
|
||||
IsFeedingMaterial = CalculateIsAllFeedingMaterial(layers),
|
||||
LayerObjectArray = layerObjects
|
||||
};
|
||||
result.Add(rackDto);
|
||||
@@ -158,4 +160,40 @@ public class BigScreenService : BaseService<Storagelocation>, IBigScreenService
|
||||
|
||||
return result;
|
||||
}
|
||||
// 将复杂逻辑封装到方法中
|
||||
private bool CalculateIsAllFeedingMaterial(List<Storagelocation> layers)
|
||||
{
|
||||
int OneTotalPackageNum = layers.Where(it => it.LayerNum == 1).Sum(it => it.PackageNum ?? 0);
|
||||
int SecondTotalPackageNum = layers.Where(it => it.LayerNum == 2).Sum(it => it.PackageNum ?? 0);
|
||||
int alarmNum = 2;
|
||||
if (layers.Any(ls => ls.Remark == "合并料架"))
|
||||
{
|
||||
alarmNum = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
alarmNum = layers[0].AlarmNum ?? 0;
|
||||
}
|
||||
return OneTotalPackageNum < alarmNum || SecondTotalPackageNum < alarmNum;
|
||||
|
||||
}
|
||||
|
||||
private bool CalculateIsOneLayerNumFeedingMaterial(Storagelocation layer)
|
||||
{
|
||||
if (layer.Remark == "合并料架")
|
||||
{
|
||||
int totalPackageNum = Context.Queryable<Storagelocation>()
|
||||
.Where(it => it.LayerNum == layer.LayerNum)
|
||||
.Where(it => it.RackCode == layer.RackCode)
|
||||
.Sum(it => it.PackageNum ?? 0);
|
||||
return totalPackageNum < 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (layer.PackageNum ?? 0) < (layer.AlarmNum ?? 2) && layer.IsLackAlarm == 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
21
DOAN.Service/PBL/IService/IAlarmLogService.cs
Normal file
21
DOAN.Service/PBL/IService/IAlarmLogService.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using DOAN.Model.PBL.Dto;
|
||||
using DOAN.Model.PBL;
|
||||
|
||||
namespace DOAN.Service.PBL.IPBLService
|
||||
{
|
||||
/// <summary>
|
||||
/// 库存报警日志service接口
|
||||
/// </summary>
|
||||
public interface IAlarmLogService : IBaseService<AlarmLog>
|
||||
{
|
||||
PagedInfo<AlarmLogDto> GetList(AlarmLogQueryDto parm);
|
||||
|
||||
AlarmLog GetInfo(string Id);
|
||||
|
||||
|
||||
AlarmLog AddAlarmLog(AlarmLog parm);
|
||||
int UpdateAlarmLog(AlarmLog parm);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,9 @@ using Mapster;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using static System.Formats.Asn1.AsnWriter;
|
||||
|
||||
namespace DOAN.Service.PBL
|
||||
{
|
||||
@@ -39,77 +41,154 @@ namespace DOAN.Service.PBL
|
||||
/// <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();
|
||||
if (MirrorshellShelfList != null && MirrorshellShelfList.Count() > 0)
|
||||
try
|
||||
{
|
||||
Storagelocation storagelocation = new();
|
||||
// 是否合并料架
|
||||
bool isMergeRack = MirrorshellShelfList.Count > 1;
|
||||
if (isMergeRack)
|
||||
Context.Ado.BeginTran();
|
||||
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();
|
||||
if (MirrorshellShelfList != null && MirrorshellShelfList.Count() > 0)
|
||||
{
|
||||
// 合并料架 判断先进先出
|
||||
foreach(var shelf in MirrorshellShelfList)
|
||||
Storagelocation storagelocation = new();
|
||||
// 是否合并料架
|
||||
bool isMergeRack = MirrorshellShelfList.Count > 1;
|
||||
if (isMergeRack)
|
||||
{
|
||||
// 第一个有箱子的
|
||||
if(shelf.PackageNum > 0)
|
||||
Storagelocation leftShelf = MirrorshellShelfList[0];
|
||||
Storagelocation rightShelf = MirrorshellShelfList[1];
|
||||
// 料架今天是否有补料信息 (补料完成信号判定)
|
||||
var today = DateTime.Today;
|
||||
bool hasAlarm = Context.Queryable<AlarmLog>()
|
||||
.Where(it => it.ActionTime != null &&
|
||||
it.ActionTime >= today &&
|
||||
it.ActionTime < today.AddDays(1))
|
||||
.Where(it => it.StoragelocationId == leftShelf.Id || it.StoragelocationId == rightShelf.Id)
|
||||
.OrderByDescending(it => it.ActionTime)
|
||||
.Any();
|
||||
int packageTotal = leftShelf.PackageNum.Value + rightShelf.PackageNum.Value;
|
||||
//1. 在今日有补料信号的前提下 料架>6箱(已补料,未消耗最新箱,先消耗旧箱,哪边存在报警补哪边)
|
||||
if (packageTotal == 8 && hasAlarm)
|
||||
{
|
||||
storagelocation = shelf;
|
||||
continue;
|
||||
if (leftShelf.IsLackAlarm == 1)
|
||||
{
|
||||
storagelocation = leftShelf;
|
||||
}
|
||||
else if (rightShelf.IsLackAlarm == 1)
|
||||
{
|
||||
storagelocation = rightShelf;
|
||||
}
|
||||
else
|
||||
{
|
||||
storagelocation = rightShelf;
|
||||
}
|
||||
}
|
||||
else if (packageTotal == 7 && hasAlarm)
|
||||
{
|
||||
if (leftShelf.IsLackAlarm == 1)
|
||||
{
|
||||
storagelocation = leftShelf;
|
||||
}
|
||||
else if (rightShelf.IsLackAlarm == 1)
|
||||
{
|
||||
storagelocation = rightShelf;
|
||||
}
|
||||
else
|
||||
{
|
||||
storagelocation = rightShelf;
|
||||
}
|
||||
// 切换报警
|
||||
DoChangeAlarmStatus(leftShelf, rightShelf);
|
||||
}
|
||||
else if (packageTotal <= 6 && packageTotal > 4 && hasAlarm)
|
||||
{
|
||||
if (leftShelf.IsLackAlarm == 1)
|
||||
{
|
||||
storagelocation = rightShelf;
|
||||
}
|
||||
else if (rightShelf.IsLackAlarm == 1)
|
||||
{
|
||||
storagelocation = leftShelf;
|
||||
}
|
||||
else
|
||||
{
|
||||
storagelocation = rightShelf;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 默认情况
|
||||
// 合并料架 判断 20250224 左先出原则
|
||||
foreach (var shelf in MirrorshellShelfList)
|
||||
{
|
||||
// 第一个有箱子的料架
|
||||
if (shelf.PackageNum > 0)
|
||||
{
|
||||
storagelocation = shelf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (storagelocation.RackCode == null)
|
||||
{
|
||||
storagelocation = MirrorshellShelfList[^1];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (storagelocation.RackCode == null)
|
||||
else
|
||||
{
|
||||
storagelocation = MirrorshellShelfList[^1];
|
||||
// 单独料架
|
||||
storagelocation = MirrorshellShelfList[0];
|
||||
}
|
||||
// 3.对应料架亮灯
|
||||
bool isSucesss = pLCTool.WriteBit(storagelocation.PlcAddress, true);
|
||||
if (isSucesss)
|
||||
{
|
||||
storagelocation.IsLight = 1;
|
||||
result += Context.Updateable(storagelocation).ExecuteCommand();
|
||||
}
|
||||
//亮灯日志
|
||||
Light_Log light_Log = new Light_Log();
|
||||
light_Log.Id = XUEHUA;
|
||||
light_Log.LightOperation = 1;
|
||||
light_Log.Operationer = "PBL";
|
||||
light_Log.CreatedTime = DateTime.Now;
|
||||
light_Log.ShelfCode = storagelocation.RackCode;
|
||||
light_Log.LayerNum = storagelocation.LayerNum;
|
||||
light_Log.IsSuccess = isSucesss;
|
||||
result += Context.Insertable(light_Log).ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 单独料架
|
||||
storagelocation = MirrorshellShelfList[0];
|
||||
// 发送socket 通知
|
||||
string message =
|
||||
$"MES产品编号{light.AssemblyPartNumber}或者版本{light.Version},在PBL中找不到。请维护PBL料架信息--{DateTime.Now}";
|
||||
notificationHubContext.Clients.All.SendAsync("PBL_bom_except", message);
|
||||
Context.Ado.RollbackTran();
|
||||
return false;
|
||||
}
|
||||
// 3.对应料架亮灯
|
||||
bool isSucesss = pLCTool.WriteBit(storagelocation.PlcAddress, true);
|
||||
if (isSucesss) {
|
||||
storagelocation.IsLight = 1;
|
||||
result += Context.Updateable(storagelocation).ExecuteCommand();
|
||||
}
|
||||
//亮灯日志
|
||||
Light_Log light_Log = new Light_Log();
|
||||
light_Log.Id = XUEHUA;
|
||||
light_Log.LightOperation = 1;
|
||||
light_Log.Operationer = "PBL";
|
||||
light_Log.CreatedTime = DateTime.Now;
|
||||
light_Log.ShelfCode = storagelocation.RackCode;
|
||||
light_Log.LayerNum = storagelocation.LayerNum;
|
||||
light_Log.IsSuccess = isSucesss;
|
||||
result += Context.Insertable(light_Log).ExecuteCommand();
|
||||
notificationHubContext.Clients.All.SendAsync("PBL_storagelocation_change");
|
||||
Context.Ado.CommitTran();
|
||||
return result > 0;
|
||||
}
|
||||
else
|
||||
catch (Exception)
|
||||
{
|
||||
// 发送socket 通知
|
||||
string message =
|
||||
$"MES产品编号{light.AssemblyPartNumber}或者版本{light.Version},在PBL中找不到。请维护PBL料架信息--{DateTime.Now}";
|
||||
notificationHubContext.Clients.All.SendAsync("PBL_bom_except", message);
|
||||
|
||||
Context.Ado.RollbackTran();
|
||||
return false;
|
||||
}
|
||||
return result > 0;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -159,7 +238,27 @@ namespace DOAN.Service.PBL
|
||||
CreatedTime = DateTime.Now
|
||||
};
|
||||
result += Context.Insertable(light_Log).ExecuteCommand();
|
||||
notificationHubContext.Clients.All.SendAsync("PBL_storagelocation_change");
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 交换合并料架报警配置
|
||||
/// </summary>
|
||||
/// <param name="leftShelf"></param>
|
||||
/// <param name="rightShelf"></param>
|
||||
/// <returns></returns>
|
||||
public int DoChangeAlarmStatus(Storagelocation leftShelf, Storagelocation rightShelf)
|
||||
{
|
||||
int result = 0;
|
||||
// 都判断完后切换报警
|
||||
leftShelf.IsLackAlarm = leftShelf.IsLackAlarm == 1 ? 0 : 1;
|
||||
leftShelf.AlarmNum = leftShelf.IsLackAlarm == 1 ? rightShelf.AlarmNum : 0;
|
||||
result += Context.Updateable(leftShelf).ExecuteCommand();
|
||||
rightShelf.IsLackAlarm = rightShelf.IsLackAlarm == 1 ? 0 : 1;
|
||||
rightShelf.AlarmNum = rightShelf.IsLackAlarm == 1 ? leftShelf.AlarmNum : 0;
|
||||
result += Context.Updateable(rightShelf).ExecuteCommand();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user