Authored by hugufei

pi索引中添加toAddScorePoolIds

package com.yoho.search.dal;
import com.yoho.search.dal.model.CsRecommendSknPool;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface CsRecommendSknPoolMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -14,4 +17,7 @@ public interface CsRecommendSknPoolMapper {
int updateByPrimaryKeySelective(CsRecommendSknPool record);
int updateByPrimaryKey(CsRecommendSknPool record);
List<CsRecommendSknPool> selectBySkns(@Param(value = "skns") List<Integer> skns);
}
\ No newline at end of file
... ...
... ... @@ -86,4 +86,15 @@
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectBySkns" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from cs_recommend_skn_pool
where skn in
<foreach item="item" index="index" collection="skns"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -2,24 +2,41 @@ package com.yoho.search.consumer.index.increment.yhb_operations;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.service.daoService.ProductService;
import com.yoho.search.consumer.service.logicService.CsRecommendSknPoolLogicService;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.CsRecommendSknPoolMapper;
import com.yoho.search.dal.model.CsRecommendSknPool;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
@SearchMqConsumerListerner(dbName = "yhb_operations", tableName = "cs_recommend_skn_pool")
public class CsRecommendSknPoolMqListener extends AbstractMqListener {
@Autowired
private CsRecommendSknPoolMapper csRecommendSknPoolMapper;
@Autowired
private CsRecommendSknPoolLogicService csRecommendSknPoolLogicService;
@Autowired
private ProductService productService;
@Override
protected void deleteData(String id) throws Exception {
csRecommendSknPoolMapper.deleteByPrimaryKey(Integer.valueOf(id));
Integer idInt = Integer.valueOf(id);
CsRecommendSknPool csRecommendSknPool = csRecommendSknPoolMapper.selectByPrimaryKey(idInt);
if (csRecommendSknPool == null) {
return;
}
csRecommendSknPoolMapper.deleteByPrimaryKey(csRecommendSknPool.getId());
this.updateProductIndex(csRecommendSknPool.getSkn());
}
@Override
... ... @@ -33,5 +50,21 @@ public class CsRecommendSknPoolMqListener extends AbstractMqListener {
} else {
csRecommendSknPoolMapper.updateByPrimaryKey(csRecommendSknPool);
}
this.updateProductIndex(csRecommendSknPool.getSkn());
}
private void updateProductIndex(Integer skn) {
if (skn == null) {
return;
}
Integer productId = productService.selectProductIdBySkn(skn);
if (productId == null) {
return;
}
List<Integer> poolIds = csRecommendSknPoolLogicService.queryRecommendSknPools(skn);
Map<String, Object> indexData = new HashMap<>();
indexData.put(ProductIndexEsField.productId, productId);
indexData.put(ProductIndexEsField.toAddScorePoolIds, StringUtils.join(poolIds, ","));
this.updateProductIndexWithDataMap(indexData, productId);
}
}
... ...
... ... @@ -641,6 +641,10 @@
"toAddScore": {
"type": "keyword"
},
"toAddScorePoolIds": {
"type": "text",
"analyzer": "comma_spliter"
},
"flowType": {
"type": "long"
},
... ...
... ... @@ -99,6 +99,8 @@ public class ProductIndexBO extends ProductIBO implements Serializable {
// from score_skn_rule
private String toAddScore;
// from cs_recommend_skn_pool
private String toAddScorePools;
// from videos
private String specialSearchFieldVideo;
... ... @@ -661,4 +663,11 @@ public class ProductIndexBO extends ProductIBO implements Serializable {
this.forbiddenPageIds = forbiddenPageIds;
}
public String getToAddScorePools() {
return toAddScorePools;
}
public void setToAddScorePools(String toAddScorePools) {
this.toAddScorePools = toAddScorePools;
}
}
\ No newline at end of file
... ...
package com.yoho.search.consumer.service.logicService;
import com.yoho.search.dal.CsRecommendSknPoolMapper;
import com.yoho.search.dal.model.CsRecommendSknPool;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
public class CsRecommendSknPoolLogicService {
private static final Logger logger = LoggerFactory.getLogger(CsRecommendSknPoolLogicService.class.getSimpleName());
@Autowired
private CsRecommendSknPoolMapper csRecommendSknPoolMapper;
public List<Integer> queryRecommendSknPools(Integer skn) {
Map<Integer, List<Integer>> result = this.queryRecommendSknPools(Arrays.asList(skn));
return result.containsKey(skn) ? result.get(skn) : new ArrayList<>();
}
public Map<Integer, List<Integer>> queryRecommendSknPools(List<Integer> skns) {
try {
if (CollectionUtils.isEmpty(skns)) {
return new HashMap<>();
}
List<CsRecommendSknPool> recommendSknPoolList = csRecommendSknPoolMapper.selectBySkns(skns);
if (CollectionUtils.isEmpty(recommendSknPoolList)) {
return new HashMap<>();
}
final Map<Integer, List<Integer>> result = new HashMap<>();
recommendSknPoolList.stream().forEach(recommendSknPool -> {
List<Integer> poolIds = result.computeIfAbsent(recommendSknPool.getSkn(), skn -> new ArrayList<>());
poolIds.add(recommendSknPool.getPoolId());
});
return result;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new HashMap<>();
}
}
}
... ...
... ... @@ -195,6 +195,7 @@ public class ProductIndexBOToMapService {
map.put(ProductIndexEsField.isFobbiden, productIndexBO.getIsFobbiden());
map.put(ProductIndexEsField.storeShowStatus, productIndexBO.getStoreShowStatus());
map.put(ProductIndexEsField.toAddScore, productIndexBO.getToAddScore());
map.put(ProductIndexEsField.toAddScorePoolIds, productIndexBO.getToAddScorePools());
map.put(ProductIndexEsField.specialSearchField, productIndexBO.getSpecialSearchField());
map.put(ProductIndexEsField.specialSearchFieldVideo, productIndexBO.getSpecialSearchFieldVideo());
... ...
package com.yoho.search.consumer.service.logicService.productIndex;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.logicService.CsRecommendSknPoolLogicService;
import com.yoho.search.consumer.service.logicService.tbl.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Component
public class CsRecommendSknPoolBuilder implements IndexFieldBuilder {
@Autowired
private CsRecommendSknPoolLogicService csRecommendSknPoolLogicService;
@Override
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> idList, List<Integer> sknList) {
Map<Integer, List<Integer>> result = csRecommendSknPoolLogicService.queryRecommendSknPools(sknList);
productIndexBOs.stream().forEach(e->{
List<Integer> poolIds = result.getOrDefault(e.getProductSkn(),new ArrayList<>());
e.setToAddScorePools(StringUtils.join(poolIds,","));
});
}
}
... ...