Authored by WN\wangnan

productprice修改表结构

... ... @@ -16,8 +16,6 @@ public interface ProductPriceMapper {
List<ProductPrice> selectPageLists(@Param(value="offset")Integer offset, @Param(value="pageSize")Integer pageSize);
List<ProductPrice> selectByIds(List<Integer> ids);
List<ProductPrice> selectBySkns(List<Integer> skns);
int selectCount();
... ...
... ... @@ -3,15 +3,10 @@
<mapper namespace="com.yoho.search.dal.ProductPriceMapper">
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.ProductPrice">
<id column="product_id" property="productId" jdbcType="INTEGER" />
<result column="market_price" property="marketPrice" jdbcType="DECIMAL" />
<id column="product_skn" property="productSkn" jdbcType="INTEGER" />
<result column="retail_price" property="retailPrice" jdbcType="DECIMAL" />
<result column="sales_price" property="salesPrice" jdbcType="DECIMAL" />
<result column="purchase_price" property="purchasePrice" jdbcType="DECIMAL" />
<result column="special_price" property="specialPrice" jdbcType="DECIMAL" />
<result column="yoho_coin_num" property="yohoCoinNum" jdbcType="INTEGER" />
<result column="purchase_num" property="purchaseNum" jdbcType="DECIMAL" />
<result column="purchase_cost" property="purchaseCost" jdbcType="DECIMAL" />
<result column="tariff" property="tariff" jdbcType="DECIMAL" />
<result column="vip_discount_type" property="vipDiscountType" jdbcType="INTEGER" />
<result column="vip_discount" property="vipDiscount" jdbcType="DECIMAL" />
<result column="vip_price" property="vipPrice" jdbcType="DECIMAL" />
... ... @@ -19,7 +14,6 @@
<result column="vip2_price" property="vip2Price" jdbcType="DECIMAL" />
<result column="vip3_price" property="vip3Price" jdbcType="DECIMAL" />
<result column="student_price" property="studentPrice" jdbcType="DECIMAL" />
<result column="product_skn" property="productSkn" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
<result column="student_coin_rate" property="studentCoinRate" jdbcType="DECIMAL" />
<result column="lastReducePriceTime" property="lastReducePriceTime" jdbcType="INTEGER" />
... ... @@ -28,9 +22,8 @@
</resultMap>
<sql id="Base_Column_List">
product_id, market_price, sales_price, purchase_price,
special_price, yoho_coin_num,purchase_num, purchase_cost,
tariff, vip_discount_type, vip_discount, vip_price,
product_id, retail_price, sales_price, purchase_price,
vip_discount_type, vip_discount, vip_price,
vip1_price, vip2_price,
vip3_price,student_price,
product_skn,
... ... @@ -43,32 +36,27 @@
select
<include refid="Base_Column_List" />
from product_price
where product_id = #{productId,jdbcType=INTEGER}
where product_skn = #{productSkn,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"
timeout="20000">
delete from product_price
where product_id =
#{productId,jdbcType=INTEGER}
where product_skn =
#{productSkn,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.search.dal.model.ProductPrice"
timeout="20000">
insert ignore into product_price (
product_id, market_price, sales_price,purchase_price,
special_price, yoho_coin_num,purchase_num, purchase_cost,
tariff, vip_discount_type, vip_discount, vip_price,
retail_price, sales_price,purchase_price,
, vip_discount_type, vip_discount, vip_price,
vip1_price, vip2_price, vip3_price,student_price,
product_skn, update_time, student_coin_rate,lastReducePriceTime,
product_vip_status,basic_price
)values (
#{productId,jdbcType=INTEGER},
#{marketPrice,jdbcType=DECIMAL},#{salesPrice,jdbcType=DECIMAL},#{purchasePrice,jdbcType=DECIMAL},
#{specialPrice,jdbcType=DECIMAL},
#{yohoCoinNum,jdbcType=INTEGER},#{purchaseNum,jdbcType=DECIMAL},
#{purchaseCost,jdbcType=DECIMAL},
#{tariff,jdbcType=DECIMAL},#{vipDiscountType,jdbcType=INTEGER},
#{retailPrice,jdbcType=DECIMAL},#{salesPrice,jdbcType=DECIMAL},#{purchasePrice,jdbcType=DECIMAL},
#{vipDiscountType,jdbcType=INTEGER},
#{vipDiscount,jdbcType=DECIMAL}, #{vipPrice,jdbcType=DECIMAL},
#{vip1Price,jdbcType=DECIMAL},
#{vip2Price,jdbcType=DECIMAL},#{vip3Price,jdbcType=DECIMAL},#{studentPrice,jdbcType=DECIMAL},
... ... @@ -82,8 +70,8 @@
timeout="20000">
update product_price
<set>
<if test="marketPrice != null">
market_price = #{marketPrice,jdbcType=DECIMAL},
<if test="retailPrice != null">
retail_price = #{retailPrice,jdbcType=DECIMAL},
</if>
<if test="salesPrice != null">
sales_price = #{salesPrice,jdbcType=DECIMAL},
... ... @@ -91,21 +79,6 @@
<if test="purchasePrice != null">
purchase_price = #{purchasePrice,jdbcType=DECIMAL},
</if>
<if test="specialPrice != null">
special_price = #{specialPrice,jdbcType=DECIMAL},
</if>
<if test="yohoCoinNum != null">
yoho_coin_num = #{yohoCoinNum,jdbcType=INTEGER},
</if>
<if test="purchaseNum != null">
purchase_num = #{purchaseNum,jdbcType=DECIMAL},
</if>
<if test="purchaseCost != null">
purchase_cost = #{purchaseCost,jdbcType=DECIMAL},
</if>
<if test="tariff != null">
tariff = #{tariff,jdbcType=DECIMAL},
</if>
<if test="vipDiscountType != null">
vip_discount_type = #{vipDiscountType,jdbcType=INTEGER},
</if>
... ... @@ -123,11 +96,10 @@
</if>
<if test="vip3Price != null">
vip3_price = #{vip3Price,jdbcType=DECIMAL},
</if>
student_price = #{studentPrice,jdbcType=DECIMAL},
<if test="productSkn != null">
product_skn = #{productSkn,jdbcType=INTEGER},
</if>
</if>
<if test="studentPrice != null">
student_price = #{studentPrice,jdbcType=DECIMAL},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=INTEGER},
</if>
... ... @@ -144,7 +116,7 @@
basic_price = #{basicPrice,jdbcType=DECIMAL},
</if>
</set>
where product_id = #{productId,jdbcType=INTEGER}
where product_skn = #{productSkn,jdbcType=INTEGER}
</update>
<select id="selectCount" resultType="java.lang.Integer" timeout="20000">
... ... @@ -157,16 +129,6 @@
from product_price limit #{offset},#{pageSize}
</select>
<select id="selectByIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from product_price where product_id in
<foreach item="item" index="index" collection="list" open="("
separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectBySkns" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
... ...
... ... @@ -97,8 +97,8 @@ public class ProductMqListener extends AbstractIndexMqListener {
// 处理isNew(规则:首次上架7天内展示且折扣率小于88折)
productIBO.setIsnew("N");
ProductPrice productPrice = productPriceService.getById(productId);
if (productPrice != null && productPriceBuilder.isNew(productIBO.getFirstShelveTime(), productPrice.getMarketPrice(), productPrice.getSalesPrice())) {
ProductPrice productPrice = productPriceService.getBySkn(productSkn);
if (productPrice != null && productPriceBuilder.isNew(productIBO.getFirstShelveTime(), productPrice.getRetailPrice(), productPrice.getSalesPrice())) {
productIBO.setIsnew("Y");
}
logger.info("[step3=getProductI][productId={}][cost={}ms]", productId, costStatistics.getCost());
... ...
... ... @@ -58,23 +58,23 @@ public class ProductPriceMqListener extends AbstractIndexMqListener {
@Override
protected void deleteData(String id) throws Exception {
// 1、获取productId
Integer productId = Integer.valueOf(id);
Integer productSkn = Integer.valueOf(id);
// 2、删除数据库
long begin = System.currentTimeMillis();
productPriceService.delete(productId);
productPriceService.delete(productSkn);
logger.info("[func=deleteData][step=deleteFromBb][productId={}][cost={}ms]", id, this.getCost(begin));
// 3、清空ProductIndex索引中的价格相关参数
begin = System.currentTimeMillis();
this.updateProductIndexByClearPrice(productId);
this.updateProductIndexByClearPrice(productSkn);
}
@Override
protected void updateData(JSONObject data) throws Exception {
ProductPrice productPrice = (ProductPrice) ConvertUtils.transMap2Bean(ProductPrice.class, data);
if (productPrice == null || productPrice.getProductId() == null) {
if (productPrice == null || productPrice.getProductSkn() == null) {
return;
}
// 1、保存至数据库
... ... @@ -120,7 +120,6 @@ public class ProductPriceMqListener extends AbstractIndexMqListener {
ProductPriceBO productPriceBO = new ProductPriceBO(pp);
productPriceBuilder.fillProductPriceBO(productPriceBO);
indexData.put("productId", productPriceBO.getProductId());
indexData.put("specialPrice", this.getDoubleFromBigDecimal(productPriceBO.getSpecialPrice()));
indexData.put("marketPrice", this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice()));
indexData.put("salesPrice", this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice()));
indexData.put("vipPrice", this.getDoubleFromBigDecimal(productPriceBO.getVipPrice()));
... ... @@ -151,10 +150,9 @@ public class ProductPriceMqListener extends AbstractIndexMqListener {
/**
* 清除商品索引里 相关的价格参数
*/
private void updateProductIndexByClearPrice(Integer productId) {
private void updateProductIndexByClearPrice(Integer productSkn) {
Map<String, Object> indexData = new HashMap<String, Object>(30);
indexData.put("productId", productId);
indexData.put("specialPrice", null);
indexData.put("productSkn", productSkn);
indexData.put("marketPrice", null);
indexData.put("salesPrice", null);
indexData.put("vipPrice", null);
... ... @@ -174,7 +172,7 @@ public class ProductPriceMqListener extends AbstractIndexMqListener {
indexData.put("priceUpdateTime", 0);
indexData.put("isnew", "N");
// 更新商品索引
this.updateProductIndexWithDataMap(indexData, productId);
this.updateProductIndexWithDataMap(indexData, productSkn);
}
}
... ...
package com.yoho.search.consumer.service.base;
import java.util.List;
import com.yoho.search.dal.ProductPriceMapper;
import com.yoho.search.dal.model.ProductPrice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yoho.search.dal.ProductPriceMapper;
import com.yoho.search.dal.model.ProductPrice;
import java.util.List;
@Component
//@Transactional
... ... @@ -15,8 +14,8 @@ public class ProductPriceService {
@Autowired
private ProductPriceMapper productPriceMapper;
public ProductPrice getById(Integer productId) {
return productPriceMapper.selectByPrimaryKey(productId);
public ProductPrice getBySkn(Integer productSkn) {
return productPriceMapper.selectByPrimaryKey(productSkn);
}
public int insert(ProductPrice productPrice) {
... ... @@ -28,15 +27,15 @@ public class ProductPriceService {
}
public int saveOrUpdate(ProductPrice productPrice) {
if (productPrice.getProductId() == null || productPriceMapper.selectByPrimaryKey(productPrice.getProductId()) == null) {
if (productPrice.getProductSkn() == null || productPriceMapper.selectByPrimaryKey(productPrice.getProductSkn()) == null) {
return productPriceMapper.insert(productPrice);
} else {
return productPriceMapper.updateByPrimaryKeySelective(productPrice);
}
}
public int delete(Integer productId) {
return productPriceMapper.deleteByPrimaryKey(productId);
public int delete(Integer productSkn) {
return productPriceMapper.deleteByPrimaryKey(productSkn);
}
public List<ProductPrice> getPageLists(int start, int size) {
... ...
... ... @@ -7,7 +7,6 @@ import java.math.BigDecimal;
public class ProductPriceBO {
private Integer productId;
private BigDecimal specialPrice;
private BigDecimal marketPrice;
private BigDecimal salesPrice;
private BigDecimal vipPrice;
... ... @@ -34,9 +33,7 @@ public class ProductPriceBO {
public ProductPriceBO(ProductPrice productPrice) {
super();
this.productId = productPrice.getProductId();
this.specialPrice = productPrice.getSpecialPrice();
this.marketPrice = productPrice.getMarketPrice();
this.marketPrice = productPrice.getRetailPrice();
this.salesPrice = productPrice.getSalesPrice();
this.vipPrice = productPrice.getVipPrice();
this.vipDiscountType = productPrice.getVipDiscountType();
... ... @@ -76,14 +73,6 @@ public class ProductPriceBO {
this.productId = productId;
}
public BigDecimal getSpecialPrice() {
return specialPrice;
}
public void setSpecialPrice(BigDecimal specialPrice) {
this.specialPrice = specialPrice;
}
public BigDecimal getMarketPrice() {
return marketPrice;
}
... ...
... ... @@ -73,7 +73,7 @@ public class StorageSkuLogicService {
}
Map<Integer, Goods> goodsMap = getGoodsMap(goodsIds);
Map<Integer, ProductColors> productColorsMap = getProductColorMap(productIds);
Map<Integer, ProductPrice> productPriceMap = getProductPrice(productIds);
Map<Integer, ProductPrice> productPriceMap = getProductPrice(productSknList);
Map<Integer, Product15DaySalesNum> product15DaySalesNumMap = getProductSalesMap(productSknList);
Map<Integer, BasePinRatio> basePinRatioMap = getBasePinRatioMap(productSknList);
Map<Integer, BrokenCode> brokenCodesMap = getBrokenCodeMap(productSknList);
... ... @@ -127,12 +127,12 @@ public class StorageSkuLogicService {
return product15DaySalesNumMap;
}
private Map<Integer, ProductPrice> getProductPrice(List<Integer> productIds) {
if (CollectionUtils.isEmpty(productIds)) {
private Map<Integer, ProductPrice> getProductPrice(List<Integer> productSknList) {
if (CollectionUtils.isEmpty(productSknList)) {
return new HashMap<>();
}
List<ProductPrice> productPrices = productPriceMapper.selectByIds(productIds);
Map<Integer, ProductPrice> productPriceMap = productPrices.stream().parallel().collect(Collectors.toMap(ProductPrice::getProductId, (p) -> p));
List<ProductPrice> productPrices = productPriceMapper.selectBySkns(productSknList);
Map<Integer, ProductPrice> productPriceMap = productPrices.stream().parallel().collect(Collectors.toMap(ProductPrice::getProductSkn, (p) -> p));
return productPriceMap;
}
... ... @@ -206,9 +206,9 @@ public class StorageSkuLogicService {
ProductPrice pp = productPriceMap.get(storageSkuBO.getProductId());
storageSkuBO.setIsDiscount("N");
if (null != pp) {
storageSkuBO.setMarketPrice(pp.getMarketPrice());
storageSkuBO.setMarketPrice(pp.getRetailPrice());
storageSkuBO.setSalesPrice(pp.getSalesPrice());
storageSkuBO.setIsDiscount(pp.getSalesPrice().compareTo(pp.getMarketPrice()) < 0 ? "Y" : "N");
storageSkuBO.setIsDiscount(pp.getSalesPrice().compareTo(pp.getRetailPrice()) < 0 ? "Y" : "N");
}
}
... ...
... ... @@ -34,8 +34,8 @@ public class ProductPriceBuilder implements ViewBuilder {
@Override
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
List<ProductPrice> productPrices = productPriceMapper.selectByIds(ids);
Map<Integer, ProductPrice> productPricesMap = productPrices.stream().collect(Collectors.toMap(ProductPrice::getProductId, (p) -> p));
List<ProductPrice> productPrices = productPriceMapper.selectBySkns(sknList);
Map<Integer, ProductPrice> productPricesMap = productPrices.stream().collect(Collectors.toMap(ProductPrice::getProductSkn, (p) -> p));
for (ProductIndexBO pi : productIndexBOs) {
// set default
pi.setIsDiscount("N");
... ... @@ -58,7 +58,6 @@ public class ProductPriceBuilder implements ViewBuilder {
ProductPriceBO productPriceBO = new ProductPriceBO(productPrice);
this.fillProductPriceBO(productPriceBO);
pi.setSpecialPrice(productPriceBO.getSpecialPrice());
pi.setMarketPrice(productPriceBO.getMarketPrice());
pi.setVipDiscountType(productPriceBO.getVipDiscountType());
pi.setSalesPrice(productPriceBO.getSalesPrice());
... ...