zhaoy 8 months ago
parent
commit
76c9c39e01
15 changed files with 259 additions and 66 deletions
  1. BIN
     
  2. BIN
     
  3. +1
    -1
      BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs
  4. +3
    -1
      BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResultSAASManageDto.cs
  5. +1
    -1
      BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs
  6. +1
    -1
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/MaterialServices.cs
  7. +1
    -1
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/IMaterialServices.cs
  8. +27
    -55
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs
  9. +71
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Dtos/PushDataDto.cs
  10. +1
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Dtos/PushDeviceDto.cs
  11. +12
    -1
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/IThirdpartyPushService.cs
  12. +112
    -4
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/ThirdpartyPushService.cs
  13. +7
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/ThirdpartyPushServices.cs
  14. +21
    -0
      BPA.SAAS.Manage.Core/System/BPA_ThirdpartyPushRecord.cs
  15. +1
    -1
      BPA.SAAS.Manage.Web.Entry/appsettings.json

BIN
View File


BIN
View File


+ 1
- 1
BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs View File

@@ -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)) + "&";
}

}


+ 3
- 1
BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResultSAASManageDto.cs View File

@@ -10,7 +10,7 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto
{
public int statusCode { get; set; }

public ResultSAASManageDataDto<T> data { get; set; }
public T data { get; set; }

public string succeeded { get; set; }

@@ -19,6 +19,8 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto
public string extras { get; set; }

public int timestamp { get; set; }


}

public class ResultSAASManageDataDto<T>


+ 1
- 1
BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs View File

@@ -106,7 +106,7 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Enum
/// <summary>
/// 下发错误
/// </summary>
[ErrorCodeItemMetadata("下发错误")]
[ErrorCodeItemMetadata("操作成功,下发错误")]
Code10016,
}
}

+ 1
- 1
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/MaterialServices.cs View File

@@ -42,7 +42,7 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Service
/// <param name="InputDto"></param>
/// <returns></returns>
[HttpPost("/api/ExternalPlatform/Material/AddMaterial")]
public async Task<bool> AddMaterial(BaseRequestDto<MaterialCreateDto> InputDto)
public async Task<string> AddMaterial(BaseRequestDto<MaterialCreateDto> InputDto)
{
return await _materialServices.AddMaterial(InputDto);
}


+ 1
- 1
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/IMaterialServices.cs View File

@@ -28,7 +28,7 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Service
/// </summary>
/// <param name="InputDto"></param>
/// <returns></returns>
Task<bool> AddMaterial(BaseRequestDto<MaterialCreateDto> inputDto);
Task<string> AddMaterial(BaseRequestDto<MaterialCreateDto> inputDto);

/// <summary>
/// 删除物料


+ 27
- 55
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs View File

@@ -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
{
@@ -68,7 +70,7 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Service
/// </summary>
/// <param name="InputDto"></param>
/// <returns></returns>
public async Task<bool> AddMaterial(BaseRequestDto<MaterialCreateDto> inputDto)
public async Task<string> AddMaterial(BaseRequestDto<MaterialCreateDto> inputDto)
{
try
{
@@ -129,67 +131,37 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Service
throw Oops.Oh(ErrorCodeEnum.Code1002);
}

var input = new List<PushDeviceDto>();


if (inputDto.StoreIdList != null && inputDto.StoreIdList.Count > 0)
{
input = await SqlSugarDb.Db.Queryable<BPA_DeviceInfo, BPA_Product>((a, b) => new JoinQueryInfos(
JoinType.Left, a.ProductId == b.Id))
.Where(x => inputDto.StoreIdList.Contains(x.StopId))
.Select((a, b) => new PushDeviceDto
{
deviceAutoKey = a.AutoKey,
deviceId = a.Id,
deviceName = a.DeviceName,
messageId = "",
productName = ""

})
.ToListAsync();
SqlSugarDb.Db.Ado.CommitTran();

}
#region 下发数据到设备

if (inputDto.DeviceIdList != null && inputDto.DeviceIdList.Count > 0)
var data = new PushDataBatchingDto()
{
input = await SqlSugarDb.Db.Queryable<BPA_DeviceInfo, BPA_Product>((a, b) => new JoinQueryInfos(
JoinType.Left, a.ProductId == b.Id))
.Where(x => inputDto.StoreIdList.Contains(x.StopId))
.Select((a, b) => new PushDeviceDto
{
deviceAutoKey = a.AutoKey,
deviceId = a.Id,
deviceName = a.DeviceName,
messageId = "",
productKey = "",
productName = b.Name,
productVersion = a.ProductVersionId,
type = 2
})
.ToListAsync();
}

//4.添加记录
foreach (var item in input)
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)
{
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 = JsonConvert.SerializeObject(item),
});
await _thirdpartyPushService.AddPushRecordAndPushDevice<MaterialCreateDto>(inputDto, 2, materialData.Id,
JsonConvert.SerializeObject(data));
}
//5.发送mq
await _thirdpartyPushService.PushDevice(input);

#endregion


