{"title": "优化以下代码\n for (SupplierPeriodDto supplierPeriodDto : supplierPeriodDtoList) {\n BigDecimal totalAmount = BigDecimal.ZERO;\n BigDecimal totalPayAmount = BigDecimal.ZERO;\n BigDecimal totalFreightAmount = BigDecimal.ZERO;\n BigDecimal totalCouponAmount = BigDecimal.ZERO;\n for (SupplierOrderDto orderDto : supplierOrderDto) {\n long deliveryTime = DateUtil.parse(DateUtil.formatDateTime(orderDto.getDeliveryTime())).getTime();\n long startTimes = DateUtil.parse(DateUtil.formatDateTime(supplierPeriodDto.getStartTime())).getTime();\n long endTime = DateUtil.parse(DateUtil.formatDateTime(supplierPeriodDto.getEndTime())).getTime();\n if (deliveryTime > endTime) {\n break;\n }\n //发货时间在结账周期\n if (deliveryTime >= startTimes && deliveryTime <= endTime) {\n //应收货款;小规模对应普票;专票对应一般纳税人\n BigDecimal payAmount = merchantMap.get(orderDto.getMerchantId()) == 1 ? orderDto.getTaxPrice() : orderDto.getOnePrice();\n totalPayAmount = totalPayAmount.add(payAmount);\n totalAmount = totalAmount.add(orderDto.getTotalAmount());\n totalFreightAmount = totalFreightAmount.add(orderDto.getFreightAmount());\n totalCouponAmount = totalCouponAmount.add(orderDto.getCouponAmount());\n }\n }\n supplierPeriodDto.setTotalAmount(totalAmount);\n supplierPeriodDto.setTotalPayAmount(totalPayAmount);\n supplierPeriodDto.setTotalFreightAmount(totalFreightAmount);\n supplierPeriodDto.setTotalCouponAmount(totalCouponAmount);\n }

Java代码优化:提升循环效率和可读性

原文地址: https://www.cveoy.top/t/topic/pu9U 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录