优化以下代码: if (supplierGoodsDTO.getDeliveryWay() == DeliveryWayEnum.PLATFORM_DELIVERY) { //判断商品类目 if (!CollectionUtils.isEmpty(goodsCategoryId)) { if (goodsCategoryId.contains(goodsDTO.getGoodsCategoryId())) { appGoodsVO.setIsOverBought(true); } else { //判断商品是否存在买多返多 if (goodsId.contains(goodsDTO.getId())) { appGoodsVO.setIsOverBought(true); } else { appGoodsVO.setIsOverBought(false); } } } else { //判断商品是否存在买多返多 if (goodsId.contains(goodsDTO.getId())) { appGoodsVO.setIsOverBought(true); } else { appGoodsVO.setIsOverBought(false); } } }
时间: 2024-01-11 18:02:51 浏览: 97
Error:in ./node-modules/axios/lib/platform/index.js
优化后的代码如下:
```
if (supplierGoodsDTO.getDeliveryWay() == DeliveryWayEnum.PLATFORM_DELIVERY) {
boolean isOverBought = false;
if (CollectionUtils.isEmpty(goodsCategoryId) || goodsCategoryId.contains(goodsDTO.getGoodsCategoryId()) || goodsId.contains(goodsDTO.getId())) {
isOverBought = true;
}
appGoodsVO.setIsOverBought(isOverBought);
}
```
优化思路:
1. 将 `appGoodsVO.setIsOverBought()` 的设置操作放到一个变量中,避免重复代码;
2. 判断条件合并,将原来的嵌套判断改为一层判断,简化逻辑。
阅读全文