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