90 lines
2.4 KiB
Java
90 lines
2.4 KiB
Java
package com.team.style;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
/**
|
|
* 团队编码风格演示类。
|
|
*/
|
|
public class TeamStyleService {
|
|
|
|
private static final Logger LOGGER = Logger.getLogger(TeamStyleService.class.getName());
|
|
|
|
private final List<OrderInfo> orderStore;
|
|
|
|
public TeamStyleService() {
|
|
final List<OrderInfo> store = new ArrayList<>();
|
|
store.add(new OrderInfo("order-001", new BigDecimal("99.90")));
|
|
store.add(new OrderInfo("order-002", new BigDecimal("199.00")));
|
|
this.orderStore = Collections.unmodifiableList(store);
|
|
}
|
|
|
|
/**
|
|
* 查询订单列表。
|
|
*
|
|
* @param orderId 订单编号
|
|
* @return 订单列表
|
|
*/
|
|
public List<OrderInfo> handleOrderQuery(final String orderId) {
|
|
if (orderId == null || orderId.isBlank()) {
|
|
throw new IllegalArgumentException("orderId must not be blank");
|
|
}
|
|
final String normalizedOrderId = orderId.strip();
|
|
final List<OrderInfo> result = new ArrayList<>();
|
|
for (final OrderInfo order : orderStore) {
|
|
if (order.getOrderId().equals(normalizedOrderId)) {
|
|
result.add(order);
|
|
}
|
|
}
|
|
if (LOGGER.isLoggable(Level.FINE)) {
|
|
LOGGER.fine("order query executed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 订单控制器。
|
|
*/
|
|
public static class OrderController {
|
|
|
|
private final TeamStyleService service;
|
|
|
|
public OrderController(final TeamStyleService service) {
|
|
this.service = Objects.requireNonNull(service, "service must not be null");
|
|
}
|
|
|
|
public List<OrderInfo> listOrders(final String orderId) {
|
|
return service.handleOrderQuery(orderId);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 订单信息传输对象。
|
|
*
|
|
* @author demo
|
|
*/
|
|
public static class OrderInfo {
|
|
|
|
private final String orderId;
|
|
private final BigDecimal amount;
|
|
|
|
public OrderInfo(final String orderId, final BigDecimal amount) {
|
|
this.orderId = orderId;
|
|
this.amount = amount;
|
|
}
|
|
|
|
public String getOrderId() {
|
|
return orderId;
|
|
}
|
|
|
|
public BigDecimal getAmount() {
|
|
return amount;
|
|
}
|
|
}
|
|
}
|