Authored by LUOXC

update

... ... @@ -26,23 +26,12 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.*;
import javax.mail.util.ByteArrayDataSource;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.yohoufo.order.common.BillTradeStatus.HK_AMOUNT_PAYING;
import static com.yohoufo.order.common.BillTradeStatus.HK_AMOUNT_WAIT_PAYMENT;
... ... @@ -139,16 +128,21 @@ public class HkAccountSettlement {
.ifPresent(buyerOrderGoods -> {
getStoragePrice(buyerOrderGoods, storagePrices).ifPresent(storagePrice -> {
getProduct(storagePrice, products).ifPresent(product -> {
Optional<JSONObject> feesOpt = getFees(buyerOrderGoods, fees);
TradeBillResult billResult = TradeBillResult.builder()
.uid(uid)
.orderCode(buyerOrderGoods.getOrderCode())
.productNo(product.getProductCode())
.productName(product.getProductName())
.goodsAmount(buyerOrderGoods.getGoodsAmount())
.tariffAmount(buyerOrderGoods.getTariffAmount())
.platformServiceAmount(tradeBill.getSystemAmount())
.bankTransferAmount(feesOpt
.map(e -> e.getBigDecimal("bankTransferfee"))
.orElse(BigDecimal.ZERO))
.payAmount(tradeBill.getAmount())
.platformServiceAmount(getPlatformFee(buyerOrderGoods, fees).orElse(BigDecimal.ZERO))
.platformServiceAmount(feesOpt
.map(e -> e.getJSONObject("platformFee"))
.map(e -> e.getBigDecimal("total"))
.orElse(BigDecimal.ZERO))
.payType(tradeBill.getTradeType() == 1 ? "保证金"
: tradeBill.getTradeType() == 2 ? "货款"
: tradeBill.getTradeType() == 3 ? "补偿款" : "")
... ... @@ -173,8 +167,8 @@ public class HkAccountSettlement {
// 商品名称
private String productName;
private BigDecimal goodsAmount;
// 税费
private BigDecimal tariffAmount;
// 银行转账费
private BigDecimal bankTransferAmount;
//平台服务费
private BigDecimal platformServiceAmount;
// 打款金额
... ... @@ -189,13 +183,11 @@ public class HkAccountSettlement {
.findAny();
}
private Optional<BigDecimal> getPlatformFee(BuyerOrderGoods buyerOrderGoods, List<SellerOrderMeta> fees) {
private Optional<JSONObject> getFees(BuyerOrderGoods buyerOrderGoods, List<SellerOrderMeta> fees) {
return fees.stream()
.filter(e -> e.getSkup().equals(buyerOrderGoods.getSkup()))
.map(SellerOrderMeta::getMetaValue)
.map(JSONObject::parseObject)
.map(e -> e.getJSONObject("platformFee"))
.map(e -> e.getBigDecimal("total"))
.findAny();
}
... ... @@ -251,7 +243,7 @@ public class HkAccountSettlement {
private String buildDate(List<TradeBillResult> tradeBillResults) {
StringBuffer text = new StringBuffer();
text.append("用户UID,订单编号,商品货号,商品名称,商品金额,费,平台服务费,打款金额,金额类型");
text.append("用户UID,订单编号,商品货号,商品名称,商品金额,银行转账费,平台服务费,打款金额,金额类型");
Function<Function<TradeBillResult, BigDecimal>, BigDecimal> total = map -> tradeBillResults.stream().map(map).reduce(BigDecimal.ZERO, BigDecimal::add);
tradeBillResults.forEach(tradeBillResult -> text.append("\n")
.append(tradeBillResult.getUid()).append(",")
... ... @@ -259,7 +251,7 @@ public class HkAccountSettlement {
.append(tradeBillResult.getProductNo()).append(",")
.append(tradeBillResult.getProductName()).append(",")
.append(tradeBillResult.getGoodsAmount()).append(",")
.append(tradeBillResult.getTariffAmount()).append(",")
.append(tradeBillResult.getBankTransferAmount()).append(",")
.append(tradeBillResult.getPlatformServiceAmount()).append(",")
.append(tradeBillResult.getPayAmount()).append(",")
.append(tradeBillResult.getPayType())
... ... @@ -270,7 +262,7 @@ public class HkAccountSettlement {
.append(",")// 商品货号
.append(",")//商品名称
.append(total.apply(TradeBillResult::getGoodsAmount)).append(",")
.append(total.apply(TradeBillResult::getTariffAmount)).append(",")
.append(total.apply(TradeBillResult::getBankTransferAmount)).append(",")
.append(total.apply(TradeBillResult::getPlatformServiceAmount)).append(",")
.append(total.apply(TradeBillResult::getPayAmount)).append(",")
// 金额类型
... ...