perf(退货审批): 添加性能监控日志记录各阶段执行时间
添加各关键步骤的执行时间记录,用于监控和优化退货审批流程的性能。记录包括模型加载、商品列表查询、库存操作等各阶段耗时,并写入操作日志以便后续分析。
This commit is contained in:
parent
11743ff77d
commit
c33f8951d7
|
@ -443,9 +443,12 @@ public class ReturnApprovalApplicationService {
|
||||||
* 执行更新审批状态为通过以及之后的操作
|
* 执行更新审批状态为通过以及之后的操作
|
||||||
*/
|
*/
|
||||||
public void updateApprovalStatusAndComplete(UpdateReturnApprovalCommand command) {
|
public void updateApprovalStatusAndComplete(UpdateReturnApprovalCommand command) {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// 加载退货审批模型
|
// 加载退货审批模型
|
||||||
ReturnApprovalModel model = modelFactory.loadById(command.getApprovalId());
|
ReturnApprovalModel model = modelFactory.loadById(command.getApprovalId());
|
||||||
|
long modelLoadTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// 设置审批人信息
|
// 设置审批人信息
|
||||||
if (StringUtils.isNotBlank(command.getAuditName())) {
|
if (StringUtils.isNotBlank(command.getAuditName())) {
|
||||||
model.setAuditName(command.getAuditName());
|
model.setAuditName(command.getAuditName());
|
||||||
|
@ -455,14 +458,18 @@ public class ReturnApprovalApplicationService {
|
||||||
model.setAuditName(qyUserEntity.getName());
|
model.setAuditName(qyUserEntity.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
long auditInfoTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// 获取关联的订单商品列表
|
// 获取关联的订单商品列表
|
||||||
List<ApprovalGoodsEntity> approvalGoodsList = approvalGoodsService.selectByApprovalId(model.getApprovalId());
|
List<ApprovalGoodsEntity> approvalGoodsList = approvalGoodsService.selectByApprovalId(model.getApprovalId());
|
||||||
if (approvalGoodsList == null || approvalGoodsList.isEmpty()) {
|
if (approvalGoodsList == null || approvalGoodsList.isEmpty()) {
|
||||||
throw new RuntimeException("未找到关联的订单商品");
|
throw new RuntimeException("未找到关联的订单商品");
|
||||||
}
|
}
|
||||||
|
long goodsListTime = System.currentTimeMillis();
|
||||||
|
|
||||||
List<ApprovalGoodsCellEntity> approvalGoodsCellEntities = approvalGoodsCellService.selectByApprovalId(model.getApprovalId());
|
List<ApprovalGoodsCellEntity> approvalGoodsCellEntities = approvalGoodsCellService.selectByApprovalId(model.getApprovalId());
|
||||||
|
long goodsCellTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// 获取关联的商品列表
|
// 获取关联的商品列表
|
||||||
QueryWrapper<ShopGoodsEntity> goodsWrapper = new QueryWrapper<>();
|
QueryWrapper<ShopGoodsEntity> goodsWrapper = new QueryWrapper<>();
|
||||||
goodsWrapper.in("goods_id", approvalGoodsList.stream().map(ApprovalGoodsEntity::getGoodsId).distinct().collect(Collectors.toList()))
|
goodsWrapper.in("goods_id", approvalGoodsList.stream().map(ApprovalGoodsEntity::getGoodsId).distinct().collect(Collectors.toList()))
|
||||||
|
@ -471,12 +478,14 @@ public class ReturnApprovalApplicationService {
|
||||||
if (goodsList == null || goodsList.isEmpty()) {
|
if (goodsList == null || goodsList.isEmpty()) {
|
||||||
throw new RuntimeException("未找到关联的商品");
|
throw new RuntimeException("未找到关联的商品");
|
||||||
}
|
}
|
||||||
|
long shopGoodsTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// 初始化商品和格口模型列表
|
// 初始化商品和格口模型列表
|
||||||
QueryWrapper<CabinetCellEntity> cellEntityQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<CabinetCellEntity> cellEntityQueryWrapper = new QueryWrapper<>();
|
||||||
cellEntityQueryWrapper.in("cell_id", approvalGoodsCellEntities.stream().map(ApprovalGoodsCellEntity::getCellId).collect(Collectors.toList()))
|
cellEntityQueryWrapper.in("cell_id", approvalGoodsCellEntities.stream().map(ApprovalGoodsCellEntity::getCellId).collect(Collectors.toList()))
|
||||||
.eq("deleted", false);
|
.eq("deleted", false);
|
||||||
List<CabinetCellEntity> cabinetCellList = cabinetCellService.list(cellEntityQueryWrapper);
|
List<CabinetCellEntity> cabinetCellList = cabinetCellService.list(cellEntityQueryWrapper);
|
||||||
|
long cabinetCellTime = System.currentTimeMillis();
|
||||||
|
|
||||||
for (ApprovalGoodsCellEntity approvalGoodsCell : approvalGoodsCellEntities) {
|
for (ApprovalGoodsCellEntity approvalGoodsCell : approvalGoodsCellEntities) {
|
||||||
if (approvalGoodsCell.getAllocateQuantity() == null || approvalGoodsCell.getAllocateQuantity().compareTo(0) <= 0) {
|
if (approvalGoodsCell.getAllocateQuantity() == null || approvalGoodsCell.getAllocateQuantity().compareTo(0) <= 0) {
|
||||||
|
@ -515,10 +524,14 @@ public class ReturnApprovalApplicationService {
|
||||||
model.setAuditUserid(command.getAuditUserid());
|
model.setAuditUserid(command.getAuditUserid());
|
||||||
model.setApprovalTime(new Date());
|
model.setApprovalTime(new Date());
|
||||||
|
|
||||||
|
long stockTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// 调用固资通服务的出库方法
|
// 调用固资通服务的出库方法
|
||||||
assetApplicationService.consumeOutput(model.getCorpid(), model.getApplyUserid(), model.getAuditUserid(),
|
assetApplicationService.consumeOutput(model.getCorpid(), model.getApplyUserid(), model.getAuditUserid(),
|
||||||
model, approvalGoodsList, goodsList);
|
model, approvalGoodsList, goodsList);
|
||||||
|
|
||||||
|
long consumeOutputTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// 开始执行数据库操作
|
// 开始执行数据库操作
|
||||||
model.setStatus(2); // 2表示审核通过状态
|
model.setStatus(2); // 2表示审核通过状态
|
||||||
model.updateById();
|
model.updateById();
|
||||||
|
@ -528,6 +541,28 @@ public class ReturnApprovalApplicationService {
|
||||||
|
|
||||||
// 批量更新格口库存
|
// 批量更新格口库存
|
||||||
cabinetCellList.forEach(CabinetCellEntity::updateById);
|
cabinetCellList.forEach(CabinetCellEntity::updateById);
|
||||||
|
|
||||||
|
long updateDatabaseTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
try {
|
||||||
|
AddPaymentOperationLogCommand paymentOperationLogCommand = new AddPaymentOperationLogCommand();
|
||||||
|
paymentOperationLogCommand.setOperationType("assetApprovalTime");
|
||||||
|
paymentOperationLogCommand.setStatus(1);
|
||||||
|
paymentOperationLogCommand.setRemark(String.format("Method execution times - Model load: %dms, Audit info: %dms, Goods list: %dms, Goods cell: %dms, Shop goods: %dms, Cabinet cell: %dms, Stock: %dms, Consume output: %dms, Update database: %dms",
|
||||||
|
modelLoadTime - startTime,
|
||||||
|
auditInfoTime - modelLoadTime,
|
||||||
|
goodsListTime - auditInfoTime,
|
||||||
|
goodsCellTime - goodsListTime,
|
||||||
|
shopGoodsTime - goodsCellTime,
|
||||||
|
cabinetCellTime - shopGoodsTime,
|
||||||
|
stockTime - cabinetCellTime,
|
||||||
|
consumeOutputTime - stockTime,
|
||||||
|
updateDatabaseTime - consumeOutputTime));
|
||||||
|
paymentOperationLogCommand.initBaseEntity();
|
||||||
|
paymentOperationLogApplicationService.addPaymentOperationLog(paymentOperationLogCommand);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("记录操作日志失败", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue