Authored by wangnan9279

砍价列表中的ufo商品返回现货价格

... ... @@ -14,11 +14,13 @@
<result column="status" property="status" jdbcType="INTEGER"/>
<result column="update_time" property="updateTime" jdbcType="INTEGER"/>
<result column="create_time" property="createTime" jdbcType="INTEGER"/>
<result column="is_hide" property="isHide" jdbcType="INTEGER"/>
<result column="pre_sale_flag" property="preSaleFlag" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
id,skup, product_id, goods_id, storage_id, depot_num, seller_uid, price, status, update_time,
create_time
create_time,is_hide,pre_sale_flag
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
... ... @@ -69,6 +71,12 @@
<if test="createTime != null">
create_time,
</if>
<if test="isHide != null">
is_hide,
</if>
<if test="preSaleFlag != null">
pre_sale_flag,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
... ... @@ -104,6 +112,12 @@
<if test="createTime != null">
#{createTime,jdbcType=INTEGER},
</if>
<if test="isHide != null">
#{isHide,jdbcType=INTEGER},
</if>
<if test="preSaleFlag != null">
#{preSaleFlag,jdbcType=INTEGER},
</if>
</trim>
</insert>
... ... @@ -140,6 +154,12 @@
<if test="createTime != null">
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if test="isHide != null">
is_hide = #{isHide,jdbcType=INTEGER},
</if>
<if test="preSaleFlag != null">
pre_sale_flag = #{preSaleFlag,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
... ... @@ -155,7 +175,9 @@
price = #{price,jdbcType=DECIMAL},
status = #{status,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER}
create_time = #{createTime,jdbcType=INTEGER},
is_hide = #{isHide,jdbcType=INTEGER},
pre_sale_flag = #{preSaleFlag,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
... ...
... ... @@ -749,6 +749,9 @@
"type": "text",
"analyzer": "lowercase_keyword",
"search_analyzer": "lowercase_keyword"
},
"ufoAvailableNowPrice": {
"type": "double"
}
}
}
... ...
... ... @@ -236,6 +236,9 @@
},
"offerPrice": {
"type": "double"
},
"availableNowPrice": {
"type": "double"
}
}
}
... ...
package com.yoho.search.consumer.service.bo;
import java.math.BigDecimal;
import com.yoho.search.dal.model.ProductPrice;
import java.math.BigDecimal;
public class ProductPriceBO {
private Integer productSkn = 0;
... ... @@ -40,7 +40,10 @@ public class ProductPriceBO {
private String isLatestReducePrice = "N";
private String isnew = "N";
private String specialSearchFieldPrice = "";
// ufo-价格
private Double ufoAvailableNowPrice;
public ProductPriceBO(Integer productSkn) {
this.productSkn = productSkn;
}
... ... @@ -256,4 +259,11 @@ public class ProductPriceBO {
this.isnew = isnew;
}
public Double getUfoAvailableNowPrice() {
return ufoAvailableNowPrice;
}
public void setUfoAvailableNowPrice(Double ufoAvailableNowPrice) {
this.ufoAvailableNowPrice = ufoAvailableNowPrice;
}
}
... ...
package com.yoho.search.consumer.service.bo;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author wangnan
* @version 2019/5/28
*/
@Data
public class UfoPriceBO {
//所有有效库存最低价 storage_price status=1 的
BigDecimal price;
//所有现货库存最低价 storage_price status=1 pre_sale_flag=1 的
BigDecimal availableNowPrice;
}
... ...
... ... @@ -71,4 +71,6 @@ public class UfoProductIndexBO {
private Byte isSynCalender;
//发售价
private BigDecimal offerPrice;
//现货最低价
private Double availableNowPrice;
}
... ...
... ... @@ -94,6 +94,7 @@ public class ProductIndexBOToMapService {
map.put(ProductIndexEsField.specialoffer, productPriceBO.getSpecialoffer());
map.put(ProductIndexEsField.specialSearchFieldPrice, productPriceBO.getSpecialSearchFieldPrice());
map.put(ProductIndexEsField.isLatestReducePrice, productPriceBO.getIsLatestReducePrice());
map.put(ProductIndexEsField.ufoAvailableNowPrice, productPriceBO.getUfoAvailableNowPrice());
map.put(ProductIndexEsField.isnew, productPriceBO.getIsnew());
/*---------------处理价格相关属性end-------------------------------*/
... ...
package com.yoho.search.consumer.service.logicService.ufo;
import com.yoho.search.consumer.service.bo.UfoPriceBO;
import com.yoho.search.consumer.service.bo.UfoProductIndexBO;
import com.yoho.search.dal.UfoStorageMapper;
import com.yoho.search.dal.UfoStoragePriceMapper;
... ... @@ -40,20 +41,56 @@ public class UfoStoragePriceFieldBuilder implements UfoIndexFieldBuilder {
for (UfoProductIndexBO ufoProductIndexBO : ufoProductIndexBOList) {
List<StoragePrice> storagePriceList = ufoStoragePriceMap.get(ufoProductIndexBO.getId());
ufoProductIndexBO.setPrice(-1d);
ufoProductIndexBO.setAvailableNowPrice(-1d);
ufoProductIndexBO.setStorage(0);
if (CollectionUtils.isEmpty(storagePriceList)) {
continue;
}
BigDecimal price = buildPrice(storagePriceList, ufoStorageMap);
if (price == null) {
UfoPriceBO ufoPriceBO = buildUfoPriceBO(storagePriceList, ufoStorageMap);
if (ufoPriceBO.getPrice() == null) {
continue;
}
ufoProductIndexBO.setPrice(price.doubleValue());
ufoProductIndexBO.setPrice(ufoPriceBO.getPrice().doubleValue());
ufoProductIndexBO.setStorage(1);
if (ufoPriceBO.getAvailableNowPrice() == null) {
continue;
}
ufoProductIndexBO.setAvailableNowPrice(ufoPriceBO.getAvailableNowPrice().doubleValue());
}
}
public BigDecimal buildPrice(List<StoragePrice> storagePriceList, Map<Integer, Storage> ufoStorageMap) {
/**
* 构建UfoPriceBO
*/
public UfoPriceBO buildUfoPriceBO(List<StoragePrice> storagePriceList, Map<Integer, Storage> ufoStorageMap) {
UfoPriceBO ufoPriceBO = new UfoPriceBO();
List<StoragePrice> validStoragePriceList = getValidStoragePriceList(storagePriceList, ufoStorageMap);
//获取所有有效库存最低价
if (CollectionUtils.isEmpty(validStoragePriceList)) {
return ufoPriceBO;
}
BigDecimal price = validStoragePriceList.get(0).getPrice();
if (price == null) {
return ufoPriceBO;
}
ufoPriceBO.setPrice(price);
//获取现货最低价
List<StoragePrice> validAvailableNowStoragePriceList = validStoragePriceList.stream().filter(p -> p.getPreSaleFlag() == 0).sorted(Comparator.comparing(StoragePrice::getPrice)).collect(Collectors.toList());
BigDecimal availableNowPrice = validAvailableNowStoragePriceList.get(0).getPrice();
if (availableNowPrice == null) {
return ufoPriceBO;
}
ufoPriceBO.setAvailableNowPrice(availableNowPrice);
return ufoPriceBO;
}
/**
* 获取所有有效的StoragePrice列表
* 条件为:1.status为1(可售) 2.价格小于等于库存规定的最高价
*/
private List<StoragePrice> getValidStoragePriceList(List<StoragePrice> storagePriceList, Map<Integer, Storage> ufoStorageMap) {
List<StoragePrice> validStoragePriceList = new ArrayList<>();
for (StoragePrice storagePrice : storagePriceList) {
if (storagePrice.getStatus() != 1) {
... ... @@ -76,15 +113,9 @@ public class UfoStoragePriceFieldBuilder implements UfoIndexFieldBuilder {
if (CollectionUtils.isEmpty(validStoragePriceList)) {
return null;
}
validStoragePriceList = validStoragePriceList.stream().sorted(Comparator.comparing(StoragePrice::getPrice)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(validStoragePriceList)) {
return null;
}
BigDecimal price = validStoragePriceList.get(0).getPrice();
if (price == null) {
return null;
}
return price;
return validStoragePriceList.stream().sorted(Comparator.comparing(StoragePrice::getPrice)).collect(Collectors.toList());
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.consumer.service.logicService.ufo.ufo2yoho;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.bo.ProductPriceBO;
import com.yoho.search.consumer.service.bo.UfoPriceBO;
import com.yoho.search.consumer.service.logicService.ufo.UfoStoragePriceFieldBuilder;
import com.yoho.search.dal.model.ufo_product.Product;
import com.yoho.search.dal.model.ufo_product.Storage;
... ... @@ -10,8 +11,9 @@ import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
... ... @@ -42,14 +44,18 @@ public class UfoToYohoPriceService {
productIndexBO.setStatus(0);
return;
}
BigDecimal price = ufoStoragePriceFieldBuilder.buildPrice(storagePriceList, idStorageMap);
if (price == null) {
UfoPriceBO ufoPriceBO = ufoStoragePriceFieldBuilder.buildUfoPriceBO(storagePriceList, idStorageMap);
if (ufoPriceBO.getPrice() == null) {
productIndexBO.setStatus(0);
return;
}
ProductPriceBO productPriceBo = new ProductPriceBO(productIndexBO.getProductSkn());
productPriceBo.setMarketPrice(price);
productPriceBo.setSalesPrice(price);
productPriceBo.setMarketPrice(ufoPriceBO.getPrice());
productPriceBo.setSalesPrice(ufoPriceBO.getPrice());
productPriceBo.setUfoAvailableNowPrice(-1d);
if (ufoPriceBO.getAvailableNowPrice() != null) {
productPriceBo.setUfoAvailableNowPrice(ufoPriceBO.getAvailableNowPrice().doubleValue());
}
productIndexBO.setProductPriceBO(productPriceBo);
}
}
... ...