提交 34c41b40 作者: xiaowang

返回规格价格

上级 47883ca3
......@@ -86,7 +86,7 @@ public interface ProductDao {
List<InventorySpecDO> listInventorySpec(Integer id);
BigDecimal feignGetUnitPriceByTag(PriceAcquisition priceAcquisition);
List<BigDecimal> feignGetUnitPriceByTag(PriceAcquisition priceAcquisition);
List<MallGoodsSpecInfoDO> listProdSpecInfo(@Param("prodIds") Set<Integer> prodIds);
......@@ -121,4 +121,6 @@ public interface ProductDao {
@Param("prodSkuSpecIds") Set<Integer> prodSkuSpecIds);
int countSpecByProdSkuId(Integer id);
BigDecimal getMarketplacePrice(PriceAcquisition priceAcquisition);
}
......@@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author 23214
*/
......@@ -12,9 +14,6 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
public class PriceAcquisition {
@ApiModelProperty(value = "用户id")
private Integer userId;
@ApiModelProperty(value = "规格id")
private Integer specsId;
......@@ -22,6 +21,6 @@ public class PriceAcquisition {
private Integer day;
@ApiModelProperty(value = "渠道等级id")
private Integer channelLevelId;
private List<Integer> channelLevelId;
}
\ No newline at end of file
......@@ -306,20 +306,48 @@ public class ProductServiceImpl implements ProductSkuService {
@Override
public BigDecimal feignGetUnitPriceByTag(PriceAcquisition priceAcquisition) {
Map<Integer, Integer> dayMap = new HashMap<>();
dayMap.put(0, 7);
dayMap.put(8, 15);
dayMap.put(16, 30);
dayMap.put(31, Integer.MAX_VALUE);
Integer dayRange =
dayMap.entrySet().stream()
.filter(entry -> priceAcquisition.getDay() <= entry.getKey())
.findFirst()
.map(Map.Entry::getValue)
.orElseThrow(() -> new RuntimeException("租赁期限错误错误!"));
List<Integer> channelLevelId = priceAcquisition.getChannelLevelId();
if (channelLevelId == null){
return new BigDecimal(0);
}
// 设置时间区间
int dayRange = getDayRange(priceAcquisition.getDay());
priceAcquisition.setDay(dayRange);
return productDao.feignGetUnitPriceByTag(priceAcquisition);
// 获取市场价
BigDecimal marketplacePrice = productDao.getMarketplacePrice(priceAcquisition);
if (marketplacePrice == null) {
return new BigDecimal(0);
}
// 获取渠道价格
List<BigDecimal> price = productDao.feignGetUnitPriceByTag(priceAcquisition);
if (price.size()==0) {
return marketplacePrice;
}else {
List<BigDecimal> sortedPrice = price.stream()
.sorted(Comparator.naturalOrder())
.collect(Collectors.toList());
BigDecimal bigDecimal = sortedPrice.get(0);
if (bigDecimal.compareTo(marketplacePrice) < 0){
return bigDecimal;
}else if (bigDecimal.compareTo(marketplacePrice) > 0){
return marketplacePrice;
}else {
return marketplacePrice;
}
}
}
public int getDayRange(int day) {
if (between(day, 0 ,7)) return 0;
if (between(day, 8, 15)) return 1;
if (between(day, 16,30)) return 2;
if (day > 30) return 3;
throw new RuntimeException("租期有误!");
}
private boolean between(int num, int start, int end){
return num >= start && num <= end;
}
@Override
......
......@@ -319,14 +319,6 @@
AND mp.is_deleted = 0
AND gi.is_deleted = 0
</select>
<select id="feignGetUnitPriceByTag" resultType="java.math.BigDecimal">
select price
from product_spec_price
where product_spec_id = #{specsId}
and cooperation_tag = #{channelLevelId}
and `type` = 1
and lease_term = #{day}
</select>
<select id="listProdSpecInfo" resultType="com.mmc.pms.entity.MallGoodsSpecInfoDO">
SELECT
gi.id, gi.directory_id, mpsip.id as mallSkuInfoSpecId, mpsip.is_deleted as sku_spec_deleted, ps.spec_name,
......@@ -528,4 +520,27 @@
where product_id = #{id}
and is_deleted = 0
</select>
<select id="getMarketplacePrice" resultType="java.math.BigDecimal">
select product_spec_id productSpecId,
cooperation_tag cooperationTag,
price,
lease_term
from product_spec_price
where `type` = 1
and lease_term = #{day}
and cooperation_tag = 0
and product_spec_id = #{specsId}
</select>
<select id="feignGetUnitPriceByTag" resultType="java.math.BigDecimal">
select price
from product_spec_price
<where>
product_spec_id = #{specsId}
and `type` = 1
and lease_term = #{day}
<foreach collection="channelLevelId" index="index" separator="," open="and cooperation_tag in(" close=")" item="d">
#{d}
</foreach>
</where>
</select>
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论