现场PBL修改后代码提交

This commit is contained in:
2024-11-13 15:53:15 +08:00
parent 4fcad8a63e
commit 368941225e
14 changed files with 319 additions and 188 deletions

View File

@@ -1,4 +1,5 @@
using DOAN.Model.PBL.Dto;
using DOAN.Infrastructure.PLC;
using DOAN.Model.PBL.Dto;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
@@ -10,8 +11,9 @@ namespace DOAN.Service.PBL.IService
{
public interface IMESInteractionServcie
{
bool MESLightUp(LightUpDto light);
bool MESLightDown(string scan_code);
bool TestPLc(string address, PLCTool pLCTool);
bool MESLightUp(LightUpDto light,PLCTool pLCTool);
bool MESLightDown(string scan_code,PLCTool pLCTool);
}
}

View File

@@ -25,6 +25,7 @@ namespace DOAN.Service.PBL
var response = Queryable()
.Where(predicate.ToExpression())
.OrderByDescending(it => it.CreatedTime)
.ToPage<Inventorylog, InventorylogDto>(parm);
return response;

View File

@@ -24,6 +24,7 @@ namespace DOAN.Service.PBL
var response = Queryable()
.Where(predicate.ToExpression())
.OrderByDescending(it=>it.CreatedTime)
.ToPage<LightLog, LightLogDto>(parm);
return response;
@@ -72,8 +73,8 @@ namespace DOAN.Service.PBL
private static Expressionable<LightLog> QueryExp(LightLogQueryDto parm)
{
var predicate = Expressionable.Create<LightLog>()
.AndIF(parm.TimeRange[0]>DateTime.MinValue, it => it.CreatedTime >=parm.TimeRange[0])
.AndIF(parm.TimeRange[1]>DateTime.MinValue, it => it.CreatedTime <=parm.TimeRange[1])
.AndIF(parm.TimeRange[0]>DateTime.MinValue, it => it.CreatedTime >= parm.TimeRange[0])
.AndIF(parm.TimeRange[1]>DateTime.MinValue, it => it.CreatedTime <= parm.TimeRange[1].Value.Add(new TimeSpan(23, 59, 59)))
;
return predicate;

View File

@@ -1,14 +1,10 @@
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using DOAN.Model.PBL.Dto;
using DOAN.Infrastructure.PLC;
using DOAN.Model.PBL;
using DOAN.Repository;
using DOAN.Model.PBL.Dto;
using DOAN.Service.PBL.IService;
using Infrastructure.Attribute;
using Mapster;
using System.Runtime.InteropServices;
using SqlSugar;
using System.Security.Cryptography.X509Certificates;
using DOAN.Infrastructure.PLC;
using Newtonsoft.Json.Linq;
namespace DOAN.Service.PBL
@@ -19,10 +15,22 @@ namespace DOAN.Service.PBL
[AppService(ServiceType = typeof(IMESInteractionServcie), ServiceLifetime = LifeTime.Transient)]
public class MESInteractionServcie : BaseService<Storagelocation>, IMESInteractionServcie
{
public bool MESLightUp(LightUpDto light)
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;
@@ -31,70 +39,80 @@ namespace DOAN.Service.PBL
// 2.根据总成零件号 ,版本 查询对应零件号,使得对应料架亮灯
// 同一个会有多个料架
//镜壳 料架
Storagelocation MirrorshellShelf = Context.Queryable<Storagelocation>().Where(it => it.Partnumber ==
SqlFunc.Subqueryable<Billofmaterials>().Where(It => It.Productcode == light.AssemblyPartNumber && It.Version == light.Version).Select(it => it.MirrorshellCode)).First();
List<Storagelocation> MirrorshellShelfList = Context.Queryable<Storagelocation>().Where(it => it.Partnumber ==
SqlFunc.Subqueryable<Billofmaterials>().Where(It => It.Productcode == light.AssemblyPartNumber && It.Version == light.Version).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();
// 3.对应料架亮灯
//TODO PLC 交互
// 对应料架 亮灯字段
// 通知PLC
bool isSucesss = PLCTool.WriteBit(MirrorshellShelf.PlcAddress, true);
if (isSucesss)
// 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)
{
MirrorshellShelf.IsLight = 1;
MirrorshellBody.IsLight = 1;
Context.Insertable(MirrorshellShelf).ExecuteCommand();
Context.Insertable(MirrorshellBody).ExecuteCommand();
}
//亮灯日志
Light_Log light_Log = new Light_Log();
light_Log.Id = XUEHUA;
light_Log.LightOperation = 1;
if (MirrorshellShelf != null)
{
light_Log.ShelfCode = MirrorshellShelf.RackCode;
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();
}
}
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;
if (MirrorshellShelf != null)
else
{
light_Log2.ShelfCode = MirrorshellShelf.RackCode;
return false;
}
light_Log2.Operationer = "PBL";
light_Log2.CreatedTime = DateTime.Now;
light_Log2.IsSuccess = isSucesss;
Context.Insertable(light_Log2).ExecuteCommand();
int result = Context.Insertable(light_Log).ExecuteCommand();
return result > 0;
}
/// <summary>
/// 灭灯
/// MES灭灯
/// </summary>
/// <param name="scan_code"></param>
/// <returns></returns>
public bool MESLightDown(string scan_code)
public bool MESLightDown(string scan_code, PLCTool pLCTool)
{
int result = 0;
// 1.记录MES交互记录
MES_Interation_Log item = new MES_Interation_Log();
item.Id = XUEHUA;
@@ -102,35 +120,57 @@ namespace DOAN.Service.PBL
item.CreatedTime = DateTime.Now;
Context.Insertable(item).ExecuteCommand();
//2 找到对应的料架 灭灯
Storagelocation storagelocation = Context.Queryable<Storagelocation>().Where(it => it.Partnumber == scan_code).First();
//TODO PLC 交互
bool isSuccess= PLCTool.WriteBit(storagelocation.PlcAddress, false);
if (isSuccess)
{
storagelocation.IsLight = 0;
storagelocation.PackageNum =storagelocation.PackageNum - 1;
//3 扣减对应的库存
Context.Insertable(storagelocation).ExecuteCommand();
}
//灭灯日志
Light_Log light_Log = new Light_Log();
light_Log.Id = XUEHUA;
light_Log.LightOperation = 2;
//2 找到对应的库存最大料架 灭灯
Storagelocation storagelocation = Context.Queryable<Storagelocation>().Where(it => it.Partnumber == 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, 19, 20, 21, 22 };
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;
}
light_Log.IsSuccess = isSuccess;
light_Log.Operationer = "PBL";
light_Log.CreatedTime = DateTime.Now;
int result = Context.Insertable(light_Log).ExecuteCommand();
return result > 0;
}
}
}

View File

@@ -25,6 +25,7 @@ namespace DOAN.Service.PBL
var response = Queryable()
.Where(predicate.ToExpression())
.OrderByDescending(it => it.CreatedTime)
.ToPage<MesInterationLog, MesInterationLogDto>(parm);
return response;
@@ -75,7 +76,7 @@ namespace DOAN.Service.PBL
var predicate = Expressionable.Create<MesInterationLog>()
.AndIF(!string.IsNullOrEmpty(parm.Workorder),it=>it.Workorder.Contains(parm.Workorder))
.AndIF(parm.TimeRange[0]>DateTime.MinValue, it => it.CreatedTime >=parm.TimeRange[0])
.AndIF(parm.TimeRange[1]>DateTime.MinValue, it => it.CreatedTime <=parm.TimeRange[1])
.AndIF(parm.TimeRange[1]>DateTime.MinValue, it => it.CreatedTime <=parm.TimeRange[1].Value.Add(new TimeSpan(23, 59, 59)))
;
return predicate;