|
|
@@ -1,5 +1,6 @@ |
|
|
|
using BPA.Franchisee.Application.FranchiseeCenter.GoodsServices; |
|
|
|
using BPA.SAAS.Manage.Application.DataBase.Dtos.Batching; |
|
|
|
using BPA.SAAS.Manage.Application.DataBase.Dtos.Bom; |
|
|
|
using BPA.SAAS.Manage.Application.DataBase.Dtos.Goods; |
|
|
|
using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttribute; |
|
|
|
using BPA.SAAS.Manage.Application.DataBase.Interface; |
|
|
@@ -254,19 +255,26 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services |
|
|
|
/// </summary> |
|
|
|
/// <param name="dto"></param> |
|
|
|
/// <returns></returns> |
|
|
|
public async Task<PageUtil> GetGoodsBomPageAsync(OrtherGoodsQueryDto dto) |
|
|
|
public async Task<PageUtil> GetGoodsBomPageAsync(GoodsBomQueryDto dto) |
|
|
|
{ |
|
|
|
RefAsync<int> total = 0; |
|
|
|
var res =await _db.Queryable<BPA_Bom, BPA_GoodsBom>((a, b) => new JoinQueryInfos( |
|
|
|
JoinType.Left, a.Id == b.BomId |
|
|
|
var res =await _db.Queryable<BPA_Bom, BPA_BomAttributeValueRe>((a, b) => new JoinQueryInfos( |
|
|
|
JoinType.Left, a.Id == b.BoomId |
|
|
|
)) |
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(dto.GoodsId), (a, b) => b.Goods_Id == dto.GoodsId) |
|
|
|
.Select((a, b) => new |
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(dto.GoodsId), (a, b) => b.GoodsId==dto.GoodsId) |
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(dto.Name), (a, b) => a.Name.Contains(dto.Name)) |
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(dto.GoodsAttributeValue), (a, b) => b.GoodsAttributeValue.Contains(dto.GoodsAttributeValue)) |
|
|
|
.Select((a, b) => new GoodsBomPageView |
|
|
|
{ |
|
|
|
Id = b.Id, |
|
|
|
Name = a.Name, |
|
|
|
BomId= b.BomId, |
|
|
|
IsMain = a.IsMain |
|
|
|
BomId= b.BoomId, |
|
|
|
IsMain = a.IsMain, |
|
|
|
GoodsAttributeValueId=b.GoodsAttributeValueId, |
|
|
|
}).Mapper(x => |
|
|
|
{ |
|
|
|
var AttributeValue = _db.Queryable<BPA_GoodsAttributeValue>().Where(p => x.GoodsAttributeValueId.Contains(p.Id)).Select(p=>p.AttributeValue).ToArray(); |
|
|
|
x.GoodsAttributeValue =string.Join("-", AttributeValue); |
|
|
|
}) |
|
|
|
.ToPageListAsync(dto.Current, dto.PageSize, total); |
|
|
|
PageUtil util = new PageUtil() |
|
|
@@ -283,10 +291,12 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services |
|
|
|
/// <returns></returns> |
|
|
|
public async Task<bool> BatchDelGoodsBomAsync(string Ids) |
|
|
|
{ |
|
|
|
// var GoodsBom=_db.Queryable<BPA_GoodsBom>().Where(x => x.Id == Ids).First(); |
|
|
|
|
|
|
|
// var GoodsBom=_db.Queryable<BPA_GoodsBom>().Where(x => x.Id == Ids).First(); |
|
|
|
var model=_db.Queryable<BPA_BomAttributeValueRe>().Where(x => x.Id == Ids).First(); |
|
|
|
if(model==null) throw Oops.Oh("配方不存在"); |
|
|
|
_db.Deleteable<BPA_GoodsBom>().Where(x => x.Goods_Id == model.GoodsId && x.BomId== model.BoomId).ExecuteCommand(); |
|
|
|
// 查询数据库中是否存在未删除的商品 |
|
|
|
var res = _db.Deleteable<BPA_GoodsBom>().In(Ids).ExecuteCommand(); |
|
|
|
var res = _db.Deleteable<BPA_BomAttributeValueRe>().In(Ids).ExecuteCommand(); |
|
|
|
return res > 0; |
|
|
|
} |
|
|
|
/// <summary> |
|
|
@@ -348,34 +358,38 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services |
|
|
|
bPA_BomAttributeValueRe.GoodsId = dto.GoodsId; |
|
|
|
bPA_BomAttributeValueRe.BoomId = newbPA_BOM.Id; |
|
|
|
bPA_BomAttributeValueRe.GoodsAttributeValueId = string.Join(",", dto.Shuxing); |
|
|
|
bPA_BomAttributeValueRe.GoodsAttributeValue = dto.GoodsAttributeValue; |
|
|
|
//添加商品配方属性关系 |
|
|
|
_db.Insertable(bPA_BomAttributeValueRe).ExecuteCommand(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (dto.BomId.Count > 0) |
|
|
|
if (string.IsNullOrWhiteSpace(dto.BomId)) throw Oops.Oh("请选择配方"); |
|
|
|
if (!string.IsNullOrWhiteSpace(dto.BomId)) |
|
|
|
{ |
|
|
|
List<BPA_GoodsBom> bomlist = new(); |
|
|
|
List<BPA_BomAttributeValueRe> bPA_BomAttributeValueRelist = new(); |
|
|
|
for (int i = 0; i < dto.BomId.Count; i++) |
|
|
|
var check=_db.Queryable<BPA_GoodsBom>().Where(x => x.Goods_Id == dto.GoodsId && x.BomId == dto.BomId).Any(); |
|
|
|
if (!check) |
|
|
|
{ |
|
|
|
BPA_GoodsBom bom = new BPA_GoodsBom(); |
|
|
|
bom.Goods_Id = dto.GoodsId; |
|
|
|
bom.BomId = dto.BomId[i]; |
|
|
|
bom.BomId = dto.BomId; |
|
|
|
bom.Status = CommonStatus.ENABLE; |
|
|
|
bomlist.Add(bom); |
|
|
|
BPA_BomAttributeValueRe bPA_BomAttributeValueRe = new(); |
|
|
|
bPA_BomAttributeValueRe.Id = Guid.NewGuid().ToString(); |
|
|
|
bPA_BomAttributeValueRe.GoodsId = dto.GoodsId; |
|
|
|
bPA_BomAttributeValueRe.BoomId = dto.BomId[i]; |
|
|
|
bPA_BomAttributeValueRe.GoodsAttributeValueId = string.Join(",", dto.Shuxing); |
|
|
|
bPA_BomAttributeValueRelist.Add(bPA_BomAttributeValueRe); |
|
|
|
//添加商品配方关系 |
|
|
|
_db.Insertable(bom).CallEntityMethod(m => m.Create()).ExecuteCommand(); |
|
|
|
} |
|
|
|
//添加商品配方关系 |
|
|
|
_db.Insertable(bomlist).CallEntityMethod(m => m.Create()).ExecuteCommand(); |
|
|
|
string vid = string.Join(",", dto.Shuxing); |
|
|
|
var checkvid = _db.Queryable<BPA_BomAttributeValueRe>().Where(x => x.GoodsId == dto.GoodsId && x.BoomId == dto.BomId && x.GoodsAttributeValueId== vid).Any(); |
|
|
|
if(checkvid) throw Oops.Oh("该配方已经存在"); |
|
|
|
//添加商品配方属性关系 |
|
|
|
_db.Insertable(bPA_BomAttributeValueRelist).ExecuteCommand(); |
|
|
|
} |
|
|
|
BPA_BomAttributeValueRe bPA_BomAttributeValueRe = new(); |
|
|
|
bPA_BomAttributeValueRe.Id = Guid.NewGuid().ToString(); |
|
|
|
bPA_BomAttributeValueRe.GoodsId = dto.GoodsId; |
|
|
|
bPA_BomAttributeValueRe.BoomId = dto.BomId; |
|
|
|
bPA_BomAttributeValueRe.GoodsAttributeValueId = vid; |
|
|
|
bPA_BomAttributeValueRe.GoodsAttributeValue = dto.GoodsAttributeValue; |
|
|
|
_db.Insertable(bPA_BomAttributeValueRe).ExecuteCommand(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
_db.Ado.CommitTran(); |
|
|
|
return true; |
|
|
|