Ver código fonte

提交

master
gwbvipvip 8 meses atrás
pai
commit
319c518e2e
19 arquivos alterados com 946 adições e 2 exclusões
  1. +16
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResponDataBase.cs
  2. +36
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs
  3. +62
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/DeviceServices.cs
  4. +15
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceDto.cs
  5. +38
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceInsertDto.cs
  6. +56
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DevicePageInputDto.cs
  7. +38
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceUpateDto.cs
  8. +21
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/StopDto.cs
  9. +196
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/DeviceService.cs
  10. +41
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/IDeviceService.cs
  11. +15
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsDto.cs
  12. +40
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsInsertDto.cs
  13. +57
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsPageInputDto.cs
  14. +41
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsUpdateDto.cs
  15. +64
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs
  16. +170
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs
  17. +38
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/IGoodsService.cs
  18. +1
    -1
      BPA.SAAS.Manage.Web.Entry/Properties/launchSettings.json
  19. +1
    -1
      BPA.SAAS.Manage.Web.Entry/appsettings.json

+ 16
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResponDataBase.cs Ver arquivo

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto
{
public class ResponDataBase
{
public string statusCode { get; set; }
public object data { get; set; }
public string succeeded { get; set; }
public string errors { get; set; }
}
}

+ 36
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs Ver arquivo

@@ -55,6 +55,42 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Enum
/// </summary> /// </summary>
[ErrorCodeItemMetadata("签名过期")] [ErrorCodeItemMetadata("签名过期")]
Code1006, Code1006,
/// <summary>
/// 系统异常
/// </summary>
[ErrorCodeItemMetadata("系统异常")]
Code1007,
/// <summary>
/// 商品不存在
/// </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,



/// <summary> /// <summary>
/// 授权过期 /// 授权过期


+ 62
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/DeviceServices.cs Ver arquivo

@@ -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);
}
}
}

+ 15
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceDto.cs Ver arquivo

@@ -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; }
}
}

+ 38
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceInsertDto.cs Ver arquivo

@@ -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; }
}
}

+ 56
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DevicePageInputDto.cs Ver arquivo

@@ -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;
}
}
}
}
}

+ 38
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceUpateDto.cs Ver arquivo

@@ -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; }
}
}

+ 21
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/StopDto.cs Ver arquivo

@@ -0,0 +1,21 @@
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 StopDto
{
public string Id { get; set; }
public string Name { get; set; }
public string OrgId { get; set; }
public string OrgName { get; set; }
public string Phone { get; set; }
public int Sort { get; set; }
public string Description { get; set; }
public string GroupId { get; set; }
public DateTime CreateAt { get; set; }
}
}

+ 196
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/DeviceService.cs Ver arquivo

@@ -0,0 +1,196 @@
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.Application.DataBase.Dtos.GoodsAttribute;
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 Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ResponDataBase = BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto.ResponDataBase;

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 resStop = JsonConvert.DeserializeObject<ResponDataBase>(responseStop);
if (resStop.statusCode != "200") throw Oops.Oh("获取场景数据失败");
var dataStop = JsonConvert.DeserializeObject<List<StopDto>>(resStop.data.ToString());
if (dataStop.Count==0) throw Oops.Oh("获取场景数据失败");
if(!dataStop.Where(x=>x.Id == dto.StopId).Any()) throw Oops.Oh("场景不存在");

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 resStop = JsonConvert.DeserializeObject<ResponDataBase>(responseStop);
if (resStop.statusCode != "200") throw Oops.Oh("获取场景数据失败");
var dataStop = JsonConvert.DeserializeObject<List<StopDto>>(resStop.data.ToString());
if (dataStop.Count == 0) throw Oops.Oh("获取场景数据失败");
if (!dataStop.Where(x => x.Id == dto.StopId).Any()) throw Oops.Oh("场景不存在");

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);
}
}
}

+ 41
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/IDeviceService.cs Ver arquivo

@@ -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);
}
}

+ 15
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsDto.cs Ver arquivo

@@ -0,0 +1,15 @@
using BPA.SAAS.Manage.Core.DataBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos
{
public class GoodsDto:BPA_GoodsInfo
{
public string GoodsTypeName { get; set; }
public string GoodsUnitName { get; set; }
}
}

+ 40
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsInsertDto.cs Ver arquivo

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos
{
public class GoodsInsertDto
{
/// <summary>
/// 商品名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Descritption { get; set; }
/// <summary>
/// 图片
/// </summary>
public string ImgUrl { get; set; }
/// <summary>
/// 价格
/// </summary>
public decimal Price { get; set; }
/// <summary>
/// 是否称重
/// </summary>
public bool IsWeigh { get; set; }
/// <summary>
/// 商品分类id
/// </summary>
public string GoodsTypeId { get; set; }
/// <summary>
/// 商品单位id
/// </summary>
public string GoodsUintId { get; set; }
}
}

+ 57
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsPageInputDto.cs Ver arquivo

