定时服务启动方式调整,并调整相关业务代码
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
@@ -41,6 +42,7 @@ using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||||
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
|
||||
using Tnb.WarehouseMgr.Entities.Entity;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
using Tnb.WarehouseMgr.Print;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
@@ -79,9 +81,10 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
}
|
||||
|
||||
protected Task<ClaimsPrincipal> GetUserIdentity()
|
||||
protected Task<ClaimsPrincipal> GetUserIdentity(string? asscessToken = null)
|
||||
{
|
||||
var claims = JWTEncryption.ReadJwtToken(UserManager.AsscessToken)?.Claims;
|
||||
var at = asscessToken ?? UserManager.AsscessToken;
|
||||
var claims = JWTEncryption.ReadJwtToken(at)?.Claims;
|
||||
ClaimsIdentity toKen = new ClaimsIdentity();
|
||||
foreach (Claim item in claims)
|
||||
{
|
||||
@@ -150,6 +153,165 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
/// <summary>
|
||||
/// 条码打印
|
||||
/// </summary>
|
||||
/// <param name="barCodes">条码</param>
|
||||
/// <returns></returns>
|
||||
protected Task BarCodePrint(List<string> barCodes)
|
||||
{
|
||||
var tcs = new TaskCompletionSource();
|
||||
// open port.
|
||||
try
|
||||
{
|
||||
int nLen, ret, sw;
|
||||
byte[] pbuf = new byte[128];
|
||||
string strmsg;
|
||||
|
||||
IntPtr ver;
|
||||
System.Text.Encoding encAscII = System.Text.Encoding.ASCII;
|
||||
System.Text.Encoding encUnicode = System.Text.Encoding.Unicode;
|
||||
|
||||
// dll version.
|
||||
ver = PPLBUtility.B_Get_DLL_Version(0);
|
||||
// search port.
|
||||
nLen = PPLBUtility.B_GetUSBBufferLen() + 1;
|
||||
strmsg = "DLL ";
|
||||
strmsg += Marshal.PtrToStringAnsi(ver);
|
||||
strmsg += "\r\n";
|
||||
if (nLen > 1)
|
||||
{
|
||||
byte[] buf1, buf2;
|
||||
int len1 = 128, len2 = 128;
|
||||
buf1 = new byte[len1];
|
||||
buf2 = new byte[len2];
|
||||
PPLBUtility.B_EnumUSB(pbuf);
|
||||
PPLBUtility.B_GetUSBDeviceInfo(1, buf1, out len1, buf2, out len2);
|
||||
sw = 1;
|
||||
if (1 == sw)
|
||||
{
|
||||
ret = PPLBUtility.B_CreatePrn(12, encAscII.GetString(buf2, 0, len2));// open usb.
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = PPLBUtility.B_CreateUSBPort(1);// must call B_GetUSBBufferLen() function fisrt.
|
||||
}
|
||||
if (0 != ret)
|
||||
{
|
||||
strmsg += "Open USB fail!";
|
||||
}
|
||||
else
|
||||
{
|
||||
strmsg += "Open USB:\r\nDevice name: ";
|
||||
strmsg += encAscII.GetString(buf1, 0, len1);
|
||||
strmsg += "\r\nDevice path: ";
|
||||
strmsg += encAscII.GetString(buf2, 0, len2);
|
||||
//sw = 2;
|
||||
if (2 == sw)
|
||||
{
|
||||
//Immediate Error Report.
|
||||
PPLBUtility.B_WriteData(1, encAscII.GetBytes("^ee\r\n"), 5);//^ee
|
||||
ret = PPLBUtility.B_ReadData(pbuf, 4, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(PPLBUtility.szSavePath);
|
||||
ret = PPLBUtility.B_CreatePrn(0, PPLBUtility.szSaveFile);// open file.
|
||||
strmsg += "Open ";
|
||||
strmsg += PPLBUtility.szSaveFile;
|
||||
if (0 != ret)
|
||||
{
|
||||
strmsg += " file fail!";
|
||||
}
|
||||
else
|
||||
{
|
||||
strmsg += " file succeed!";
|
||||
}
|
||||
}
|
||||
if (0 != ret)
|
||||
return null;
|
||||
|
||||
// sample setting.
|
||||
PPLBUtility.B_Set_Originpoint(0, 0);
|
||||
PPLBUtility.B_Select_Option(2);
|
||||
PPLBUtility.B_Set_Darkness(8);
|
||||
PPLBUtility.B_Del_Pcx("*");// delete all picture.
|
||||
PPLBUtility.B_Set_LabelForSmartPrint(254 * 3, 30);//label information: length= 3 * 25.4 mm, gap= 3 mm.
|
||||
|
||||
|
||||
foreach (var code in barCodes)
|
||||
{
|
||||
//print text, true type text.
|
||||
PPLBUtility.B_Prn_Text(200, 50, 0, 2, 2, 2, 'N', code);
|
||||
//barcode.
|
||||
PPLBUtility.B_Prn_Barcode(160, 100, 0, "E80", 8, 500, 70, 'N', code);//have a counter
|
||||
// output.
|
||||
PPLBUtility.B_Print_Out(1);// copy 2.
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tcs.SetException(ex);
|
||||
JNPF.Logging.Log.Error("条码打印时出现错误", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// close port.
|
||||
//PPLBUtility.B_ClosePrn();
|
||||
}
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
#region 斑马打印
|
||||
/// <summary>
|
||||
/// 打印
|
||||
/// </summary>
|
||||
/// <param name="zplStr"></param>
|
||||
/// <returns></returns>
|
||||
//[NonAction]
|
||||
//protected async Task Print(string zplStr)
|
||||
//{
|
||||
// var zpl_string = @$"^XA
|
||||
// ^XA^LH0,0^LL100^PW580
|
||||
// ^FX 文本
|
||||
// ^FO 80,100^BCN,100,10^FDQA,Hello world^FS
|
||||
// ^FO 150,200^A0N 80,50^FD Hello world^FS
|
||||
// ^XZ";
|
||||
// List<DiscoveredPrinter> printerList = await GetUSBPrinters();
|
||||
// if (printerList?.Count > 0)
|
||||
// {
|
||||
// // in this case, we arbitrarily are printing to the first found printer
|
||||
// DiscoveredPrinter discoveredPrinter = printerList[0];
|
||||
// Connection connection = discoveredPrinter.GetConnection();
|
||||
// connection.Open();
|
||||
// connection.Write(Encoding.UTF8.GetBytes(zplStr));
|
||||
// }
|
||||
//}
|
||||
|
||||
//private Task<List<DiscoveredPrinter>> GetUSBPrinters()
|
||||
//{
|
||||
// var tcs = new TaskCompletionSource<List<DiscoveredPrinter>>();
|
||||
// List<DiscoveredPrinter> printerList = new();
|
||||
// try
|
||||
// {
|
||||
// foreach (DiscoveredUsbPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters())
|
||||
// {
|
||||
// printerList.Add(usbPrinter);
|
||||
// Console.WriteLine(usbPrinter);
|
||||
// }
|
||||
// }
|
||||
// catch (ConnectionException e)
|
||||
// {
|
||||
// JNPF.Logging.Log.Error("获取本地打印机时出错", e);
|
||||
// tcs.SetException(e);
|
||||
// }
|
||||
// Console.WriteLine("Done discovering local printers.");
|
||||
// tcs.SetResult(printerList);
|
||||
// return tcs.Task;
|
||||
//}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Api响应结果
|
||||
|
||||
Reference in New Issue
Block a user