提交 34c41b40 作者: xiaowang

返回规格价格

上级 47883ca3
...@@ -86,7 +86,7 @@ public interface ProductDao { ...@@ -86,7 +86,7 @@ public interface ProductDao {
List<InventorySpecDO> listInventorySpec(Integer id); List<InventorySpecDO> listInventorySpec(Integer id);
BigDecimal feignGetUnitPriceByTag(PriceAcquisition priceAcquisition); List<BigDecimal> feignGetUnitPriceByTag(PriceAcquisition priceAcquisition);
List<MallGoodsSpecInfoDO> listProdSpecInfo(@Param("prodIds") Set<Integer> prodIds); List<MallGoodsSpecInfoDO> listProdSpecInfo(@Param("prodIds") Set<Integer> prodIds);
...@@ -121,4 +121,6 @@ public interface ProductDao { ...@@ -121,4 +121,6 @@ public interface ProductDao {
@Param("prodSkuSpecIds") Set<Integer> prodSkuSpecIds); @Param("prodSkuSpecIds") Set<Integer> prodSkuSpecIds);
int countSpecByProdSkuId(Integer id); int countSpecByProdSkuId(Integer id);
BigDecimal getMarketplacePrice(PriceAcquisition priceAcquisition);
} }
...@@ -5,6 +5,8 @@ import lombok.AllArgsConstructor; ...@@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.List;
/** /**
* @author 23214 * @author 23214
*/ */
...@@ -12,9 +14,6 @@ import lombok.NoArgsConstructor; ...@@ -12,9 +14,6 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class PriceAcquisition { public class PriceAcquisition {
@ApiModelProperty(value = "用户id")
private Integer userId;
@ApiModelProperty(value = "规格id") @ApiModelProperty(value = "规格id")
private Integer specsId; private Integer specsId;
...@@ -22,6 +21,6 @@ public class PriceAcquisition { ...@@ -22,6 +21,6 @@ public class PriceAcquisition {
private Integer day; private Integer day;
@ApiModelProperty(value = "渠道等级id") @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 { ...@@ -306,20 +306,48 @@ public class ProductServiceImpl implements ProductSkuService {
@Override @Override
public BigDecimal feignGetUnitPriceByTag(PriceAcquisition priceAcquisition) { public BigDecimal feignGetUnitPriceByTag(PriceAcquisition priceAcquisition) {
Map<Integer, Integer> dayMap = new HashMap<>(); List<Integer> channelLevelId = priceAcquisition.getChannelLevelId();
dayMap.put(0, 7); if (channelLevelId == null){
dayMap.put(8, 15); return new BigDecimal(0);
dayMap.put(16, 30); }
dayMap.put(31, Integer.MAX_VALUE); // 设置时间区间
int dayRange = getDayRange(priceAcquisition.getDay());
Integer dayRange =
dayMap.entrySet().stream()
.filter(entry -> priceAcquisition.getDay() <= entry.getKey())
.findFirst()
.map(Map.Entry::getValue)
.orElseThrow(() -> new RuntimeException("租赁期限错误错误!"));
priceAcquisition.setDay(dayRange); 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 @Override
......
...@@ -319,14 +319,6 @@ ...@@ -319,14 +319,6 @@
AND mp.is_deleted = 0 AND mp.is_deleted = 0
AND gi.is_deleted = 0 AND gi.is_deleted = 0
</select> </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 id="listProdSpecInfo" resultType="com.mmc.pms.entity.MallGoodsSpecInfoDO">
SELECT SELECT
gi.id, gi.directory_id, mpsip.id as mallSkuInfoSpecId, mpsip.is_deleted as sku_spec_deleted, ps.spec_name, gi.id, gi.directory_id, mpsip.id as mallSkuInfoSpecId, mpsip.is_deleted as sku_spec_deleted, ps.spec_name,
...@@ -528,4 +520,27 @@ ...@@ -528,4 +520,27 @@
where product_id = #{id} where product_id = #{id}
and is_deleted = 0 and is_deleted = 0
</select> </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> </mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论