@@ -65,5 +65,31 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Enum | |||
/// </summary> | |||
[ErrorCodeItemMetadata("商品不存在")] | |||
Code1008, | |||
/// <summary> | |||
/// 场景id不能为空 | |||
/// </summary> | |||
[ErrorCodeItemMetadata("场景id不能为空")] | |||
Code1009, | |||
/// <summary> | |||
/// 产品不存在 | |||
/// </summary> | |||
[ErrorCodeItemMetadata("产品不存在")] | |||
Code10010, | |||
/// <summary> | |||
/// 产品版本不存在 | |||
/// </summary> | |||
[ErrorCodeItemMetadata("产品版本不存在")] | |||
Code10011, | |||
/// <summary> | |||
/// 设备不存在 | |||
/// </summary> | |||
[ErrorCodeItemMetadata("设备不存在")] | |||
Code10012, | |||
/// <summary> | |||
/// 产品标签不存在 | |||
/// </summary> | |||
[ErrorCodeItemMetadata("产品标签不存在")] | |||
Code10013, | |||
} | |||
} |
@@ -0,0 +1,62 @@ | |||
using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos; | |||
using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Services; | |||
using BPA.SAAS.Manage.Core.Base; | |||
using Microsoft.AspNetCore.Components.Forms; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device | |||
{ | |||
[ApiDescriptionSettings("开放平台", Tag = "设备管理"), AllowAnonymous] | |||
public class DeviceServices:IDynamicApiController | |||
{ | |||
IDeviceService _deviceService; | |||
public DeviceServices(IDeviceService deviceService) | |||
{ | |||
_deviceService= deviceService; | |||
} | |||
/// <summary> | |||
/// 分页查询 | |||
/// </summary> | |||
/// <param name="inputDto"></param> | |||
/// <returns></returns> | |||
[HttpPost("/api/ExternalPlatform/Device/GetDevicePageList")] | |||
public async Task<PageUtil<List<DeviceDto>>> GetDevicePageList(DevicePageInputDto inputDto) | |||
{ | |||
return await _deviceService.GetDevicePageList(inputDto); | |||
} | |||
/// <summary> | |||
/// 添加 | |||
/// </summary> | |||
/// <param name="dto"></param> | |||
/// <returns></returns> | |||
[HttpPost("/api/ExternalPlatform/Device/AddDevice")] | |||
public async Task<bool> AddDevice(DeviceInsertDto dto) | |||
{ | |||
return await _deviceService.AddDevice(dto); | |||
} | |||
/// <summary> | |||
/// 更新 | |||
/// </summary> | |||
/// <param name="dto"></param> | |||
/// <returns></returns> | |||
[HttpPost("/api/ExternalPlatform/Device/UpdateDevice")] | |||
public async Task<bool> UpdateDevice(DeviceUpateDto dto) | |||
{ | |||
return await _deviceService.UpdateDevice(dto); | |||
} | |||
/// <summary> | |||
/// 删除 | |||
/// </summary> | |||
/// <param name="ids"></param> | |||
/// <returns></returns> | |||
[HttpPost("/api/ExternalPlatform/Device/DeleteDevice")] | |||
public async Task<bool> DeleteDevice(string[] ids) | |||
{ | |||
return await _deviceService.DeleteDevice(ids); | |||
} | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
using BPA.SAAS.Manage.Core.Device; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos | |||
{ | |||
public class DeviceDto: BPA_DeviceInfo | |||
{ | |||
public string ProductName { get; set; } | |||
public string ProductVesion { get; set; } | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
using BPA.SAAS.Manage.Comm.Enum; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos | |||
{ | |||
public class DeviceInsertDto | |||
{ | |||
/// <summary> | |||
/// 设备名称 | |||
/// </summary> | |||
public string DeviceName { get; set; } | |||
/// <summary> | |||
/// 设备标签 | |||
/// </summary> | |||
public string DeviceTypeId { get; set; } | |||
/// <summary> | |||
///归属场景(店铺) | |||
/// </summary> | |||
public string StopId { get; set; } | |||
/// <summary> | |||
/// 所属产品 | |||
/// </summary> | |||
public string ProductId { get; set; } | |||
/// <summary> | |||
/// 产品标签 | |||
/// </summary> | |||
public string ProductCode { get; set; } | |||
/// <summary> | |||
/// 产品版本 | |||
/// </summary> | |||
public string ProductVersionId { get; set; } | |||
} | |||
} |
@@ -0,0 +1,56 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos | |||
{ | |||
public class DevicePageInputDto | |||
{ | |||
public string ProductName { get; set; } | |||
public string ProductVesion { get; set; } | |||
/// <summary> | |||
/// 当前页码 | |||
/// </summary> | |||
private int current; | |||
public virtual int Current | |||
{ | |||
get | |||
{ | |||
return current; | |||
} | |||
set | |||
{ | |||
current = value; | |||
if (current <= 0) | |||
{ | |||
current = 1; | |||
} | |||
} | |||
} | |||
//public int? Status { get; set; } | |||
/// <summary> | |||
/// 页码容量 | |||
/// </summary> | |||
private int pagesize; | |||
public virtual int PageSize | |||
{ | |||
get | |||
{ | |||
return pagesize; | |||
} | |||
set | |||
{ | |||
pagesize = value; | |||
if (pagesize <= 0) | |||
{ | |||
pagesize = 10; | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos | |||
{ | |||
public class DeviceUpateDto | |||
{ | |||
public string Id { get; set; } | |||
/// <summary> | |||
/// 设备名称 | |||
/// </summary> | |||
public string DeviceName { get; set; } | |||
/// <summary> | |||
/// 设备标签 | |||
/// </summary> | |||
public string DeviceTypeId { get; set; } | |||
/// <summary> | |||
///归属场景(店铺) | |||
/// </summary> | |||
public string StopId { get; set; } | |||
/// <summary> | |||
/// 所属产品 | |||
/// </summary> | |||
public string ProductId { get; set; } | |||
/// <summary> | |||
/// 产品标签 | |||
/// </summary> | |||
public string ProductCode { get; set; } | |||
/// <summary> | |||
/// 产品版本 | |||
/// </summary> | |||
public string ProductVersionId { get; set; } | |||
} | |||
} |
@@ -0,0 +1,181 @@ | |||
using BPA.KitChen.GroupMeal.SqlSugar; | |||
using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; | |||
using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; | |||
using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos; | |||
using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos; | |||
using BPA.SAAS.Manage.Comm.Const; | |||
using BPA.SAAS.Manage.Core.Base; | |||
using BPA.SAAS.Manage.Core.DataBase; | |||
using BPA.SAAS.Manage.Core.Device; | |||
using BPA.SAAS.Manage.Core.Product; | |||
using Furion.DependencyInjection; | |||
using Furion.RemoteRequest.Extensions; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Services | |||
{ | |||
public class DeviceService: UserAnalysis, IDeviceService, ITransient | |||
{ | |||
private string BaseServerUrl = App.GetConfig<string>("baseurl"); | |||
/// <summary> | |||
/// 分页查询 | |||
/// </summary> | |||
/// <param name="inputDto"></param> | |||
/// <returns></returns> | |||
public async Task<PageUtil<List<DeviceDto>>> GetDevicePageList(DevicePageInputDto inputDto) | |||
{ | |||
int total = new RefAsync<int>(); | |||
var data =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)) | |||
.WhereIF(!string.IsNullOrEmpty(inputDto.ProductName), (a, b, c) => b.Name.Contains(inputDto.ProductName)) | |||
.WhereIF(!string.IsNullOrEmpty(inputDto.ProductVesion), (a, b, c) => c.Vesion.Contains(inputDto.ProductVesion)) | |||
.Select((a, b, c) => new DeviceDto() | |||
{ | |||
Id = a.Id.SelectAll(), | |||
ProductName = b.Name, | |||
ProductVesion = c.Vesion | |||
}).ToPageListAsync(inputDto.Current, inputDto.PageSize, total); | |||
return new PageUtil<List<DeviceDto>>() | |||
{ | |||
Total = total, | |||
Data = data | |||
}; | |||
} | |||
/// <summary> | |||
/// 添加 | |||
/// </summary> | |||
/// <param name="dto"></param> | |||
/// <returns></returns> | |||
public async Task<bool> AddDevice(DeviceInsertDto dto) | |||
{ | |||
try | |||
{ | |||
SqlSugarDb.Db.BeginTran(); | |||
var resEntity = new BPA_DeviceInfo(); | |||
resEntity.DeviceName = dto.DeviceName; | |||
await CheckInsertParm(dto);//验证参数 | |||
resEntity.StopId = dto.StopId; | |||
resEntity.ProductId = dto.ProductId; | |||
resEntity.ProductVersionId = dto.ProductVersionId; | |||
if (string.IsNullOrWhiteSpace(dto.ProductCode)) | |||
{ | |||
var check = SqlSugarDb.Db.Queryable<BPA_DeviceType>().Where(x => x.Name == "默认标签").First(); | |||
if (check != null) | |||
{ | |||
resEntity.DeviceTypeId = check.Id; | |||
} | |||
else | |||
{ | |||
var DeviceType = await SqlSugarDb.Db.Insertable(new BPA_DeviceType() { Name = "默认标签" }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); | |||
resEntity.DeviceTypeId = DeviceType.Id; | |||
} | |||
} | |||
var res = await SqlSugarDb.Db.Insertable(resEntity).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); | |||
SqlSugarDb.Db.CommitTran(); | |||
return res > 0; | |||
} | |||
catch (Exception) | |||
{ | |||
SqlSugarDb.Db.RollbackTran(); | |||
throw Oops.Oh(ErrorCodeEnum.Code1007); | |||
} | |||
} | |||
/// <summary> | |||
/// 更新 | |||
/// </summary> | |||
/// <param name="dto"></param> | |||
/// <returns></returns> | |||
public async Task<bool>UpdateDevice(DeviceUpateDto dto) | |||
{ | |||
var resEntity = SqlSugarDb.Db.Queryable<BPA_DeviceInfo>().Where(it => it.IsDeleted == 0).First(it => it.Id == dto.Id); | |||
await CheckUpdateParm(dto);//验证参数 | |||
resEntity.DeviceName = dto.DeviceName; | |||
resEntity.StopId = dto.StopId; | |||
resEntity.ProductId = dto.ProductId; | |||
resEntity.ProductVersionId = dto.ProductVersionId; | |||
if (!string.IsNullOrWhiteSpace(dto.ProductCode)) | |||
{ | |||
var check = SqlSugarDb.Db.Queryable<BPA_DeviceType>().Where(x => x.Id == dto.ProductCode).First(); | |||
if (check != null) | |||
{ | |||
resEntity.DeviceTypeId = check.Id; | |||
} | |||
else | |||
{ | |||
throw Oops.Oh(ErrorCodeEnum.Code10013); | |||
} | |||
} | |||
else | |||
{ | |||
var check = SqlSugarDb.Db.Queryable<BPA_DeviceType>().Where(x => x.Name == "默认标签").First(); | |||
if (check != null) | |||
{ | |||
resEntity.DeviceTypeId = check.Id; | |||
} | |||
else | |||
{ | |||
var DeviceType = await SqlSugarDb.Db.Insertable(new BPA_DeviceType() { Name = "默认标签" }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); | |||
resEntity.DeviceTypeId = DeviceType.Id; | |||
} | |||
} | |||
var res = await SqlSugarDb.Db.Updateable(resEntity).ExecuteCommandAsync(); | |||
return res > 0; | |||
} | |||
/// <summary> | |||
/// 删除 | |||
/// </summary> | |||
/// <param name="ids"></param> | |||
/// <returns></returns> | |||
public async Task<bool> DeleteDevice(string[] ids) | |||
{ | |||
var model = SqlSugarDb.Db.Queryable<BPA_DeviceInfo>().Where(x => ids.Contains(x.Id)).ToList(); | |||
if (model == null) throw Oops.Oh(ErrorCodeEnum.Code10012); | |||
var res = await SqlSugarDb.Db.Deleteable(model).ExecuteCommandAsync(); | |||
return res > 0; | |||
} | |||
/// <summary> | |||
/// 校验参数 | |||
/// </summary> | |||
/// <param name="dto"></param> | |||
/// <returns></returns> | |||
private async Task CheckInsertParm(DeviceInsertDto dto) | |||
{ | |||
if (string.IsNullOrWhiteSpace(dto.StopId)) throw Oops.Oh(ErrorCodeEnum.Code1009); | |||
var getStopurl = BaseServerUrl + "api/store/getbyIdstorelist_alm?id=" + dto.StopId; | |||
var responseStop = await getStopurl.SetHeaders(new | |||
{ | |||
groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value | |||
}).SetHttpMethod(HttpMethod.Get).GetAsStringAsync(); | |||
var checkProduct = SqlSugarDb.Db.Queryable<BPA_Product>().Where(x => x.Id == dto.ProductId).Any(); | |||
if (!checkProduct) throw Oops.Oh(ErrorCodeEnum.Code10010); | |||
var checkProductVesion = SqlSugarDb.Db.Queryable<BPA_ProductVesion>().Where(x => x.Id == dto.ProductVersionId).Any(); | |||
if (!checkProductVesion) throw Oops.Oh(ErrorCodeEnum.Code10011); | |||
} | |||
/// <summary> | |||
/// 校验参数 | |||
/// </summary> | |||
/// <param name="dto"></param> | |||
/// <returns></returns> | |||
private async Task CheckUpdateParm(DeviceUpateDto dto) | |||
{ | |||
if (string.IsNullOrWhiteSpace(dto.StopId)) throw Oops.Oh(ErrorCodeEnum.Code1009); | |||
var getStopurl = BaseServerUrl + "api/store/getbyIdstorelist_alm?id=" + dto.StopId; | |||
var responseStop = await getStopurl.SetHeaders(new | |||
{ | |||
groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value | |||
}).SetHttpMethod(HttpMethod.Get).GetAsStringAsync(); | |||
var checkProduct = SqlSugarDb.Db.Queryable<BPA_Product>().Where(x => x.Id == dto.ProductId).Any(); | |||
if (!checkProduct) throw Oops.Oh(ErrorCodeEnum.Code10010); | |||
var checkProductVesion = SqlSugarDb.Db.Queryable<BPA_ProductVesion>().Where(x => x.Id == dto.ProductVersionId).Any(); | |||
if (!checkProductVesion) throw Oops.Oh(ErrorCodeEnum.Code10011); | |||
} | |||
} | |||
} |
@@ -0,0 +1,41 @@ | |||
using BPA.KitChen.GroupMeal.SqlSugar; | |||
using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; | |||
using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos; | |||
using BPA.SAAS.Manage.Core.Base; | |||
using BPA.SAAS.Manage.Core.Device; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Services | |||
{ | |||
public interface IDeviceService | |||
{ | |||
/// <summary> | |||
/// 分页查询 | |||
/// </summary> | |||
/// <param name="inputDto"></param> | |||
/// <returns></returns> | |||
Task<PageUtil<List<DeviceDto>>> GetDevicePageList(DevicePageInputDto inputDto); | |||
/// <summary> | |||
/// 添加 | |||
/// </summary> | |||
/// <param name="dto"></param> | |||
/// <returns></returns> | |||
Task<bool> AddDevice(DeviceInsertDto dto); | |||
/// <summary> | |||
/// 更新 | |||
/// </summary> | |||
/// <param name="dto"></param> | |||
/// <returns></returns> | |||
Task<bool> UpdateDevice(DeviceUpateDto dto); | |||
/// <summary> | |||
/// 删除 | |||
/// </summary> | |||
/// <param name="ids"></param> | |||
/// <returns></returns> | |||
Task<bool> DeleteDevice(string[] ids); | |||
} | |||
} |
@@ -8,7 +8,7 @@ | |||
} | |||
}, | |||
"AllowedHosts": "*", | |||
"baseurl": "http://localhost:5008/", | |||
"baseurl": "http://localhost:5007/", | |||
"ConnectionConfigs": [ | |||
{ | |||
"ConnectionString": "server=10.2.1.21;Database=bpa_kitchen_kitchenbasemanage;Uid=root;Pwd=cygadmin;Allow Zero Datetime=True;Convert Zero Datetime=True;", | |||