Feature: Add SKU prices in RMB, to be used in priority if present

pull/6221/head
Qiuyi LI 2023-08-09 11:30:27 +02:00
parent 6c8d0c06b7
commit bc05f0db5a
5 changed files with 68 additions and 43 deletions

View File

@ -78,7 +78,7 @@ public class InvoiceController {
Set<String> skuIds = orderContents.stream().map(PlatformOrderContent::getSkuId).collect(Collectors.toSet());
List<String> skusWithoutPrice = platformOrderContentMap.searchSkuDetail(new ArrayList<>(skuIds))
.stream()
.filter(skuDetail -> skuDetail.getPrice().getPrice() == null)
.filter(skuDetail -> skuDetail.getPrice().getPrice() == null && skuDetail.getPrice().getPriceRmb() == null)
.map(SkuDetail::getErpCode)
.collect(Collectors.toList());
if (skusWithoutPrice.isEmpty()) {

View File

@ -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.
*/
@Data
@ -19,6 +19,8 @@ public class OrderContentDetail {
private final Integer quantity;
private final BigDecimal exchangeRate;
/**
* Calculate the reduced amount by applying the promotion to the sku.
*
@ -35,7 +37,7 @@ public class OrderContentDetail {
* @return the total price (price * quantity)
*/
public BigDecimal totalPrice() {
BigDecimal unit = skuDetail.getPrice().getPrice(quantity);
BigDecimal unit = skuDetail.getPrice().getPrice(quantity, exchangeRate);
BigDecimal total = unit.multiply(new BigDecimal(quantity));
log.info("unit: {}", unit);
log.info("total: {}", total);
@ -43,7 +45,7 @@ public class OrderContentDetail {
}
public BigDecimal unitPrice(){
return skuDetail.getPrice().getPrice(quantity);
return skuDetail.getPrice().getPrice(quantity, exchangeRate);
}
public int promotionCount() {

View File

@ -13,13 +13,14 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
/**
* @Description: The price of a sku
* @Description: SKU
* @Author: jeecg-boot
* @Date: 2021-04-16
* @Version: V1.0
* @Date: 2023-05-10
* @Version: V1.1
*/
@ApiModel(value = "sku对象", description = "SKU表")
@Setter
@ -30,21 +31,36 @@ public class SkuPrice implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id in the DB
*
*/
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键")
@Getter
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
*/
@Dict(dictTable = "sku", dicText = "erp_code", dicCode = "id")
@ApiModelProperty(value = "SKU ID")
@Getter
private String skuId;
/**
*
*/
@ -60,59 +76,57 @@ public class SkuPrice implements Serializable {
@ApiModelProperty(value = "优惠价起订量")
@Getter
private Integer threshold;
/**
* , maybe null from DB which stands for no discount price
*
*/
@Excel(name = "优惠价", width = 15)
@ApiModelProperty(value = "优惠价")
@Getter
private BigDecimal discountedPrice;
private java.math.BigDecimal discountedPrice;
/**
*
*/
@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")
@ApiModelProperty(value = "生效日期")
@Getter
private Date date;
/**创建人*/
@ApiModelProperty(value = "创建人")
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
private Date createTime;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期")
private Date updateTime;
/**更新人*/
@ApiModelProperty(value = "更新人")
private String updateBy;
/**
*
*/
@Excel(name = "人民币价格", width = 15)
@ApiModelProperty(value = "人民币价格")
@Getter
private java.math.BigDecimal priceRmb;
/**
*
*/
@Excel(name = "人民币优惠价", width = 15)
@ApiModelProperty(value = "人民币优惠价")
@Getter
private java.math.BigDecimal discountedPriceRmb;
/**
* The price of a sku depends on its quantity, Given a quantity here, return the correspondent price.
*
* @param quantity a quantity
* @param eurToRmb Exchange rate from EUR to RMB
* @return the price correspondent to the quantity
*/
public BigDecimal getPrice(int quantity) {
if (quantity >= threshold) {
return discountedPrice == null ? price : discountedPrice;
public BigDecimal getPrice(int quantity, BigDecimal eurToRmb) {
BigDecimal priceCandidate = price;
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() {
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);
}
}

View File

@ -96,6 +96,8 @@
<result property="threshold" column="threshold"/>
<result property="discountedPrice" column="discounted_price"/>
<result property="date" column="price_date"/>
<result property="priceRmb" column="price_rmb"/>
<result property="discountedPriceRmb" column="discounted_price_rmb"/>
</resultMap>
<resultMap id="promotionResultMap" type="org.jeecg.modules.business.entity.Promotion">

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import lombok.extern.slf4j.Slf4j;
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.PlatformOrderMapper;
import org.jeecg.modules.business.service.IClientService;
@ -24,6 +25,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
@ -48,14 +50,17 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
private final PlatformOrderContentMapper platformOrderContentMap;
private final IShippingFeesWaiverProductService shippingFeesWaiverProductService;
private final IClientService clientService;
private final ExchangeRatesMapper exchangeRatesMapper;
@Autowired
public PlatformOrderServiceImpl(PlatformOrderMapper platformOrderMap, PlatformOrderContentMapper platformOrderContentMap,
IShippingFeesWaiverProductService shippingFeesWaiverProductService, IClientService clientService) {
IShippingFeesWaiverProductService shippingFeesWaiverProductService, IClientService clientService,
ExchangeRatesMapper exchangeRatesMapper) {
this.platformOrderMap = platformOrderMap;
this.platformOrderContentMap = platformOrderContentMap;
this.shippingFeesWaiverProductService = shippingFeesWaiverProductService;
this.clientService = clientService;
this.exchangeRatesMapper = exchangeRatesMapper;
}
@Override
@ -217,6 +222,7 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
@Override
public List<OrderContentDetail> searchPurchaseOrderDetail(List<SkuQuantity> skuQuantities) {
BigDecimal eurToRmb = exchangeRatesMapper.getLatestExchangeRate("EUR", "RMB");
// convert list of (ID, quantity) to map between ID and quantity
Map<String, Integer> skuQuantity =
skuQuantities.stream()
@ -234,7 +240,8 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
.map(
skuDetail -> new OrderContentDetail(
skuDetail,
skuQuantity.get(skuDetail.getSkuId())
skuQuantity.get(skuDetail.getSkuId()),
eurToRmb
)
)
.collect(toList());