using Tiger.Model;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq.Expressions;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Rhea.Common;
|
using System.Net;
|
using System.Linq;
|
using Newtonsoft.Json;
|
using Tiger.IBusiness;
|
using Microsoft.AspNetCore.Http;
|
using Tiger.Model.Entitys.MES.BizMesWoBatch;
|
using Tiger.Model.Entitys.MES.BizMesWo;
|
using Tiger.Model.Entitys.MES.BizBasPkgRule;
|
using Tiger.Model.Entitys.MES.Position;
|
|
namespace Tiger.Business.MES
|
{
|
public partial class BizBasRule : IBasRule
|
{
|
/// <summary>
|
/// 保存物料条码规则
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> SaveBasItemRule(BizBasItemRuleInput input)
|
{
|
var result = new ApiAction();
|
try
|
{
|
var ItemCustIds = input.ItemCusts.Select(q => q.ID).ToList();
|
List<BAS_ITEM_CUST> list = ItemCustIds.Count>0? await Biz.Db.Queryable<BAS_ITEM_CUST>()
|
.Where(q => !SqlFunc.ContainsArray(ItemCustIds, q.ID) && input.ItemCusts[0].ITEM_ID == q.ITEM_ID)
|
.ToListAsync() : new();
|
var db = Biz.Db;
|
var dbTran = db.UseTran(() =>
|
{
|
if (input.Item != null)
|
{
|
db.Updateable(input.Item).UpdateColumns(q => q.RULE_CODE).ExecuteCommand();
|
}
|
var z = db.Storageable(input.ItemCusts)
|
.WhereColumns(t => new { t.ID, t.GHOST_ROW })
|
.ToStorage();
|
z.AsInsertable.ExecuteCommand();
|
z.AsUpdateable.ExecuteCommand();
|
|
db.Deleteable(list).ExecuteCommand();
|
});
|
if (!dbTran.IsSuccess)
|
{
|
result.IsSuccessed = false;
|
result.Message = $"保存物料条码规则异常";
|
}
|
}
|
catch (Exception ex)
|
{
|
result.CatchExceptionWithLog(ex, "保存物料条码规则异常");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 保存包装规则,包括明细和重量范围
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> SaveBasPkgRule(BizBasPkgRuleInput input)
|
{
|
var result = new ApiAction();
|
try
|
{
|
var pkgProds = input.PkgProd.Select(q => q.ID).ToList();
|
List<BAS_PKG_PROD> listPrd = pkgProds.Count > 0 ? await Biz.Db.Queryable<BAS_PKG_PROD>()
|
.Where(q => !SqlFunc.ContainsArray(pkgProds, q.ID) && q.PKG_RULE_ID == input.PkgProd[0].PKG_RULE_ID)
|
.ToListAsync() : new();
|
var pkgDtl = input.PkgDtl.Select(q => q.ID).ToList();
|
List<BAS_PKG_DTL> listDtl = pkgDtl.Count > 0 ? await Biz.Db.Queryable<BAS_PKG_DTL>()
|
.Where(q => !SqlFunc.ContainsArray(pkgDtl, q.ID) && q.PKG_RULE_ID == input.PkgDtl[0].PKG_RULE_ID)
|
.ToListAsync() : new();
|
var db = Biz.Db;
|
var dbTran = db.UseTran(() =>
|
{
|
var z = db.Storageable(input.PkgDtl)
|
.WhereColumns(t => new { t.ID, t.GHOST_ROW })
|
.ToStorage();
|
z.AsInsertable.ExecuteCommand();
|
z.AsUpdateable.ExecuteCommand();
|
|
var o = db.Storageable(input.PkgProd)
|
.WhereColumns(t => new { t.ID, t.GHOST_ROW })
|
.ToStorage();
|
o.AsInsertable.ExecuteCommand();
|
o.AsUpdateable.ExecuteCommand();
|
|
db.Deleteable(listPrd).ExecuteCommand();
|
db.Deleteable(listDtl).ExecuteCommand();
|
});
|
if (!dbTran.IsSuccess)
|
{
|
result.IsSuccessed = false;
|
result.LocaleMsg = new($"保存包装规则异常");
|
}
|
}
|
catch (Exception ex)
|
{
|
result.CatchExceptionWithLog(ex, "保存包装规则异常");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 获取箱号
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> GetCardOrBoxCode(GetCodeInput input)
|
{
|
var result = new ApiAction();
|
try
|
{
|
result.Data = input.IsTry == "Y" ? Cache.CodeRule[input.Code]?.TryGenerate(input.Prefix, $"{input.BatchNo}-{input.Qty}-").Data.ToString() ?? "" : Cache.CodeRule[input.Code]?.Generate(input.Prefix, $"{input.BatchNo}-{input.Qty}-").Data.ToString() ?? "";
|
}
|
catch (Exception ex)
|
{
|
result.CatchExceptionWithLog(ex, "获取箱号异常");
|
}
|
return result;
|
}
|
}
|
}
|