Authored by LUOXC

refactor

package com.yohoufo.order.model;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.experimental.Builder;
import java.util.List;
... ... @@ -20,9 +21,12 @@ public class InviteSettlementItemListVO {
int totalElements;
String totalOrderAmount;
String totalSettleAmount;
String paidAmount;
String waitPayAmount;
List<InviteSettlementItemVO> list;
@Data
@Accessors(chain = true)
public static class InviteSettlementItemVO {
String buyerOrderCode;
String sellerName;
... ...
... ... @@ -2,7 +2,6 @@ package com.yohoufo.order.service.impl;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.InviteSettlementItemMapper;
import com.yohoufo.dal.order.InviteSettlementMapper;
import com.yohoufo.dal.order.InviterMapper;
... ... @@ -30,8 +29,12 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static com.yohoufo.common.utils.DateUtil.formatYYMMddHHmmssPoint;
import static com.yohoufo.dal.order.model.InviteSettlement.STATUS_WAIT_SETTLE;
import static com.yohoufo.order.utils.InviteSettlementUtils.formatAmount;
import static com.yohoufo.order.utils.ServiceExceptions.throwServiceException;
/**
... ... @@ -72,9 +75,9 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService {
.map(inviteSettlement -> {
InviteSettlementListVO.InviteSettlementVO item = new InviteSettlementListVO.InviteSettlementVO();
item.setSettleCode(String.format("%010d", inviteSettlement.getSettleCode()));
item.setSettleAmount(InviteSettlementUtils.format("+%s", inviteSettlement.getSettleAmount()));
item.setSettleTime(DateUtil.formatYYMMddHHmmssPoint(inviteSettlement.getSettleTime()));
item.setPaidTime(DateUtil.formatYYMMddHHmmssPoint(inviteSettlement.getPaidTime()));
item.setSettleAmount(formatAmount("+%s", inviteSettlement.getSettleAmount()));
item.setSettleTime(formatYYMMddHHmmssPoint(inviteSettlement.getSettleTime()));
item.setPaidTime(formatYYMMddHHmmssPoint(inviteSettlement.getPaidTime()));
return item;
})
.collect(Collectors.toList());
... ... @@ -97,10 +100,14 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService {
.pageSize(limit)
.pageTotal((totalElements % limit == 0) ? (totalElements / limit) : (totalElements / limit + 1))
.totalElements(totalElements)
.totalOrderAmount(InviteSettlementUtils.format(totalOrderAmount))
.totalSettleAmount(InviteSettlementUtils.format(totalSettleAmount));
.totalOrderAmount(formatAmount(totalOrderAmount))
.totalSettleAmount(formatAmount(totalSettleAmount));
if (totalElements == 0) {
return builder.list(Lists.newArrayList()).build();
return builder
.paidAmount(formatAmount(BigDecimal.ZERO))
.waitPayAmount(formatAmount(BigDecimal.ZERO))
.list(Lists.newArrayList())
.build();
}
int start = (page - 1) * limit;
List<InviteSettlementItem> list = inviteSettlementItemMapper.select(uid, settlementType, time.getLeft(), time.getRight(), start, limit);
... ... @@ -110,18 +117,30 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService {
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList()));
Predicate<InviteSettlementItem> itemHasPaid = item -> {
int status = settlementStatusMap.getOrDefault(item.getInviteSettlementId(), STATUS_WAIT_SETTLE).intValue();
return InviteSettlement.STATUS_PAID == status;
};
return builder
.list(list.stream().map(item -> {
Integer settlementStatus = settlementStatusMap.getOrDefault(item.getInviteSettlementId(), InviteSettlement.STATUS_WAIT_SETTLE);
InviteSettlementItemListVO.InviteSettlementItemVO vo = new InviteSettlementItemListVO.InviteSettlementItemVO();
vo.setBuyerOrderCode(item.getBuyerOrderCode().toString());
vo.setSellerName(sellerUidNickNameMap.get(item.getSellerUid()));
vo.setOrderAmount(InviteSettlementUtils.format(item.getOrderAmount()));
vo.setOrderCreateTime(DateUtil.formatYYMMddHHmmssPoint(item.getOrderCreateTime()));
vo.setSettleAmount(InviteSettlementUtils.format(item.getSettleAmount()));
vo.setStatusDesc(settlementStatus.equals(InviteSettlement.STATUS_PAID) ? "已付款" : "待付款");
return vo;
}).collect(Collectors.toList()))
.paidAmount(formatAmount(list.stream()
.filter(itemHasPaid)
.map(InviteSettlementItem::getSettleAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add)))
.waitPayAmount(formatAmount(list.stream()
.filter(itemHasPaid.negate())
.map(InviteSettlementItem::getSettleAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add)))
.list(list.stream()
.map(item -> new InviteSettlementItemListVO.InviteSettlementItemVO()
.setBuyerOrderCode(item.getBuyerOrderCode().toString())
.setSellerName(sellerUidNickNameMap.get(item.getSellerUid()))
.setOrderAmount(formatAmount(item.getOrderAmount()))
.setOrderCreateTime(formatYYMMddHHmmssPoint(item.getOrderCreateTime()))
.setSettleAmount(formatAmount(item.getSettleAmount()))
.setStatusDesc(itemHasPaid.test(item) ? "已付款" : "待付款"))
.collect(Collectors.toList()))
.build();
}
... ...
... ... @@ -16,11 +16,11 @@ import java.util.function.BiPredicate;
*/
public class InviteSettlementUtils {
public static String format(BigDecimal src) {
return format("%s", src);
public static String formatAmount(BigDecimal src) {
return formatAmount("%s", src);
}
public static String format(String format, BigDecimal src) {
public static String formatAmount(String format, BigDecimal src) {
if (Objects.isNull(src)) {
return null;
} else {
... ...