diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs index a9d5282..f313488 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs @@ -83,7 +83,7 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto { if (p.GetValue(t, null) != null && p.GetValue(t, null).ToString() != "") { - retstr = retstr + p.Name + "=" + p.GetValue(t, null) + "&"; + retstr = retstr + p.Name + "=" +JsonConvert.SerializeObject(p.GetValue(t, null)) + "&"; } } diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs index 4e3503c..6526add 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs @@ -15,6 +15,8 @@ using BPA.SAAS.Manage.Core.Device; using BPA.SAAS.Manage.Core.Product; using Microsoft.AspNetCore.Components.Forms; using Newtonsoft.Json; +using NPOI.SS.Formula.Functions; +using System.Drawing.Drawing2D; namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Services { @@ -129,99 +131,33 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Service throw Oops.Oh(ErrorCodeEnum.Code1002); } + SqlSugarDb.Db.Ado.CommitTran(); + #region 下发数据到设备 - if (inputDto.IsPush) + var data = new PushDataBatchingDto() { - var input = new List(); - - if (inputDto.StoreIdList != null && inputDto.StoreIdList.Count > 0) - { - input = await SqlSugarDb.Db.Queryable((a, b, c) => new JoinQueryInfos( - JoinType.Left, a.ProductId == b.Id, - JoinType.Left, a.ProductVersionId == c.Id - )) - .Where((a, b, c) => inputDto.StoreIdList.Contains(a.StopId)) - .Select((a, b, c) => new PushDeviceDto - { - deviceAutoKey = a.AutoKey, - deviceId = a.Id, - deviceName = a.DeviceName, - messageId = CurrentUser.MessageId, - productKey = b.Key, - productName = b.Name, - productVersion = c.Vesion, - type = 2 - - }) - .ToListAsync(); - - } - - if (inputDto.DeviceIdList != null && inputDto.DeviceIdList.Count > 0) - { - input = await SqlSugarDb.Db.Queryable((a, b, c) => new JoinQueryInfos( - JoinType.Left, a.ProductId == b.Id, - JoinType.Left, a.ProductVersionId == c.Id)) - .Where((a, b, c) => inputDto.DeviceIdList.Contains(a.Id)) - .Select((a, b, c) => new PushDeviceDto - { - deviceAutoKey = a.AutoKey, - deviceId = a.Id, - deviceName = a.DeviceName, - messageId = CurrentUser.MessageId, - productKey = b.Key, - productName = b.Name, - productVersion = c.Vesion, - type = 2, - }) - .ToListAsync(); - } - - //4.添加记录 - foreach (var item in input) - { - await _thirdpartyPushService.AddThirdpartyPushRecord(new Core.System.BPA_ThirdpartyPushRecord() - { - CallbackUrl = inputDto.CallbackUrl, - GroupId = CurrentUser.GroupId, - Id = Guid.NewGuid().ToString(), - IsPush = false, - MessageId = CurrentUser.MessageId, - PushDevice = item.deviceId, - PushData = materialData.Id, - Status = 1, - Type = 2, - }); - item.data = JsonConvert.SerializeObject(new List() - { - new() - { - Aittribute= materialData.Aittribute, - AutoKey= materialData.AutoKey, - Code=materialData.Code, - ForeignKeyRe= materialData.ForeignKeyRe, - Id=materialData.Id, - Name= materialData.Batching_Name, - netrecovery= materialData.netrecovery, - outstockUint= materialData.outstockUint, - Price= materialData.Price, - proportion= materialData.proportion, - Specs= materialData.Specs, - StockUint= materialData.StockUint, - StockUintName= materialData.StockUint, - TypeID= materialData.TypeID, - } - }); - } - SqlSugarDb.Db.Ado.CommitTran(); - //5.发送mq - await _thirdpartyPushService.PushDevice(input); - } - else + Aittribute = materialData.Aittribute, + AutoKey = materialData.AutoKey, + Code = materialData.Code, + ForeignKeyRe = materialData.ForeignKeyRe, + Id = materialData.Id, + Name = materialData.Batching_Name, + netrecovery = materialData.netrecovery, + outstockUint = materialData.outstockUint, + Price = materialData.Price, + proportion = materialData.proportion, + Specs = materialData.Specs, + StockUint = materialData.StockUint, + StockUintName = materialData.StockUint, + TypeID = materialData.TypeID, + }; + if (inputDto.IsPush) { - SqlSugarDb.Db.Ado.CommitTran(); + await _thirdpartyPushService.AddPushRecordAndPushDevice(inputDto, 2, materialData.Id, + JsonConvert.SerializeObject(data)); } + #endregion diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/IThirdpartyPushService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/IThirdpartyPushService.cs index 3c6d6aa..60c058a 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/IThirdpartyPushService.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/IThirdpartyPushService.cs @@ -1,4 +1,5 @@ -using BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.Dtos; +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.Dtos; using BPA.SAAS.Manage.Core.System; using System; using System.Collections.Generic; @@ -33,6 +34,15 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.S /// Task UpdateThirdpartyPushRecord(ThirdpartyPushRecordDto inputDto); + /// + /// 添加下发记录和下发数据 + /// + /// + /// 2:物料 + /// 改动的数据 如物料的id 商品的id 订单的订单号 + /// 下发到设备的数据 json + /// + Task AddPushRecordAndPushDevice(BaseRequestDto inputDto, int type, string pushData,string pushMQData); /// /// 更具店铺获取设备 diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/ThirdpartyPushService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/ThirdpartyPushService.cs index 7d9b7f4..d2a49e0 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/ThirdpartyPushService.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/ThirdpartyPushService.cs @@ -2,10 +2,12 @@ using BPA.SAAS.KitChenManage.Core; using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Dtos; using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Services; using BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.Dtos; using BPA.SAAS.Manage.Comm.Util; using BPA.SAAS.Manage.Core.Device; +using BPA.SAAS.Manage.Core.Product; using BPA.SAAS.Manage.Core.System; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Newtonsoft.Json; @@ -72,7 +74,7 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.S data.IsPush = inputDto.IsPush; data.CreateAt = DateTime.Now; data.Status = 0; - var res = await SqlSugarDb.Db.Updateable(data).ExecuteCommandAsync(); + var result= await SqlSugarDb.Db.Updateable(data).ExecuteCommandAsync(); //回调 @@ -80,14 +82,20 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.S if (data.Type==2) { - urlstr = $@"?materialId={data.PushData}&Device={inputDto.DeviceId}"; + urlstr = $@"{data.CallbackUrl}?materialId={data.PushData}&Device={inputDto.DeviceId}"; Dictionary dic = new Dictionary(); var inputData =""; - HttpHelper.PostData(urlstr, inputData, Encoding.UTF8, "application/json", dic); + var res= HttpHelper.PostData(urlstr, inputData, Encoding.UTF8, "application/json", dic); + if (res.ToUpper()=="true".ToUpper()) + { + data.IsCallback = true; + } + data.CallbackInfo= res; + await SqlSugarDb.Db.Updateable(data).ExecuteCommandAsync(); } - return res > 0; + return result > 0; } @@ -107,6 +115,89 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.S } + /// + /// 添加下发记录和下发数据 + /// + /// + /// 1.商品 2.物料 3.配方 4.工艺 + /// 改动的数据 如物料的id 商品的id 订单的订单号 + /// 下发到设备的数据 json + /// + public async Task AddPushRecordAndPushDevice(BaseRequestDto inputDto, int type, string pushData, string pushMQData) + { + var input = new List(); + + if (inputDto.StoreIdList != null && inputDto.StoreIdList.Count > 0) + { + input = await SqlSugarDb.Db.Queryable((a, b, c) => new JoinQueryInfos( + JoinType.Left, a.ProductId == b.Id, + JoinType.Left, a.ProductVersionId == c.Id + )) + .Where((a, b, c) => inputDto.StoreIdList.Contains(a.StopId)) + .Select((a, b, c) => new PushDeviceDto + { + deviceAutoKey = a.AutoKey, + deviceId = a.Id, + deviceName = a.DeviceName, + messageId = CurrentUser.MessageId, + productKey = b.Key, + productName = b.Name, + productVersion = c.Vesion, + type = 2 + + }) + .ToListAsync(); + + } + + if (inputDto.DeviceIdList != null && inputDto.DeviceIdList.Count > 0) + { + input = await SqlSugarDb.Db.Queryable((a, b, c) => new JoinQueryInfos( + JoinType.Left, a.ProductId == b.Id, + JoinType.Left, a.ProductVersionId == c.Id)) + .Where((a, b, c) => inputDto.DeviceIdList.Contains(a.Id)) + .Select((a, b, c) => new PushDeviceDto + { + deviceAutoKey = a.AutoKey, + deviceId = a.Id, + deviceName = a.DeviceName, + messageId = CurrentUser.MessageId, + productKey = b.Key, + productName = b.Name, + productVersion = c.Vesion, + type = 2, + }) + .ToListAsync(); + } + + //4.添加记录 + foreach (var item in input) + { + await AddThirdpartyPushRecord(new Core.System.BPA_ThirdpartyPushRecord() + { + CallbackUrl = inputDto.CallbackUrl, + GroupId = CurrentUser.GroupId, + Id = Guid.NewGuid().ToString(), + IsPush = false, + MessageId = CurrentUser.MessageId, + PushDevice = item.deviceId, + PushData = pushData, + Status = 1, + Type = type, + IsCallback=false, + CallbackInfo = "", + }); + item.data =$"[{pushMQData}]"; + } + + //5.发送mqy + await PushDevice(input); + + return true; + } + + + #endregion } diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/ThirdpartyPushServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/ThirdpartyPushServices.cs index f919e38..0126445 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/ThirdpartyPushServices.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/ThirdpartyPushServices.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush { + [ApiDescriptionSettings("开放平台", Tag = "aaaa")] public class ThirdpartyPushServices: IDynamicApiController { IThirdpartyPushService _thirdpartyPushService; @@ -52,6 +53,12 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush { return await _thirdpartyPushService.GetDeviceByStoreId(inputDto); } + + [ AllowAnonymous, NonUnify] + public async Task aaaaa() + { + return true; + } #endregion } } diff --git a/BPA.SAAS.Manage.Core/System/BPA_ThirdpartyPushRecord.cs b/BPA.SAAS.Manage.Core/System/BPA_ThirdpartyPushRecord.cs index 74d6826..7032d89 100644 --- a/BPA.SAAS.Manage.Core/System/BPA_ThirdpartyPushRecord.cs +++ b/BPA.SAAS.Manage.Core/System/BPA_ThirdpartyPushRecord.cs @@ -44,9 +44,26 @@ namespace BPA.SAAS.Manage.Core.System /// public string PushData { get; set; } + + /// + /// 0: 成功 1:失败 + /// public int Status { get; set; } + /// + /// 1.商品 2.物料 3.配方 4.工艺 + /// public int Type { get; set; } + /// + /// 是否回调 + /// + public bool IsCallback { get; set; } + + /// + /// 回调信息 + /// + public string CallbackInfo { get; set; } + } }