Authored by wangnan

storageupdatetime

... ... @@ -4,6 +4,7 @@ import com.yoho.search.dal.model.Product;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface ProductMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -24,6 +25,8 @@ public interface ProductMapper {
Integer selectSknByProductId(Integer productId);
Map<Integer,Integer> selectSknsByProductIds(List<Integer> productIds);
List<Product> getAll();
int count();
... ...
... ... @@ -3,6 +3,9 @@ package com.yoho.search.dal;
import com.yoho.search.dal.model.ProductTiming;
import java.util.List;
import java.util.Map;
public interface ProductTimingMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -14,6 +17,8 @@ public interface ProductTimingMapper {
ProductTiming selectBySkn(Integer skn);
Map<Integer,Integer> selectBySkns(List<Integer> skns);
int updateByPrimaryKeySelective(ProductTiming record);
int updateByPrimaryKey(ProductTiming record);
... ...
... ... @@ -748,8 +748,18 @@
</foreach>
</select>
<select id="selectListByIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from product where id in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectSknsByProductIds" resultMap="java.util.Map">
select
<include refid="Base_Column_List"/>
erp_product_id,id
from product where id in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
... ...
... ... @@ -31,6 +31,15 @@
from product_timing
where product_skn = #{skn,jdbcType=INTEGER} limit 1
</select>
<select id="selectBySkns" resultMap="java.util.Map">
select
product_skn,out_sale_time
from product_timing where product_skn in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from product_timing
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -99,7 +99,7 @@ public class StorageMqListener extends AbstractMqListener implements ChannelAwar
return;
}
//3、更新productIndex
this.updateProductIndex(productId, System.currentTimeMillis(), key);
this.updateProductIndex(productId,productSkn, System.currentTimeMillis(), key);
logger.info("[func=StorageMqListener][step=updateProductIndex][key={}][cost={}ms]", key, costStatistics.getCost());
//4、更新storageSku
... ... @@ -139,7 +139,7 @@ public class StorageMqListener extends AbstractMqListener implements ChannelAwar
storageSkuIndexService.deleteStorageSkuIndex(storage.getErpSkuId(), begin, key);
}
private void updateProductIndex(Integer productId, long begin, final String key) {
private void updateProductIndex(Integer productId,Integer productSkn, long begin, final String key) {
Map<String, Object> indexData = new HashMap<String, Object>();
indexData.put("productId", productId);
List<Storage> storageList = storageService.getStoragesByProductId(productId);
... ... @@ -168,8 +168,10 @@ public class StorageMqListener extends AbstractMqListener implements ChannelAwar
}
//获取storageUpdateTime
List<Integer> productIds = new ArrayList<>();
List<Integer> skns = new ArrayList<>();
productIds.add(productId);
List<StorageUpdateTime> storageUpdateTimes = productIndexLogicService.getStorageUpdateTimeBO(productIds);
skns.add(productSkn)
List<StorageUpdateTime> storageUpdateTimes = productIndexLogicService.getStorageUpdateTimeBO(productIds,skns);
if (CollectionUtils.isNotEmpty(storageUpdateTimes)) {
StorageUpdateTime storageUpdateTime = storageUpdateTimes.get(0);
indexData.put("storageUpdateTime", storageUpdateTime.getStorageUpdateTime());
... ...
... ... @@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
@Component
//@Transactional
... ... @@ -53,4 +54,6 @@ public class ProductService {
public Product getBySkn(Integer skn){return productMapper.selectBySkn(skn); }
public Map<Integer,Integer> selectSknsByProductIds(List<Integer> ProductIds){return productMapper.selectSknsByProductIds(ProductIds);}
}
... ...
... ... @@ -5,6 +5,9 @@ import com.yoho.search.dal.model.ProductTiming;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* Created by wangnan on 2016/11/24.
*/
... ... @@ -39,4 +42,8 @@ public class ProductTimingService {
return productTimingMapper.deleteByPrimaryKey(id);
}
public Map<Integer,Integer> selectBySkns(List<Integer> skns){
return productTimingMapper.selectBySkns(skns);
}
}
... ...
... ... @@ -190,7 +190,7 @@ public class ProductIndexLogicService {
Map<Integer, ProductStyles> productStylesMap = getProductStylesMap(ids);
Map<Integer, ProductGoodsBO> productGoodsesMap = getProductGoodsesMap(ids);
Map<Integer, ProductDefaultImage> productDefaultImagesMap = getProductDefaultImagesMap(ids);
Map<Integer, StorageUpdateTime> getStorageUpdateTimeBOsMap = getStorageUpdateTimeBOsMap(ids);
Map<Integer, StorageUpdateTime> getStorageUpdateTimeBOsMap = getStorageUpdateTimeBOsMap(ids,skns);
Map<Integer, ProductActivitiesBO> productActivitiesMap = getProductActivitiesMap(skns);
Map<Integer, ProductSearchSortWeightBO> productSearchSortWeightsMap = getProductSearchSortWeightsMap(skns);
... ... @@ -923,8 +923,8 @@ public class ProductIndexLogicService {
* @param ids
* @return
*/
public Map<Integer, StorageUpdateTime> getStorageUpdateTimeBOsMap(List<Integer> ids) {
List<StorageUpdateTime> storageUpdateTimes = storageUpdateTimeLogicService.getData(ids);
public Map<Integer, StorageUpdateTime> getStorageUpdateTimeBOsMap(List<Integer> ids,List<Integer> skns) {
List<StorageUpdateTime> storageUpdateTimes = storageUpdateTimeLogicService.getData(ids,skns);
return storageUpdateTimes.stream().parallel().collect(Collectors.toMap(StorageUpdateTime::getProductId, (p) -> p));
}
... ... @@ -1063,8 +1063,8 @@ public class ProductIndexLogicService {
* @param ids
* @return
*/
public List<StorageUpdateTime> getStorageUpdateTimeBO(List<Integer> ids) {
return storageUpdateTimeLogicService.getData(ids);
public List<StorageUpdateTime> getStorageUpdateTimeBO(List<Integer> ids,List<Integer> skns) {
return storageUpdateTimeLogicService.getData(ids,skns);
}
... ...
package com.yoho.search.consumer.service.logic;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.consumer.service.base.ProductService;
import com.yoho.search.consumer.service.base.ProductTimingService;
import com.yoho.search.consumer.service.base.StorageService;
import com.yoho.search.dal.ProductMapper;
import com.yoho.search.dal.model.ProductTiming;
import com.yoho.search.dal.model.StorageUpdateTime;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ... @@ -14,6 +13,7 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by wangnan on 2016/11/22.
... ... @@ -24,15 +24,14 @@ public class StorageUpdateTimeLogicService {
private final Logger logger = LoggerFactory.getLogger(StorageUpdateTimeLogicService.class);
@Autowired
private ProductMapper productMapper;
@Autowired
private StorageService storageService;
@Autowired
private ProductTimingService productTimingService;
@Autowired
private ProductService productService;
public List<StorageUpdateTime> getData(List<Integer> productIds) {
if (CollectionUtils.isEmpty(productIds)) {
logger.warn("[class=StorageUpdateTimeLogicService][fun=getData][message={}]","productIds is empty");
public List<StorageUpdateTime> getData(List<Integer> productIds,List<Integer> productSkns) {
if (CollectionUtils.isEmpty(productIds)||CollectionUtils.isEmpty(productSkns)) {
return new ArrayList<StorageUpdateTime>();
}
//查询Product对应的StorageUpdateTime
... ... @@ -41,21 +40,18 @@ public class StorageUpdateTimeLogicService {
logger.warn("[class=StorageUpdateTimeLogicService][fun=getData][message={}]","storageUpdateTimes is empty");
return new ArrayList<StorageUpdateTime>();
}
//获取多少天后过期Map,key:skn value:outsaletime
Map<Integer,Integer> outSaleTimeMap = productTimingService.selectBySkns(productSkns);
//key:productId value:productSkn
Map<Integer,Integer> productSknMap =productService.selectSknsByProductIds(productIds);
for (StorageUpdateTime storageUpdateTime : storageUpdateTimes) {
//获取多少天后过期
Integer productSkn = productMapper.selectSknByProductId(storageUpdateTime.getProductId());
ProductTiming productTiming = productTimingService.getBySkn(productSkn);
Integer outSaleTime = new Integer(0);
if (productTiming != null && productTiming.getOutSaleTime() != null) {
outSaleTime = productTiming.getOutSaleTime();
}
Integer outSaleTime = outSaleTimeMap.get(productSknMap.get(storageUpdateTime.getProductId()));
//当前的updateTime+过期天数,再取到那天的23:59
Integer updateTime = storageUpdateTime.getStorageUpdateTime();
updateTime = DateUtil.addTimeSecondByDayAmount(updateTime, outSaleTime);
updateTime = DateUtil.getLastTimeSecond(outSaleTime);
if(updateTime==null){
updateTime = new Integer(0);
}
updateTime = DateUtil.getLastTimeSecond(DateUtil.addTimeSecondByDayAmount(updateTime, outSaleTime));
storageUpdateTime.setStorageUpdateTime(updateTime);
}
return storageUpdateTimes;
... ...