优化这段代码:public void fixedSpProduct(List<CrmSpProduct> crmSpProductList,Long spApplyId) { if (CollectionUtils.isNotEmpty(crmSpProductList)) { Map<String,Object> map = new HashMap<>(); map.put("SP_APPLY_ID",spApplyId); List<CrmSpProduct> list = this.getBaseMapper().selectByMap(map); if (CollectionUtils.isNotEmpty(list)){ crmSpProductMapper.deleteByMap(map); } for (CrmSpProduct c : crmSpProductList){ c.setSpApplyId(spApplyId); } super.saveOrUpdateBatch(crmSpProductList); } else { throw new BusinessRuntimeException("当前没有任何产品清单,操作失败"); } }
时间: 2023-06-02 07:03:22 浏览: 133
CollectionUtils:CollectionUtils 类
可以考虑使用批量操作来优化代码:
```
public void fixedSpProduct(List<CrmSpProduct> crmSpProductList,Long spApplyId) {
if (CollectionUtils.isEmpty(crmSpProductList)) {
throw new BusinessRuntimeException("当前没有任何产品清单,操作失败");
}
Map<String,Object> map = new HashMap<>();
map.put("SP_APPLY_ID",spApplyId);
crmSpProductMapper.deleteByMap(map);
for (CrmSpProduct c : crmSpProductList){
c.setSpApplyId(spApplyId);
}
super.saveOrUpdateBatch(crmSpProductList);
}
```
阅读全文