diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/BaseRequestDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/BaseRequestDto.cs index ae99417..20ce942 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/BaseRequestDto.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/BaseRequestDto.cs @@ -25,4 +25,5 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto public List DataInfo { get; set; } } + } diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs index 6557e31..6f66eff 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/DtoValidator.cs @@ -92,8 +92,10 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto } else { + var jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - retstr = retstr + p.Name + "=" + JsonConvert.SerializeObject(p.GetValue(t, null)) + "&"; + retstr = retstr + p.Name + "=" + JsonConvert.SerializeObject(p.GetValue(t, null), Formatting.None, jsonSetting) + "&"; + } } 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 7b6dcd0..9498a50 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Material/Services/MaterialService.cs @@ -75,93 +75,105 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Service try { + var list=new List(); + SqlSugarDb.Db.Ado.BeginTran(); - //1.物料单位查询 - var typeData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Name == inputDto.DataInfo.TypeName); - if (typeData == null) - { - typeData = new BPA_BatchingType() + foreach (var item in inputDto.DataInfo) + { + //1.物料单位查询 + var typeData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Name == item.TypeName); + if (typeData == null) { - GroupId = CurrentUser.GroupId, - Id = Guid.NewGuid().ToString(), - Name = string.IsNullOrEmpty(inputDto.DataInfo.TypeName) ? "默认分类" : inputDto.DataInfo.TypeName, - }; - SqlSugarDb.Db.Insertable(typeData).ExecuteCommand(); - } - //2.单位查询 - var uintData = await SqlSugarDb.Db.Queryable() - .FirstAsync(x => x.Name == inputDto.DataInfo.UintName); - if (uintData == null) - { - uintData = new BPA_BatchingUint() + typeData = new BPA_BatchingType() + { + GroupId = CurrentUser.GroupId, + Id = Guid.NewGuid().ToString(), + Name = string.IsNullOrEmpty(item.TypeName) ? "默认分类" : item.TypeName, + }; + SqlSugarDb.Db.Insertable(typeData).ExecuteCommand(); + } + + //2.单位查询 + var uintData = await SqlSugarDb.Db.Queryable() + .FirstAsync(x => x.Name == item.UintName); + if (uintData == null) { - GroupId = CurrentUser.GroupId, - Id = Guid.NewGuid().ToString(), - Name = string.IsNullOrEmpty(inputDto.DataInfo.UintName) ? "默认分类" : inputDto.DataInfo.UintName, - }; - SqlSugarDb.Db.Insertable(uintData).ExecuteCommand(); - } - //3.物料查询 - var materialData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Batching_Name == inputDto.DataInfo.Name || x.Code == inputDto.DataInfo.Code); - if (materialData == null) - { - materialData = new BPA_Batching() + uintData = new BPA_BatchingUint() + { + GroupId = CurrentUser.GroupId, + Id = Guid.NewGuid().ToString(), + Name = string.IsNullOrEmpty(item.UintName) ? "默认分类" : item.UintName, + }; + SqlSugarDb.Db.Insertable(uintData).ExecuteCommand(); + } + //3.物料查询 + var materialData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Batching_Name == item.Name || x.Code == item.Code); + if (materialData == null) { - Id = Guid.NewGuid().ToString(), - GroupId = CurrentUser.GroupId, - Aittribute = 0, - Batching_Name = inputDto.DataInfo.Name, - Batching_Type = typeData.Id, - Code = inputDto.DataInfo.Code, - Price = 0, - Specs = "", - outstockUint = uintData.Id, - Status = CommonStatus.ENABLE, - StockUint = uintData.Id, - TypeID = typeData.Id, - IsDeleted = 0, - }; + materialData = new BPA_Batching() + { + Id = Guid.NewGuid().ToString(), + GroupId = CurrentUser.GroupId, + Aittribute = 0, + Batching_Name = item.Name, + Batching_Type = typeData.Id, + Code = item.Code, + Price = 0, + Specs = "", + outstockUint = uintData.Id, + Status = CommonStatus.ENABLE, + StockUint = uintData.Id, + TypeID = typeData.Id, + IsDeleted = 0, + }; - SqlSugarDb.Db.Insertable(materialData).ExecuteCommand(); - } - else - { - throw Oops.Oh(ErrorCodeEnum.Code1002); + SqlSugarDb.Db.Insertable(materialData).ExecuteCommand(); + } + else + { + throw Oops.Oh(ErrorCodeEnum.Code1002); + } + list.Add(materialData); } SqlSugarDb.Db.Ado.CommitTran(); #region 下发数据到设备 - var data = new PushDataBatchingDto() + var data = new List(); + foreach (var item in list) { - 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, - }; + data.Add(new PushDataBatchingDto() + { + Aittribute = item.Aittribute, + AutoKey = item.AutoKey, + Code = item.Code, + ForeignKeyRe = item.ForeignKeyRe, + Id = item.Id, + Name = item.Batching_Name, + netrecovery = item.netrecovery, + outstockUint = item.outstockUint, + Price = item.Price, + proportion = item.proportion, + Specs = item.Specs, + StockUint = item.StockUint, + StockUintName = item.StockUint, + TypeID = item.TypeID, + }); + } + if (inputDto.IsPush) { - await _thirdpartyPushService.AddPushRecordAndPushDevice(inputDto, 2, materialData.Id, + await _thirdpartyPushService.AddPushRecordAndPushDevice(inputDto, 2, JsonConvert.SerializeObject(list.Select(x => x.Id).ToList()), JsonConvert.SerializeObject(data)); } #endregion - return materialData.Id; + return JsonConvert.SerializeObject(list.Select(x => x.Id).ToList()); } catch (Exception e) { @@ -205,8 +217,17 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Service try { SqlSugarDb.Db.Ado.BeginTran(); + + if (inputDto.DataInfo.Count>1) + { + throw Oops.Oh("不支持多物料修改"); + } + + var materia = inputDto.DataInfo.FirstOrDefault(); + + //1.物料单位查询 - var typeData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Name == inputDto.DataInfo.TypeName); + var typeData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Name == materia.TypeName); if (typeData == null) { @@ -214,28 +235,28 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Service { GroupId = CurrentUser.GroupId, Id = Guid.NewGuid().ToString(), - Name = string.IsNullOrEmpty(inputDto.DataInfo.TypeName) ? "默认分类" : inputDto.DataInfo.TypeName, + Name = string.IsNullOrEmpty(materia.TypeName) ? "默认分类" : materia.TypeName, }; SqlSugarDb.Db.Insertable(typeData).ExecuteCommand(); } //2.单位查询 var uintData = await SqlSugarDb.Db.Queryable() - .FirstAsync(x => x.Name == inputDto.DataInfo.UintName); + .FirstAsync(x => x.Name == materia.UintName); if (uintData == null) { uintData = new BPA_BatchingUint() { GroupId = CurrentUser.GroupId, Id = Guid.NewGuid().ToString(), - Name = string.IsNullOrEmpty(inputDto.DataInfo.UintName) ? "默认分类" : inputDto.DataInfo.UintName, + Name = string.IsNullOrEmpty(materia.UintName) ? "默认分类" : materia.UintName, }; SqlSugarDb.Db.Insertable(uintData).ExecuteCommand(); } //3.物料查询 - var material = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Code == inputDto.DataInfo.Code || x.Batching_Name == inputDto.DataInfo.Name); + var material = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Code == materia.Code || x.Batching_Name == materia.Name); - var materialData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Id == inputDto.DataInfo.Id); + var materialData = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Id == materia.Id); if (materialData == null) { @@ -253,9 +274,9 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Service Id = Guid.NewGuid().ToString(), GroupId = CurrentUser.GroupId, Aittribute = 0, - Batching_Name = inputDto.DataInfo.Name, + Batching_Name = materia.Name, Batching_Type = typeData.Id, - Code = inputDto.DataInfo.Code, + Code = materia.Code, Price = 0, Specs = "", outstockUint = uintData.Id, 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 d2a49e0..0730a04 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/ThirdpartyPushService.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/ThirdpartyPush/Services/ThirdpartyPushService.cs @@ -187,7 +187,7 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.S IsCallback=false, CallbackInfo = "", }); - item.data =$"[{pushMQData}]"; + item.data = pushMQData; } //5.发送mqy