mirror of https://github.com/jeecgboot/jeecg-boot
Feature: Add SKU prices in RMB, to be used in priority if present
parent
6c8d0c06b7
commit
bc05f0db5a
|
@ -78,7 +78,7 @@ public class InvoiceController {
|
||||||
Set<String> skuIds = orderContents.stream().map(PlatformOrderContent::getSkuId).collect(Collectors.toSet());
|
Set<String> skuIds = orderContents.stream().map(PlatformOrderContent::getSkuId).collect(Collectors.toSet());
|
||||||
List<String> skusWithoutPrice = platformOrderContentMap.searchSkuDetail(new ArrayList<>(skuIds))
|
List<String> skusWithoutPrice = platformOrderContentMap.searchSkuDetail(new ArrayList<>(skuIds))
|
||||||
.stream()
|
.stream()
|
||||||
.filter(skuDetail -> skuDetail.getPrice().getPrice() == null)
|
.filter(skuDetail -> skuDetail.getPrice().getPrice() == null && skuDetail.getPrice().getPriceRmb() == null)
|
||||||
.map(SkuDetail::getErpCode)
|
.map(SkuDetail::getErpCode)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (skusWithoutPrice.isEmpty()) {
|
if (skusWithoutPrice.isEmpty()) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.math.BigDecimal;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class describe the relation among a sku identified by its id, its quantity,
|
* This class describes the relation among a sku identified by its id, its quantity,
|
||||||
* and its correspondent price and promotion.
|
* and its correspondent price and promotion.
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@ -19,6 +19,8 @@ public class OrderContentDetail {
|
||||||
|
|
||||||
private final Integer quantity;
|
private final Integer quantity;
|
||||||
|
|
||||||
|
private final BigDecimal exchangeRate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the reduced amount by applying the promotion to the sku.
|
* Calculate the reduced amount by applying the promotion to the sku.
|
||||||
*
|
*
|
||||||
|
@ -35,7 +37,7 @@ public class OrderContentDetail {
|
||||||
* @return the total price (price * quantity)
|
* @return the total price (price * quantity)
|
||||||
*/
|
*/
|
||||||
public BigDecimal totalPrice() {
|
public BigDecimal totalPrice() {
|
||||||
BigDecimal unit = skuDetail.getPrice().getPrice(quantity);
|
BigDecimal unit = skuDetail.getPrice().getPrice(quantity, exchangeRate);
|
||||||
BigDecimal total = unit.multiply(new BigDecimal(quantity));
|
BigDecimal total = unit.multiply(new BigDecimal(quantity));
|
||||||
log.info("unit: {}", unit);
|
log.info("unit: {}", unit);
|
||||||
log.info("total: {}", total);
|
log.info("total: {}", total);
|
||||||
|
@ -43,7 +45,7 @@ public class OrderContentDetail {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal unitPrice(){
|
public BigDecimal unitPrice(){
|
||||||
return skuDetail.getPrice().getPrice(quantity);
|
return skuDetail.getPrice().getPrice(quantity, exchangeRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int promotionCount() {
|
public int promotionCount() {
|
||||||
|
|
|
@ -13,13 +13,14 @@ import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: The price of a sku
|
* @Description: SKU价格表
|
||||||
* @Author: jeecg-boot
|
* @Author: jeecg-boot
|
||||||
* @Date: 2021-04-16
|
* @Date: 2023-05-10
|
||||||
* @Version: V1.0
|
* @Version: V1.1
|
||||||
*/
|
*/
|
||||||
@ApiModel(value = "sku对象", description = "SKU表")
|
@ApiModel(value = "sku对象", description = "SKU表")
|
||||||
@Setter
|
@Setter
|
||||||
|
@ -30,21 +31,36 @@ public class SkuPrice implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* id in the DB
|
* 主键
|
||||||
*/
|
*/
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
@ApiModelProperty(value = "主键")
|
@ApiModelProperty(value = "主键")
|
||||||
@Getter
|
@Getter
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "创建人")
|
||||||
|
private java.lang.String createBy;
|
||||||
|
/**
|
||||||
|
* 创建日期
|
||||||
|
*/
|
||||||
|
@JsonFormat(timezone = "GMT+2", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ApiModelProperty(value = "创建日期")
|
||||||
|
private java.util.Date createTime;
|
||||||
|
/**
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "更新人")
|
||||||
|
private java.lang.String updateBy;
|
||||||
/**
|
/**
|
||||||
* SKU ID
|
* SKU ID
|
||||||
*/
|
*/
|
||||||
@Dict(dictTable = "sku", dicText = "erp_code", dicCode = "id")
|
@Dict(dictTable = "sku", dicText = "erp_code", dicCode = "id")
|
||||||
@ApiModelProperty(value = "SKU ID")
|
@ApiModelProperty(value = "SKU ID")
|
||||||
@Getter
|
|
||||||
private String skuId;
|
private String skuId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 价格
|
* 价格
|
||||||
*/
|
*/
|
||||||
|
@ -60,59 +76,57 @@ public class SkuPrice implements Serializable {
|
||||||
@ApiModelProperty(value = "优惠价起订量")
|
@ApiModelProperty(value = "优惠价起订量")
|
||||||
@Getter
|
@Getter
|
||||||
private Integer threshold;
|
private Integer threshold;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 优惠价, maybe null from DB which stands for no discount price
|
* 优惠价
|
||||||
*/
|
*/
|
||||||
@Excel(name = "优惠价", width = 15)
|
@Excel(name = "优惠价", width = 15)
|
||||||
@ApiModelProperty(value = "优惠价")
|
@ApiModelProperty(value = "优惠价")
|
||||||
@Getter
|
@Getter
|
||||||
private BigDecimal discountedPrice;
|
private java.math.BigDecimal discountedPrice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生效日期
|
* 生效日期
|
||||||
*/
|
*/
|
||||||
@Excel(name = "生效日期", width = 15, format = "yyyy-MM-dd")
|
@Excel(name = "生效日期", width = 15, format = "yyyy-MM-dd")
|
||||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
|
@JsonFormat(timezone = "GMT+2", pattern = "yyyy-MM-dd")
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
@ApiModelProperty(value = "生效日期")
|
@ApiModelProperty(value = "生效日期")
|
||||||
@Getter
|
|
||||||
private Date date;
|
private Date date;
|
||||||
|
/**
|
||||||
/**创建人*/
|
* 人民币价格
|
||||||
@ApiModelProperty(value = "创建人")
|
*/
|
||||||
private String createBy;
|
@Excel(name = "人民币价格", width = 15)
|
||||||
|
@ApiModelProperty(value = "人民币价格")
|
||||||
/**创建日期*/
|
@Getter
|
||||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
private java.math.BigDecimal priceRmb;
|
||||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
/**
|
||||||
@ApiModelProperty(value = "创建日期")
|
* 人民币优惠价
|
||||||
private Date createTime;
|
*/
|
||||||
|
@Excel(name = "人民币优惠价", width = 15)
|
||||||
/**更新日期*/
|
@ApiModelProperty(value = "人民币优惠价")
|
||||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
@Getter
|
||||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
private java.math.BigDecimal discountedPriceRmb;
|
||||||
@ApiModelProperty(value = "更新日期")
|
|
||||||
private Date updateTime;
|
|
||||||
|
|
||||||
/**更新人*/
|
|
||||||
@ApiModelProperty(value = "更新人")
|
|
||||||
private String updateBy;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The price of a sku depends on its quantity, Given a quantity here, return the correspondent price.
|
* The price of a sku depends on its quantity, Given a quantity here, return the correspondent price.
|
||||||
*
|
*
|
||||||
* @param quantity a quantity
|
* @param quantity a quantity
|
||||||
|
* @param eurToRmb Exchange rate from EUR to RMB
|
||||||
* @return the price correspondent to the quantity
|
* @return the price correspondent to the quantity
|
||||||
*/
|
*/
|
||||||
public BigDecimal getPrice(int quantity) {
|
public BigDecimal getPrice(int quantity, BigDecimal eurToRmb) {
|
||||||
if (quantity >= threshold) {
|
BigDecimal priceCandidate = price;
|
||||||
return discountedPrice == null ? price : discountedPrice;
|
BigDecimal discountedPriceCandidate = discountedPrice == null ? price : discountedPrice;
|
||||||
|
if (priceRmb != null) {
|
||||||
|
priceCandidate = priceRmb.divide(eurToRmb, RoundingMode.HALF_UP);
|
||||||
|
discountedPriceCandidate = discountedPriceRmb == null ? priceCandidate : discountedPriceRmb.divide(eurToRmb, RoundingMode.HALF_UP);
|
||||||
}
|
}
|
||||||
return price;
|
if (quantity >= threshold) {
|
||||||
|
return discountedPriceCandidate;
|
||||||
|
}
|
||||||
|
return priceCandidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s, %s[%d]", price, discountedPrice, threshold);
|
return String.format("%s, %s[%d], %s(RMB), %s[%d](RMB)", price, discountedPrice, threshold, priceRmb, discountedPriceRmb, threshold);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,8 @@
|
||||||
<result property="threshold" column="threshold"/>
|
<result property="threshold" column="threshold"/>
|
||||||
<result property="discountedPrice" column="discounted_price"/>
|
<result property="discountedPrice" column="discounted_price"/>
|
||||||
<result property="date" column="price_date"/>
|
<result property="date" column="price_date"/>
|
||||||
|
<result property="priceRmb" column="price_rmb"/>
|
||||||
|
<result property="discountedPriceRmb" column="discounted_price_rmb"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<resultMap id="promotionResultMap" type="org.jeecg.modules.business.entity.Promotion">
|
<resultMap id="promotionResultMap" type="org.jeecg.modules.business.entity.Promotion">
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jeecg.modules.business.entity.*;
|
import org.jeecg.modules.business.entity.*;
|
||||||
|
import org.jeecg.modules.business.mapper.ExchangeRatesMapper;
|
||||||
import org.jeecg.modules.business.mapper.PlatformOrderContentMapper;
|
import org.jeecg.modules.business.mapper.PlatformOrderContentMapper;
|
||||||
import org.jeecg.modules.business.mapper.PlatformOrderMapper;
|
import org.jeecg.modules.business.mapper.PlatformOrderMapper;
|
||||||
import org.jeecg.modules.business.service.IClientService;
|
import org.jeecg.modules.business.service.IClientService;
|
||||||
|
@ -24,6 +25,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
|
@ -48,14 +50,17 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
|
||||||
private final PlatformOrderContentMapper platformOrderContentMap;
|
private final PlatformOrderContentMapper platformOrderContentMap;
|
||||||
private final IShippingFeesWaiverProductService shippingFeesWaiverProductService;
|
private final IShippingFeesWaiverProductService shippingFeesWaiverProductService;
|
||||||
private final IClientService clientService;
|
private final IClientService clientService;
|
||||||
|
private final ExchangeRatesMapper exchangeRatesMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public PlatformOrderServiceImpl(PlatformOrderMapper platformOrderMap, PlatformOrderContentMapper platformOrderContentMap,
|
public PlatformOrderServiceImpl(PlatformOrderMapper platformOrderMap, PlatformOrderContentMapper platformOrderContentMap,
|
||||||
IShippingFeesWaiverProductService shippingFeesWaiverProductService, IClientService clientService) {
|
IShippingFeesWaiverProductService shippingFeesWaiverProductService, IClientService clientService,
|
||||||
|
ExchangeRatesMapper exchangeRatesMapper) {
|
||||||
this.platformOrderMap = platformOrderMap;
|
this.platformOrderMap = platformOrderMap;
|
||||||
this.platformOrderContentMap = platformOrderContentMap;
|
this.platformOrderContentMap = platformOrderContentMap;
|
||||||
this.shippingFeesWaiverProductService = shippingFeesWaiverProductService;
|
this.shippingFeesWaiverProductService = shippingFeesWaiverProductService;
|
||||||
this.clientService = clientService;
|
this.clientService = clientService;
|
||||||
|
this.exchangeRatesMapper = exchangeRatesMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -217,6 +222,7 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<OrderContentDetail> searchPurchaseOrderDetail(List<SkuQuantity> skuQuantities) {
|
public List<OrderContentDetail> searchPurchaseOrderDetail(List<SkuQuantity> skuQuantities) {
|
||||||
|
BigDecimal eurToRmb = exchangeRatesMapper.getLatestExchangeRate("EUR", "RMB");
|
||||||
// convert list of (ID, quantity) to map between ID and quantity
|
// convert list of (ID, quantity) to map between ID and quantity
|
||||||
Map<String, Integer> skuQuantity =
|
Map<String, Integer> skuQuantity =
|
||||||
skuQuantities.stream()
|
skuQuantities.stream()
|
||||||
|
@ -234,7 +240,8 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
|
||||||
.map(
|
.map(
|
||||||
skuDetail -> new OrderContentDetail(
|
skuDetail -> new OrderContentDetail(
|
||||||
skuDetail,
|
skuDetail,
|
||||||
skuQuantity.get(skuDetail.getSkuId())
|
skuQuantity.get(skuDetail.getSkuId()),
|
||||||
|
eurToRmb
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.collect(toList());
|
.collect(toList());
|
||||||
|
|
Loading…
Reference in New Issue