销售发货接口、原材料仓优化调整、日志优化
This commit is contained in:
@@ -670,6 +670,130 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销售发货单
|
||||
/// </summary>
|
||||
[HttpPost, NonUnify, AllowAnonymous]
|
||||
public async Task<Entities.Dto.Outputs.Result> SaleShipping(SaleShippingInput input)
|
||||
{
|
||||
|
||||
|
||||
LoggerErp2Mes.LogInformation($"【SaleShipping】ERP传入数据:{JsonConvert.SerializeObject(input)}");
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
if (string.IsNullOrEmpty(input.erp_pk))
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【SaleShipping】主表主键不能为空!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"主表主键不能为空!");
|
||||
}
|
||||
|
||||
int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count();
|
||||
if (count_erp_line_pk > 0)
|
||||
{
|
||||
_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);
|
||||
}
|
||||
|
||||
BasWarehouse warehouse_outstock = await db.Queryable<BasWarehouse>().Where(r => r.whcode == input.warehouse_code).FirstAsync();
|
||||
if (warehouse_outstock == null)
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($"【MaterialTransfer】无法查询到出库仓库{input.warehouse_code}的档案记录!");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, $"无法查询到出库仓库{input.warehouse_code}的档案记录!");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await db.Ado.BeginTranAsync();
|
||||
WmsSaleH wmsSaleH = new WmsSaleH();
|
||||
string Code = await _billRuleService.GetBillNumber("WmsSale");
|
||||
|
||||
wmsSaleH.bill_code = Code;
|
||||
wmsSaleH.erp_bill_code = input.bill_code;
|
||||
wmsSaleH.bill_type = "25103439022357";//销售出库单
|
||||
wmsSaleH.status = WmsWareHouseConst.BILLSTATUS_ADD_ID;
|
||||
wmsSaleH.warehouse_id = warehouse_outstock.id;
|
||||
wmsSaleH.customer_code = input.customer_code;
|
||||
var customer = await db.Queryable<BasCustomer>().Where(p => p.customer_code == input.customer_code).FirstAsync();
|
||||
if (customer != null)
|
||||
{
|
||||
wmsSaleH.customer_id = customer.id;
|
||||
wmsSaleH.customer_name = customer.customer_name;
|
||||
}
|
||||
|
||||
wmsSaleH.ship_date = input.ship_date.Value;
|
||||
wmsSaleH.erp_pk = input.erp_pk;
|
||||
wmsSaleH.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsSaleH.create_time = DateTime.Now;
|
||||
|
||||
await db.Insertable(wmsSaleH).ExecuteCommandAsync();
|
||||
|
||||
|
||||
List<WmsSaleD> wmsSaleDs = new List<WmsSaleD>();
|
||||
foreach (var detail in input.details)
|
||||
{
|
||||
WmsSaleD wmsSaleD = new WmsSaleD();
|
||||
|
||||
wmsSaleD.bill_id = wmsSaleH.id;
|
||||
wmsSaleD.material_code = detail.material_code;
|
||||
wmsSaleD.purchase_qty = detail.sale_qty.Value;
|
||||
wmsSaleD.code_batch = detail.code_batch;
|
||||
wmsSaleD.erp_line_pk = detail.erp_line_pk;
|
||||
wmsSaleD.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsSaleD.create_time = DateTime.Now;
|
||||
|
||||
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();
|
||||
if (erpExtendField != null)
|
||||
{
|
||||
wmsSaleD.unit_id = erpExtendField.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【MaterialTransfer】表体明细中单位{detail.unit_code}在wms系统中未找到!");
|
||||
throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500);
|
||||
}
|
||||
|
||||
var material = await db.Queryable<BasMaterial>().Where(p => p.code == detail.material_code).FirstAsync();
|
||||
if (material != null)
|
||||
{
|
||||
wmsSaleD.material_id = material.id;
|
||||
wmsSaleD.material_name = material.name;
|
||||
wmsSaleD.material_specification = material.material_specification;
|
||||
}
|
||||
|
||||
wmsSaleDs.Add(wmsSaleD);
|
||||
}
|
||||
|
||||
await db.Insertable(wmsSaleDs).ExecuteCommandAsync();
|
||||
|
||||
await db.Ado.CommitTranAsync();
|
||||
|
||||
LoggerErp2Mes.LogInformation($"【SaleShipping】成功生成单据:{Code}");
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LoggerErp2Mes.LogError($"【SaleShipping】{ex.Message}");
|
||||
LoggerErp2Mes.LogError($"【SaleShipping】{ex.StackTrace}");
|
||||
await db.Ado.RollbackTranAsync();
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected Task<Entities.Dto.Outputs.Result> ToApiResult(HttpStatusCode statusCode, string msg)
|
||||
{
|
||||
Entities.Dto.Outputs.Result result = new()
|
||||
|
||||
Reference in New Issue
Block a user