Authored by Zhao

添加最新降价

package com.yoho.search.dal;
import com.yoho.search.dal.model.ProductPrice;
import com.yoho.search.dal.model.ProductPriceHistory;
import java.util.List;
public interface ProductPriceHistoryMapper {
int deleteByPrimaryKey(Integer productId);
//skn 查变价
ProductPriceHistory selectByPrimaryKey(Integer productSkn);
int insert(ProductPriceHistory productPriceHistory);
//晚上的job,备份前一天的价格
int backupHistoryPrice();
//同步最新价格 增量和全量
int updateCurrentPrice();
}
\ No newline at end of file
... ...
package com.yoho.search.dal.model;
import com.yoho.search.base.utils.DateUtil;
import sun.dc.pr.PRError;
import java.math.BigDecimal;
public class ProductPriceHistory {
private Integer productSkn;
private BigDecimal currentSalesPrice;
private BigDecimal historySalesPrice;
private Integer updateTime;
public static ProductPriceHistory create(Integer productSkn, BigDecimal currentSalesPrice) {
ProductPriceHistory productPriceHistory = new ProductPriceHistory();
productPriceHistory.setProductSkn(productSkn);
productPriceHistory.setCurrentSalesPrice(currentSalesPrice);
productPriceHistory.setHistorySalesPrice(BigDecimal.ZERO);
productPriceHistory.setUpdateTime(DateUtil.getCurrentTimeSecond());
return productPriceHistory;
}
public Integer getProductSkn() {
return productSkn;
}
public void setProductSkn(Integer productSkn) {
this.productSkn = productSkn;
}
public BigDecimal getCurrentSalesPrice() {
return currentSalesPrice;
}
public void setCurrentSalesPrice(BigDecimal currentSalesPrice) {
this.currentSalesPrice = currentSalesPrice;
}
public BigDecimal getHistorySalesPrice() {
return historySalesPrice;
}
public void setHistorySalesPrice(BigDecimal historySalesPrice) {
this.historySalesPrice = historySalesPrice;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.search.dal.ProductPriceHistoryMapper">
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.ProductPriceHistory">
<id column="product_skn" property="productSkn" jdbcType="INTEGER" />
<result column="current_sales_price" property="currentSalesPrice" jdbcType="DECIMAL" />
<result column="history_sales_price" property="historySalesPrice" jdbcType="DECIMAL" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List">
product_skn,current_sales_price,history_sales_price,update_time
</sql>
<insert id="insert" parameterType="com.yoho.search.dal.model.ProductPriceHistory" timeout="20000">
insert ignore into product_price_history (product_skn,current_sales_price,history_sales_price,update_time)
values (
#{productSkn,jdbcType=INTEGER},#{currentSalesPrice,jdbcType=DECIMAL},#{historySalesPrice,jdbcType=DECIMAL},#{updateTime,jdbcType=INTEGER}
)
</insert>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" timeout="20000">
delete from product_price_history where product_skn = #{productSkn}
</delete>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" timeout="20000">
select <include refid="Base_Column_List" /> from product_price_history where product_skn = #{productSkn}
</select>
<update id="backupHistoryPrice">
update product_price_history set history_sales_price = current_sales_price
</update>
<update id="updateCurrentPrice">
update product_price_history a INNER JOIN product_price b on a.product_skn = b.product_skn set a.current_sales_price = b.current_price
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -114,6 +114,7 @@ public class ProductPriceMqListener extends AbstractIndexMqListener {
indexData.put("priceUpdateTime", 0);
indexData.put("isnew", "N");
indexData.put(ProductIndexEsField.specialSearchFieldPrice, "");
indexData.put("isLatestReducePrice", "N");
// 更新商品索引
this.updateProductIndexWithDataMap(indexData, productId);
}
... ...
package com.yoho.search.consumer.job;
import com.yoho.search.dal.ProductPriceHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class HistoryPriceJob {
@Autowired
private ProductPriceHistoryMapper productPriceHistoryMapper;
@Scheduled(cron = "0 30 2 * * ?")
public void updateHistoryPriceTask () {
productPriceHistoryMapper.backupHistoryPrice();
productPriceHistoryMapper.updateCurrentPrice();
}
}
... ...
... ... @@ -776,6 +776,10 @@
},
"sevendayMoney": {
"type": "double"
},
"isLatestReducePrice": {
"type": "string",
"index": "not_analyzed"
}
}
}
... ...
package com.yoho.search.consumer.service.base;
import com.yoho.search.dal.ProductPriceHistoryMapper;
import com.yoho.search.dal.ProductPriceMapper;
import com.yoho.search.dal.model.ProductPrice;
import com.yoho.search.dal.model.ProductPriceHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ... @@ -13,6 +15,8 @@ public class ProductPriceService {
@Autowired
private ProductPriceMapper productPriceMapper;
@Autowired
private ProductPriceHistoryMapper productPriceHistoryMapper;
public ProductPrice getBySkn(Integer productSkn) {
return productPriceMapper.selectByPrimaryKey(productSkn);
... ... @@ -27,14 +31,21 @@ public class ProductPriceService {
}
public int saveOrUpdate(ProductPrice productPrice) {
if (productPrice.getProductSkn() == null || productPriceMapper.selectByPrimaryKey(productPrice.getProductSkn()) == null) {
return productPriceMapper.insert(productPrice);
int affect = 0;
ProductPrice oldProductPrice = productPriceMapper.selectByPrimaryKey(productPrice.getProductSkn());
if (productPrice.getProductSkn() == null || oldProductPrice == null) {
affect = productPriceMapper.insert(productPrice);
} else {
return productPriceMapper.updateByPrimaryKeySelective(productPrice);
affect = productPriceMapper.updateByPrimaryKeySelective(productPrice);
if (affect > 0 && productPriceHistoryMapper.selectByPrimaryKey(productPrice.getProductSkn()) == null && productPrice.getCurrentPrice().compareTo(oldProductPrice.getCurrentPrice()) < 0) {
productPriceHistoryMapper.insert(ProductPriceHistory.create(productPrice.getProductSkn(), oldProductPrice.getCurrentPrice()));
}
}
return affect;
}
public int delete(Integer productSkn) {
productPriceHistoryMapper.deleteByPrimaryKey(productSkn);
return productPriceMapper.deleteByPrimaryKey(productSkn);
}
... ...
... ... @@ -147,7 +147,17 @@ public class ProductIndexBO extends ProductIBO implements Serializable {
//product_sales_info
private BigDecimal sevendayMoney;
public BigDecimal getSevendayMoney() {
private String isLatestReducePrice;
public String getIsLatestReducePrice() {
return isLatestReducePrice;
}
public void setIsLatestReducePrice(String isLatestReducePrice) {
this.isLatestReducePrice = isLatestReducePrice;
}
public BigDecimal getSevendayMoney() {
return sevendayMoney;
}
... ...
... ... @@ -30,6 +30,7 @@ public class ProductPriceBO {
private String isStudentPrice;
private String isstudentrebate;
private String vipLevels;
private String isLatestReducePrice;
public ProductPriceBO(ProductPrice productPrice) {
super();
... ... @@ -60,6 +61,14 @@ public class ProductPriceBO {
this.vipDiscount = productPrice.getVipDiscount();
}
public String getIsLatestReducePrice() {
return isLatestReducePrice;
}
public void setIsLatestReducePrice(String isLatestReducePrice) {
this.isLatestReducePrice = isLatestReducePrice;
}
public BigDecimal getVipDiscount() {
return vipDiscount;
}
... ...
... ... @@ -217,6 +217,8 @@ public class ProductIndexBOToMapService {
map.put(ProductIndexEsField.flowType, productIndexBO.getFlowType());
map.put(ProductIndexEsField.sevendayMoney,productIndexBO.getSevendayMoney());
map.put("isLatestReducePrice", productIndexBO.getIsLatestReducePrice());
return map;
}
... ...
... ... @@ -9,6 +9,8 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.yoho.search.dal.ProductPriceHistoryMapper;
import com.yoho.search.dal.model.ProductPriceHistory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -35,6 +37,8 @@ public class ProductPriceBuilder implements ViewBuilder {
@Autowired
private ProductPriceMapper productPriceMapper;
@Autowired
private ProductPriceHistoryMapper productPriceHistoryMapper;
@Autowired
private VipPriceLogicService vipPriceLogicService;
@Autowired
private SpecialDealLogicService specialSearchFieldLogicService;
... ... @@ -52,7 +56,7 @@ public class ProductPriceBuilder implements ViewBuilder {
}
// 构造ProductPriceBO
ProductPriceBO productPriceBO = new ProductPriceBO(productPrice);
this.buildProductPriceBO(productPriceBO);
this.buildProductPriceBO(productPriceBO, productPrice);
// 构造ProductIndexBO
this.buildProductIndexBO(productIndexBO, productPriceBO);
} catch (Exception e) {
... ... @@ -64,7 +68,7 @@ public class ProductPriceBuilder implements ViewBuilder {
/**
* 增量+全量都调用
*/
public void buildProductPriceBO(ProductPriceBO productPriceBO) {
public void buildProductPriceBO(ProductPriceBO productPriceBO, ProductPrice productPrice) {
// 1、计算并重设vip相关价格
vipPriceLogicService.fillProductPriceVipPrice(productPriceBO);
// 2、计算折扣相关
... ... @@ -85,6 +89,7 @@ public class ProductPriceBuilder implements ViewBuilder {
BigDecimal studentPrice = productPriceBO.getStudentPrice();
productPriceBO.setIsStudentPrice(studentPrice== null || studentPrice.compareTo(BigDecimal.ZERO)==0 ? "N" : "Y");
productPriceBO.setIsstudentrebate(productPriceBO.getStudentCoinRate() == null || productPriceBO.getStudentCoinRate().compareTo(BigDecimal.ZERO) == 0 ? "N" : "Y");
productPriceBO.setIsLatestReducePrice(isLatestReducePrice(productPrice.getProductSkn(), productPrice.getCurrentPrice()));
}
private void buildProductIndexBO(ProductIndexBO productIndexBO, ProductPriceBO productPriceBO) {
... ... @@ -124,6 +129,7 @@ public class ProductPriceBuilder implements ViewBuilder {
}
// 计算specialSearchFieldPrice
productIndexBO.setSpecialSearchFieldPrice(specialSearchFieldLogicService.getSpecialSearchFieldPrice(productPriceBO));
productIndexBO.setIsLatestReducePrice(productPriceBO.getIsLatestReducePrice());
}
public Map<String, Object> getProductPriceModelMap(Integer productId, Integer firstShelveTime, ProductPrice pp) {
... ... @@ -134,7 +140,7 @@ public class ProductPriceBuilder implements ViewBuilder {
}
// 构造ProductPriceBO
ProductPriceBO productPriceBO = new ProductPriceBO(pp);
this.buildProductPriceBO(productPriceBO);
this.buildProductPriceBO(productPriceBO, pp);
indexData.put("productId", productId);
indexData.put("marketPrice", this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice()));
indexData.put("salesPrice", this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice()));
... ... @@ -157,9 +163,24 @@ public class ProductPriceBuilder implements ViewBuilder {
indexData.put("isnew", "Y");
}
indexData.put(ProductIndexEsField.specialSearchFieldPrice, specialSearchFieldLogicService.getSpecialSearchFieldPrice(productPriceBO));
indexData.put("isLatestReducePrice", productPriceBO.getIsLatestReducePrice());
return indexData;
}
private String isLatestReducePrice(Integer productSkn, BigDecimal price) {
if (price == null) {
return "N";
}
ProductPriceHistory productPriceHistory = productPriceHistoryMapper.selectByPrimaryKey(productSkn);
if (productPriceHistory == null) {
return "N";
}
if (price.compareTo(productPriceHistory.getCurrentSalesPrice()) == 0) {
return price.compareTo(productPriceHistory.getHistorySalesPrice()) < 0 ? "Y" : "N";
}
return price.compareTo(productPriceHistory.getCurrentSalesPrice()) < 0 ? "Y" : "N";
}
/**
* isNew 标签逻辑
*/
... ...