在中国程序媛中,他们的代码有什么样的魅力,Aone联合云栖社区、饿了么、钉钉、阿里云、天猫、口碑发起首届程序媛比码活动——不秀大长腿,秀高智商;不秀美图照,秀代码图,参与晒码互动游戏赢“83行代码”T恤!
我们来说说这群女工程师的第83行代码及代码背后的故事:
public class PurchaseProcessExecutorImpl implements PurchaseProcessExecutor {
/**
* 外部库存服务
*/
private OutInventoryService outInventoryService;
/**
* 执行外部扣减流程,同时更新扣减状态
*
* @param bizOrder
* @return
*/
@Override
public void executeSubtract(InventoryOrder bizOrder, String uid) {
List<SubtractProcessDetail> details = bizOrder.getSubtractProcess();
//生成外部预算请求,key是outInvId
List<OutInventoryControlRequest> outReqs = convert2OutInvReqs(details);
//通过budgetCore进行扣减
Map<String, BudgetControlResult> res = budgetCoreControl(outReqs, uid, ControlType.SUBTRACT);
//更新扣减单元状态
updateUnitStatus(res, details);
//更新子单扣减状态
updateOrderStatus(details);
//更新主单状态
bizOrder.updateSubtractStatus();
}
/**
* 执行回补流程,同时更新回补状态
* @param subtractOrder
* @param rollbackOrder
* @param uid
*/
@Override
public void executeRollback(InventoryOrder subtractOrder, InventoryOrder rollbackOrder,
String uid) {
//生成外部预算请求
List<OutInventoryControlRequest> outReqs = convert2OutInvReqs(
rollbackOrder.getRollbackProcess());
//通过budgetCore进行回补
Map<String, BudgetControlResult> res = budgetCoreControl(outReqs, uid, ControlType.ROLLBACK);
//更新回补单元状态
updateUnitStatus(res, rollbackOrder.getRollbackProcess());
//更新子单状态
updateOrderStatus(rollbackOrder.getRollbackProcess());
//更新主单状态
rollbackOrder.updateRollbackStatus();
}
/**
* 更新扣减单元状态
*
* @param res
* @param details
*/
private <T extends PurchaseProcessDetail> void updateUnitStatus(Map<String, BudgetControlResult> res,
List<T> details) {
if (CollectionTool.isEmpty(details)) {
return;
}
//结果解析
details.forEach(detail -> {
//根据扣减结果更新状态
detail.getUnits()
.forEach(unit -> unit.updateUnitStatus(res.get(unit.getOutInventoryId())));
});
}
/**
* 更新子单明细状态
* @param details
* @param <T>
*/
private <T extends PurchaseProcessDetail> void updateOrderStatus(List<T> details) {
if (CollectionTool.isEmpty(details)) {
return;
}
details.forEach(detail -> detail.updateStatus());
}
/**
* 通过budgetCore进行回补 or 扣减
*
* @param outReqs
* @param uid
*/
private Map<String, BudgetControlResult> budgetCoreControl(List<OutInventoryControlRequest> outReqs,
String uid,
ControlType controlType) {
Map<String, BudgetControlResult> budgetControlResultMap = new HashMap<>();
if (CollectionTool.isEmpty(outReqs)) {
return budgetControlResultMap;
}
//根据类型调用bc进行回补or扣减
if (ControlType.SUBTRACT == controlType) {
//扣减
budgetControlResultMap = outInventoryService.batchSubtract(uid, outReqs);
} else if (ControlType.ROLLBACK == controlType) {
//回补
budgetControlResultMap = outInventoryService.batchRollback(uid, outReqs);
} else {
InvBizLog.procWarn(InvBizType.INV_SUBTRACT, InvSecErrorCode.BC_NOT_SUPPORT, "bc控制模式不支持",
controlType);
}
if (CollectionTool.isEmpty(budgetControlResultMap)) {
InvBizLog.fail(InvBizType.INV_SUBTRACT, InvSecErrorCode.LOAD_BUD_CORE_RESULT_NULL,
"budgetCore调用失败");
throw new InvBusinessException(InvSecErrorCode.LOAD_BUD_CORE_RESULT_NULL, true);
}
InvBizLog.proc(InvBizType.INV_SUBTRACT, "budgetCore调用结束,结果={0}", budgetControlResultMap);
return budgetControlResultMap;
}
}
与衔远小姐姐互动,为她打call——>点击进去衔远晒码
更多小姐姐,点击进入查看代码
有被代码耽误的钉钉吃货程序媛,写代码写到忘记吃饭的——采霜
她急需能把她从代码中叫醒去吃饭的小伙伴,赶紧勾搭;
http://yq.aliyun.com/roundtable/126499/answer/170319#visit170319
有以代码为乐的饿了么大前端打(bei)杂(guo)工程师——敖天羽
http://yq.aliyun.com/roundtable/126499/answer/170299#visit170299
还有全栈美女工程师——前端后端一锅端的——墨瑜女神
http://yq.aliyun.com/roundtable/126499/answer/170316#visit170316
还有阿里云活好码赞,像男人一样活着的技术专家小姐姐——清宵http://yq.aliyun.com/roundtable/126499/answer/170296#visit170296
和天猫Java程序媛,happy(被)来(逼)的——采月
http://yq.aliyun.com/roundtable/126499/answer/170354#visit170354
阿里口碑 搜索推荐组的JAVA女工程师——妍霏
http://yq.aliyun.com/roundtable/126499/answer/214059#visit214059
阿里口碑基础平台技术部的工程师-衔远,一个技术与马甲线并存的mm
http://yq.aliyun.com/roundtable/126499/answer/248798#visit248798
云栖社区聚能聊专家,具有知性温婉气质的——海洋的云http://yq.aliyun.com/roundtable/126499/answer/170290#visit170290
福州市五佰网络科技有限公司的Java女工程师——江小白太白
http://yq.aliyun.com/roundtable/126499/answer/189332#visit189332
在下*的程序媛——cn_suqingnian
http://yq.aliyun.com/roundtable/126499/answer/170309#visit170309
交通银行的前端女工程师——昆0830
http://yq.aliyun.com/roundtable/126499/answer/201979#visit201979