fix(报废审批): 修复审批流程中的异常处理和物料校验问题
- 在QcScrapRecordsService中重构审批逻辑,增加事务管理和异常回滚 - 添加成品物料信息校验,使用物料供应商代码替代记录中的供应商代码 - 完善工单不存在时的错误处理 - 在控制器中统一异常处理,返回更友好的错误信息
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Azure;
|
||||
using DOAN.Admin.WebApi.Filters;
|
||||
using DOAN.Model.BZFM;
|
||||
using DOAN.Model.BZFM.Dto;
|
||||
@@ -146,12 +147,26 @@ namespace DOAN.Admin.WebApi.Controllers.BZFM
|
||||
[FromBody] ScrapApproveDto parm
|
||||
)
|
||||
{
|
||||
var response = _QcScrapRecordsService.ApproveScrapRecord(
|
||||
id,
|
||||
parm.IsApproved,
|
||||
parm.Approver
|
||||
);
|
||||
return ToResponse(response);
|
||||
try
|
||||
{
|
||||
var response = _QcScrapRecordsService.ApproveScrapRecord(
|
||||
id,
|
||||
parm.IsApproved,
|
||||
parm.Approver
|
||||
);
|
||||
if(response > 0)
|
||||
{
|
||||
return ToResponse(new ApiResult(200, response));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ToResponse(new ApiResult(500, "审批记录失败"));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ToResponse(new ApiResult(500, ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -203,19 +218,22 @@ namespace DOAN.Admin.WebApi.Controllers.BZFM
|
||||
return ToResponse(StatusCodes.Status400BadRequest, "工单号不能为空");
|
||||
}
|
||||
var response = _QcScrapRecordsService.CreateScrapOrderByWorkorder(parm);
|
||||
if(response == "ok")
|
||||
if (response == "ok")
|
||||
{
|
||||
return SUCCESS(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ToResponse(new ApiResult(StatusCodes.Status500InternalServerError, response));
|
||||
return ToResponse(
|
||||
new ApiResult(StatusCodes.Status500InternalServerError, response)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ToResponse(new ApiResult(StatusCodes.Status500InternalServerError, ex.Message));
|
||||
return ToResponse(
|
||||
new ApiResult(StatusCodes.Status500InternalServerError, ex.Message)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,12 +260,16 @@ namespace DOAN.Admin.WebApi.Controllers.BZFM
|
||||
}
|
||||
else
|
||||
{
|
||||
return ToResponse(new ApiResult(StatusCodes.Status500InternalServerError, response));
|
||||
return ToResponse(
|
||||
new ApiResult(StatusCodes.Status500InternalServerError, response)
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ToResponse(new ApiResult(StatusCodes.Status500InternalServerError, ex.Message));
|
||||
return ToResponse(
|
||||
new ApiResult(StatusCodes.Status500InternalServerError, ex.Message)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +296,9 @@ namespace DOAN.Admin.WebApi.Controllers.BZFM
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ToResponse(new ApiResult(StatusCodes.Status500InternalServerError, ex.Message));
|
||||
return ToResponse(
|
||||
new ApiResult(StatusCodes.Status500InternalServerError, ex.Message)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,15 +321,19 @@ namespace DOAN.Admin.WebApi.Controllers.BZFM
|
||||
}
|
||||
else
|
||||
{
|
||||
return ToResponse(new ApiResult(
|
||||
StatusCodes.Status400BadRequest,
|
||||
"撤销不良品记录失败,可能记录已被审批或不存在"
|
||||
));
|
||||
return ToResponse(
|
||||
new ApiResult(
|
||||
StatusCodes.Status400BadRequest,
|
||||
"撤销不良品记录失败,可能记录已被审批或不存在"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ToResponse(new ApiResult(StatusCodes.Status500InternalServerError, ex.Message));
|
||||
return ToResponse(
|
||||
new ApiResult(StatusCodes.Status500InternalServerError, ex.Message)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,10 +272,9 @@ namespace DOAN.Service.BZFM
|
||||
/// <returns></returns>
|
||||
public int ApproveScrapRecord(long id, bool isApproved, string approver)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
UseTran2(() =>
|
||||
try
|
||||
{
|
||||
int result = 0;
|
||||
// 获取记录信息
|
||||
var record = Context.Queryable<QcScrapRecords>().Where(x => x.Id == id).First();
|
||||
|
||||
@@ -290,6 +289,15 @@ namespace DOAN.Service.BZFM
|
||||
throw new Exception("只有待审批状态的记录才能被审批");
|
||||
}
|
||||
|
||||
// 成品物料信息校验
|
||||
var productMaterialInfo = Context.Queryable<MmMaterial>().Where(it => it.MaterialCode == record.ProductCode).First();
|
||||
if (productMaterialInfo == null)
|
||||
{
|
||||
throw new Exception("主体编号不存在");
|
||||
}
|
||||
|
||||
|
||||
Context.Ado.BeginTran();
|
||||
// 更新审批信息
|
||||
var updateObj = new QcScrapRecords
|
||||
{
|
||||
@@ -310,6 +318,10 @@ namespace DOAN.Service.BZFM
|
||||
x.UpdatedTime,
|
||||
})
|
||||
.ExecuteCommand();
|
||||
if(result < 0)
|
||||
{
|
||||
throw new Exception("更新审批信息失败");
|
||||
}
|
||||
|
||||
// 是否审批通过
|
||||
if (isApproved)
|
||||
@@ -321,15 +333,16 @@ namespace DOAN.Service.BZFM
|
||||
.Queryable<ProWorkorder>()
|
||||
.Where(x => x.Workorder == record.Workorder)
|
||||
.First();
|
||||
if (workorderInfo != null)
|
||||
{
|
||||
workorderInfo.DefectNum += (int)record.ScrapQuantity;
|
||||
Context
|
||||
.Updateable(workorderInfo)
|
||||
.UpdateColumns(x => new { x.DefectNum })
|
||||
.ExecuteCommand();
|
||||
if (workorderInfo == null) {
|
||||
throw new Exception($"未找到对应工单:{record.Workorder}");
|
||||
}
|
||||
workorderInfo.DefectNum += (int)record.ScrapQuantity;
|
||||
Context
|
||||
.Updateable(workorderInfo)
|
||||
.UpdateColumns(x => new { x.DefectNum })
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
// 调用入库单服务添加到不良库
|
||||
InboundReceiptDto revokeRecepitDto = new()
|
||||
{
|
||||
@@ -338,7 +351,7 @@ namespace DOAN.Service.BZFM
|
||||
BatchNo = record.BatchNo,
|
||||
LocationCode = "BL001",
|
||||
WarehouseCode = "WH007",
|
||||
SupplierCode = record.SupplierCode,
|
||||
SupplierCode = productMaterialInfo.SupplierCode,
|
||||
StoveCode = record.StoveCode,
|
||||
Workorder = record.Workorder,
|
||||
WorkorderRaw = record.ScrapOrderNo,
|
||||
@@ -353,7 +366,7 @@ namespace DOAN.Service.BZFM
|
||||
);
|
||||
if (createReceiptresult != "ok")
|
||||
{
|
||||
throw new Exception(createReceiptresult);
|
||||
throw new Exception($"{createReceiptresult}");
|
||||
}
|
||||
|
||||
// 根据报废类型处理
|
||||
@@ -412,9 +425,15 @@ namespace DOAN.Service.BZFM
|
||||
// }
|
||||
//}
|
||||
}
|
||||
});
|
||||
Context.Ado.CommitTran();
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Context.Ado.RollbackTran();
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user