现在问题处理
This commit is contained in:
@@ -1217,6 +1217,7 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销售发货单
|
||||
/// </summary>
|
||||
@@ -1243,16 +1244,16 @@ namespace Tnb.WarehouseMgr
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
var wmsSaleShippingsDistinct = input.details.Select(r => new
|
||||
{
|
||||
material_id = r.material_code,
|
||||
code_batch = r.code_batch,
|
||||
}).Distinct();
|
||||
if (wmsSaleShippingsDistinct.Count() < input.details.Count)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【SaleShipping】表体存在物料和批号重复的明细!");
|
||||
throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
}
|
||||
//var wmsSaleShippingsDistinct = input.details.Select(r => new
|
||||
//{
|
||||
// material_id = r.material_code,
|
||||
// code_batch = r.code_batch,
|
||||
//}).Distinct();
|
||||
//if (wmsSaleShippingsDistinct.Count() < input.details.Count)
|
||||
//{
|
||||
// _LoggerErp2Mes.LogWarning($@"【SaleShipping】表体存在物料和批号重复的明细!");
|
||||
// throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
//}
|
||||
|
||||
WmsErpWarehouserelaH wmsErpWarehouserelaH = await db.Queryable<WmsErpWarehouserelaH>().Where(r => r.erp_warehousecode == input.warehouse_code).FirstAsync();
|
||||
if (wmsErpWarehouserelaH == null)
|
||||
@@ -1272,7 +1273,7 @@ namespace Tnb.WarehouseMgr
|
||||
await db.Ado.BeginTranAsync();
|
||||
|
||||
// 判断是否重复传输
|
||||
WmsSaleH wmsSaleHRep = await db.Queryable<WmsSaleH>().Where(r => r.erp_pk == input.erp_pk).FirstAsync();
|
||||
WmsSaleH wmsSaleHRep = await db.Queryable<WmsSaleH>().Where(r => r.erp_bill_code == input.bill_code).FirstAsync();
|
||||
if (wmsSaleHRep != null)
|
||||
{
|
||||
// 判断单据是否已经下发
|
||||
@@ -1349,7 +1350,7 @@ namespace Tnb.WarehouseMgr
|
||||
wmsSaleD.material_name = material.name;
|
||||
wmsSaleD.material_specification = material.material_specification;
|
||||
}
|
||||
|
||||
wmsSaleD.auxprop = detail.auxprop;
|
||||
wmsSaleDs.Add(wmsSaleD);
|
||||
}
|
||||
|
||||
@@ -1553,7 +1554,7 @@ namespace Tnb.WarehouseMgr
|
||||
msRawmatTransferinstockD.matname = material.name;
|
||||
msRawmatTransferinstockD.matspecification = material.material_specification;
|
||||
}
|
||||
|
||||
msRawmatTransferinstockD.auxprop = detail.auxprop;
|
||||
wmsRawmatTransferinstockDs.Add(msRawmatTransferinstockD);
|
||||
}
|
||||
|
||||
@@ -1624,6 +1625,7 @@ namespace Tnb.WarehouseMgr
|
||||
wmsTransferInstockD.material_code = material.code;
|
||||
wmsTransferInstockD.material_desc = material.material_specification;
|
||||
}
|
||||
wmsTransferInstockD.auxprop = detail.auxprop;
|
||||
|
||||
wmsTransferInstockDs.Add(wmsTransferInstockD);
|
||||
}
|
||||
@@ -2182,6 +2184,8 @@ namespace Tnb.WarehouseMgr
|
||||
wmsRawmatOutstockH.bill_code = code;
|
||||
wmsRawmatOutstockH.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsRawmatOutstockH.create_time = DateTime.Now;
|
||||
wmsRawmatOutstockH.erp_bill_code = input.outstock_order;
|
||||
wmsRawmatOutstockH.warehouse_id = WmsWareHouseConst.WAREHOUSE_YCL_ID;
|
||||
//wmsRawmatOutstockH.biller = input.biller;
|
||||
wmsRawmatOutstockH.department = input.dept_code;
|
||||
wmsRawmatOutstockH.erp_pk = input.erp_pk;
|
||||
@@ -2192,7 +2196,7 @@ namespace Tnb.WarehouseMgr
|
||||
WmsRawmatOutstockD wmsRawmatOutstockD = new WmsRawmatOutstockD();
|
||||
wmsRawmatOutstockD.bill_id = wmsRawmatOutstockH.id;
|
||||
wmsRawmatOutstockD.unit = detail.unit_code;
|
||||
var erpExtendField = await db.Queryable<ErpExtendField>().InnerJoin<DictionaryDataEntity>((a, b) => a.table_id == b.Id).Where((a, b) => a.cunitid == detail.unit_code).Select((a, b) => b).FirstAsync();
|
||||
var erpExtendField = await db.Queryable<ErpExtendField>().InnerJoin<DictionaryDataEntity>((a, b) => a.table_id == b.Id).Where((a, b) => b.EnCode == detail.unit_code).Select((a, b) => b).FirstAsync();
|
||||
if (erpExtendField != null)
|
||||
{
|
||||
wmsRawmatOutstockD.unit = erpExtendField.EnCode;
|
||||
@@ -2219,7 +2223,7 @@ namespace Tnb.WarehouseMgr
|
||||
wmsRawmatOutstockD.material_name = material.name;
|
||||
wmsRawmatOutstockD.material_specification = material.material_specification;
|
||||
}
|
||||
|
||||
wmsRawmatOutstockD.auxprop = detail.auxprop;
|
||||
wmsRawmatOutstockDs.Add(wmsRawmatOutstockD);
|
||||
}
|
||||
|
||||
@@ -2244,6 +2248,140 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 材料出库单(批量)
|
||||
/// </summary>
|
||||
[HttpPost, NonUnify, AllowAnonymous]
|
||||
public async Task<Entities.Dto.Outputs.Result> RawmatOutstockBatch(List<ErpRawmatOutstockInput> inputs)
|
||||
{
|
||||
LoggerErp2Mes.LogInformation($"【RawmatOutstock】ERP传入数据:{JsonConvert.SerializeObject(inputs)}");
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
|
||||
List<string> error_erpbillcodes = new List<string>();
|
||||
foreach (ErpRawmatOutstockInput input in inputs)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【RawmatOutstock】主表主键不能为空!");
|
||||
throw new AppFriendlyException($@"主表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【RawmatOutstock】子表主键不能为空!");
|
||||
throw new AppFriendlyException($@"子表主键不能为空!", 500);
|
||||
}
|
||||
|
||||
//var wmsRawmatOutstocksDistinct = input.details.Select(r => new
|
||||
//{
|
||||
// material_id = r.material_code,
|
||||
// code_batch = r.code_batch,
|
||||
//}).Distinct();
|
||||
//if (wmsRawmatOutstocksDistinct.Count() < input.details.Count)
|
||||
//{
|
||||
// _LoggerErp2Mes.LogWarning($@"【RawmatOutstock】表体存在物料和批号重复的明细!");
|
||||
// throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500);
|
||||
//}
|
||||
|
||||
await db.Ado.BeginTranAsync();
|
||||
// 判断是否重复传输
|
||||
WmsRawmatOutstockH wmsRawmatOutstockHRep = await db.Queryable<WmsRawmatOutstockH>().Where(r => r.erp_bill_code == input.outstock_order).FirstAsync();
|
||||
if (wmsRawmatOutstockHRep != null)
|
||||
{
|
||||
// 判断单据是否已经下发
|
||||
List<WmsRawmatOutstockD> _wmsRawmatOutstockDs = await db.Queryable<WmsRawmatOutstockD>().Where(r => r.bill_id == wmsRawmatOutstockHRep.id).ToListAsync();
|
||||
bool isxf = _wmsRawmatOutstockDs.Where(r => r.actual_outstock_qty > 0).Any();
|
||||
if (isxf)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【RawmatOutstock】wms已下发使用材料出库单{input.outstock_order}!");
|
||||
throw new AppFriendlyException($@"wms已下发使用材料出库单{input.outstock_order}!", 500);
|
||||
}
|
||||
else // 删除数据重新插入
|
||||
{
|
||||
await db.Deleteable<WmsRawmatOutstockH>().Where(r => r.id == wmsRawmatOutstockHRep.id).ExecuteCommandAsync();
|
||||
await db.Deleteable<WmsRawmatOutstockD>().Where(r => r.bill_id == wmsRawmatOutstockHRep.id).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
WmsRawmatOutstockH wmsRawmatOutstockH = new WmsRawmatOutstockH();
|
||||
string code = await _billRuleService.GetBillNumber("rawmatoutstock");
|
||||
wmsRawmatOutstockH.bill_code = code;
|
||||
wmsRawmatOutstockH.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsRawmatOutstockH.create_time = DateTime.Now;
|
||||
wmsRawmatOutstockH.erp_bill_code = input.outstock_order;
|
||||
wmsRawmatOutstockH.warehouse_id = WmsWareHouseConst.WAREHOUSE_YCL_ID;
|
||||
//wmsRawmatOutstockH.biller = input.biller;
|
||||
wmsRawmatOutstockH.department = input.dept_code;
|
||||
wmsRawmatOutstockH.erp_pk = input.erp_pk;
|
||||
wmsRawmatOutstockH.issuance_status = "0";
|
||||
List<WmsRawmatOutstockD> wmsRawmatOutstockDs = new List<WmsRawmatOutstockD>();
|
||||
foreach (var detail in input.details)
|
||||
{
|
||||
WmsRawmatOutstockD wmsRawmatOutstockD = new WmsRawmatOutstockD();
|
||||
wmsRawmatOutstockD.bill_id = wmsRawmatOutstockH.id;
|
||||
wmsRawmatOutstockD.unit = detail.unit_code;
|
||||
var erpExtendField = await db.Queryable<ErpExtendField>().InnerJoin<DictionaryDataEntity>((a, b) => a.table_id == b.Id).Where((a, b) => b.EnCode == detail.unit_code).Select((a, b) => b).FirstAsync();
|
||||
if (erpExtendField != null)
|
||||
{
|
||||
wmsRawmatOutstockD.unit = erpExtendField.EnCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOrder】表体明细中单位{detail.unit_code}在wms系统中未找到!");
|
||||
throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500);
|
||||
}
|
||||
|
||||
wmsRawmatOutstockD.qty = detail.qty;
|
||||
wmsRawmatOutstockD.batchno = detail.code_batch;
|
||||
wmsRawmatOutstockD.erp_line_pk = detail.erp_line_pk;
|
||||
wmsRawmatOutstockD.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsRawmatOutstockD.create_time = DateTime.Now;
|
||||
wmsRawmatOutstockD.lineno = detail.lineno;
|
||||
wmsRawmatOutstockD.actual_outstock_qty = 0;
|
||||
|
||||
var material = await db.Queryable<BasMaterial>().Where(p => p.code == detail.material_code).FirstAsync();
|
||||
if (material != null)
|
||||
{
|
||||
wmsRawmatOutstockD.material_id = material.id;
|
||||
wmsRawmatOutstockD.material_code = material.code;
|
||||
wmsRawmatOutstockD.material_name = material.name;
|
||||
wmsRawmatOutstockD.material_specification = material.material_specification;
|
||||
}
|
||||
|
||||
wmsRawmatOutstockDs.Add(wmsRawmatOutstockD);
|
||||
}
|
||||
|
||||
await db.Insertable(wmsRawmatOutstockH).ExecuteCommandAsync();
|
||||
await db.Insertable(wmsRawmatOutstockDs).ExecuteCommandAsync();
|
||||
|
||||
await db.Ado.CommitTranAsync();
|
||||
|
||||
LoggerErp2Mes.LogInformation($"【RawmatOutstock】成功生成单据:{code}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error_erpbillcodes.Add($"bip单据号{input.outstock_order}: {ex.Message}");
|
||||
LoggerErp2Mes.LogError($"【RawmatOutstock】{ex.Message}");
|
||||
LoggerErp2Mes.LogError($"【RawmatOutstock】{ex.StackTrace}");
|
||||
await db.Ado.RollbackTranAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
if (error_erpbillcodes.Count > 0)
|
||||
{
|
||||
LoggerErp2Mes.LogWarning($"同步失败信息:{string.Join(',', error_erpbillcodes)}");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"同步失败信息:{string.Join(',', error_erpbillcodes)}");
|
||||
}
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 盘点单
|
||||
/// </summary>
|
||||
@@ -2332,7 +2470,7 @@ namespace Tnb.WarehouseMgr
|
||||
wmsInventorycheckH.biller = input.biller;
|
||||
wmsInventorycheckH.erp_bill_code = input.erp_bill_code;
|
||||
wmsInventorycheckH.erp_pk = input.erp_pk;
|
||||
|
||||
wmsInventorycheckH.check_date = input.check_date;
|
||||
await db.Insertable(wmsInventorycheckH).ExecuteCommandAsync();
|
||||
|
||||
|
||||
@@ -2373,7 +2511,7 @@ namespace Tnb.WarehouseMgr
|
||||
_LoggerErp2Mes.LogWarning($@"【Inventorycheck】表体明细中单位{detail.unit_code}在wms系统中未找到!");
|
||||
throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500);
|
||||
}
|
||||
|
||||
wmsInventorycheckD.auxprop = detail.auxprop;
|
||||
wmsInventorycheckDs.Add(wmsInventorycheckD);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user