public List<CustomerDTO> getCustomerSalaryByDepartmentNumber(String departmentNumber) {
List<CustomerDTO> customers = customerService.getCustomerSalaryByDepartmentNumber(departmentNumber);
if (CollectionUtils.isNotEmpty(customers)) {
for (CustomerDTO customer : customers) {
customerService.updateCustomDataOne(customer);
customerService.updateCustomDataTwo(customer);
}
}
return customers;
}
我是新来RxJava,并试图了解我想重构上面的Rx的Java简单的代码观测量 的概念,不希望在年底使用Observable.just(customers);
的方法。如果有人能指引我正确的方向,这将是有益的。我们如何转换下面的代码在RxJava代码
请看下面的代码并提供建议。
public Observable<Object> getCustomerSalaryByDepartmentNumber(String departmentNumber) {
Observable<List<CustomerDTO>> customersObservable = Observable.just(departmentNumber).map(dnum -> {
return customerService.getCustomerSalaryByDepartmentNumber(dnum);
});
return customersObservable.map(customers -> {
return Observable.from(customers).map(customer -> {
return Observable.zip(
Observable.just(customerService.updateCustomDataOne(customer)),
Observable.just(customerService.updateCustomDataTwo(customer)),
(r, u) -> {
customer.setCustomDataOne(r.getCustomDataOne());
return customer;
});
});
});
}
感谢您的建议。 – Parmod