|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Data;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using NLog;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace DS.Module.PrintModule
|
|
|
|
|
{
|
|
|
|
|
public class PrintService: IPrintService
|
|
|
|
|
{
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
|
private readonly IUser user;
|
|
|
|
|
private readonly string ip;
|
|
|
|
|
private readonly int port;
|
|
|
|
|
private readonly string accessKey;
|
|
|
|
|
private readonly string accessSecret;
|
|
|
|
|
private readonly string moduleUrl;
|
|
|
|
|
private readonly string templateUrl;
|
|
|
|
|
private readonly string jsonPrintInfoUrl;
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 构造函数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
|
public PrintService(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
|
|
|
|
|
|
ip = AppSetting.app(new string[] { "PrintService", "IP" }).ObjToString();
|
|
|
|
|
port = AppSetting.app(new string[] { "PrintService", "Port" }).ToInt();
|
|
|
|
|
accessKey = AppSetting.app(new string[] { "PrintService", "AccessKey" }).ObjToString();
|
|
|
|
|
accessSecret = AppSetting.app(new string[] { "PrintService", "AccessSecret" }).ObjToString();
|
|
|
|
|
moduleUrl = AppSetting.app(new string[] { "PrintService", "GetModuleListUrl" }).ObjToString();
|
|
|
|
|
templateUrl = AppSetting.app(new string[] { "PrintService", "GetTemplateListUrl" }).ObjToString();
|
|
|
|
|
jsonPrintInfoUrl = AppSetting.app(new string[] { "PrintService", "GetJsonPrintInfoUrl" }).ObjToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取打印模块列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult GetOpenPrintModuleList()
|
|
|
|
|
{
|
|
|
|
|
// 只要平台信息参数一致,多个请求只需设置一次参数
|
|
|
|
|
HttpUtillib.SetPlatformInfo(accessKey, accessSecret, ip, port, false);
|
|
|
|
|
DataResult res = new DataResult();
|
|
|
|
|
|
|
|
|
|
// 发起POST请求,超时时间15秒,返回响应字节数组
|
|
|
|
|
string result = HttpUtillib.HttpGet(moduleUrl, 15);
|
|
|
|
|
if (null == result)
|
|
|
|
|
{
|
|
|
|
|
res = DataResult.Failed("请求失败,请联系管理员");
|
|
|
|
|
// 请求失败
|
|
|
|
|
// Console.WriteLine("/artemis/api/resource/v1/cameras/indexCode: POST fail");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res = JsonConvert.DeserializeObject<DataResult>(result);
|
|
|
|
|
// Console.WriteLine(System.Text.Encoding.UTF8.GetString(result));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取打印模板列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">模块id</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult GetOpenPrintTemplateList(string id)
|
|
|
|
|
{
|
|
|
|
|
// 只要平台信息参数一致,多个请求只需设置一次参数
|
|
|
|
|
HttpUtillib.SetPlatformInfo(accessKey, accessSecret, ip, port, false);
|
|
|
|
|
DataResult res = new DataResult();
|
|
|
|
|
|
|
|
|
|
// 发起POST请求,超时时间15秒,返回响应字节数组
|
|
|
|
|
string result = HttpUtillib.HttpGet(templateUrl+"?id=" + id, 15);
|
|
|
|
|
if (null == result)
|
|
|
|
|
{
|
|
|
|
|
res = DataResult.Failed("请求失败,请联系管理员");
|
|
|
|
|
// 请求失败
|
|
|
|
|
// Console.WriteLine("/artemis/api/resource/v1/cameras/indexCode: POST fail");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res = JsonConvert.DeserializeObject<DataResult>(result);
|
|
|
|
|
// Console.WriteLine(System.Text.Encoding.UTF8.GetString(result));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取Json打印信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult GetOpenJsonPrintInfo(OpenJsonPrintReq req)
|
|
|
|
|
{
|
|
|
|
|
// 只要平台信息参数一致,多个请求只需设置一次参数
|
|
|
|
|
HttpUtillib.SetPlatformInfo(accessKey, accessSecret, ip, port, false);
|
|
|
|
|
DataResult res = new DataResult();
|
|
|
|
|
|
|
|
|
|
// 发起POST请求,超时时间15秒,返回响应字节数组
|
|
|
|
|
string result = HttpUtillib.HttpPost(jsonPrintInfoUrl, JsonConvert.SerializeObject(req), 30);
|
|
|
|
|
if (null == result)
|
|
|
|
|
{
|
|
|
|
|
res = DataResult.Failed("请求失败,请联系管理员");
|
|
|
|
|
// 请求失败
|
|
|
|
|
// Console.WriteLine("/artemis/api/resource/v1/cameras/indexCode: POST fail");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res = JsonConvert.DeserializeObject<DataResult>(result);
|
|
|
|
|
// Console.WriteLine(System.Text.Encoding.UTF8.GetString(result));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|