diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsQueryDto.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsQueryDto.cs index 99a6e94..4b9be07 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsQueryDto.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsQueryDto.cs @@ -19,6 +19,8 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.Goods /// 状态 【正常 停用】默认 正常 /// public string Status { get; set; } - + public string Descritption { get; set; } + + } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs index f8b26da..36d6c75 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs @@ -20,6 +20,7 @@ using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.SS.Util; using NPOI.XSSF.UserModel; +using Org.BouncyCastle.Asn1.Cms; using System; using System.Collections; using System.ComponentModel.DataAnnotations.Schema; @@ -67,7 +68,10 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services { conModels.Add(new ConditionalModel() { FieldName = "a.Status", ConditionalType = ConditionalType.Like, FieldValue = dto.Status }); } - + if (!string.IsNullOrEmpty(dto.Descritption)) + { + conModels.Add(new ConditionalModel() { FieldName = "a.Descritption", ConditionalType = ConditionalType.Like, FieldValue = dto.Descritption }); + } #endregion RefAsync total = 0; @@ -774,8 +778,8 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services deviceGoodsPositionList.Add(new BPA_DeviceGoodsPosition() { - DeviceId = thisDevice.Id, - GoodsId = thisGoods.Id, + DeviceId = thisDevice?.Id, + GoodsId = thisGoods?.Id, Id = Guid.NewGuid().ToString(), Position1 = item.Position1, Position2 = item.Position2, @@ -836,13 +840,14 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services var thisName = goodTechnologyModel[i].Name == null ? cName : goodTechnologyModel[i].Name; - var data = await _db.Queryable() - .Where(x => x.Name == thisName && x.DeviceVersionKey == device.ProductVersionId).FirstAsync(); - - var data2 = await _db.Queryable() - .Where(x => x.ActionName == goodTechnologyModel[i].Configuration && x.ProductFunctionId == data.Id).FirstAsync(); - - + var data = await _db.Queryable() + .Where(x => x.Name == thisName && x.DeviceVersionId == device.ProductVersionId).FirstAsync(); + var data2 = new BPA_TechnologyAction(); + if (data != null) + { + data2 = await _db.Queryable() + .Where(x => x.ActionName == goodTechnologyModel[i].Configuration && x.TechnologyId == data.Id).FirstAsync(); + } var batching = new BPA_Batching(); var IsBatch = goodTechnologyModel[i].Name != "液体料"; @@ -905,8 +910,8 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services { var v1 = json.FirstOrDefault(x => x.actionName == "主料名称"); var v2 = deviceGoodsPosition.FirstOrDefault(x => x.GoodsName == name2 && x.DeviceName == name1); - var jsondb = await _db.Queryable() - .Where(x => x.ProductFunctionId == thisItem.ChnologyId) + var jsondb = await _db.Queryable() + .Where(x => x.TechnologyId == thisItem.ChnologyId) .ToListAsync(); foreach (var item in from item in jsondb let insertableJsondb = json.FirstOrDefault(x => x.technologyactionId == item.Id) where insertableJsondb == null select item) @@ -915,7 +920,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services { actionName = item.ActionName, actionValue = item.ActionName == "主料重量" ? "0" : item.ActionValue, - chnologyId = item.ProductFunctionId, + chnologyId = item.TechnologyId, index = thisItem.Index, technologyactionId = item.Id @@ -978,11 +983,13 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services } if (value.ToString().Trim() == goodsName.Trim()) { - if (item2.IsDefined(typeof(ColumnAttribute), false)) - { - ColumnAttribute attribute = (ColumnAttribute)item2.GetCustomAttribute(typeof(ColumnAttribute), false); - return attribute.Name; - } + ColumnAttribute attribute = (ColumnAttribute)item2.GetCustomAttribute(typeof(ColumnAttribute), false); + return attribute?.Name; + //if (item2.IsDefined(typeof(ColumnAttribute), false)) + //{ + // ColumnAttribute attribute = (ColumnAttribute)item2.GetCustomAttribute(typeof(ColumnAttribute), false); + // return attribute.Name; + //} } } return ""; diff --git a/BPA.SAAS.Manage.Application/Device/Dtos/ProductFunction/ProductFunctionBaseDto.cs b/BPA.SAAS.Manage.Application/Device/Dtos/ProductFunction/ProductFunctionBaseDto.cs index 722d07f..4f9ed45 100644 --- a/BPA.SAAS.Manage.Application/Device/Dtos/ProductFunction/ProductFunctionBaseDto.cs +++ b/BPA.SAAS.Manage.Application/Device/Dtos/ProductFunction/ProductFunctionBaseDto.cs @@ -58,5 +58,6 @@ namespace BPA.SAAS.Manage.Application.Device.Dtos.ProductFunction /// public string Description { get; set; } public string ProductId { get; set; } + public string DataJson { get; set; } } } diff --git a/BPA.SAAS.Manage.Application/Device/Services/ProductFunctionService.cs b/BPA.SAAS.Manage.Application/Device/Services/ProductFunctionService.cs index ad21bff..1ce9470 100644 --- a/BPA.SAAS.Manage.Application/Device/Services/ProductFunctionService.cs +++ b/BPA.SAAS.Manage.Application/Device/Services/ProductFunctionService.cs @@ -4,6 +4,7 @@ using BPA.SAAS.Manage.Comm.Const; using BPA.SAAS.Manage.Comm.Enum; using BPA.SAAS.Manage.Core.Base; using BPA.SAAS.Manage.Core.Product; +using Newtonsoft.Json; using NPOI.POIFS.Crypt.Dsig; using NPOI.Util; using System; @@ -45,6 +46,7 @@ namespace BPA.SAAS.Manage.Application.Device.Services x.Id, x.ForeignKeyRe, x.DeviceVersionKey, + x.DataJson, DeviceTypeKey = b.ProductId, Vesion = b.Vesion, CreateAt=x.CreateAt, @@ -58,6 +60,7 @@ namespace BPA.SAAS.Manage.Application.Device.Services BoolLabel = x.BoolLabel, ReadWrite = x.ReadWrite, Description= x.Description, + }) .ToPageListAsync(inputDto.Current, inputDto.PageSize, total); return new PageUtil() @@ -99,6 +102,10 @@ namespace BPA.SAAS.Manage.Application.Device.Services } else { + if (!string.IsNullOrWhiteSpace(inputDto.DataJson)) + { + if (!IsValidJson(inputDto.DataJson.Replace("\n", ""))) throw Oops.Oh("json字符格式不正确"); + } var res =await _db.Insertable(new BPA_ProductFunction() { Id = Guid.NewGuid().ToString(), @@ -119,6 +126,7 @@ namespace BPA.SAAS.Manage.Application.Device.Services ReadWrite = inputDto.ReadWrite, Description=inputDto.Description, ProductId= inputDto.ProductId, + DataJson= inputDto.DataJson?.Replace("\n",""), }).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); return res > 0; } @@ -132,6 +140,10 @@ namespace BPA.SAAS.Manage.Application.Device.Services { var check = _db.Queryable().Any(a => a.Id != inputDto.Id && a.Name == inputDto.Name); if (check) throw Oops.Oh("功能名称已存在"); + if (!string.IsNullOrWhiteSpace(inputDto.DataJson)) + { + if(!IsValidJson(inputDto.DataJson.Replace("\n", ""))) throw Oops.Oh("json字符格式不正确"); + } var data = _db.Queryable().Where(a => a.Id == inputDto.Id).First(); data.Name = inputDto.Name; data.DeviceVersionKey = inputDto.DeviceVersionKey; @@ -145,6 +157,7 @@ namespace BPA.SAAS.Manage.Application.Device.Services data.BoolLabel = inputDto.BoolLabel; data.ReadWrite = inputDto.ReadWrite; data.Description= inputDto.Description; + data.DataJson= inputDto.DataJson?.Replace("\n", ""); data.Status = (CommonStatus)Enum.ToObject(typeof(CommonStatus), inputDto.Status); var res =await _db.Updateable(data).ExecuteCommandAsync(); return res > 0; @@ -252,5 +265,19 @@ namespace BPA.SAAS.Manage.Application.Device.Services return res > 0; } #endregion + + private bool IsValidJson(string jsonString) + { + try + { + JsonConvert.DeserializeObject(jsonString); + return true; + } + catch (Exception ex) + { + Console.WriteLine("Invalid JSON string: " + ex.Message); + return false; + } + } } } diff --git a/BPA.SAAS.Manage.Core/Product/BPA_ProductFunction.cs b/BPA.SAAS.Manage.Core/Product/BPA_ProductFunction.cs index bfd81fa..2c5e8b1 100644 --- a/BPA.SAAS.Manage.Core/Product/BPA_ProductFunction.cs +++ b/BPA.SAAS.Manage.Core/Product/BPA_ProductFunction.cs @@ -76,5 +76,6 @@ namespace BPA.SAAS.Manage.Core.Product /// public string Description { get; set; } public string ProductId { get; set; } + public string DataJson { get; set; } } }