diff --git a/Admin.Core.Api/Admin.Core.Api.xml b/Admin.Core.Api/Admin.Core.Api.xml index 6c8e5d8..a52ca7a 100644 --- a/Admin.Core.Api/Admin.Core.Api.xml +++ b/Admin.Core.Api/Admin.Core.Api.xml @@ -330,7 +330,7 @@ - + 小料同步MES物料信息 @@ -395,12 +395,24 @@ 投料仓服务 - + + + 料筒服务类 + + + + + 称重服务类 + + + 构造方法 + + @@ -454,6 +466,13 @@ + + + 根据罐号查询称量列表 + + + + Controller代码生成 @@ -1730,6 +1749,216 @@ DeleteSubscriptionFiles + + + 总页数 + + + + + 页码 + + + + + 数据对象 + + + + + 总记录数 + + + + + 每页记录数 + + + + + 尾页编号 + + + + + 起始页编号 + + + + + 物料id + + + + + 物料名称 + + + + + 物料状态(0禁用, 1启用) + + + + + 物料编号 + + + + + 物料创建时间 + + + + + 总页数 + + + + + 页码 + + + + + 数据对象 + + + + + 总记录数 + + + + + 每页记录数 + + + + + 尾页编号 + + + + + 起始页编号 + + + + + 物料id + + + + + 物料名称 + + + + + 物料状态(0禁用, 1启用) + + + + + 物料编号 + + + + + 物料创建时间 + + + + + 状态码 + + + + + 消息提示 + + + + + 结果对象 + + + + + Token(后续请求需要携带这个Token) + + + + + Token失效时间 + + + + + 循环执行的服务 + + + + + + + 分页拉取所有Mes物料信息 + + + + + + 分页拉取所有MesBom配方信息 + + + + + + 获取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 + + + + 获取请求的主机名 + + + + + + + 向物料数据库中动态同步mes数据,没有就插入,不同就修改 + + + + Program diff --git a/Admin.Core.Api/Controllers/Business/MaterialController.cs b/Admin.Core.Api/Controllers/Business/MaterialController.cs index b9450f5..d35d294 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 @@ -265,21 +264,24 @@ 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(Guid.NewGuid().ToString("N"), materialCode, materialName, isEnable, createDateTime); if (result) { - return Success(result); + return Success(result, "成功"); + } + else + { + return Failed("执行失败!"); } } catch (Exception ex) { - + return Failed("执行失败!"); } - return Failed("执行失败!"); } } } \ No newline at end of file diff --git a/Admin.Core.Api/Controllers/Business/WarehouseController.cs b/Admin.Core.Api/Controllers/Business/WarehouseController.cs index 81e26d0..bae9a04 100644 --- a/Admin.Core.Api/Controllers/Business/WarehouseController.cs +++ b/Admin.Core.Api/Controllers/Business/WarehouseController.cs @@ -15,7 +15,12 @@ using Admin.Core.Model.ViewModels; using Microsoft.AspNetCore.Mvc.ViewEngines; using System.Collections; using NPOI.SS.Formula.Functions; +<<<<<<< HEAD using TouchSocket.Core; +======= +using System.Numerics; +using Admin.Core.IService.IService_New; +>>>>>>> dep_wangsr namespace Admin.Core.Api.Controllers.Business { @@ -39,16 +44,30 @@ namespace Admin.Core.Api.Controllers.Business /// private readonly IHw_WarehouseServices _hw_WarehouseService; + /// + /// 料筒服务类 + /// + private readonly IHw_BarrelServices _hw_BarrelService; + + /// + /// 称重服务类 + /// + private readonly ILR_weighServices _lr_weighService; + #region 构造方法 /// /// 构造方法 /// /// /// - public WarehouseController(IHw_WarehouseServices hw_WarehouseServices, ISysUserService sysUserService) : base(sysUserService) + /// + /// + public WarehouseController(IHw_WarehouseServices hw_WarehouseServices, ISysUserService sysUserService, IHw_BarrelServices hwBarrelService, ILR_weighServices lrweighService) : base(sysUserService) { _sysUserService = sysUserService; _hw_WarehouseService = hw_WarehouseServices; + _hw_BarrelService = hwBarrelService; + _lr_weighService = lrweighService; } #endregion @@ -62,13 +81,13 @@ namespace Admin.Core.Api.Controllers.Business /// 料桶Id /// [HttpGet] - public async Task> GetByBarrelInfo(string kettleBarCode, string planId,string code) + public async Task> GetByBarrelInfo(string kettleBarCode, string planId, string code) { if (!code.IsNotEmptyOrNull()) { return Failed("传入参数为空!"); } - var query = await _hw_WarehouseService.GetXlInfo(kettleBarCode.Trim(),planId.Trim(),code.Trim()); + var query = await _hw_WarehouseService.GetXlInfo(kettleBarCode.Trim(), planId.Trim(), code.Trim()); if (query == null) { return Failed("查询失败!"); @@ -85,7 +104,7 @@ namespace Admin.Core.Api.Controllers.Business /// 计划Id /// [HttpGet] - public async Task> GetByCode(string code,string planId) + public async Task> GetByCode(string code, string planId) { if (!code.IsNotEmptyOrNull()) @@ -97,11 +116,11 @@ namespace Admin.Core.Api.Controllers.Business return Failed("传入计划ID参数为空!"); } var query = await _hw_WarehouseService.QueryByCode(code.Trim(), planId); - - if (query==null) + + if (query == null) { return Failed("查询失败!"); - } + } return Success(query); } #endregion @@ -122,7 +141,7 @@ namespace Admin.Core.Api.Controllers.Business var result = await _hw_WarehouseService.UpdatePlcState(view); if (result) { - return Success(result); + return Success(result); } return Failed("执行失败!"); } @@ -193,13 +212,13 @@ namespace Admin.Core.Api.Controllers.Business /// /// [HttpGet] - public async Task> ExecPlcState(string code,int state) + public async Task> ExecPlcState(string code, int state) { if (!code.IsNotEmptyOrNull() || !state.IsNotEmptyOrNull()) { return Failed("传入参数为空!"); } - var result = await _hw_WarehouseService.UpdatePlcState(code,state); + var result = await _hw_WarehouseService.UpdatePlcState(code, state); if (result) { return Success(result); @@ -222,7 +241,7 @@ namespace Admin.Core.Api.Controllers.Business var result = await _hw_WarehouseService.GetPlanWeightInfo(); if (result != null) { - return Success(result,"成功"); + return Success(result, "成功"); } return Failed>("执行失败!"); } @@ -248,7 +267,34 @@ namespace Admin.Core.Api.Controllers.Business messageModel.success = true; messageModel.data = list; return Success(list); - } + } #endregion + + /// + /// 根据罐号查询称量列表 + /// + /// + /// + [HttpGet] + public async Task>> GetWeightInfoByBarrelID(string barrelBarcode) + { + if (!barrelBarcode.IsNotEmptyOrNull()) + { + return Failed>("传入参数为空!"); + } + MessageModel> messageModel = new MessageModel>(); + string planID = _hw_BarrelService.GetPlanIdByBarrelID(barrelBarcode.Trim()); + if (string.IsNullOrEmpty(planID)) + { + return Failed>("查询不到罐号对应的计划ID!"); + } + List list = _lr_weighService.GetRecentWeightList(planID); + if (list != null) + { + return Success(list); + } + return Failed>("执行失败!"); + + } } } \ No newline at end of file diff --git a/Admin.Core.Api/Log4net.config b/Admin.Core.Api/Log4net.config index d7e7064..627f877 100644 --- a/Admin.Core.Api/Log4net.config +++ b/Admin.Core.Api/Log4net.config @@ -6,7 +6,7 @@ - + @@ -26,8 +26,6 @@ - - @@ -52,6 +50,15 @@ + + + + + + + + + @@ -61,5 +68,6 @@ + \ No newline at end of file diff --git a/Admin.Core.Api/PLTBusiness/Entity/BomData.cs b/Admin.Core.Api/PLTBusiness/Entity/BomData.cs new file mode 100644 index 0000000..3a9e5b0 --- /dev/null +++ b/Admin.Core.Api/PLTBusiness/Entity/BomData.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using SqlSugar; + + +namespace Admin.Core.Api.PLTBusiness.Entity +{ + public class BomData + { + /// + /// 总页数 + /// + 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 BomRecordListItem + { + /// + /// 物料id + /// + public int id { get; set; } + /// + /// 物料名称 + /// + 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/LRWeighData.cs b/Admin.Core.Api/PLTBusiness/Entity/LRWeighData.cs new file mode 100644 index 0000000..d0a3f18 --- /dev/null +++ b/Admin.Core.Api/PLTBusiness/Entity/LRWeighData.cs @@ -0,0 +1,24 @@ +using System; + +namespace Admin.Core.Api.PLTBusiness.Entity +{ + public class LRWeighData + { + public string BinSerial { get; set; } + + + public string SetWeight { get; set; } + + + public string RealWeight { get; set; } + + + public string MainID { get; set; } + + + public DateTime EndTime { get; set; } + + + + } +} diff --git a/Admin.Core.Api/PLTBusiness/Entity/MaterialData.cs b/Admin.Core.Api/PLTBusiness/Entity/MaterialData.cs new file mode 100644 index 0000000..05ffac0 --- /dev/null +++ b/Admin.Core.Api/PLTBusiness/Entity/MaterialData.cs @@ -0,0 +1,67 @@ +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 + { + /// + /// 物料id + /// + public int id { get; set; } + /// + /// 物料名称 + /// + 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..50df55a --- /dev/null +++ b/Admin.Core.Api/PLTBusiness/HttpService.cs @@ -0,0 +1,458 @@ +using Admin.Core.Api.PLTBusiness.Entity; +using Admin.Core.Common; +using Admin.Core.IService; +using Admin.Core.PlcServer; +using Admin.Core.Service; +using log4net; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using NPOI.HSSF.Record; +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 log4net.ILog log = LogManager.GetLogger(typeof(HttpService)); + + private readonly IServiceScopeFactory _scopeFactory; + + private readonly IHttpClientFactory _httpClientFactory; + + private readonly Ixl_recipeServices _xlrecipeServices; + + private readonly string _host = "http://192.168.111.141:8090"; + + private string _token; + + private int _tokenExpirationTime = 0; + + public HttpService(IHttpClientFactory httpClientFactory, IServiceScopeFactory scopeFactory, Ixl_recipeServices xlrecipeServices) + { + _httpClientFactory = httpClientFactory; + _scopeFactory = scopeFactory; + _xlrecipeServices = xlrecipeServices; + } + + /// + /// 循环执行的服务 + /// + /// + /// + protected async override Task ExecuteAsync(CancellationToken stoppingToken) + { + int second = 1000 * 10; + using var scope = _scopeFactory.CreateScope(); + var services = scope.ServiceProvider; + var xlBusiness = services.GetService(); + while (!stoppingToken.IsCancellationRequested) + { + + //执行任务 + //log.Info($"{DateTime.Now}"); + + if (_tokenExpirationTime == 0) + { + if (await GetToken()) + { + log.Info("Token Get! Value:" + _token); + } + else + { + log.Error("Token Get Falied"); + } + + } + else if (_tokenExpirationTime <= 86400) + { + RefreshToken(); + } + else + { + _tokenExpirationTime = _tokenExpirationTime - (second / 1000); + } + + try + { + //物料信息同步 + if (_token.IsNotEmptyOrNull()) + { + await xlBusiness.InsertNewMaterialData(await GetMaterialDataPageList()); + //await _xlrecipeServices.xlUpdateOrAdd(); + } + else + { + log.Error("No Token!!!"); + } + } + catch (Exception ex) + { + log.Error("Error: " + ex); + } + + await Task.Delay(second); + } + + } + + #region Mes信息拉取 + + /// + /// 分页拉取所有Mes物料信息 + /// + /// + private async Task> GetMaterialDataPageList() + { + int pageSize = 200; + int pageIndex = 0; + int pageCount = 1; + string orgCode = "Mesnac"; + List allMaterials = new List(); + Dictionary _pageInfo = new Dictionary() + { + {"pageIndex", 200}, + {"pageSize", 0}, + {"orgCode", "Mesnac"}, + }; + try + { + do + { + string body = JsonSerializer.Serialize(_pageInfo); + string materialJson = await PostAsync(_host + "/qtn/api/q7/com/inventory/page", + body, "application/json", "application/json", + new Dictionary { { "token", _token } }, 10); + ResponseRoot responseRoot = JsonSerializer.Deserialize>(materialJson); + if (responseRoot == null) + { + log.Error("物料信息拉取失败!"); + return null; + } + if (responseRoot.code != 200) + { + log.Error("ERROR 状态码:" + responseRoot.code); + return null; + } + pageCount = responseRoot.Data.pageCount; + pageIndex = responseRoot.Data.pageIndex; + allMaterials.AddRange(responseRoot.Data.recordList); + pageIndex = pageIndex + 1; + } + while (pageIndex < pageSize); + } + catch (Exception ex) + { + log.Error("Mes物料信息拉取失败 Error: " + ex); + return null; + } + + return allMaterials; + } + + /// + /// 分页拉取所有MesBom配方信息 + /// + /// + private async Task> GetRecipeDataPageList() + { + int pageSize = 200; + int pageIndex = 0; + int pageCount = 1; + string orgCode = "Mesnac"; + List allBoms = new List(); + Dictionary _pageInfo = new Dictionary() + { + {"pageIndex", 200}, + {"pageSize", 0}, + {"orgCode", "Mesnac"}, + }; + try + { + do + { + string body = JsonSerializer.Serialize(_pageInfo); + string bomJson = await PostAsync(_host + "/qtn/api/q7/com/bom/page", + body, "application/json", "application/json", + new Dictionary { { "token", _token } }, 10); + ResponseRoot responseRoot = JsonSerializer.Deserialize>(bomJson); + if (responseRoot == null) + { + log.Error("Bom信息拉取失败!"); + return null; + } + if (responseRoot.code != 200) + { + log.Error("ERROR 状态码:" + responseRoot.code); + return null; + } + pageCount = responseRoot.Data.pageCount; + pageIndex = responseRoot.Data.pageIndex; + allBoms.AddRange(responseRoot.Data.recordList); + pageIndex = pageIndex + 1; + } + while (pageIndex < pageSize); + } + catch (Exception ex) + { + log.Error("MesBom信息拉取失败 Error: " + ex); + return null; + } + + return allBoms; + } + + #endregion + + #region Token获取 + + /// + /// 获取Token + /// + private async Task GetToken() + { + Dictionary _tokenDictionary = new Dictionary() + { + {"authCode", "QT_XXX"}, + {"appid", "q7cloud_XXX"}, + {"secret", "f434eab8b9652524dc719e33f4ff255a45570XXX"} + }; + + 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) + { + log.Error("Token获取失败!"); + return false; + } + if (responseRoot.code != 200) + { + log.Error("ERROR 状态码:" + responseRoot.code); + return false; + } + _token = responseRoot.Data.token; + _tokenExpirationTime = responseRoot.Data.expiration; + log.Info("Token获取成功:" + _token + "超时时间:" + _tokenExpirationTime); + return true; + } + catch (Exception ex) + { + log.Error("Token获取失败 ERROR: " + ex.ToString()); + return false; + } + } + + /// + /// 刷新Token + /// + private async Task RefreshToken() + { + try + { + string tokenJson = await PostAsync(_host + "/qtn/api/auth/token/refresh", "" + , "application/json", "application/x-www-form-urlencoded" + , new Dictionary() { { "token", _token } }, 10); + ResponseRoot responseRoot = JsonSerializer.Deserialize>(tokenJson); + if (responseRoot == null) + { + log.Error("Token更新失败!"); + return false; + } + if (responseRoot.code != 200) + { + log.Error("ERROR 状态码:" + responseRoot.code); + return false; + } + _token = responseRoot.Data.token; + _tokenExpirationTime = responseRoot.Data.expiration; + log.Info("Token更新成功:" + _token + "超时时间:" + _tokenExpirationTime); + return true; + } + catch (Exception ex) + { + log.Error("Token更新失败 ERROR: " + ex.ToString()); + return false; + } + } + + #endregion + + #region HTTP操作 + + /// + /// 发起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) + { + log.Error($"Post请求失败 URL:{url} ERROR: {ex.ToString()} Time: {DateTime.Now}"); + throw; + } + + } + + + /// + /// 发起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) + { + log.Error($"Get请求失败 URL:{url} ERROR: {ex.ToString()} Time: {DateTime.Now}"); + throw; + } + } + + + + 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(); + log.Info($"Response: {responseBody}"); + } + else + { + log.Error($"Error: {response.StatusCode}"); + } + } + + #endregion + + #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..67ef605 --- /dev/null +++ b/Admin.Core.Api/PLTBusiness/XlBusiness.cs @@ -0,0 +1,76 @@ +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; + } + + /// + /// 向物料数据库中动态同步mes数据,没有就插入,不同就修改 + /// + /// + /// + public async Task InsertNewMaterialData(List list) + { + try + { + foreach (var mesMaterial in list) + { + // Step 3: 在B表中查询是否存在相同ID的记录 + var material = await _xl_materialService.SelectXlMaterialById(mesMaterial.id.ToString()); + + if (material == null) + { + // Step 4: 如果B表中不存在该物料,插入新物料 + await _xl_materialService.xlInsertMaterial( + mesMaterial.id.ToString(), + mesMaterial.code, mesMaterial.name, mesMaterial.status, + Convert.ToDateTime(mesMaterial.createTime)); + } + else + { + // Step 5: 如果B表中存在该物料且有更新,更新物料信息 + if (material.Material_code != mesMaterial.code || + material.Material_name != mesMaterial.name || + material.IsEnable != (mesMaterial.status == 1 ? "是" : "否") || + material.CreateDateTime != Convert.ToDateTime(mesMaterial.createTime)) + { + await _xl_materialService.xlUpdateMaterial( + mesMaterial.id.ToString(), + mesMaterial.code, mesMaterial.name, mesMaterial.status, + Convert.ToDateTime(mesMaterial.createTime)); + } + } + } + return true; + } + catch (Exception ex) + { + throw; + } + } + + + } +} diff --git a/Admin.Core.Api/Program.cs b/Admin.Core.Api/Program.cs index ff3e6a6..2a03d20 100644 --- a/Admin.Core.Api/Program.cs +++ b/Admin.Core.Api/Program.cs @@ -28,6 +28,8 @@ namespace Admin.Core.Api // web Ӧóֹ߳, ֱرա // 쳣鿴 Log ļµ쳣־ .Run(); + + } /// @@ -59,5 +61,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..e3d7e2f 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 { @@ -40,7 +42,7 @@ namespace Admin.Core.Api { Configuration = configuration; Env = env; - + } /// @@ -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/IHw_BarrelServices.cs b/Admin.Core.IService/IService_New/IHw_BarrelServices.cs new file mode 100644 index 0000000..c640c97 --- /dev/null +++ b/Admin.Core.IService/IService_New/IHw_BarrelServices.cs @@ -0,0 +1,22 @@ +using Admin.Core.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Admin.Core.IService.IService_New +{ + /// + /// 料筒服务类 + /// + public interface IHw_BarrelServices : IBaseServices + { + /// + /// 根据罐号获取料罐ID + /// + /// + /// + string GetPlanIdByBarrelID(string barrelBarcode); + } +} diff --git a/Admin.Core.IService/IService_New/ILR_weighServices.cs b/Admin.Core.IService/IService_New/ILR_weighServices.cs index d55505f..e3e0fcc 100644 --- a/Admin.Core.IService/IService_New/ILR_weighServices.cs +++ b/Admin.Core.IService/IService_New/ILR_weighServices.cs @@ -1,5 +1,6 @@ using Admin.Core.IService; using Admin.Core.Model; +using System.Collections.Generic; namespace Admin.Core.IService { @@ -8,5 +9,10 @@ namespace Admin.Core.IService /// public interface ILR_weighServices :IBaseServices { - } + /// + /// 通过计划号获取最近一次的称量列表 + /// + /// + List GetRecentWeightList(string planCode); + } } \ No newline at end of file diff --git a/Admin.Core.IService/IService_New/Ixl_materialServices.cs b/Admin.Core.IService/IService_New/Ixl_materialServices.cs index ed7b2c1..78242c4 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 @@ -38,6 +39,49 @@ namespace Admin.Core.IService Task> MaterialVerification(string barCode); - Task xlInsertMaterial(string materialCode, string materialName); + /// + /// 物料插入 + /// + /// + /// + /// + /// + /// + /// + Task xlInsertMaterial( + string id, + string materialCode, + string materialName, + int isEnable, + DateTime createDatetime); + + /// + /// 物料更新 + /// + /// + /// + /// + /// + /// + /// + Task xlUpdateMaterial( + string id, + string materialCode, + string materialName, + int isEnable, + DateTime createDatetime); + + /// + /// 物料查询 + /// + /// + Task> xlMaterialList(); + + /// + /// 根据ID查询 + /// + /// + /// + Task SelectXlMaterialById(string id); } } \ No newline at end of file diff --git a/Admin.Core.IService/IService_New/Ixl_recipeServices.cs b/Admin.Core.IService/IService_New/Ixl_recipeServices.cs index 0b8e2d9..da6f8a1 100644 --- a/Admin.Core.IService/IService_New/Ixl_recipeServices.cs +++ b/Admin.Core.IService/IService_New/Ixl_recipeServices.cs @@ -1,5 +1,7 @@ using Admin.Core.IService; using Admin.Core.Model; +using System.Collections.Generic; +using System.Threading.Tasks; namespace Admin.Core.IService { @@ -8,5 +10,31 @@ namespace Admin.Core.IService /// public interface Ixl_recipeServices :IBaseServices { + /// + /// 新增配方信息 + /// + /// + /// + Task xlInsertRecipe(xl_recipe recipe); + + /// + /// 更新配方信息 + /// + /// + /// + Task xlUpdateRecipe(xl_recipe recipe); + + /// + /// 获取配方列表 + /// + /// + Task> xlGetAllRecipes(); + + /// + /// 如果有记录就更新,没有记录就新增 + /// + /// + /// + Task xlUpdateOrAdd(xl_recipe recipe); } } \ No newline at end of file diff --git a/Admin.Core.Model/Model_New/xl_recipe.cs b/Admin.Core.Model/Model_New/xl_recipe.cs index b1008cd..f7c5c12 100644 --- a/Admin.Core.Model/Model_New/xl_recipe.cs +++ b/Admin.Core.Model/Model_New/xl_recipe.cs @@ -9,153 +9,149 @@ namespace Admin.Core.Model /// ///配方信息 /// - [SugarTable( "xl_recipe", "cwss_xl")] + [SugarTable("xl_recipe", "cwss_xl")] public class xl_recipe { - public xl_recipe() - { - } - /// - /// Desc: - /// Default: - /// Nullable:False - /// -public string ID { get; set; } - /// - /// Desc:机台号 - /// Default: - /// Nullable:True - /// -public string Equip_Code { get; set; } - /// - /// Desc:配方编码 - /// Default: - /// Nullable:True - /// -public string Recipe_Code { get; set; } - /// - /// Desc:配方版本号 - /// Default: - /// Nullable:True - /// -public string Version { get; set; } - /// - /// Desc:配方别名 - /// Default: - /// Nullable:True - /// -public string Recipe_Name { get; set; } - /// - /// Desc:配方版本号 - /// Default: - /// Nullable:True - /// -public string Mixer_line { get; set; } - /// - /// Desc:配方类型 - /// Default: - /// Nullable:True - /// -public int? Recipe_type { get; set; } - /// - /// Desc:配方习惯 - /// Default: - /// Nullable:True - /// -public int? Recipe_Used { get; set; } - /// - /// Desc:配方验证 - /// Default:0 - /// Nullable:True - /// -public int? Recipe_Verify { get; set; } - /// - /// Desc:总计重量 - /// Default: - /// Nullable:True - /// -public decimal? Total_Weight { get; set; } - /// - /// Desc:总计误差 - /// Default: - /// Nullable:True - /// -public decimal? Total_Error { get; set; } - /// - /// Desc:结束时间 - /// Default: - /// Nullable:True - /// -public string End_datetime { get; set; } - /// - /// Desc:备注 - /// Default: - /// Nullable:True - /// -public string Remark { get; set; } - /// - /// Desc:附件用户 - /// Default: - /// Nullable:True - /// -public int? Attach_User { get; set; } - /// - /// Desc:分组袋 - /// Default: - /// Nullable:True - /// -public int? GroupBags { get; set; } - /// - /// Desc: - /// Default: - /// Nullable:True - /// -public int? IF_FLAG { get; set; } - /// - /// Desc:有效性 - /// Default: - /// Nullable:True - /// -public int? Validity { get; set; } - /// - /// Desc:有效天数 - /// Default: - /// Nullable:True - /// -public int? ValidDays { get; set; } - /// - /// Desc: - /// Default: - /// Nullable:True - /// -public string UpdateByID { get; set; } - /// - /// Desc: - /// Default: - /// Nullable:True - /// -public string UpdateBy { get; set; } - /// - /// Desc: - /// Default: - /// Nullable:True - /// -public string CreatorID { get; set; } - /// - /// Desc: - /// Default: - /// Nullable:True - /// -public string Creator { get; set; } - /// - /// Desc: - /// Default: - /// Nullable:True - /// -public DateTime? CreateDateTime { get; set; } -/// -/// 是否产前验证 -/// -public int IsCheck { get; set; } + public xl_recipe() + { + } + /// + /// Desc: + /// Default: + /// Nullable:False + /// + public string ID { get; set; } + /// + /// Desc:机台号 + /// Default: + /// Nullable:True + /// + public string Equip_Code { get; set; } + /// + /// Desc:配方编码 + /// Default: + /// Nullable:True + /// + public string Recipe_Code { get; set; } + /// + /// Desc:配方版本号 + /// Default: + /// Nullable:True + /// + public string Version { get; set; } + /// + /// Desc:配方别名 + /// Default: + /// Nullable:True + /// + public string Recipe_Name { get; set; } + /// + /// Desc:配方版本号 + /// Default: + /// Nullable:True + /// + public string Mixer_line { get; set; } + /// + /// Desc:配方类型 + /// Default: + /// Nullable:True + /// + public int? Recipe_type { get; set; } + /// + /// Desc:配方习惯 + /// Default: + /// Nullable:True + /// + public int? Recipe_Used { get; set; } + /// + /// Desc:配方验证 + /// Default:0 + /// Nullable:True + /// + public int? Recipe_Verify { get; set; } + /// + /// Desc:总计重量 + /// Default: + /// Nullable:True + /// + public decimal? Total_Weight { get; set; } + /// + /// Desc:总计误差 + /// Default: + /// Nullable:True + /// + public decimal? Total_Error { get; set; } + /// + /// Desc:结束时间 + /// Default: + /// Nullable:True + /// + public string End_datetime { get; set; } + /// + /// Desc:备注 + /// Default: + /// Nullable:True + /// + public string Remark { get; set; } + /// + /// Desc:附件用户 + /// Default: + /// Nullable:True + /// + public int? Attach_User { get; set; } + /// + /// Desc:分组袋 + /// Default: + /// Nullable:True + /// + public int? GroupBags { get; set; } + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public int? IF_FLAG { get; set; } + /// + /// Desc:有效性 + /// Default: + /// Nullable:True + /// + public int? Validity { get; set; } + /// + /// Desc:有效天数 + /// Default: + /// Nullable:True + /// + public int? ValidDays { get; set; } + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string UpdateByID { get; set; } + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string UpdateBy { get; set; } + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string CreatorID { get; set; } + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string Creator { get; set; } + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public DateTime? CreateDateTime { get; set; } } } \ No newline at end of file diff --git a/Admin.Core.PlcServer/Impl/SiemensPlc.cs b/Admin.Core.PlcServer/Impl/SiemensPlc.cs index 393ce05..042b6bf 100644 --- a/Admin.Core.PlcServer/Impl/SiemensPlc.cs +++ b/Admin.Core.PlcServer/Impl/SiemensPlc.cs @@ -507,7 +507,7 @@ namespace Admin.Core.PlcServer { siemensS7Net.ReceiveTimeOut = 2000; OperateResult read = await siemensS7Net.ReadBoolAsync(address); - log.Info($"心跳方法是否成功:{read.IsSuccess};反馈:{read.Message}"); + //log.Info($"心跳方法是否成功:{read.IsSuccess};反馈:{read.Message}"); if (read.IsSuccess) { IsConnected = true; diff --git a/Admin.Core.Service/Service_New/Hw_BarrelServices.cs b/Admin.Core.Service/Service_New/Hw_BarrelServices.cs new file mode 100644 index 0000000..c1644d7 --- /dev/null +++ b/Admin.Core.Service/Service_New/Hw_BarrelServices.cs @@ -0,0 +1,36 @@ +using Admin.Core.IRepository; +using Admin.Core.IService; +using Admin.Core.IService.IService_New; +using Admin.Core.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Admin.Core.Service.Service_New +{ + public class Hw_BarrelServices : BaseServices, IHw_BarrelServices + { + + private readonly IBaseRepository _dal; + public Hw_BarrelServices(IBaseRepository dal) + { + this._dal = dal; + base.BaseDal = dal; + } + + public string GetPlanIdByBarrelID(string barrelBarcode) + { + try + { + string planId = _dal.Query(x => x.BarCode == barrelBarcode).FirstOrDefault().PlanId.ToString(); + return planId; + } + catch + { + throw; + } + } + } +} diff --git a/Admin.Core.Service/Service_New/LR_weighServices.cs b/Admin.Core.Service/Service_New/LR_weighServices.cs index 62767e6..bfdd653 100644 --- a/Admin.Core.Service/Service_New/LR_weighServices.cs +++ b/Admin.Core.Service/Service_New/LR_weighServices.cs @@ -2,6 +2,9 @@ using Admin.Core.Service; using Admin.Core.IService; using Admin.Core.Model; +using System.Collections.Generic; +using System.Linq; +using System; namespace Admin.Core.Service { @@ -13,5 +16,20 @@ namespace Admin.Core.Service this._dal = dal; base.BaseDal = dal; } + + public List GetRecentWeightList(string planCode) + { + try + { + List list = _dal.Query(x => x.Plan_ID == planCode).ToList(); + int maxMainID = list.Max(x => x.MainId); + List groupList = list.Where(x => x.MainId == maxMainID).ToList(); + return groupList; + } + catch + { + throw; + } + } } } \ 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 75082d0..6fcf5da 100644 --- a/Admin.Core.Service/Service_New/xl_materialServices.cs +++ b/Admin.Core.Service/Service_New/xl_materialServices.cs @@ -658,6 +658,7 @@ namespace Admin.Core.Service #endregion #region 料框防错验证——只验证单料 + public async Task> MaterialVerification(string barCode) { MessageModel messageModel = new MessageModel(); @@ -709,30 +710,36 @@ namespace Admin.Core.Service } #endregion + /// - /// 小料上位机同步插入物料信息 + /// 小料上位机插入物料信息 /// /// /// /// /// /// - public async Task xlInsertMaterial(string materialCode, string materialName) + public async Task xlInsertMaterial( + string id, + string materialCode, + string materialName, + int isEnable, + DateTime createDatetime) { try { xl_material xl_m = new xl_material() { - ID = Guid.NewGuid().ToString("N"), + ID = id, 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); @@ -747,10 +754,87 @@ namespace Admin.Core.Service } catch (Exception ex) { - return false; + throw; } } + /// + /// 小料上位机更新物料信息 + /// + /// + /// + /// + /// + /// + 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) + { + throw; + } + + } + /// + /// 获取小料上位机物料信息 + /// + /// + /// + /// + /// + /// + public async Task> xlMaterialList() + { + try + { + return await _xl_materialRepository.QueryAsync(); + } + catch (Exception ex) + { + throw; + } + } + + /// + /// 根据ID查询物料信息 + /// + /// + /// + /// + public async Task SelectXlMaterialById(string id) + { + try + { + return await _xl_materialRepository.QueryByIdAsync(id); + } + catch (Exception ex) + { + throw; + } + } } } \ No newline at end of file diff --git a/Admin.Core.Service/Service_New/xl_recipeServices.cs b/Admin.Core.Service/Service_New/xl_recipeServices.cs index d888f81..c613aa9 100644 --- a/Admin.Core.Service/Service_New/xl_recipeServices.cs +++ b/Admin.Core.Service/Service_New/xl_recipeServices.cs @@ -2,6 +2,13 @@ using Admin.Core.Service; using Admin.Core.IService; using Admin.Core.Model; +using System.Threading.Tasks; +using System.Collections.Generic; +using System; +using Serilog; +using NPOI.SS.Formula.Functions; +using System.Linq; +using Microsoft.Extensions.Logging; namespace Admin.Core.Service { @@ -13,5 +20,69 @@ namespace Admin.Core.Service this._dal = dal; base.BaseDal = dal; } + + public async Task> xlGetAllRecipes() + { + try + { + return await _dal.QueryAsync(); + } + catch(Exception ex) + { + throw; + } + } + + public async Task xlInsertRecipe(xl_recipe recipe) + { + try + { + if(await _dal.AddAsync(recipe) == 1) + { + return true; + } + else + { + return false; + } + } + catch(Exception ex) + { + throw; + } + } + + public async Task xlUpdateRecipe(xl_recipe recipe) + { + try + { + return await _dal.UpdateAsync(recipe); + } + catch(Exception ex) + { + throw; + } + } + + public async Task xlUpdateOrAdd(xl_recipe recipe) + { + try + { + var record = await _dal.QueryAsync(x => x.Recipe_Code == recipe.Recipe_Code); + if(record == null || record.Count == 0) + { + recipe.ID = record[0].ID; + return await xlUpdateRecipe(recipe); + } + else + { + return await xlInsertRecipe(recipe); + } + } + catch (Exception ex) + { + throw; + } + } } } \ No newline at end of file