193 lines
8.4 KiB
C#
193 lines
8.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Aspose.Cells.Drawing;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.Common.Security;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.EquipMgr.Entities;
|
|
using Tnb.EquipMgr.Entities.Dto;
|
|
using Tnb.EquipMgr.Entities.Entity;
|
|
using Tnb.EquipMgr.Interfaces;
|
|
|
|
namespace Tnb.EquipMgr
|
|
{
|
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
public class ToolMoldProductService : IToolMoldProductService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly IUserManager _userManager;
|
|
private readonly ISqlSugarRepository<ToolMolds> _repository;
|
|
public ToolMoldProductService(IUserManager userManager, ISqlSugarRepository<ToolMolds> repository)
|
|
{
|
|
_userManager = userManager;
|
|
_repository = repository;
|
|
}
|
|
/// <summary>
|
|
/// 根据模具id获取产品集合
|
|
/// </summary>
|
|
/// <param name="mold"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<List<ProductListOutput>> GetProductLists(ToolMoldInput ToolMoldInput)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
var list = await db.Queryable<BasProduct, ToolMoldsProduct>((a, b) => new object[]
|
|
{
|
|
JoinType.Inner, a.id == b.product_id,
|
|
})
|
|
.Where((a, b) => b.mold_id == ToolMoldInput.mold)
|
|
.Select((a, b) => new ProductListOutput
|
|
{
|
|
id = a.id,
|
|
product_code = a.product_code,
|
|
product_name = a.product_name,
|
|
product_standard = a.product_standard,
|
|
product_group=b.product_group,
|
|
real_cavity_qty = b.real_cavity_qty.HasValue ? b.real_cavity_qty.Value : 0
|
|
}).ToListAsync();
|
|
return list;
|
|
}
|
|
/// <summary>
|
|
/// 增加模具产品绑定
|
|
/// </summary>
|
|
/// <param name="mold"></param>
|
|
/// <param name="productid"></param>
|
|
/// <param name="real_cavity_qty"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> SaveData(ToolMoldInput ToolMoldInput)
|
|
{
|
|
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
|
{
|
|
var ToolMoldsProduct= await _repository.AsSugarClient().Queryable<ToolMoldsProduct>().Where(p=>p.mold_id== ToolMoldInput.mold&&p.product_id== ToolMoldInput.productid).FirstAsync();
|
|
if (ToolMoldsProduct == null)
|
|
{
|
|
var entity = new ToolMoldsProduct();
|
|
entity.id = SnowflakeIdHelper.NextId();
|
|
entity.mold_id = ToolMoldInput.mold;
|
|
entity.product_id = ToolMoldInput.productid;
|
|
entity.real_cavity_qty = ToolMoldInput.real_cavity_qty;
|
|
entity.create_time = DateTime.Now;
|
|
entity.create_id = _userManager.UserId;
|
|
await _repository.AsSugarClient().Insertable<ToolMoldsProduct>(entity).ExecuteCommandAsync();
|
|
}
|
|
else {
|
|
ToolMoldsProduct.real_cavity_qty= ToolMoldInput.real_cavity_qty;
|
|
await _repository.AsSugarClient().Updateable<ToolMoldsProduct>(ToolMoldsProduct).ExecuteCommandAsync();
|
|
}
|
|
|
|
|
|
});
|
|
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
|
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// 批量删除模具产品绑定
|
|
/// </summary>
|
|
/// <param name="mold"></param>
|
|
/// <param name="productids"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> DetachMoldData(ToolMoldInput ToolMoldInput)
|
|
{
|
|
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
|
{
|
|
var arr = _repository.AsSugarClient().Queryable<ToolMoldsProduct>().Where(x => x.mold_id == ToolMoldInput.mold && ToolMoldInput.productids.Contains(x.product_id)).ToList();
|
|
await _repository.AsSugarClient().Deleteable<ToolMoldsProduct>(arr).ExecuteCommandAsync();
|
|
|
|
});
|
|
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
|
return result.IsSuccess ? "操作成功" : result.ErrorMessage;
|
|
}
|
|
/// <summary>
|
|
/// 产品同组
|
|
/// </summary>
|
|
/// <param name="mold"></param>
|
|
/// <param name="productids"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> SaveProductGroup(ToolMoldInput ToolMoldInput)
|
|
{
|
|
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
|
{
|
|
var arr = _repository.AsSugarClient().Queryable<ToolMoldsProduct>().Where(x => x.mold_id == ToolMoldInput.mold && ToolMoldInput.productids.Contains(x.product_id)).ToList();
|
|
var sign = SnowflakeIdHelper.NextId();
|
|
arr.ForEach(p => { p.product_group = sign; });
|
|
await _repository.AsSugarClient().Updateable<ToolMoldsProduct>(arr).ExecuteCommandAsync();
|
|
|
|
});
|
|
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
|
return result.IsSuccess ? "操作成功" : result.ErrorMessage;
|
|
}
|
|
/// <summary>
|
|
/// 取消产品同组
|
|
/// </summary>
|
|
/// <param name="mold"></param>
|
|
/// <param name="productids"></param>
|
|
/// <returns></returns>
|
|
public async Task<dynamic> CancelProductGroup(ToolMoldInput ToolMoldInput)
|
|
{
|
|
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
|
{
|
|
var arr = _repository.AsSugarClient().Queryable<ToolMoldsProduct>().Where(x => x.mold_id == ToolMoldInput.mold && ToolMoldInput.productids.Contains(x.product_id)).ToList();
|
|
arr.ForEach(p => { p.product_group = string.Empty; });
|
|
await _repository.AsSugarClient().Updateable<ToolMoldsProduct>(arr).ExecuteCommandAsync();
|
|
|
|
});
|
|
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
|
return result.IsSuccess ? "操作成功" : result.ErrorMessage;
|
|
}
|
|
/// <summary>
|
|
/// 根据产品id获取模具集合
|
|
/// </summary>
|
|
/// <param name="productid"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<List<MoldListOutput>> GetMoldLists(ToolMoldInput ToolMoldInput)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
var list = await db.Queryable<ToolMolds, ToolMoldsProduct>((a, b) => new object[]
|
|
{
|
|
JoinType.Inner, a.id == b.mold_id,
|
|
})
|
|
.Where((a, b) => b.product_id == ToolMoldInput.productid)
|
|
.Select((a, b) => new MoldListOutput
|
|
{
|
|
id = a.id,
|
|
mold_code = a.mold_code,
|
|
mold_name = a.mold_name,
|
|
cavity_qty = a.cavity_qty.HasValue ? a.cavity_qty.Value : 0,
|
|
real_cavity_qty = b.real_cavity_qty.HasValue ? b.real_cavity_qty.Value : 0
|
|
}).ToListAsync();
|
|
return list;
|
|
}
|
|
/// <summary>
|
|
/// 批量删除产品模具绑定
|
|
/// </summary>
|
|
/// <param name="molds"></param>
|
|
/// <param name="productid"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> DetachProductData(ToolMoldInput ToolMoldInput)
|
|
{
|
|
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
|
{
|
|
var arr = _repository.AsSugarClient().Queryable<ToolMoldsProduct>().Where(x => ToolMoldInput.molds.Contains(x.mold_id) && x.product_id == ToolMoldInput.productid).ToList();
|
|
await _repository.AsSugarClient().Deleteable<ToolMoldsProduct>(arr).ExecuteCommandAsync();
|
|
});
|
|
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
|
return result.IsSuccess ? "操作成功" : result.ErrorMessage;
|
|
}
|
|
}
|
|
}
|