You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

775 lines
33 KiB
C#

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SlnMesnac.Business.@base;
using SlnMesnac.Common;
using SlnMesnac.Config;
using SlnMesnac.Model.domain;
using SlnMesnac.Model.dto;
using SlnMesnac.Model.enums;
using SlnMesnac.Plc;
using SlnMesnac.Repository.service;
using SlnMesnac.Rfid;
using SlnMesnac.TouchSocket;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using TouchSocket.Core;
using static System.Net.Mime.MediaTypeNames;
#region << <20><> <20><> ע <20><> >>
/*--------------------------------------------------------------------
* <EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> (c) 2024 WenJY <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* CLR<EFBFBD><EFBFBD><EFBFBD>4.0.30319.42000
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>LAPTOP-E0N2L34V
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռSlnMesnac.Business
* Ψһ<EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>f79d6d97-d9b0-4b0b-a442-e6bb1c1c79e6
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD>WenJY
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>wenjy@mesnac.com
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>2024-04-10 16:36:01
* <EFBFBD><EFBFBD><EFBFBD>V1.0.0
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
*--------------------------------------------------------------------
* <EFBFBD>޸<EFBFBD><EFBFBD>ˣ<EFBFBD>
* ʱ<EFBFBD>
* <EFBFBD>޸<EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* <EFBFBD><EFBFBD><EFBFBD>V1.0.0
*--------------------------------------------------------------------*/
#endregion << <20><> <20><> ע <20><> >>
namespace SlnMesnac.Business
{
/// <summary>
/// <20><EFBFBD><E8B1B8><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>߼<EFBFBD>
/// </summary>
public class ProdCompletionBusiness : BaseBusiness
{
private FJ500Comm.FJ500SP fj500s = new FJ500Comm.FJ500SP();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܻ<EFBFBD><DCBB><EFBFBD><EFBFBD>豸״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>
private int PmTryAmount = 0;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>յ<EFBFBD><D5B5>ظ<EFBFBD>ˢ<EFBFBD><CBA2>ʱ<EFBFBD><EFBFBD><E4A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private DateTime PmHeartTime = DateTime.Now;
private readonly IMesProductPlanService _mesProductPlanService;
private readonly IMesProductOrderService _mesProductOrderService;
private readonly IMesPrdBarCodeService _barCodeTaskService;
private readonly IBaseMaterialInfoService _baseMaterialInfoService;
private readonly IMesBaseBarcodeInfoService _mesBaseBarcodeInfoService;
public readonly IMesPrdBarCodeService _mesPrdBarCodeService;
private readonly IRealPalletTaskService _realPalletTaskService;
private readonly UdpServer udpServer;
private DebugConfig debugConfig = DebugConfig.Instance;
private ISqlSugarClient sqlSugarClient;
public ProdCompletionBusiness(ISqlSugarClient _sqlSugarClient, ILogger<BaseBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IMesPrdBarCodeService barCodeTaskService, IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider)
{
udpServer = serviceProvider.GetRequiredService<UdpServer>();
UdpServer.ReceivedPMCodeEvent += PmCodeHandler;
sqlSugarClient = _sqlSugarClient;
_mesProductPlanService = mesProductPlanService;
_barCodeTaskService = barCodeTaskService;
_realPalletTaskService = serviceProvider.GetRequiredService<IRealPalletTaskService>();
_mesBaseBarcodeInfoService = serviceProvider.GetRequiredService<IMesBaseBarcodeInfoService>();
_mesPrdBarCodeService = serviceProvider.GetRequiredService<IMesPrdBarCodeService>();
_mesProductOrderService = serviceProvider.GetRequiredService<IMesProductOrderService>();
_baseMaterialInfoService = serviceProvider.GetRequiredService<IBaseMaterialInfoService>();
Init();
// test();
}
private void test()
{
// MesProductPlanDetail? mesProductPlanDetail = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<MesProductPlanDetail>().First(x => x.PlanCode == "20240724144533JL001");
sqlSugarClient.AsTenant().BeginTran();
string epc = "A123456";
_mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto);
string bigCode = GenerateBigBarcode(productPlanDto, epc);
BindingBarCode(bigCode, epc, productPlanDto);
sqlSugarClient.AsTenant().BeginTran();
}
private static bool isEmptyPalletHandleRunning = false;
public void Init()
{
Task.Run(async () =>
{
await EmptyPalletHandle();
});
Task.Run(() =>
{
DeviceOutPutHandle();
});
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸״̬<D7B4><CCAC><EFBFBD><EFBFBD>
checkPmStatus();
}
#region <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>ͨѶ
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
/// </summary>
public void checkPmStatus()
{
Task.Run(() =>
{
while (true)
{
try
{
//<2F><><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>״ָ̬<CCAC><D6B8>
// udpServer.SendMessage(fj500s.CheckState());
// Thread.Sleep(1000 * 5);
// <20><><EFBFBD>·<EFBFBD><C2B7>ʹ<EFBFBD><CDB4><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EBA3AC>֤ʼ<D6A4><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SendFirstPmCode();
}
catch (Exception ex)
{
_logger.LogError("checkStatus<75>쳣:" + ex.Message);
}
Thread.Sleep(1000 * 30);
if (DateTime.Now - PmHeartTime > TimeSpan.FromMinutes(2))
{
//<2F><><EFBFBD><EFBFBD>
_logger.LogError("====================<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>");
AddAlarm(WarnStatusEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡʧ<EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>30<EFBFBD><EFBFBD>);
PmTryAmount++;
}
}
});
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// 1.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// 2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
/// </summary>
/// <param name="str"></param>
private void PmCodeHandler(string str)
{
PmHeartTime = DateTime.Now;
try
{
int LastTryAmount = PmTryAmount;
var result = fj500s.GetAck(str);
if (result == "00")
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳɹ<DDB3>
_logger.LogInformation("====================<3D>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳɹ<DDB3>");
PmTryAmount = 0;
}
else if (result == "0E")
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
_logger.LogError($"====================<3D>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD><CFBB><EFBFBD><EFBFBD><EFBFBD>ӡʧ<D3A1><CAA7>Ԥ<EFBFBD><D4A4>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>:{PmTryAmount}");
PmTryAmount++;
if (PmTryAmount <= 30)
{
//<2F><><EFBFBD>·<EFBFBD><C2B7><EFBFBD>
Task.Run(() =>
{
Thread.Sleep(1000 * 5);
SendFirstPmCode();
});
}
else
{
_logger.LogError("====================<3D><><EFBFBD><EFBFBD>30<33>Σ<EFBFBD><CEA3><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>");
AddAlarm(WarnStatusEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡʧ<EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>30<EFBFBD><EFBFBD>);
}
}
else if (result == "0F")
{
_logger.LogInformation("====================<3D>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>");
updatePrdBarcodeInfo();
SendFirstPmCode();
_logger.LogInformation("====================<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>");
PmTryAmount = 0;
}
if (LastTryAmount>0 && PmTryAmount==0)
{ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
_logger.LogInformation("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
deleteAlarm(WarnStatusEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡʧ<EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>30<EFBFBD><EFBFBD>);
}
}
catch (Exception ex)
{
_logger.LogError("PmCodeHandler<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣:" + ex.Message);
}
}
/// <summary>
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4>ӡδ<D3A1><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
private void SendFirstPmCode()
{
MesPrdBarcodeInfo mesPrdBarcodeInfo = _barCodeTaskService.Query(x => x.PrintFlag == "0" && x.BindStatus == 0).OrderBy(x => x.PrdBarcodeId).FirstOrDefault();
if(mesPrdBarcodeInfo != null)
{
udpServer.SendMessage(mesPrdBarcodeInfo.PrdBarcodeInfo);
}
else
{
_logger.LogError("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>");
}
}
/// <summary>
/// <20><>ӡ<EFBFBD><D3A1><EFBFBD>ɸ<EFBFBD><C9B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
private void updatePrdBarcodeInfo()
{
MesPrdBarcodeInfo mesPrdBarcodeInfo = _barCodeTaskService.Query(x => x.PrintFlag == "0" && x.BindStatus == 0).OrderBy(x => x.PrdBarcodeId).FirstOrDefault();
mesPrdBarcodeInfo.PrintFlag = "1";
mesPrdBarcodeInfo.PrintTime = DateTime.Now;
_barCodeTaskService.Update(mesPrdBarcodeInfo);
}
#endregion
/// <summary>
/// <20><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
private async void DeviceOutPutHandle()
{
// <20><>ȡRFIDʧ<44><CAA7><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><35><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>
int readRfidAmount = 0;
while (true)
{
try
{
var plc = base.GetPlcByKey("plc");
if (plc == null)
{
_logger.LogInformation("<22><>ȡС<C8A1><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>,PLC<4C><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϢΪ<CFA2><CEAA>......");
Thread.Sleep(3000);
continue;
}
// plc.writeStringByAddress(GetPlcAddressByConfigKey("2¥<32><C2A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RFID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ"), "JYHB01010125", 12);
if (!plc.readBoolByAddress(GetPlcAddressByConfigKey("2¥С<C2A5><D0A1><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>λ<EFBFBD>ź<EFBFBD>")))
{
_logger.LogInformation("<22>ȴ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>źŴ<C5BA><C5B4><EFBFBD>......");
Thread.Sleep(5000);
continue;
}
string rfid = plc.readStringByAddress(GetPlcAddressByConfigKey("2¥<32><C2A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RFID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ"), 12).Replace("\0", "");
if (!string.IsNullOrWhiteSpace(rfid))
{
_logger.LogInformation("С<><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD>RFID<49>ˣ<EFBFBD><CBA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>");
Thread.Sleep(5000);
continue;
}
string epcStr = await ReadEpcStrByRfidKeyAsync("secondFloorOut");
if (string.IsNullOrEmpty(epcStr))
{
_logger.LogError("С<><D0A1><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>λ<EFBFBD>źŴ<C5BA><C5B4><EFBFBD>,<2C><>ȡRFIDʧ<44><CAA7>......");
//<2F>ж<EFBFBD>ǰһλ<D2BB><CEBB><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̻<EFBFBD><CCBB><EFBFBD>
RealPalletTask realPalletTask = _realPalletTaskService.Query().FirstOrDefault();
if (realPalletTask != null)
{
epcStr = realPalletTask.PalletCode;
}
else
{
readRfidAmount++;
if (readRfidAmount == 5)
{
string virtualEpc = NoReadRFIDAlarm();
_logger.LogError("С<><D0A1><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>λ<EFBFBD>źŴ<C5BA><C5B4><EFBFBD>,<2C><>ȡRFIDʧ<44>ܳ<EFBFBD><DCB3><EFBFBD>5<EFBFBD><35>......");
if (!string.IsNullOrEmpty(virtualEpc))
{
//TODU <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><CCBA><EFBFBD>Ҫ<EFBFBD><D2AA>ϵͳ<CFB5>
epcStr = virtualEpc;
_logger.LogError("С<><D0A1><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>λ<EFBFBD>źŴ<C5BA><C5B4><EFBFBD>,<2C><>ȡRFIDʧ<44>ܳ<EFBFBD><DCB3><EFBFBD>5<EFBFBD><35>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD>:" + virtualEpc);
}
}
else
{
Thread.Sleep(1000 * 5);
continue;
}
}
}
RefreshMessage($"С<><D0A1><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD>ȡ<EFBFBD><C8A1>RFID<49><44><EFBFBD><EFBFBD>{epcStr},<2C><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
_mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto);
if (productPlanDto == null)
{
//throw new ArgumentException($"δ<><CEB4>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD>");
//<2F>޼ƻ<DEBC>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޼ƻ<DEBC><C6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MaterialId<49><64><EFBFBD>޸ģ<DEB8><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
productPlanDto = new MesProductPlanDto();
productPlanDto.PlanCode = "0";
productPlanDto.MaterialId = long.Parse(debugConfig.MaterialId);
productPlanDto.SaleOrderId = 0;
productPlanDto.SaleorderCode = "0";
}
#region <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sqlSugarClient.AsTenant().BeginTran();
//1.<2E><><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mes_barcode_info<66><6F>
string bigCode = GenerateBigBarcode(productPlanDto, epcStr);
//2.40<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺ţ<EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󶨴<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>̰󶨴<CCB0><F3B6A8B4><EFBFBD><EFBFBD><EFBFBD>
BindingBarCode(bigCode, epcStr, productPlanDto);
//3.<2E><><EFBFBD><EFBFBD>mes_product_plan<61><6E>mes_product_order<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UpdatePlanInfoAndOrder(productPlanDto);
// ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>̺<EFBFBD>
List<RealPalletTask> realPalletList = _realPalletTaskService.Query(x => x.PalletCode == epcStr);
if (realPalletList != null && realPalletList.Count > 0)
{
sqlSugarClient.AsTenant().GetConnection("mes").Deleteable(realPalletList).ExecuteCommand();
}
// д<><D0B4>PLC RFID<49>Ź<EFBFBD><C5B9><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
plc.writeStringByAddress(GetPlcAddressByConfigKey("2¥<32><C2A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RFID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ"), epcStr, 12);
// plc.writeByteByAddress(GetPlcAddressByConfigKey("2¥С<C2A5><D0A1><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>λ<EFBFBD>ź<EFBFBD>"), 2);
readRfidAmount = 0;
sqlSugarClient.AsTenant().CommitTran();
#endregion
}
catch (Exception ex)
{
sqlSugarClient.AsTenant().RollbackTran();
_logger.LogError($"DeviceOutPutHandle<6C>쳣:{ex.Message}");
}
Thread.Sleep(1000 * 5);
}
}
/// <summary>
/// <20><><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mes_barcode_info<66><6F>
/// </summary>
/// <param name="productPlanDto"></param>
/// <param name="epcStr"></param>
/// <returns></returns>
private string GenerateBigBarcode(MesProductPlanDto productPlanDto, string epcStr)
{
string bigBarcode = productPlanDto.PlanCode + DateTime.Now.ToString("_MMddHHmmss");
MesBaseBarcodeInfo mesBaseBarcodeInfo = new MesBaseBarcodeInfo();
mesBaseBarcodeInfo.printTime = DateTime.Now;
mesBaseBarcodeInfo.printPerson = "SlnMesnac";
mesBaseBarcodeInfo.printFlag = "1";
mesBaseBarcodeInfo.batchFlag = "0";
mesBaseBarcodeInfo.barcodeType = "3";
mesBaseBarcodeInfo.barcodeInfo = bigBarcode;
mesBaseBarcodeInfo.batchCode = bigBarcode;
mesBaseBarcodeInfo.palletInfoCode = epcStr;
mesBaseBarcodeInfo.materialId = productPlanDto.MaterialId;
mesBaseBarcodeInfo.amount = 1;
mesBaseBarcodeInfo.printNumber = 1;
mesBaseBarcodeInfo.productionDate = DateTime.Now;
mesBaseBarcodeInfo.acceptedDate = DateTime.Now;
mesBaseBarcodeInfo.planCode = productPlanDto.PlanCode;
MesProductPlanDetail? mesProductPlanDetail = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<MesProductPlanDetail>().First(x => x.PlanCode == productPlanDto.PlanCode);
if (mesProductPlanDetail != null)
{
mesBaseBarcodeInfo.planDetailCode = mesProductPlanDetail.PlanDetailCode;
}
mesBaseBarcodeInfo.safeFlag = productPlanDto.SaleOrderId == 0 ? "1" : "0";
mesBaseBarcodeInfo.saleOrderId = productPlanDto.SaleOrderId;
mesBaseBarcodeInfo.saleorderCode = productPlanDto.SaleorderCode;
mesBaseBarcodeInfo.bindStatus = "1";
mesBaseBarcodeInfo.bindTime = DateTime.Now;
mesBaseBarcodeInfo.updateBy = "SlnMesnac";
mesBaseBarcodeInfo.updateTime = DateTime.Now;
mesBaseBarcodeInfo.completeFlag = "1";
mesBaseBarcodeInfo.singleFlag = "0";
var materialInfo = _baseMaterialInfoService.Query(x => x.MaterialId == productPlanDto.MaterialId).FirstOrDefault();
if (materialInfo != null)
{
mesBaseBarcodeInfo.barcodeSpec = materialInfo.MaterialSpec;
}
sqlSugarClient.AsTenant().GetConnection("mes").Insertable(mesBaseBarcodeInfo).ExecuteCommand();
return bigBarcode;
}
/// <summary>
/// 40<34><30>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EBBCB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺ţ<CCBA>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>󶨴<EFBFBD><F3B6A8B4><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="bigBarcode"></param>
/// <param name="epcStr"></param>
private void BindingBarCode(string bigBarcode, string epcStr, MesProductPlanDto productPlanDto)
{
List<MesPrdBarcodeInfo> list = _mesPrdBarCodeService.GetUseBarCodeList();
if (list == null || list.Count == 0)
{
throw new InvalidOperationException("<22><><EFBFBD><EFBFBD>δ<EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>԰󶨵<D4B0>С<EFBFBD><D0A1><EFBFBD><EFBFBD>");
}
if (list.Where(x => x.PrintFlag == "1").ToList().Count < 40)
{
// <20><><EFBFBD>͵ͼ<CDB5><CDBC>𱨾<EFBFBD>
AddAlarm(WarnStatusEnum.<EFBFBD><EFBFBD><EFBFBD>̰<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>40);
}
foreach (var item in list)
{
item.PalletInfoCode = epcStr;
item.MesBarcodeInfo = bigBarcode;
item.BindTime = DateTime.Now;
item.BindStatus = 1;
}
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(list).ExecuteCommand();
//<2F><><EFBFBD>̰󶨴<CCB0><F3B6A8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
BasePalletInfo palletInfo = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<BasePalletInfo>().Where(x => x.PalletInfoCode == epcStr).First();
if (palletInfo != null)
{
palletInfo.MaterialBarcode = bigBarcode;
palletInfo.MaterialId = productPlanDto.MaterialId;
}
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(palletInfo).ExecuteCommand();
}
private void UpdatePlanInfoAndOrder(MesProductPlanDto productPlanDto)
{
MesProductPlan productPlan = _mesProductPlanService.Query(x => x.PlanCode == productPlanDto.PlanCode).FirstOrDefault();
if (productPlan == null)
{
_logger.LogInformation(<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!,<2C><><EFBFBD><EFBFBD><EFBFBD>޹<EFBFBD><DEB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼ƻ<C2BC>");
return;
}
MesProductOrder productOrder = _mesProductOrderService.Query(x => x.ProductOrderId == productPlan.ProductOrderId).FirstOrDefault();
if (productPlan == null)
{
_logger.LogInformation(<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!,<2C><><EFBFBD><EFBFBD><EFBFBD>޹<EFBFBD><DEB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼ƻ<C2BC>");
return;
}
#region <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD>
if (productPlan.CompleteAmount == 0)
{
productPlan.RealBeginTime = DateTime.Now;
}
productPlan.CompleteAmount++;
if (productPlan.CompleteAmount == productPlan.PlanAmount)
{
productPlan.RealEndTime = DateTime.Now;
productPlan.PlanStatus = Model.enums.PlanStatusEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
}
productPlan.UpdateTime = DateTime.Now;
productPlan.UpdateBy = "SlnMesnac";
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(productPlan).ExecuteCommand();
#endregion
#region <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (productOrder.CompleteAmount == 0)
{
productOrder.RealBeginTime = DateTime.Now;
}
productOrder.CompleteAmount++;
if (productOrder.CompleteAmount == productOrder.PlanAmount)
{
productOrder.RealEndTime = DateTime.Now;
productOrder.OrderStatus = "2";
}
productOrder.UpdateTime = DateTime.Now;
productOrder.UpdateBy = "SlnMesnac";
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(productOrder).ExecuteCommand();
#endregion
}
#region <20><><EFBFBD><EFBFBD>
/// <summary>
///
/// <20><><EFBFBD><EFBFBD><EBB1A8>
/// </summary>
private void AddAlarm(WarnStatusEnum warnStatusEnum)
{
try
{
sqlSugarClient.AsTenant().BeginTran();
// <20>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>߱<EFBFBD><DFB1><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>ѽ<EFBFBD><D1BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼
int warnRuleId = int.Parse(warnStatusEnum.GetDescription());
DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmTime>().First(x => x.AlarmRuleId == warnRuleId);
if (dmsRecordAlarmTime == null)
{
DmsBaseAlarmRule dmsBaseAlarmRule = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsBaseAlarmRule>().First(x => x.AlarmRuleId == warnRuleId);
dmsRecordAlarmTime = new DmsRecordAlarmTime();
dmsRecordAlarmTime.DeviceId = dmsBaseAlarmRule.DeviceId;
dmsRecordAlarmTime.AlarmRuleId = warnRuleId;
dmsRecordAlarmTime.AlarmBeginTime = DateTime.Now;
dmsRecordAlarmTime.ContinueTime = dmsBaseAlarmRule.ContinueTime;
dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason;
dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason;
dmsRecordAlarmTime.AlarmData = warnStatusEnum.ToString();
dmsRecordAlarmTime.HandleSuggest = dmsBaseAlarmRule.HandleSuggest;
dmsRecordAlarmTime.CreateBy = "SlnMesnac";
dmsRecordAlarmTime.CreateTime = DateTime.Now;
DmsRecordAlarmInfo dmsRecordAlarmInfo = new DmsRecordAlarmInfo();
dmsRecordAlarmInfo.DeviceId = dmsBaseAlarmRule.DeviceId;
dmsRecordAlarmInfo.AlarmRuleId = warnRuleId;
dmsRecordAlarmInfo.AlarmBeginTime = DateTime.Now;
dmsRecordAlarmInfo.AlarmStatus = "0";
dmsRecordAlarmInfo.NoticeStatus = "0";
dmsRecordAlarmInfo.ContinueTime = dmsBaseAlarmRule.ContinueTime;
dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason;
dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason;
dmsRecordAlarmInfo.AlarmData = warnStatusEnum.ToString();
dmsRecordAlarmInfo.HandleSuggest = dmsBaseAlarmRule.HandleSuggest;
dmsRecordAlarmInfo.CreateBy = "SlnMesnac";
dmsRecordAlarmInfo.CreateTime = DateTime.Now;
sqlSugarClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmTime).ExecuteCommand();
sqlSugarClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmInfo).ExecuteCommand();
}
else
{
dmsRecordAlarmTime.UpdateTime = DateTime.Now;
dmsRecordAlarmTime.UpdateBy = "SlnMesnac";
DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmInfo>().First(x => x.AlarmRuleId == warnRuleId);
if (dmsRecordAlarmInfo != null)
{
dmsRecordAlarmInfo.UpdateTime = DateTime.Now;
dmsRecordAlarmInfo.UpdateBy = "SlnMesnac";
}
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmTime).ExecuteCommand();
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmInfo).ExecuteCommand();
}
sqlSugarClient.AsTenant().CommitTran();
}
catch (Exception ex)
{
sqlSugarClient.AsTenant().RollbackTran();
_logger.LogError($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߸<EFBFBD><DFB8>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>쳣{warnStatusEnum.ToString()} ==>:{ex.Message}");
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <exception cref="InvalidOperationException"></exception>
private void deleteAlarm(WarnStatusEnum warnStatusEnum)
{
DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmTime>().First(x => x.AlarmRuleId == long.Parse(warnStatusEnum.GetDescription()));
if (dmsRecordAlarmTime != null)
{
sqlSugarClient.AsTenant().BeginTran();
DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmInfo>().First(x => x.AlarmRuleId == dmsRecordAlarmTime.AlarmRuleId && x.AlarmStatus == "0");
if (dmsRecordAlarmInfo != null)
{
dmsRecordAlarmInfo.AlarmEndTime = DateTime.Now;
dmsRecordAlarmInfo.AlarmStatus = "2";
dmsRecordAlarmInfo.UpdateTime = DateTime.Now;
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmInfo).ExecuteCommand();
}
sqlSugarClient.AsTenant().GetConnection("mes").Deleteable(dmsRecordAlarmTime).ExecuteCommand();
sqlSugarClient.AsTenant().CommitTran();
}
}
/// <summary>
/// <20><><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><CCBA><EFBFBD>ʱʹ<CAB1>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺Ŵ<CCBA><C5B4><EFBFBD><E6B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><CCBA>滻Ϊ<E6BBBB><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD>
/// <return> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD>
/// </summary>
private string NoReadRFIDAlarm()
{
string epcStr;
try
{
epcStr = "TEMP" + DateTime.Now.ToString("MMddHHmm");
sqlSugarClient.AsTenant().BeginTran();
// <20>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>߱<EFBFBD><DFB1><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>ѽ<EFBFBD><D1BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼
int warnRuleId = int.Parse(WarnStatusEnum.С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD>ȡRFIDʧ<EFBFBD><EFBFBD>5<EFBFBD><EFBFBD>.GetDescription());
DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmTime>().First(x => x.AlarmRuleId == warnRuleId);
if (dmsRecordAlarmTime == null)
{
DmsBaseAlarmRule dmsBaseAlarmRule = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsBaseAlarmRule>().First(x => x.AlarmRuleId == warnRuleId);
dmsRecordAlarmTime = new DmsRecordAlarmTime();
dmsRecordAlarmTime.DeviceId = dmsBaseAlarmRule.DeviceId;
dmsRecordAlarmTime.AlarmRuleId = warnRuleId;
dmsRecordAlarmTime.AlarmBeginTime = DateTime.Now;
dmsRecordAlarmTime.ContinueTime = dmsBaseAlarmRule.ContinueTime;
dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason;
dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason;
dmsRecordAlarmTime.AlarmData = WarnStatusEnum.С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD>ȡRFIDʧ<EFBFBD><EFBFBD>5<EFBFBD><EFBFBD>.ToString();
dmsRecordAlarmTime.HandleSuggest = dmsBaseAlarmRule.HandleSuggest + ";;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD>Ϊ:" + epcStr;
dmsRecordAlarmTime.CreateBy = "SlnMesnac";
dmsRecordAlarmTime.CreateTime = DateTime.Now;
DmsRecordAlarmInfo dmsRecordAlarmInfo = new DmsRecordAlarmInfo();
dmsRecordAlarmInfo.DeviceId = dmsBaseAlarmRule.DeviceId;
dmsRecordAlarmInfo.AlarmRuleId = warnRuleId;
dmsRecordAlarmInfo.AlarmBeginTime = DateTime.Now;
dmsRecordAlarmInfo.AlarmStatus = "0";
dmsRecordAlarmInfo.NoticeStatus = "0";
dmsRecordAlarmInfo.ContinueTime = dmsBaseAlarmRule.ContinueTime;
dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason;
dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason;
dmsRecordAlarmInfo.AlarmData = WarnStatusEnum.С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD>ȡRFIDʧ<EFBFBD><EFBFBD>5<EFBFBD><EFBFBD>.ToString();
dmsRecordAlarmInfo.HandleSuggest = dmsBaseAlarmRule.HandleSuggest + ";;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD>Ϊ:" + epcStr;
dmsRecordAlarmInfo.CreateBy = "SlnMesnac";
dmsRecordAlarmInfo.CreateTime = DateTime.Now;
sqlSugarClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmTime).ExecuteCommand();
sqlSugarClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmInfo).ExecuteCommand();
}
else
{
dmsRecordAlarmTime.UpdateTime = DateTime.Now;
dmsRecordAlarmTime.UpdateBy = "SlnMesnac";
DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmInfo>().First(x => x.AlarmRuleId == warnRuleId);
if (dmsRecordAlarmInfo != null)
{
dmsRecordAlarmInfo.UpdateTime = DateTime.Now;
dmsRecordAlarmInfo.UpdateBy = "SlnMesnac";
}
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmTime).ExecuteCommand();
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmInfo).ExecuteCommand();
}
sqlSugarClient.AsTenant().CommitTran();
return epcStr;
}
catch (Exception ex)
{
sqlSugarClient.AsTenant().RollbackTran();
_logger.LogError($"NoReadRFIDAlarm<72>쳣:{ex.Message}");
return "";
}
}
#endregion
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ,<2C><>ȡRFID<49><44><EFBFBD><EFBFBD>
/// </summary>
private async Task EmptyPalletHandle()
{
//<2F><>ȡPLC<4C><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>ź<EFBFBD>
while (true)
{
try
{
var plc = base.GetPlcByKey("plc");
if (plc == null)
{
_logger.LogInformation("<22><>ȡPLC<4C><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⵽λ<E2B5BD>ź<EFBFBD>,PLC<4C><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϢΪ<CFA2><CEAA>......");
Thread.Sleep(5000);
continue;
}
if (!plc.readBoolByAddress(GetPlcAddressByConfigKey("2¥<32><C2A5><EFBFBD>⵽λ<E2B5BD>ź<EFBFBD>")))
{
_logger.LogInformation("<22>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD>λ<EFBFBD>źŴ<C5BA><C5B4><EFBFBD>......");
Thread.Sleep(5000);
continue;
}
RealPalletTask realPalletTask = _realPalletTaskService.Query().FirstOrDefault();
if (realPalletTask != null)
{
_logger.LogInformation("<22><><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD>λ<EFBFBD>źŴ<C5BA><C5B4><EFBFBD>,<2C>Ѿ<EFBFBD><D1BE>ж<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>̣<EFBFBD><CCA3><EFBFBD><EFBFBD>ٶ<EFBFBD>ȡ......");
Thread.Sleep(5000);
continue;
}
//<2F><>ȡRFID<49><44><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ִ<EFBFBD>еļƻ<C4BC><C6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>̰<EFBFBD><CCB0><EFBFBD>
RefreshMessage("<22><><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD>λ<EFBFBD>źŴ<C5BA><C5B4><EFBFBD><EFBFBD>ɹ<EFBFBD>,<2C><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>RFID<49><44>Ϣ");
string epcStr = await ReadEpcStrByRfidKeyAsync("secondFloorPallet");
if (string.IsNullOrEmpty(epcStr))
{
_logger.LogError("<22><><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD>λ<EFBFBD>źŴ<C5BA><C5B4><EFBFBD>,<2C><>ȡRFIDʧ<44><CAA7>......");
Thread.Sleep(1000 * 10);
continue;
}
RefreshMessage($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RFID<49><44>Ϣ<EFBFBD><CFA2>ȡ<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>ǩ<EFBFBD><C7A9>Ϣ<EFBFBD><CFA2>{epcStr}");
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD>¼
realPalletTask = new RealPalletTask()
{
PalletCode = epcStr,
RecordTime = DateTime.Now,
};
_realPalletTaskService.Insert(realPalletTask);
}
catch (Exception e)
{
RefreshMessage($"<22><><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECB3A3>{e.Message}");
}
Thread.Sleep(1000 * 10);
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
/// </summary>
/// <param name="barCode"></param>
/// <param name="result"></param>
/// <exception cref="InvalidOperationException"></exception>
private void ExtractNumber(string barCode, out int result)
{
string pattern = @"\b0*(\d{1,6})\b$";
Match match = Regex.Match(barCode, pattern);
if (match.Success)
{
result = Convert.ToInt32(match.Groups[1].Value) + 1;
}
else
{
throw new InvalidOperationException($"ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:{barCode}<7D><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>쳣:δ<>ҵ<EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
}
}
}