diff --git a/BPA.SAAS.Manage.Application/Device/Dtos/ProductFunction/ProductFunctionPageBase.cs b/BPA.SAAS.Manage.Application/Device/Dtos/ProductFunction/ProductFunctionPageBase.cs index 4ababf4..52766b4 100644 --- a/BPA.SAAS.Manage.Application/Device/Dtos/ProductFunction/ProductFunctionPageBase.cs +++ b/BPA.SAAS.Manage.Application/Device/Dtos/ProductFunction/ProductFunctionPageBase.cs @@ -14,7 +14,8 @@ namespace BPA.SAAS.Manage.Application.Device.Dtos.ProductFunction public string Name { get; set; } public string Type { get; set; } public string Vesion { get; set; } - public string DeviceTypeKey { get; set; } + public string ProductVesionId { get; set; } + public string ProductId { get; set; } public CommonStatus? Status { get; set; } } } diff --git a/BPA.SAAS.Manage.Application/Device/Dtos/ProductTopics/ProductTopicsBaseDto.cs b/BPA.SAAS.Manage.Application/Device/Dtos/ProductTopics/ProductTopicsBaseDto.cs index c41fb8a..7b86dc3 100644 --- a/BPA.SAAS.Manage.Application/Device/Dtos/ProductTopics/ProductTopicsBaseDto.cs +++ b/BPA.SAAS.Manage.Application/Device/Dtos/ProductTopics/ProductTopicsBaseDto.cs @@ -22,5 +22,6 @@ namespace BPA.SAAS.Manage.Application.Device.Dtos.ProductTopics /// public string Description { get; set; } public string ProductId { get; set; } + public string ProductVesionId { get; set; } } } diff --git a/BPA.SAAS.Manage.Application/Device/Dtos/ProductTopics/ProductTopicsQueryInputDto.cs b/BPA.SAAS.Manage.Application/Device/Dtos/ProductTopics/ProductTopicsQueryInputDto.cs index bc8c553..f203efb 100644 --- a/BPA.SAAS.Manage.Application/Device/Dtos/ProductTopics/ProductTopicsQueryInputDto.cs +++ b/BPA.SAAS.Manage.Application/Device/Dtos/ProductTopics/ProductTopicsQueryInputDto.cs @@ -10,6 +10,9 @@ namespace BPA.SAAS.Manage.Application.Device.Dtos.ProductTopics public class ProductTopicsQueryInputDto : PageInputBase { public int? TopicsType { get; set; } + public string Topics { get; set; } public string ProductId { get; set; } + public string ProductVesionId { get; set; } + public bool IsDefault { get; set; } } } diff --git a/BPA.SAAS.Manage.Application/Device/Services/DeviceVesionService.cs b/BPA.SAAS.Manage.Application/Device/Services/DeviceVesionService.cs index 1617bb9..2cede9e 100644 --- a/BPA.SAAS.Manage.Application/Device/Services/DeviceVesionService.cs +++ b/BPA.SAAS.Manage.Application/Device/Services/DeviceVesionService.cs @@ -5,6 +5,7 @@ using BPA.SAAS.Manage.Comm.Enum; using BPA.SAAS.Manage.Core.Base; using BPA.SAAS.Manage.Core.Device; using BPA.SAAS.Manage.Core.Product; +using Microsoft.AspNetCore.Server.IISIntegration; using System; using System.Collections.Generic; using System.Linq; @@ -55,14 +56,57 @@ namespace BPA.SAAS.Manage.Application.Device.Services public async Task AddDeviceVesionAsync(DeviceVesionBaseDto inputDto) { - var res = await _db.Insertable(new BPA_ProductVesion + try { - Vesion = inputDto.Vesion, - ProductId = inputDto.ProductId, - TemplatePath = inputDto.TemplatePath, - Status = CommonStatus.ENABLE - }).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); - return res > 0; + _db.Ado.BeginTran(); + var res = await _db.Insertable(new BPA_ProductVesion + { + Vesion = inputDto.Vesion, + ProductId = inputDto.ProductId, + TemplatePath = inputDto.TemplatePath, + Status = CommonStatus.ENABLE + }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); + var Product = _db.Queryable().Where(x => x.Id == inputDto.ProductId).First(); + List list = new(); + var goodspushtopics = new BPA_ProductTopics() + { + Topics = " /" + Product.Key + "/" + inputDto.Vesion + "/${deviceKey}/defaul/goodspush", + TopicsType = 2, + Description = "商品数据下发", + ProductId = inputDto.ProductId, + ProductVesionId = res.Id, + IsDefault = true + }; + var batchingpushtopics = new BPA_ProductTopics() + { + Topics = " /" + Product.Key + "/" + inputDto.Vesion + "/${deviceKey}/defaul/batvhingpush", + TopicsType = 2, + Description = "物料数据下发", + ProductId = inputDto.ProductId, + ProductVesionId = res.Id, + IsDefault = true + }; + var chnologypushtopics = new BPA_ProductTopics() + { + Topics = " /" + Product.Key + "/" + inputDto.Vesion + "/${deviceKey}/defaul/chnologypush", + TopicsType = 2, + Description = "工艺数据下发", + ProductId = inputDto.ProductId, + ProductVesionId = res.Id, + IsDefault = true + }; + list.Add(goodspushtopics); + list.Add(batchingpushtopics); + list.Add(chnologypushtopics); + await _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); + _db.Ado.CommitTran(); + return res != null; + } + catch (Exception e) + { + _db.Ado.RollbackTran(); + throw Oops.Oh("添加失败,失败信息:"+e.Message); + } } /// /// 删除 @@ -71,16 +115,35 @@ namespace BPA.SAAS.Manage.Application.Device.Services /// public async Task DelDeviceVesionAsync(List inputList) { - var data = await _db.Queryable().Where(x => inputList.Contains(x.ProductVersionId)).ToListAsync(); - if (data.Count > 0) + try { - throw Oops.Oh("当前设备类型已使用,无法删除"); - } - var datas = await _db.Queryable() - .Where(x => inputList.Contains(x.Id)) + _db.Ado.BeginTran(); + var data = await _db.Queryable().Where(x => inputList.Contains(x.ProductVersionId)).ToListAsync(); + if (data.Count > 0) + { + throw Oops.Oh("当前版本已有设备使用,无法删除"); + } + var datas = await _db.Queryable() + .Where(x => inputList.Contains(x.Id)) + .ToListAsync(); + var ProductFunctions = await _db.Queryable() + .Where(x => inputList.Contains(x.DeviceVersionKey)) + .ToListAsync(); + var ProductTopics = await _db.Queryable() + .Where(x => inputList.Contains(x.ProductVesionId)) .ToListAsync(); - _db.Deleteable(datas).ExecuteCommand(); - return true; + _db.Deleteable(ProductTopics).ExecuteCommand();//删除相关topic + _db.Deleteable(ProductFunctions).ExecuteCommand();//删除相关服务和功能 + var res=await _db.Deleteable(datas).ExecuteCommandAsync(); + _db.Ado.CommitTran(); + return res>0; + } + catch (Exception e) + { + _db.Ado.RollbackTran(); + throw Oops.Oh("删除失败,失败信息:"+e.Message); + } + } /// /// 修改 diff --git a/BPA.SAAS.Manage.Application/Device/Services/ProductFunctionService.cs b/BPA.SAAS.Manage.Application/Device/Services/ProductFunctionService.cs index 58293c5..74e537d 100644 --- a/BPA.SAAS.Manage.Application/Device/Services/ProductFunctionService.cs +++ b/BPA.SAAS.Manage.Application/Device/Services/ProductFunctionService.cs @@ -33,7 +33,7 @@ namespace BPA.SAAS.Manage.Application.Device.Services { RefAsync total = 0; var res = await _db.Queryable((x, b) => new JoinQueryInfos(JoinType.Left, b.Id == x.DeviceVersionKey)) - .Where((x,b)=>b.ProductId == inputDto.DeviceTypeKey) + .Where((x,b)=>x.ProductId == inputDto.ProductId && x.DeviceVersionKey== inputDto.ProductVesionId) .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Name), (x, b) => x.Name.Contains(inputDto.Name)) .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Type), (x, b) => x.Type==Convert.ToInt32(inputDto.Type)) .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Vesion), (x, b) => x.DeviceVersionKey == inputDto.Vesion) diff --git a/BPA.SAAS.Manage.Application/Device/Services/ProductTopicsService.cs b/BPA.SAAS.Manage.Application/Device/Services/ProductTopicsService.cs index d20652c..baf1846 100644 --- a/BPA.SAAS.Manage.Application/Device/Services/ProductTopicsService.cs +++ b/BPA.SAAS.Manage.Application/Device/Services/ProductTopicsService.cs @@ -29,8 +29,9 @@ namespace BPA.SAAS.Manage.Application.Device.Services public async Task GetProductTopicsPage(ProductTopicsQueryInputDto inputDto) { var total = new RefAsync(); - var data = await _db.Queryable().Where(x=>x.ProductId== inputDto.ProductId) + var data = await _db.Queryable().Where(x=>x.ProductId== inputDto.ProductId && x.ProductVesionId== inputDto.ProductVesionId && x.IsDefault== inputDto.IsDefault) .WhereIF(inputDto.TopicsType!=null, x => x.TopicsType==Convert.ToInt32(inputDto.TopicsType)) + .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Topics), x => x.Topics == inputDto.Topics) .OrderBy(x => x.CreateAt, OrderByType.Desc) .ToPageListAsync(inputDto.Current, inputDto.PageSize, total); diff --git a/BPA.SAAS.Manage.Core/Product/BPA_ProductTopics.cs b/BPA.SAAS.Manage.Core/Product/BPA_ProductTopics.cs index ebd30d9..95d7bb6 100644 --- a/BPA.SAAS.Manage.Core/Product/BPA_ProductTopics.cs +++ b/BPA.SAAS.Manage.Core/Product/BPA_ProductTopics.cs @@ -24,6 +24,10 @@ namespace BPA.SAAS.Manage.Core.Product /// public string Description { get; set; } public string ProductId { get; set; } - //public string GroupId { get; set; } + public string ProductVesionId { get; set; } + /// + /// 是否默认Topics + /// + public bool IsDefault { get; set; } } }