66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using Seyounth.Auto.Hs.Runtime.Balances;
|
|
using Seyounth.Auto.Hs.Runtime.Printer;
|
|
using Seyounth.Auto.Hs.Runtime.Scanner;
|
|
using Syc.Basic.Web.WMS.Dto;
|
|
using Syc.Basic.Web.WMS.Entitys;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.Domain.Repositories;
|
|
|
|
namespace Syc.Basic.Web.WMS.Service
|
|
{
|
|
public class TcpService : ApiService
|
|
{
|
|
private readonly IPrinterService printerService;
|
|
private readonly IBalanceService balanceService;
|
|
private readonly IRepository<Silk> silkRepository;
|
|
private readonly ILogger<TcpService> logger;
|
|
private readonly IScannerService scannerService;
|
|
|
|
public TcpService(IScannerService ScannerService, IPrinterService PrinterService, IBalanceService BalanceService, IRepository<Silk> SilkRepository, ILogger<TcpService> Logger,
|
|
IScanner boxScanner)
|
|
{
|
|
scannerService = ScannerService;
|
|
printerService = PrinterService;
|
|
balanceService = BalanceService;
|
|
silkRepository = SilkRepository;
|
|
logger = Logger;
|
|
|
|
scannerService.OnScanned += HandleBarcodeScanned;
|
|
}
|
|
|
|
public async Task StartScanner()
|
|
{
|
|
//启动所有的扫码枪
|
|
await scannerService.StartAsync();
|
|
logger.LogInformation("扫码服务已启动");
|
|
}
|
|
|
|
public async Task StopScanner()
|
|
{
|
|
//停止所有的扫码枪
|
|
await scannerService.StopAsync();
|
|
logger.LogInformation("扫码服务已停止");
|
|
}
|
|
private void HandleBarcodeScanned(IScanner scanner, string barcode)
|
|
{
|
|
// 处理扫码数据
|
|
logger.LogInformation($"从扫码枪 {scanner.Id} 扫描到条码: {barcode}");
|
|
|
|
// 在这里添加你的业务逻辑
|
|
ProcessBarcodeData(barcode);
|
|
}
|
|
|
|
private async Task<List<SilkDto>> ProcessBarcodeData(string barcode)
|
|
{
|
|
var datas = await silkRepository.GetListAsync();
|
|
var data = ObjectMapper.Map(datas, new List<SilkDto>());
|
|
return data;
|
|
}
|
|
}
|
|
}
|