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
{
///
/// 默认的扫码枪扫码触发事件处理
///
public class DefaultScannerEventHandle : IScannerEventHandle
{
private readonly IRepository silkRepository;
private readonly IUnitOfWorkManager uowm;
public DefaultScannerEventHandle(IRepository silkRepository, IUnitOfWorkManager unitOfWork)
{
this.silkRepository = silkRepository;
this.uowm = unitOfWork;
}
///
/// 扫码枪
///
///
///
///
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();
}
}
}
}
}