我有4个仓库,分别是A、B、C、D,假设我要从仓库拿N个商品,我先判断ABCD仓库够不够,如果不够则操作无效,然后再判断A是否少于等于N(A仓库不够库存),如果是那么再判断B仓库( 以此类推),否则(A仓库满足N个库存),直接计算
我把这个demo写出来了
也能正确达到我预期目的
但如果有10个仓库,我不能这样一直判断下去吧。
请问各位大哥,有没有什么好方法呢?
if (autoAount >= i) {
this.setAutoAount(this.getAutoAount() - i);
}else {
//少于i,需要重新计算
int iauto = 0;
iauto = i - this.getAutoAount();
this.setAutoAount(0);
if (softAount >= iauto) {
this.setSoftAount(this.getSoftAount() - iauto);
}else {
//少于iauto,需要重新计算
int isoft = 0;
isoft = iauto - this.getSoftAount();
this.setSoftAount(0);
if (halfAount >= isoft) {
this.setHalfAount(this.getHalfAount() - isoft);
}else {
//少于isoft,需要重新计算
int ihalf = 0;
ihalf = isoft - this.getHalfAount();
this.setHalfAount(0);
if (handAount >= ihalf) {
this.setHandAount(this.getHandAount() - ihalf);
}else {
//少于ihand,需要重新计算
//还少于的话,说明出错。
PacketData pd = new PacketData();
pd.setTypeData(PacketData.Game_packet_jiaohuogeikehu_Server_fail_error);
myUtil.sendtopacket(pd, oos);
}
}
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。