Pārlūkot izejas kodu

第三方商品管理接口

master
zhaoy pirms 10 mēnešiem
vecāks
revīzija
5413f9c92b
11 mainītis faili ar 438 papildinājumiem un 4 dzēšanām
  1. +10
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs
  2. +1
    -2
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/CheckServices.cs
  3. +15
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsDto.cs
  4. +40
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsInsertDto.cs
  5. +57
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsPageInputDto.cs
  6. +41
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsUpdateDto.cs
  7. +64
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs
  8. +170
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs
  9. +38
    -0
      BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/IGoodsService.cs
  10. +1
    -1
      BPA.SAAS.Manage.Web.Entry/Properties/launchSettings.json
  11. +1
    -1
      BPA.SAAS.Manage.Web.Entry/appsettings.json

+ 10
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs Parādīt failu

@@ -55,5 +55,15 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Enum
/// </summary>
[ErrorCodeItemMetadata("签名过期")]
Code1006,
/// <summary>
/// 系统异常
/// </summary>
[ErrorCodeItemMetadata("系统异常")]
Code1007,
/// <summary>
/// 商品不存在
/// </summary>
[ErrorCodeItemMetadata("商品不存在")]
Code1008,
}
}

+ 1
- 2
BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/CheckServices.cs Parādīt failu

@@ -47,12 +47,11 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.CheckService.Ser
var data = await SqlSugarDb.Db.Queryable<BPA_PlatformAuthorization>()
.ClearFilter()
.FirstAsync(x => x.Key == key);
await CheckTenant(data.GroupId);
if (data == null)
{
throw Oops.Oh(ErrorCodeEnum.Code1004);
}
await CheckTenant(data.GroupId);
}

/// <summary>


+ 15
- 0
BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsDto.cs Parādīt failu

@@ -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 Parādīt failu

@@ -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 Parādīt failu

@@ -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 Parādīt failu

@@ -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 Parādīt failu

@@ -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 Parādīt failu

@@ -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 Parādīt failu

@@ -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 Parādīt failu

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


+ 1
- 1
BPA.SAAS.Manage.Web.Entry/appsettings.json Parādīt failu

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


Notiek ielāde…
Atcelt
Saglabāt