diff --git a/Admin.Core.Api/Admin.Core.Api.xml b/Admin.Core.Api/Admin.Core.Api.xml
index 3ba0122..806a89e 100644
--- a/Admin.Core.Api/Admin.Core.Api.xml
+++ b/Admin.Core.Api/Admin.Core.Api.xml
@@ -325,7 +325,7 @@
-
+
小料同步MES物料信息
@@ -1718,6 +1718,115 @@
DeleteSubscriptionFiles
+
+
+ 总页数
+
+
+
+
+ 页码
+
+
+
+
+ 数据对象
+
+
+
+
+ 总记录数
+
+
+
+
+ 每页记录数
+
+
+
+
+ 尾页编号
+
+
+
+
+ 起始页编号
+
+
+
+
+ 物料名称
+
+
+
+
+ 物料状态(0禁用, 1启用)
+
+
+
+
+ 物料编号
+
+
+
+
+ 物料创建时间
+
+
+
+
+ 状态码
+
+
+
+
+ 消息提示
+
+
+
+
+ 结果对象
+
+
+
+
+ Token(后续请求需要携带这个Token)
+
+
+
+
+ Token失效时间
+
+
+
+
+ 发起POST异步请求
+
+ 请求地址
+ POST提交的内容
+ POST内容的媒体类型,如:application/xml、application/json
+ HTTP响应上的content-type内容头的值,如:application/xml、application/json、application/text、application/x-www-form-urlencoded等
+ 请求头信息
+ 请求超时时间,单位秒
+ 返回string
+
+
+
+ 发起GET异步请求
+
+ 返回类型
+ 请求地址
+ 请求头信息
+ 请求超时时间,单位秒
+ 返回string
+
+
+
+ 获取请求的主机名
+
+
+
+
Program
diff --git a/Admin.Core.Api/Controllers/Business/MaterialController.cs b/Admin.Core.Api/Controllers/Business/MaterialController.cs
index b936c58..eb5401c 100644
--- a/Admin.Core.Api/Controllers/Business/MaterialController.cs
+++ b/Admin.Core.Api/Controllers/Business/MaterialController.cs
@@ -45,7 +45,6 @@ namespace Admin.Core.Api
_xl_materialService = xl_materialServices;
_binServices = binServices;
_xlPlanServices = xlPlanServices;
- _xlPlanServices = xlPlanServices;
}
#endregion
@@ -247,11 +246,11 @@ namespace Admin.Core.Api
///
///
[HttpGet]
- public async Task> xlDownLoadMateralInfo(string materialCode, string materialName)
+ public async Task> XlDownLoadMateralInfo(string materialCode, string materialName, int isEnable, DateTime createDateTime)
{
try
{
- var result = await _xl_materialService.xlInsertMaterial(materialCode, materialName);
+ var result = await _xl_materialService.xlInsertMaterial(materialCode, materialName, isEnable, createDateTime);
if (result)
{
return Success(result);
diff --git a/Admin.Core.Api/PLTBusiness/Entity/MaterialData.cs b/Admin.Core.Api/PLTBusiness/Entity/MaterialData.cs
new file mode 100644
index 0000000..17cd9e6
--- /dev/null
+++ b/Admin.Core.Api/PLTBusiness/Entity/MaterialData.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using SqlSugar;
+
+
+namespace Admin.Core.Api.PLTBusiness.Entity
+{
+ public class MaterialData
+ {
+ ///
+ /// 总页数
+ ///
+ public int pageCount { get; set; }
+ ///
+ /// 页码
+ ///
+ public int pageIndex { get; set; }
+ ///
+ /// 数据对象
+ ///
+ public List recordList { get; set; }
+ ///
+ /// 总记录数
+ ///
+ public int recordCount { get; set; }
+ ///
+ /// 每页记录数
+ ///
+ public int pageSize { get; set; }
+ ///
+ /// 尾页编号
+ ///
+ public int endPageIndex { get; set; }
+ ///
+ /// 起始页编号
+ ///
+ public int beginPageIndex { get; set; }
+ }
+
+ public class MaterialRecordListItem
+ {
+ ///
+ /// 物料名称
+ ///
+ public string name { get; set; }
+ ///
+ /// 物料状态(0禁用, 1启用)
+ ///
+ public int status { get; set; }
+ ///
+ /// 物料编号
+ ///
+ public string code { get; set; }
+ ///
+ /// 物料创建时间
+ ///
+ public string createTime { get; set; }
+
+ }
+
+}
\ No newline at end of file
diff --git a/Admin.Core.Api/PLTBusiness/Entity/ResponseRoot.cs b/Admin.Core.Api/PLTBusiness/Entity/ResponseRoot.cs
new file mode 100644
index 0000000..deb0d60
--- /dev/null
+++ b/Admin.Core.Api/PLTBusiness/Entity/ResponseRoot.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Linq;
+using System.Text;
+using SqlSugar;
+
+
+namespace Admin.Core.Api.PLTBusiness.Entity
+{
+ public class ResponseRoot
+ {
+ ///
+ /// 状态码
+ ///
+ public int code { get; set; }
+ ///
+ /// 消息提示
+ ///
+ public string message { get; set; }
+ ///
+ /// 结果对象
+ ///
+ public T Data { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Admin.Core.Api/PLTBusiness/Entity/TokenData.cs b/Admin.Core.Api/PLTBusiness/Entity/TokenData.cs
new file mode 100644
index 0000000..f9be6eb
--- /dev/null
+++ b/Admin.Core.Api/PLTBusiness/Entity/TokenData.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Linq;
+using System.Text;
+using SqlSugar;
+
+
+namespace Admin.Core.Api.PLTBusiness.Entity
+{
+ public class TokenData
+ {
+ ///
+ /// Token(后续请求需要携带这个Token)
+ ///
+ public string token { get; set; }
+ ///
+ /// Token失效时间
+ ///
+ public int expiration { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Admin.Core.Api/PLTBusiness/HttpService.cs b/Admin.Core.Api/PLTBusiness/HttpService.cs
new file mode 100644
index 0000000..271f77e
--- /dev/null
+++ b/Admin.Core.Api/PLTBusiness/HttpService.cs
@@ -0,0 +1,252 @@
+using Admin.Core.Api.PLTBusiness.Entity;
+using Admin.Core.IService;
+using Admin.Core.Service;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using RabbitMQ.Client;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using System.Security.Policy;
+using System.Text;
+using System.Text.Json;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Admin.Core.Api.PLTBusiness
+{
+
+ public class HttpService : BackgroundService
+ {
+ private readonly IServiceScopeFactory _scopeFactory;
+
+ private string _token;
+
+ private int _tokenExpirationTime;
+
+ private Dictionary _tokenDictionary = new Dictionary()
+ {
+ {"authCode", "QT_XXX"},
+ {"appid", "q7cloud_XXX"},
+ {"secret", "f434eab8b9652524dc719e33f4ff255a45570XXX"}
+ };
+
+ private string _host;
+
+ private readonly IHttpClientFactory _httpClientFactory;
+
+ public HttpService(IHttpClientFactory httpClientFactory, IServiceScopeFactory scopeFactory)
+ {
+ _httpClientFactory = httpClientFactory;
+ _scopeFactory = scopeFactory;
+ }
+
+ protected async override Task ExecuteAsync(CancellationToken stoppingToken)
+ {
+ using var scope = _scopeFactory.CreateScope();
+ var services = scope.ServiceProvider;
+ var xlBusiness = services.GetService();
+
+ while (!stoppingToken.IsCancellationRequested)
+ {
+
+ //执行任务
+ Console.WriteLine($"{DateTime.Now}");
+
+ await xlBusiness.InsertNewMaterialData(null);
+
+ await Task.Delay(1000*10);
+
+ }
+ }
+
+ private async void GetToken()
+ {
+ try
+ {
+ string body = JsonSerializer.Serialize(_tokenDictionary);
+ string tokenJson = await PostAsync(_host + "/qtn/api/auth/token", body, "application/json", "application/json", null, 10);
+ ResponseRoot responseRoot = JsonSerializer.Deserialize>(tokenJson);
+ if (responseRoot == null)
+ {
+ Console.WriteLine("Token获取失败!");
+ return;
+ }
+ if(responseRoot.code != 200)
+ {
+ Console.WriteLine("ERROR 状态码:" + responseRoot.code);
+ return;
+ }
+ _token = responseRoot.Data.token;
+ _tokenExpirationTime = responseRoot.Data.expiration;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("ERROR: " + ex.ToString());
+ }
+ }
+ ///
+ /// 发起POST异步请求
+ ///
+ /// 请求地址
+ /// POST提交的内容
+ /// POST内容的媒体类型,如:application/xml、application/json
+ /// HTTP响应上的content-type内容头的值,如:application/xml、application/json、application/text、application/x-www-form-urlencoded等
+ /// 请求头信息
+ /// 请求超时时间,单位秒
+ /// 返回string
+ private async Task PostAsync(string url, string body,
+ string bodyMediaType = null,
+ string responseContentType = null,
+ Dictionary headers = null,
+ int timeOut = 30)
+ {
+ try
+ {
+ var hostName = GetHostName(url);
+ using (HttpClient client = _httpClientFactory.CreateClient(hostName))
+ {
+ client.Timeout = TimeSpan.FromSeconds(timeOut);
+ if (headers?.Count > 0)
+ {
+ foreach (string key in headers.Keys)
+ {
+ client.DefaultRequestHeaders.Add(key, headers[key]);
+ }
+ }
+ StringContent content = new StringContent(body, System.Text.Encoding.UTF8, mediaType: bodyMediaType);
+ if (!string.IsNullOrWhiteSpace(responseContentType))
+ {
+ content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(responseContentType);
+ }
+ using (HttpResponseMessage response = await client.PostAsync(url, content))
+ {
+ if (response.IsSuccessStatusCode)
+ {
+ string responseString = await response.Content.ReadAsStringAsync();
+ return responseString;
+ }
+ else
+ {
+ return string.Empty;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"ERROR: {ex.ToString()} Time: {DateTime.Now}");
+ return string.Empty;
+ }
+
+ }
+
+
+ ///
+ /// 发起GET异步请求
+ ///
+ /// 返回类型
+ /// 请求地址
+ /// 请求头信息
+ /// 请求超时时间,单位秒
+ /// 返回string
+ private async Task GetAsync(string url, Dictionary headers = null, int timeOut = 30)
+ {
+ try
+ {
+ var hostName = GetHostName(url);
+ using (HttpClient client = _httpClientFactory.CreateClient(hostName))
+ {
+ client.Timeout = TimeSpan.FromSeconds(timeOut);
+ if (headers?.Count > 0)
+ {
+ foreach (string key in headers.Keys)
+ {
+ client.DefaultRequestHeaders.Add(key, headers[key]);
+ }
+ }
+ using (HttpResponseMessage response = await client.GetAsync(url))
+ {
+ if (response.IsSuccessStatusCode)
+ {
+ string responseString = await response.Content.ReadAsStringAsync();
+ return responseString;
+ }
+ else
+ {
+ return string.Empty;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"ERROR: {ex.ToString()} Time: {DateTime.Now}");
+ return string.Empty;
+ }
+ }
+
+
+
+ private async Task Post(string url, Dictionary headers = null)
+ {
+ var hostName = GetHostName(url);
+ // 创建 HttpClient 实例
+ var client = _httpClientFactory.CreateClient(hostName);
+
+ // 定义要发送的对象
+ //var data = new
+ //{
+ // Name = "John Doe",
+ // Age = 30,
+ // Email = "john.doe@example.com"
+ //};
+
+ // 序列化对象为 JSON
+ var json = JsonSerializer.Serialize(headers);
+
+ // 创建 HttpContent,设置内容为 JSON 格式
+ var content = new StringContent(json, Encoding.UTF8, "application/json");
+
+ // 发送 POST 请求
+ var response = await client.PostAsync(url, content);
+
+ // 检查响应状态码
+ if (response.IsSuccessStatusCode)
+ {
+ // 读取响应内容
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine($"Response: {responseBody}");
+ }
+ else
+ {
+ Console.WriteLine($"Error: {response.StatusCode}");
+ }
+ }
+
+
+ #region 私有函数
+
+ ///
+ /// 获取请求的主机名
+ ///
+ ///
+ ///
+ private static string GetHostName(string url)
+ {
+ if (!string.IsNullOrWhiteSpace(url))
+ {
+ return url.Replace("https://", "").Replace("http://", "").Split('/')[0];
+ }
+ else
+ {
+ return "AnyHost";
+ }
+ }
+
+ #endregion
+
+
+ }
+}
diff --git a/Admin.Core.Api/PLTBusiness/XlBusiness.cs b/Admin.Core.Api/PLTBusiness/XlBusiness.cs
new file mode 100644
index 0000000..95ec0f8
--- /dev/null
+++ b/Admin.Core.Api/PLTBusiness/XlBusiness.cs
@@ -0,0 +1,51 @@
+using Admin.Core.Api.PLTBusiness.Entity;
+using Admin.Core.IService;
+using Admin.Core.Model;
+using Admin.Core.Service;
+using Microsoft.Extensions.Hosting;
+using RabbitMQ.Client;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using System.Security.Policy;
+using System.Text;
+using System.Text.Json;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Admin.Core.Api.PLTBusiness
+{
+
+ public class XlBusiness
+ {
+ private readonly Ixl_materialServices _xl_materialService;
+
+ public XlBusiness(Ixl_materialServices xl_materialService)
+ {
+ _xl_materialService = xl_materialService;
+ }
+
+ public async Task InsertNewMaterialData(List list)
+ {
+ List mlist = new List();
+ mlist = await _xl_materialService.xlMaterialList();
+ bool state = await _xl_materialService.xlUpdateMaterial("4cbdaa3913a54092bff72e09f13e633f"
+ , "123412421567"
+ , "更新213214测试测试"
+ , 1
+ , DateTime.Now);
+ //foreach (var mesItem in list)
+ //{
+ // foreach(var mItem in mlist)
+ // {
+
+ // }
+ //}
+
+ return true;
+ }
+
+
+ }
+}
diff --git a/Admin.Core.Api/Program.cs b/Admin.Core.Api/Program.cs
index 18820c6..e806108 100644
--- a/Admin.Core.Api/Program.cs
+++ b/Admin.Core.Api/Program.cs
@@ -28,6 +28,8 @@ namespace Admin.Core.Api
// web Ӧóֹ߳, ֱرա
// 쳣鿴 Log ļµ쳣־
.Run();
+
+
}
///
@@ -58,5 +60,6 @@ namespace Admin.Core.Api
// Ĭlog4net.confg
builder.AddLog4Net(Path.Combine(Directory.GetCurrentDirectory(), "Log4net.config"));
});
+
}
}
diff --git a/Admin.Core.Api/Startup.cs b/Admin.Core.Api/Startup.cs
index 04e8b69..5bd9af4 100644
--- a/Admin.Core.Api/Startup.cs
+++ b/Admin.Core.Api/Startup.cs
@@ -1,3 +1,4 @@
+using Admin.Core.Api.PLTBusiness;
using Admin.Core.Common;
using Admin.Core.Extensions;
using Admin.Core.IService.ISys;
@@ -23,6 +24,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
+using TouchSocket.Http;
namespace Admin.Core.Api
{
@@ -103,11 +105,16 @@ namespace Admin.Core.Api
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
-
+ //עhttp
+ services.AddHttpClient();
//
services.AddJobSetup();
//PLC
services.AddPlcSetup();
+ //ӷ
+ services.AddHostedService();
+ services.AddScoped();
+
//Redis
//services.AddRedisCacheSetup();
//Redis
diff --git a/Admin.Core.IService/IService_New/Ixl_materialServices.cs b/Admin.Core.IService/IService_New/Ixl_materialServices.cs
index 9c70dfc..dae081c 100644
--- a/Admin.Core.IService/IService_New/Ixl_materialServices.cs
+++ b/Admin.Core.IService/IService_New/Ixl_materialServices.cs
@@ -3,6 +3,7 @@ using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.ViewModels;
using System;
+using System.Collections.Generic;
using System.Threading.Tasks;
namespace Admin.Core.IService
@@ -31,6 +32,19 @@ namespace Admin.Core.IService
Task> MaterialVerification(string barCode);
- Task xlInsertMaterial(string materialCode, string materialName);
+ Task xlInsertMaterial(
+ string materialCode,
+ string materialName,
+ int isEnable,
+ DateTime createDatetime);
+
+ Task xlUpdateMaterial(
+ string id,
+ string materialCode,
+ string materialName,
+ int isEnable,
+ DateTime createDatetime);
+
+ Task> xlMaterialList();
}
}
\ No newline at end of file
diff --git a/Admin.Core.Service/Service_New/xl_materialServices.cs b/Admin.Core.Service/Service_New/xl_materialServices.cs
index 86f4626..40b3bbc 100644
--- a/Admin.Core.Service/Service_New/xl_materialServices.cs
+++ b/Admin.Core.Service/Service_New/xl_materialServices.cs
@@ -633,6 +633,7 @@ namespace Admin.Core.Service
#endregion
#region 料框防错验证——只验证单料
+
public async Task> MaterialVerification(string barCode)
{
MessageModel messageModel = new MessageModel();
@@ -684,15 +685,20 @@ namespace Admin.Core.Service
}
#endregion
+
///
- /// 小料上位机同步插入物料信息
+ /// 小料上位机插入物料信息
///
///
///
///
///
///
- public async Task xlInsertMaterial(string materialCode, string materialName)
+ public async Task xlInsertMaterial(
+ string materialCode,
+ string materialName,
+ int isEnable,
+ DateTime createDatetime)
{
try
{
@@ -701,13 +707,13 @@ namespace Admin.Core.Service
ID = Guid.NewGuid().ToString("N"),
Material_code = materialCode,
Material_name = materialName,
- CreateDateTime = DateTime.Now,
+ CreateDateTime = createDatetime,
Remark = null,
Batch_number = null,
Barcode1 = null,
Barcode2 = null,
Barcode3 = null,
- IsEnable = "是"
+ IsEnable = isEnable == 1 ? "是" : "否"
};
var result = await _xl_materialRepository.Add(xl_m);
@@ -726,6 +732,67 @@ namespace Admin.Core.Service
}
}
+ ///
+ /// 小料上位机更新物料信息
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task xlUpdateMaterial(
+ string id,
+ string materialCode,
+ string materialName,
+ int isEnable,
+ DateTime createDatetime)
+ {
+ try
+ {
+ xl_material xl_m = new xl_material()
+ {
+ ID = id,
+ Material_code = materialCode,
+ Material_name = materialName,
+ CreateDateTime = createDatetime,
+ Remark = null,
+ Batch_number = null,
+ Barcode1 = null,
+ Barcode2 = null,
+ Barcode3 = null,
+ IsEnable = isEnable == 1 ? "是" : "否"
+ };
+
+ bool result = await _xl_materialRepository.UpdateAsync(xl_m, $"ID = '{id}'");
+ return result;
+ }
+ catch (Exception e)
+ {
+ return false;
+ }
+
+ }
+
+ ///
+ /// 获取小料上位机物料信息
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task> xlMaterialList()
+ {
+ try
+ {
+ return await _xl_materialRepository.QueryAsync();
+ }
+ catch (Exception ex)
+ {
+ return null;
+ }
+ }
+
}
}
\ No newline at end of file