90 lines
3.1 KiB
C#
Raw Normal View History

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();
}
}
}
}
}