SqlSugarDb.Db.Ado.CommitTran();
return true;
return materialData.Id;
}
catch (Exception e)
{


+ 71
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Dtos/PushDataDto.cs View File

@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.Dtos
{
public class PushDataBatchingDto
{
public string Id { get; set; }
/// <summary>
/// 原料编码
/// </summary>
public string Code { get; set; }
/// <summary>
/// 商品属性 (0成品,1半成品,2,易耗品)
/// </summary>
public int Aittribute { get; set; } = 0;
/// <summary>
/// 原料名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 配料类型
/// </summary>
public string TypeName { get; set; }
/// <summary>
/// 原料类型
/// </summary>
public string TypeID { get; set; }

/// <summary>
/// 库存单位
/// </summary>
public string StockUintName { get; set; }
public string StockUint { get; set; }
/// <summary>
/// 规格属性
/// </summary>
public string Specs { get; set; }


/// <summary>
/// 成本价
/// </summary>
public decimal Price { get; set; }


/// <summary>
/// 净料率
/// </summary>
public decimal netrecovery { get; set; }

/// <summary>
/// 出库单位
/// </summary>
public string outstockUint { get; set; }


/// <summary>
/// 换算比例
/// </summary>
public decimal proportion { get; set; }


public int AutoKey { get; set; }
public string ForeignKeyRe { get; set; }
public string CreateAt { get; set; }
}
}

+ 1
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Dtos/PushDeviceDto.cs View File

@@ -49,4 +49,5 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.D

public string isDefault { get; set; }
}

}

+ 12
- 1
BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/IThirdpartyPushService.cs View File

@@ -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,16 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.S
/// <returns></returns>
Task<bool> UpdateThirdpartyPushRecord(ThirdpartyPushRecordDto inputDto);

/// <summary>
/// 添加下发记录和下发数据
/// </summary>
/// <param name="inputDto"></param>
/// <param name="type"> 2:物料</param>
/// <param name="pushData">改动的数据 如物料的id 商品的id 订单的订单号</param>
/// <param name="pushMQData">下发到设备的数据 json</param>
/// <returns></returns>
Task<bool> AddPushRecordAndPushDevice<T>(BaseRequestDto<T> inputDto, int type, string pushData,string pushMQData);

/// <summary>
/// 更具店铺获取设备
/// </summary>


+ 112
- 4
BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/ThirdpartyPushService.cs View File

@@ -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;
@@ -44,12 +46,13 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.S
{

Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("groupId", CurrentUser.GroupId);
var url = App.Configuration["baseurl"] + "api/devicepushrecode/add_alm";
var inputData = JsonConvert.SerializeObject(inputDto);
var jsonData = HttpHelper.PostData(url, inputData, Encoding.UTF8, "application/json", dic);
var data = JsonConvert.DeserializeObject<ResultSAASManageDto<ResultTenantDataItemDto>>(jsonData);
var data = JsonConvert.DeserializeObject<ResultSAASManageDto<bool>>(jsonData);
if (data.statusCode != 200) throw Oops.Oh(ErrorCodeEnum.Code10016);
if (data.data.data.Count <= 0) throw Oops.Oh(ErrorCodeEnum.Code10016);
if (!data.data) throw Oops.Oh(ErrorCodeEnum.Code10016);
return true;
}

@@ -70,11 +73,33 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.S
}
data.IsPush = inputDto.IsPush;
data.CreateAt = DateTime.Now;
var res = await SqlSugarDb.Db.Updateable(data).ExecuteCommandAsync();
return res > 0;
data.Status = 0;
var result= await SqlSugarDb.Db.Updateable(data).ExecuteCommandAsync();

//回调

var urlstr = "";

if (data.Type==2)
{
urlstr = $@"{data.CallbackUrl}?materialId={data.PushData}&Device={inputDto.DeviceId}";
Dictionary<string, string> dic = new Dictionary<string, string>();
var inputData ="";
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 result > 0;

}


/// <summary>
/// 更具店铺获取设备
/// </summary>
@@ -90,6 +115,89 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.S
}


/// <summary>
/// 添加下发记录和下发数据
/// </summary>
/// <param name="inputDto"></param>
/// <param name="type"> 1.商品 2.物料 3.配方 4.工艺</param>
/// <param name="pushData">改动的数据 如物料的id 商品的id 订单的订单号</param>
/// <param name="pushMQData">下发到设备的数据 json</param>
/// <returns></returns>
public async Task<bool> AddPushRecordAndPushDevice<T>(BaseRequestDto<T> inputDto, int type, string pushData, string pushMQData)
{
var input = new List<PushDeviceDto>();

if (inputDto.StoreIdList != null && inputDto.StoreIdList.Count > 0)
{
input = await SqlSugarDb.Db.Queryable<BPA_DeviceInfo, BPA_Product, BPA_ProductVesion>((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<BPA_DeviceInfo, BPA_Product, BPA_ProductVesion>((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
}


+ 7
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/ThirdpartyPushServices.cs View File

@@ -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<bool> aaaaa()
{
return true;
}
#endregion
}
}

+ 21
- 0
BPA.SAAS.Manage.Core/System/BPA_ThirdpartyPushRecord.cs View File

@@ -44,5 +44,26 @@ namespace BPA.SAAS.Manage.Core.System
/// </summary>
public string PushData { get; set; }


/// <summary>
/// 0: 成功 1:失败
/// </summary>
public int Status { get; set; }

/// <summary>
/// 1.商品 2.物料 3.配方 4.工艺
/// </summary>
public int Type { get; set; }

/// <summary>
/// 是否回调
/// </summary>
public bool IsCallback { get; set; }

/// <summary>
/// 回调信息
/// </summary>
public string CallbackInfo { get; set; }

}
}

+ 1
- 1
BPA.SAAS.Manage.Web.Entry/appsettings.json View File

@@ -8,7 +8,7 @@
}
},
"AllowedHosts": "*",
"baseurl": "http://localhost:5008/",
"baseurl": "http://192.168.1.19:5007/",
"ConnectionConfigs": [
{
"ConnectionString": "server=10.2.1.21;Database=bpa_kitchen_kitchenbasemanage;Uid=root;Pwd=cygadmin;Allow Zero Datetime=True;Convert Zero Datetime=True;",


Loading…
Cancel
Save