@@ -0,0 +1,57 @@
using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto;
using BPA.SAAS.Manage.Core.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos
{
public class GoodsPageInputDto
{
public string GoodsTypeName { 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;
}
}
}
}
}

+ 41
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsUpdateDto.cs Ver arquivo

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos
{
public class GoodsUpdateDto
{
public string Id { get; set; }
/// <summary>
/// 商品名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Descritption { get; set; }
/// <summary>
/// 图片
/// </summary>
public string ImgUrl { get; set; }
/// <summary>
/// 价格
/// </summary>
public decimal Price { get; set; }
/// <summary>
/// 是否称重
/// </summary>
public bool IsWeigh { get; set; }
/// <summary>
/// 商品分类id
/// </summary>
public string GoodsTypeId { get; set; }
/// <summary>
/// 商品单位id
/// </summary>
public string GoodsUintId { get; set; }
}
}

+ 64
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs Ver arquivo

@@ -0,0 +1,64 @@
using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos;
using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Services;
using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.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.Goods
{
[ApiDescriptionSettings("开放平台", Tag = "商品管理"), AllowAnonymous]
public class GoodsServices: IDynamicApiController
{
private readonly IGoodsService _goodsService;
public GoodsServices(IGoodsService goodsService)
{
_goodsService = goodsService;
}

/// <summary>
/// 分页查询商品
/// </summary>
/// <param name="inputDto"></param>
/// <returns></returns>
[HttpPost("/api/ExternalPlatform/Goods/GetGoodsPageList")]
public async Task<PageUtil<List<GoodsDto>>> GetGoodsPageList(GoodsPageInputDto inputDto)
{
return await _goodsService.GetGoodsPageList(inputDto);
}
/// <summary>
/// 添加商品
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
[HttpPost("/api/ExternalPlatform/Goods/AddGoods")]
public async Task<bool> AddGoods(GoodsInsertDto dto)
{
return await _goodsService.AddGoods(dto);
}
/// <summary>
/// 更新商品
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
[HttpPost("/api/ExternalPlatform/Goods/UpdateGoods")]
public async Task<bool> UpdateGoods(GoodsUpdateDto dto)
{
return await _goodsService.UpdateGoods(dto);
}
/// <summary>
/// 删除商品
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
[HttpPost("/api/ExternalPlatform/Goods/DeleteGoods")]
public async Task<bool> DeleteGoods(string[] ids)
{
return await _goodsService.DeleteGoods(ids);
}
}
}

+ 170
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs Ver arquivo

