if (CollUtil.isNotEmpty(fullProvince)) { LocalDate today = LocalDate.now(); LocalDate startTime = reportDTO.getStartTime(); fullProvince.forEach(province -> { TOrderMissReportVo vo = new TOrderMissReportVo(); vo.setProvinceName(province); if (startTime.isAfter(today)) { //开始时间晚于今天 vo.setOrderMissRate(null); } else if (startTime.isBefore(today)) { //开始时间早于今天 vo.setOrderMissRate(0D); } else { //开始时间等于今天 vo.setOrderMissRate(null); } tOrderMissReportVoList.add(vo); }); }JAVA代码优化
时间: 2023-11-27 09:49:38 浏览: 55
可以将if-else语句中的条件判断简化,如下所示:
```
if (startTime.isAfter(today)) {
vo.setOrderMissRate(null);
} else {
vo.setOrderMissRate(startTime.isBefore(today) ? 0D : null);
}
```
这样可以减少代码量,并让逻辑更加清晰。
相关问题
if ((!CollUtil.isNotEmpty(saveSelfRestraintList) || internalSelfRestraintProductCodeService.saveBatch(saveSelfRestraintList)) && (!CollUtil.isNotEmpty(updateApplyWorkOrderList) || internalCooperationApplyWorkOrderService.updateBatchById(updateApplyWorkOrderList)) && (!CollUtil.isNotEmpty(deleteApplyWorkOrderList) || internalCooperationApplyWorkOrderService.removeBatchByIds(deleteApplyWorkOrderList)) && (!CollUtil.isNotEmpty(selfRestraintProductCodeList) || internalCooperationApplyWorkProductCodeService.removeBatchByIds(selfRestraintProductCodeList)) && (!CollUtil.isNotEmpty(updateWorkProcedureList) || workProcedureDescService.updateBatchById(updateWorkProcedureList))){ return Result.ok(); }
根据您提供的代码片段,这是一个条件语句,用于判断一系列操作是否成功执行。如果以下条件之一为真,则返回成功的结果(Result.ok()):
1. 若 `saveSelfRestraintList` 不是空集合,并且 `internalSelfRestraintProductCodeService.saveBatch(saveSelfRestraintList)` 执行成功;
2. 若 `updateApplyWorkOrderList` 不是空集合,并且 `internalCooperationApplyWorkOrderService.updateBatchById(updateApplyWorkOrderList)` 执行成功;
3. 若 `deleteApplyWorkOrderList` 不是空集合,并且 `internalCooperationApplyWorkOrderService.removeBatchByIds(deleteApplyWorkOrderList)` 执行成功;
4. 若 `selfRestraintProductCodeList` 不是空集合,并且 `internalCooperationApplyWorkProductCodeService.removeBatchByIds(selfRestraintProductCodeList)` 执行成功;
5. 若 `updateWorkProcedureList` 不是空集合,并且 `workProcedureDescService.updateBatchById(updateWorkProcedureList)` 执行成功。
如果以上所有条件都不满足,将不会返回任何结果。
CollUtil.isNotEmpty()
CollUtil.isNotEmpty()是一个方法,用于判断一个集合是否非空。它是通过调用CollectionUtils.isNotEmpty()方法来实现的。该方法可以同时处理集合为null或者size为0的情况,因此非常方便。在CollUtil类中,还有一个与之相对应的方法CollUtil.isEmpty(),用于判断集合是否为空。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [CollectionUtils.isEmpty().isNotEmpty()](https://blog.csdn.net/qq_41981122/article/details/102826725)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [使用CollectionUtils.isNotEmpty() 判断 List Set 是否为null](https://blog.csdn.net/zl_1987/article/details/51849486)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文