PLC过站记录表
This commit is contained in:
parent
3a07efe396
commit
f6e826c2a7
@ -0,0 +1,99 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using RIZO.Admin.WebApi.PLC.Model;
|
||||
using RIZO.Admin.WebApi.PLC.Model.Dto;
|
||||
using RIZO.Admin.WebApi.PLC.Service.IService;
|
||||
//创建时间:2026-01-17
|
||||
namespace RIZO.Admin.WebApi.PLC.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// PLC返回的工位工序结果
|
||||
/// </summary>
|
||||
[Route("mes/PlcOperationResult")]
|
||||
public class PlcOperationResultController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// PLC返回的工位工序结果接口
|
||||
/// </summary>
|
||||
private readonly IPlcOperationResultService _PlcOperationResultService;
|
||||
|
||||
public PlcOperationResultController(IPlcOperationResultService PlcOperationResultService)
|
||||
{
|
||||
_PlcOperationResultService = PlcOperationResultService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询PLC返回的工位工序结果列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "plcoperationresult:list")]
|
||||
public IActionResult QueryPlcOperationResult([FromQuery] PlcOperationResultQueryDto parm)
|
||||
{
|
||||
var response = _PlcOperationResultService.GetList(parm);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询PLC返回的工位工序结果详情
|
||||
/// </summary>
|
||||
/// <param name="Id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{Id}")]
|
||||
[ActionPermissionFilter(Permission = "plcoperationresult:query")]
|
||||
public IActionResult GetPlcOperationResult(int Id)
|
||||
{
|
||||
var response = _PlcOperationResultService.GetInfo(Id);
|
||||
|
||||
var info = response.Adapt<PlcOperationResultDto>();
|
||||
return SUCCESS(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加PLC返回的工位工序结果
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "plcoperationresult:add")]
|
||||
[Log(Title = "PLC返回的工位工序结果", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult AddPlcOperationResult([FromBody] PlcOperationResultDto parm)
|
||||
{
|
||||
var modal = parm.Adapt<PlcOperationResult>().ToCreate(HttpContext);
|
||||
|
||||
var response = _PlcOperationResultService.AddPlcOperationResult(modal);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新PLC返回的工位工序结果
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "plcoperationresult:edit")]
|
||||
[Log(Title = "PLC返回的工位工序结果", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult UpdatePlcOperationResult([FromBody] PlcOperationResultDto parm)
|
||||
{
|
||||
var modal = parm.Adapt<PlcOperationResult>().ToUpdate(HttpContext);
|
||||
var response = _PlcOperationResultService.UpdatePlcOperationResult(modal);
|
||||
|
||||
return ToResponse(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除PLC返回的工位工序结果
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("delete/{ids}")]
|
||||
[ActionPermissionFilter(Permission = "plcoperationresult:delete")]
|
||||
[Log(Title = "PLC返回的工位工序结果", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult DeletePlcOperationResult([FromRoute]string ids)
|
||||
{
|
||||
var idArr = Tools.SplitAndConvert<int>(ids);
|
||||
|
||||
return ToResponse(_PlcOperationResultService.Delete(idArr));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
41
RIZO.Admin.WebApi/PLC/Model/Dto/PlcOperationResultDto.cs
Normal file
41
RIZO.Admin.WebApi/PLC/Model/Dto/PlcOperationResultDto.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using MiniExcelLibs.Attributes;
|
||||
using RIZO.Model;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace RIZO.Admin.WebApi.PLC.Model.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// PLC返回的工位工序结果查询对象
|
||||
/// </summary>
|
||||
public class PlcOperationResultQueryDto : PagerInfo
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PLC返回的工位工序结果输入输出对象
|
||||
/// </summary>
|
||||
public class PlcOperationResultDto
|
||||
{
|
||||
[Required(ErrorMessage = "ID不能为空")]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string? Sn { get; set; }
|
||||
|
||||
public string? Workstationcode { get; set; }
|
||||
|
||||
public int? Result { get; set; }
|
||||
|
||||
public int? Qty { get; set; }
|
||||
|
||||
public string? CreatedBy { get; set; }
|
||||
|
||||
public DateTime? CreatedTime { get; set; }
|
||||
|
||||
public string? UpdatedBy { get; set; }
|
||||
|
||||
public DateTime? UpdatedTime { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
62
RIZO.Admin.WebApi/PLC/Model/PlcOperationResult.cs
Normal file
62
RIZO.Admin.WebApi/PLC/Model/PlcOperationResult.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace RIZO.Admin.WebApi.PLC.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// PLC返回的工位工序结果
|
||||
/// </summary>
|
||||
[SugarTable("plc_operation_result")]
|
||||
public class PlcOperationResult
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 条码
|
||||
/// </summary>
|
||||
public string Sn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工站编码
|
||||
/// </summary>
|
||||
public string Workstationcode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工站结果;1OK,2NG
|
||||
/// </summary>
|
||||
public int? Result { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数量
|
||||
/// </summary>
|
||||
public int? Qty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "created_by")]
|
||||
public string CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "created_time")]
|
||||
public DateTime? CreatedTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新人
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "updated_by")]
|
||||
public string UpdatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "updated_time")]
|
||||
public DateTime? UpdatedTime { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
using RIZO.Admin.WebApi.PLC.Model;
|
||||
using RIZO.Admin.WebApi.PLC.Model.Dto;
|
||||
using RIZO.Model;
|
||||
using RIZO.ServiceCore;
|
||||
|
||||
namespace RIZO.Admin.WebApi.PLC.Service.IService
|
||||
{
|
||||
/// <summary>
|
||||
/// PLC返回的工位工序结果service接口
|
||||
/// </summary>
|
||||
public interface IPlcOperationResultService : IBaseService<PlcOperationResult>
|
||||
{
|
||||
PagedInfo<PlcOperationResultDto> GetList(PlcOperationResultQueryDto parm);
|
||||
|
||||
PlcOperationResult GetInfo(int Id);
|
||||
|
||||
|
||||
PlcOperationResult AddPlcOperationResult(PlcOperationResult parm);
|
||||
int UpdatePlcOperationResult(PlcOperationResult parm);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
82
RIZO.Admin.WebApi/PLC/Service/PlcOperationResultService.cs
Normal file
82
RIZO.Admin.WebApi/PLC/Service/PlcOperationResultService.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Extensions;
|
||||
using RIZO.Admin.WebApi.PLC.Model;
|
||||
using RIZO.Admin.WebApi.PLC.Model.Dto;
|
||||
using RIZO.Admin.WebApi.PLC.Service.IService;
|
||||
using RIZO.Model;
|
||||
using RIZO.Repository;
|
||||
using RIZO.ServiceCore;
|
||||
using SqlSugar;
|
||||
|
||||
namespace RIZO.Admin.WebApi.PLC.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// PLC返回的工位工序结果Service业务层处理
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(IPlcOperationResultService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class PlcOperationResultService : BaseService<PlcOperationResult>, IPlcOperationResultService
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询PLC返回的工位工序结果列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<PlcOperationResultDto> GetList(PlcOperationResultQueryDto parm)
|
||||
{
|
||||
var predicate = QueryExp(parm);
|
||||
|
||||
var response = Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.ToPage<PlcOperationResult, PlcOperationResultDto>(parm);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取详情
|
||||
/// </summary>
|
||||
/// <param name="Id"></param>
|
||||
/// <returns></returns>
|
||||
public PlcOperationResult GetInfo(int Id)
|
||||
{
|
||||
var response = Queryable()
|
||||
.Where(x => x.Id == Id)
|
||||
.First();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加PLC返回的工位工序结果
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public PlcOperationResult AddPlcOperationResult(PlcOperationResult model)
|
||||
{
|
||||
return Insertable(model).ExecuteReturnEntity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改PLC返回的工位工序结果
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdatePlcOperationResult(PlcOperationResult model)
|
||||
{
|
||||
return Update(model, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询导出表达式
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
private static Expressionable<PlcOperationResult> QueryExp(PlcOperationResultQueryDto parm)
|
||||
{
|
||||
var predicate = Expressionable.Create<PlcOperationResult>();
|
||||
|
||||
return predicate;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -38,10 +38,18 @@ namespace RIZO.Admin.WebApi.PLC.Service
|
||||
private readonly ConcurrentDictionary<string, (Plc Client, DateTime LastUsedTime)> _plcConnPool = new(); // 连接池
|
||||
|
||||
#region PLC地址块儿映射
|
||||
//保存请求返回结果
|
||||
private readonly Dictionary<string, string> _saveRequestReturnMap = new()
|
||||
{
|
||||
{ "保存请求返回", "DB1050.DBW2002" }, // Int
|
||||
//MES返回PLC请求映射
|
||||
private readonly Dictionary<string, string> _mesIntReturnMap = new()
|
||||
{
|
||||
{ "设备使能", "DB1050.DBW0" }, // Int
|
||||
{ "工位开始查询结果", "DB1050.DBW2000" }, // Int
|
||||
{ "保存结果", "DB1050.DBW2002" }, // Int
|
||||
};
|
||||
|
||||
private readonly Dictionary<string, (string Addr, int Len)> _mesStringReturnMap = new()
|
||||
{
|
||||
{ "产品型号", ("DB1001.DBB1016", 14) }, // String[14]
|
||||
{ "订单下发", ("DB1001.DBB1032", 50) }, // String[50]
|
||||
};
|
||||
|
||||
// OP020-2 专属地址映射(合盖工位,DB1001)
|
||||
@ -488,7 +496,7 @@ namespace RIZO.Admin.WebApi.PLC.Service
|
||||
{
|
||||
if (t.IsFaulted && plc is { IsConnected: true })
|
||||
{
|
||||
WritePlcSaveRequestResult(plc, ip, plcName, "6");
|
||||
WritePlcSaveRequestResult(plc, ip, plcName, prodData, "6");
|
||||
Console.WriteLine($"{plcName}({ip})数据保存失败:{t.Exception?.InnerException?.Message ?? t.Exception?.Message ?? "未知错误"}");
|
||||
}
|
||||
}, TaskContinuationOptions.OnlyOnFaulted);
|
||||
@ -499,7 +507,7 @@ namespace RIZO.Admin.WebApi.PLC.Service
|
||||
var successMsg = isConnReused
|
||||
? $"{plcName}生产数据读取成功(复用连接)"
|
||||
: $"{plcName}生产数据读取成功(新建连接)";
|
||||
WritePlcSaveRequestResult(plc, ip, plcName, "1");
|
||||
WritePlcSaveRequestResult(plc, ip, plcName, prodData, "1");
|
||||
|
||||
return (true, prodData, successMsg);
|
||||
}
|
||||
@ -2127,16 +2135,18 @@ namespace RIZO.Admin.WebApi.PLC.Service
|
||||
}
|
||||
|
||||
// 提取写PLC返回值的通用方法,统一处理逻辑和日志
|
||||
private void WritePlcSaveRequestResult(Plc plc, string ip, string plcName, string returnValue)
|
||||
private void WritePlcSaveRequestResult(Plc plc, string ip, string plcName, PlcProductionData prodData, string saveResult)
|
||||
{
|
||||
try
|
||||
{
|
||||
WritePlcValue(plc, _saveRequestReturnMap["保存请求返回"], returnValue);
|
||||
WritePlcValue(plc, _mesIntReturnMap["设备使能"], "1");
|
||||
//WritePlcValue(plc, _mesIntReturnMap["工位开始查询结果"], "1");
|
||||
WritePlcValue(plc, _mesIntReturnMap["保存结果"], saveResult);
|
||||
WritePlcValue(plc, "产品型号", prodData.ProductModel);
|
||||
WritePlcValue(plc, "订单下发", "");//??
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 标准化日志格式,包含更多上下文信息
|
||||
Console.WriteLine($"[{DateTime.Now}]{plcName}({ip}) 写保存请求返回值失败[目标值:{returnValue}]:{ex.Message}");
|
||||
{;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user