@@ -0,0 +1,170 @@
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.Goods.Dtos;
using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Dtos;
using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Services;
using BPA.SAAS.Manage.Application.DataBase.Interface;
using BPA.SAAS.Manage.Comm.Enum;
using BPA.SAAS.Manage.Core.Base;
using BPA.SAAS.Manage.Core.DataBase;
using Org.BouncyCastle.Crypto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Services
{
public class GoodsService: UserAnalysis, IGoodsService, ITransient
{
public GoodsService()
{

}
/// <summary>
/// 分页查询商品
/// </summary>
/// <param name="inputDto"></param>
/// <returns></returns>
public async Task<PageUtil<List<GoodsDto>>> GetGoodsPageList(GoodsPageInputDto inputDto)
{
int total = new RefAsync<int>();
var data = SqlSugarDb.Db.Queryable<BPA_GoodsInfo, BPA_GoodsType, BPA_GoodsUint>((a, b, c) =>
new JoinQueryInfos(JoinType.Left, a.GoodsTypeId == b.Id,
JoinType.Left, a.GoodsUintId == c.Id))
.Where((a, b, c) => a.IsDeleted == 0)
.WhereIF(!string.IsNullOrEmpty(inputDto.GoodsTypeName), (a, b, c) => b.Name.Contains(inputDto.GoodsTypeName))
.Select((a, b, c) => new GoodsDto()
{
Id =a.Id.SelectAll() ,
GoodsTypeName=b.Name,
GoodsUnitName=c.Name

}).ToPageList(inputDto.Current, inputDto.PageSize, ref total);

return new PageUtil<List<GoodsDto>>()
{
Total = total,
Data = data
};
}
/// <summary>
/// 添加商品
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
public async Task<bool> AddGoods(GoodsInsertDto dto)
{
try
{
SqlSugarDb.Db.BeginTran();
var resEntity = new BPA_GoodsInfo();
resEntity.GoodsTypeId = dto.GoodsTypeId;
resEntity.GoodsUintId = dto.GoodsUintId;
if (string.IsNullOrWhiteSpace(dto.GoodsTypeId))
{
var check=SqlSugarDb.Db.Queryable<BPA_GoodsType>().Where(x => x.Name == "默认分类").First();
if (check!=null)
{
resEntity.GoodsTypeId = check.Id;
}
else
{
var GoodsType=await SqlSugarDb.Db.Insertable(new BPA_GoodsType() { Pid="",Name= "默认分类" }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
resEntity.GoodsTypeId = GoodsType.Id;
}
}
if (string.IsNullOrWhiteSpace(dto.GoodsUintId))
{
var check = SqlSugarDb.Db.Queryable<BPA_GoodsUint>().Where(x => x.Name == "默认单位").First();
if (check != null)
{
resEntity.GoodsTypeId = check.Id;
}
else
{
var GoodsUint = await SqlSugarDb.Db.Insertable(new BPA_GoodsUint() {Name = "默认单位" }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
resEntity.GoodsUintId = GoodsUint.Id;
}
}
resEntity.Name = dto.Name;
resEntity.Descritption = dto.Descritption;
resEntity.ImgUrl = dto.ImgUrl;
resEntity.Price = dto.Price;
resEntity.IsWeigh = dto.IsWeigh;
resEntity.IsAttrubute = true;
resEntity.Code = GetNumber2(8);
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> UpdateGoods(GoodsUpdateDto dto)
{
// 查询数据库中是否存在未删除的商品类型
var resEntity = SqlSugarDb.Db.Queryable<BPA_GoodsInfo>().Where(it => it.IsDeleted == 0).First(it => it.Id == dto.Id);
if (null == resEntity)
{
throw Oops.Oh(ErrorCodeEnum.Code1008);
}
resEntity.GoodsTypeId = dto.GoodsTypeId;
resEntity.Name = dto.Name;
resEntity.Descritption = dto.Descritption;
resEntity.ImgUrl = dto.ImgUrl;
resEntity.Price = dto.Price;
resEntity.IsWeigh = dto.IsWeigh;
resEntity.GoodsUintId = dto.GoodsUintId;
var res = await SqlSugarDb.Db.Updateable(resEntity).ExecuteCommandAsync();
return res > 0;
}
/// <summary>
/// 删除商品
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public async Task<bool> DeleteGoods(string[] ids)
{
try
{
SqlSugarDb.Db.BeginTran();
var goods = SqlSugarDb.Db.Queryable<BPA_GoodsInfo>().Where(x => ids.Contains(x.Id)).ToList();
if (goods == null) throw Oops.Oh(ErrorCodeEnum.Code1008);
var goodsbom = SqlSugarDb.Db.Queryable<BPA_GoodsBom>().Where(x => ids.Contains( x.Goods_Id)).ToList();
var goodsTechnology = SqlSugarDb.Db.Queryable<BPA_GoodsTechnologyAction>().Where(x => ids.Contains(x.GoodsId)).ToList();
await SqlSugarDb.Db.Deleteable(goodsbom).ExecuteCommandAsync();
await SqlSugarDb.Db.Deleteable(goodsTechnology).ExecuteCommandAsync();
var res = await SqlSugarDb.Db.Deleteable(goods).ExecuteCommandAsync();
SqlSugarDb.Db.CommitTran();
return res > 0;
}
catch (Exception)
{
SqlSugarDb.Db.RollbackTran();
throw Oops.Oh("删除失败");
}

}
private string GetNumber2(int Length = 10)
{
byte[] buffer = Guid.NewGuid().ToByteArray();
var ram = BitConverter.ToInt64(buffer, 0);
var str = string.Format("{0}", ram.ToString().Substring(0, Length));
return str;
}
}
}

+ 38
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/IGoodsService.cs Ver arquivo

@@ -0,0 +1,38 @@
using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos;
using BPA.SAAS.Manage.Core.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Services
{
public interface IGoodsService
{
/// <summary>
/// 分页查询商品
/// </summary>
/// <param name="inputDto"></param>
/// <returns></returns>
Task<PageUtil<List<GoodsDto>>> GetGoodsPageList(GoodsPageInputDto inputDto);
/// <summary>
/// 添加商品
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
Task<bool> AddGoods(GoodsInsertDto dto);
/// <summary>
/// 更新商品
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
Task<bool> UpdateGoods(GoodsUpdateDto dto);
/// <summary>
/// 删除商品
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
Task<bool> DeleteGoods(string[] ids);
}
}

+ 1
- 1
BPA.SAAS.Manage.Web.Entry/Properties/launchSettings.json Ver arquivo

@@ -14,7 +14,7 @@
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
}, },
"dotnetRunMessages": true, "dotnetRunMessages": true,
"applicationUrl": "http://localhost:5006"
"applicationUrl": "http://localhost:5009"
}, },
"Docker": { "Docker": {
"commandName": "Docker", "commandName": "Docker",


+ 1
- 1
BPA.SAAS.Manage.Web.Entry/appsettings.json Ver arquivo

@@ -8,7 +8,7 @@
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"baseurl": "http://192.168.1.19:5008/",
"baseurl": "http://localhost:5007/",
"ConnectionConfigs": [ "ConnectionConfigs": [
{ {
"ConnectionString": "server=10.2.1.21;Database=bpa_kitchen_kitchenbasemanage;Uid=root;Pwd=cygadmin;Allow Zero Datetime=True;Convert Zero Datetime=True;", "ConnectionString": "server=10.2.1.21;Database=bpa_kitchen_kitchenbasemanage;Uid=root;Pwd=cygadmin;Allow Zero Datetime=True;Convert Zero Datetime=True;",


Carregando…
Cancelar
Salvar