2025-06-25 16:07:36 +08:00

90 lines
3.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Seyounth.Auto.Hs.Runtime.Scanner;
using Syc.Basic.Web.WMS.Entitys;
using Syc.Basic.Web.WMS.WebSocket;
using Syc.Core.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow;
namespace Syc.Basic.Web.WMS
{
/// <summary>
/// 默认的扫码枪扫码触发事件处理
/// </summary>
public class DefaultScannerEventHandle : IScannerEventHandle
{
private readonly IRepository<Silk> silkRepository;
private readonly IUnitOfWorkManager uowm;
public DefaultScannerEventHandle(IRepository<Silk> silkRepository, IUnitOfWorkManager unitOfWork)
{
this.silkRepository = silkRepository;
this.uowm = unitOfWork;
}
/// <summary>
/// 扫码枪
/// </summary>
/// <param name="code"></param>
/// <param name="id"></param>
/// <returns></returns>
public async Task ExecAsync(string code, int id)
{
using (var uow = uowm.Reserve(UnitOfWork.UnitOfWorkReservationName))
{
try
{
/*
* 如果有其他的处理写在这里或者另外建一个类实现IScannerEventHandle接口
*/
var msg = new DeviceMessage(id, "扫码枪", code);
if (!code.IsNullOrWhiteSpace())
{
var result = await silkRepository.AnyAsync(x => x.Code == code);
if (result)
msg.Value = $"存在重复编号({code}";
}
await WebSocketManager.SocketManager.BroadcastAsync(msg.ToJsonString());
await uow.CompleteAsync();
}
catch (Exception ex)
{
await uow.RollbackAsync();
}
}
}
public async Task ExecAsync2(string code, int id)
{
using (var uow = uowm.Reserve(UnitOfWork.UnitOfWorkReservationName))
{
try
{
/*
* 如果有其他的处理写在这里或者另外建一个类实现IScannerEventHandle接口
*/
var msg = new DeviceMessage(id, "体重秤", code);
if (!code.IsNullOrWhiteSpace())
{
var result = await silkRepository.AnyAsync(x => x.Code == code);
if (result)
msg.Value = $"存在重复编号({code}";
}
await WebSocketManager.SocketManager.BroadcastAsync(msg.ToJsonString());
await uow.CompleteAsync();
}
catch (Exception ex)
{
await uow.RollbackAsync();
}
}
}
}
}