|
|
@@ -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<bool> 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<BPA_Product>().Where(x => x.Id == inputDto.ProductId).First(); |
|
|
|
List<BPA_ProductTopics> 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); |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 删除 |
|
|
@@ -71,16 +115,35 @@ namespace BPA.SAAS.Manage.Application.Device.Services |
|
|
|
/// <returns></returns> |
|
|
|
public async Task<bool> DelDeviceVesionAsync(List<string> inputList) |
|
|
|
{ |
|
|
|
var data = await _db.Queryable<BPA_DeviceInfo>().Where(x => inputList.Contains(x.ProductVersionId)).ToListAsync(); |
|
|
|
if (data.Count > 0) |
|
|
|
try |
|
|
|
{ |
|
|
|
throw Oops.Oh("当前设备类型已使用,无法删除"); |
|
|
|
} |
|
|
|
var datas = await _db.Queryable<BPA_ProductVesion>() |
|
|
|
.Where(x => inputList.Contains(x.Id)) |
|
|
|
_db.Ado.BeginTran(); |
|
|
|
var data = await _db.Queryable<BPA_DeviceInfo>().Where(x => inputList.Contains(x.ProductVersionId)).ToListAsync(); |
|
|
|
if (data.Count > 0) |
|
|
|
{ |
|
|
|
throw Oops.Oh("当前版本已有设备使用,无法删除"); |
|
|
|
} |
|
|
|
var datas = await _db.Queryable<BPA_ProductVesion>() |
|
|
|
.Where(x => inputList.Contains(x.Id)) |
|
|
|
.ToListAsync(); |
|
|
|
var ProductFunctions = await _db.Queryable<BPA_ProductFunction>() |
|
|
|
.Where(x => inputList.Contains(x.DeviceVersionKey)) |
|
|
|
.ToListAsync(); |
|
|
|
var ProductTopics = await _db.Queryable<BPA_ProductTopics>() |
|
|
|
.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); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 修改 |
|
|
|