Authored by unknown

页面屏蔽使用后台提供的功能

package com.yoho.search.dal;
import java.util.List;
import com.yoho.search.dal.model.SknBlock;
public interface SknBlockMapper {
... ... @@ -10,8 +12,12 @@ public interface SknBlockMapper {
int insertSelective(SknBlock record);
SknBlock selectByPrimaryKey(Integer skn);
List<SknBlock> selectListByPrimaryKeys(List<Integer> skns);
int updateByPrimaryKeySelective(SknBlock record);
int updateByPrimaryKey(SknBlock record);
}
\ No newline at end of file
... ...
<?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.SknBlockMapper" >
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.SknBlock" >
<id column="skn" property="skn" jdbcType="INTEGER" />
<result column="page_ids" property="pageIds" jdbcType="VARCHAR" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
skn, page_ids, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from skn_block
where skn = #{skn,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from skn_block
where skn = #{skn,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.search.dal.model.SknBlock" >
insert into skn_block (skn, page_ids, update_time
)
values (#{skn,jdbcType=INTEGER}, #{pageIds,jdbcType=VARCHAR}, #{updateTime,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.yoho.search.dal.model.SknBlock" >
insert into skn_block
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="skn != null" >
skn,
</if>
<if test="pageIds != null" >
page_ids,
</if>
<if test="updateTime != null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="skn != null" >
#{skn,jdbcType=INTEGER},
</if>
<if test="pageIds != null" >
#{pageIds,jdbcType=VARCHAR},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.SknBlock" >
update skn_block
<set >
<if test="pageIds != null" >
page_ids = #{pageIds,jdbcType=VARCHAR},
</if>
<if test="updateTime != null" >
update_time = #{updateTime,jdbcType=INTEGER},
</if>
</set>
where skn = #{skn,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.SknBlock" >
update skn_block
set page_ids = #{pageIds,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=INTEGER}
where skn = #{skn,jdbcType=INTEGER}
</update>
<mapper namespace="com.yoho.search.dal.SknBlockMapper">
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.SknBlock">
<id column="skn" property="skn" jdbcType="INTEGER" />
<result column="page_ids" property="pageIds" jdbcType="VARCHAR" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List">
skn, page_ids, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap"
parameterType="java.lang.Integer">
select
<include refid="Base_Column_List" />
from skn_block
where skn = #{skn,jdbcType=INTEGER}
</select>
<select id="selectListByPrimaryKeys" resultMap="BaseResultMap"
timeout="20000">
select
<include refid="Base_Column_List" />
from skn_block
WHERE skn in
<foreach item="item" index="index" collection="list" open="("
separator="," close=")">
#{item}
</foreach>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from skn_block
where skn = #{skn,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.search.dal.model.SknBlock">
insert into skn_block (skn, page_ids, update_time
)
values (#{skn,jdbcType=INTEGER}, #{pageIds,jdbcType=VARCHAR},
#{updateTime,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.yoho.search.dal.model.SknBlock">
insert into skn_block
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="skn != null">
skn,
</if>
<if test="pageIds != null">
page_ids,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="skn != null">
#{skn,jdbcType=INTEGER},
</if>
<if test="pageIds != null">
#{pageIds,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.SknBlock">
update skn_block
<set>
<if test="pageIds != null">
page_ids = #{pageIds,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=INTEGER},
</if>
</set>
where skn = #{skn,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.SknBlock">
update skn_block
set page_ids = #{pageIds,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=INTEGER}
where skn = #{skn,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
package com.yoho.search.consumer.index.increment.productIndex;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -9,8 +12,11 @@ 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.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.consumer.index.increment.AbstractIndexMqListener;
import com.yoho.search.consumer.service.base.ProductService;
import com.yoho.search.consumer.service.base.SknBlockService;
import com.yoho.search.dal.model.Product;
import com.yoho.search.dal.model.SknBlock;
/**
... ... @@ -19,38 +25,57 @@ import com.yoho.search.dal.model.SknBlock;
@Component
public class SknBlockMqListener extends AbstractIndexMqListener {
private static final Logger logger = LoggerFactory.getLogger(SknBlockMqListener.class);
@Autowired
private SknBlockService sknBlockService;
@Override
public String getIndexName() {
return ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
}
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.SKNBLOCKMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
int intId=Integer.parseInt(id);
SknBlock sknBlock = sknBlockService.selectBySkn(intId);
if (sknBlock ==null) {
return;
}
logger.info("deleteData,skn is {}",id);
sknBlockService.deleteById(intId);
}
@Override
protected void updateData(JSONObject data) throws Exception {
SknBlock sknBlock = ConvertUtils.toJavaObject(SknBlock.class, data);
if (sknBlock == null || sknBlock.getSkn() == null) {
return;
}
logger.info("updateData,skn is {},pageIds is ",sknBlock.getSkn(),sknBlock.getPageIds());
sknBlockService.insertOrUpdate(sknBlock);
}
private static final Logger logger = LoggerFactory.getLogger(SknBlockMqListener.class);
@Autowired
private SknBlockService sknBlockService;
@Autowired
private ProductService productService;
@Override
public String getIndexName() {
return ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
}
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.SKNBLOCKMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
Integer productSkn = Integer.parseInt(id);
SknBlock sknBlock = sknBlockService.selectBySkn(productSkn);
if (sknBlock == null) {
return;
}
logger.info("deleteData,skn is {}", id);
sknBlockService.deleteById(productSkn);
this.updateProductIndex(productSkn, "");
}
@Override
protected void updateData(JSONObject data) throws Exception {
SknBlock sknBlock = ConvertUtils.toJavaObject(SknBlock.class, data);
if (sknBlock == null || sknBlock.getSkn() == null) {
return;
}
logger.info("updateData,skn is {},pageIds is ", sknBlock.getSkn(), sknBlock.getPageIds());
sknBlockService.insertOrUpdate(sknBlock);
this.updateProductIndex(sknBlock.getSkn(), sknBlock.getPageIds());
}
private void updateProductIndex(Integer productSkn, String forbiddenPageIds) {
// 获取product数据
Product product = productService.getBySkn(productSkn);
if (product == null) {
logger.warn("[func=deleteData][indexName={}] can not find this productId(skn= {}) in table product", this.getIndexName(), productSkn);
return;
}
// 更新ES数据
Map<String, Object> esData = new HashMap<String, Object>();
esData.put(ProductIndexEsField.forbiddenPageIds, forbiddenPageIds);
this.updateProductIndexWithDataMap(esData, product.getId());
}
}
... ...
... ... @@ -10,14 +10,11 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.consumer.service.logic.tools.ForbiddenPageIdsLogicService;
import com.yoho.search.core.personalized.BigDataRedisOper;
@Controller
public class ForbiddenPageIdsController {
@Autowired
private ForbiddenPageIdsLogicService forbiddenPageIdsLogicService;
@Autowired
private BigDataRedisOper<?, ?> bigDataRedisOper;
@RequestMapping(value = "/reloadForbiddenPageIds")
@ResponseBody
... ... @@ -25,7 +22,7 @@ public class ForbiddenPageIdsController {
Map<String, Object> testResult = new HashMap<String, Object>();
try {
forbiddenPageIdsLogicService.reloadForbiddenPageIds();
testResult.put("pageForbiddenSknCountMap",forbiddenPageIdsLogicService.getPageForbiddenSknCountMap());
testResult.put("pageForbiddenSknCountMap", forbiddenPageIdsLogicService.getPageForbiddenSknCountMap());
testResult.put("code", 200);
testResult.put("message", "success");
} catch (Exception e) {
... ... @@ -35,7 +32,7 @@ public class ForbiddenPageIdsController {
}
return testResult;
}
@RequestMapping(value = "/getSknForbiddenPageIds")
@ResponseBody
public Map<String, Object> getSknForbiddenPageIds(@RequestParam String productSkn) {
... ...
package com.yoho.search.consumer.service.base;
import com.yoho.search.dal.SknBlockMapper;
import com.yoho.search.dal.model.SknBlock;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.search.dal.SknBlockMapper;
import com.yoho.search.dal.model.SknBlock;
/**
* Created by mingdan.ge on 2017/7/10.
*/
... ... @@ -29,4 +32,8 @@ public class SknBlockService {
public SknBlock selectBySkn(Integer skn){
return sknBlockMapper.selectByPrimaryKey(skn);
}
public List<SknBlock> selectBySkns(List<Integer> skns){
return sknBlockMapper.selectListByPrimaryKeys(skns);
}
}
... ...
package com.yoho.search.consumer.service.logic.productIndex.viewBuilder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yoho.search.consumer.service.base.SknBlockService;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.dal.model.SknBlock;
@Component
public class ForbiddenPageIdsViewBuilder implements ViewBuilder {
@Autowired
private SknBlockService sknBlockService;
@Override
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
List<SknBlock> sknBlocks = sknBlockService.selectBySkns(sknList);
Map<Integer, String> sknForbiddenPageIdMap = new HashMap<Integer, String>();
for (SknBlock sknBlock : sknBlocks) {
sknForbiddenPageIdMap.put(sknBlock.getSkn(), sknBlock.getPageIds());
}
for (ProductIndexBO productIndexBO : productIndexBOs) {
productIndexBO.setForbiddenPageIds(MapUtils.getString(sknForbiddenPageIdMap, productIndexBO.getProductSkn(), ""));
}
}
}
... ...
... ... @@ -9,6 +9,7 @@ import com.yoho.search.consumer.service.bo.ProductStandardsBO;
import com.yoho.search.consumer.service.logic.CacheDataService;
import com.yoho.search.dal.ProductStandardRelationMapper;
import com.yoho.search.dal.model.ProductStandardRelation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -76,7 +77,8 @@ public class ProductStandardsBuilder implements ViewBuilder {
}
}
private List<ProductStandardsBO> getProductStandardsBOList(List<Integer> ids) {
@SuppressWarnings("unchecked")
private List<ProductStandardsBO> getProductStandardsBOList(List<Integer> ids) {
try {
JSONObject jsonObject = cache.get(CACHE_KEY);
Assert.isTrue(jsonObject != null, "[cache jsonObject cannot be null][fun=getProductStandardsBOList]");
... ...
... ... @@ -17,8 +17,8 @@ import com.yoho.search.consumer.service.logic.SalesCategoryLogicService;
@Service
public class SpecialDealLogicService {
@Autowired
private ForbiddenPageIdsLogicService forbiddenPageIdsLogicService;
// @Autowired
// private ForbiddenPageIdsLogicService forbiddenPageIdsLogicService;
@Autowired
private SalesCategoryLogicService salesCategoryLogicService;
... ... @@ -97,10 +97,11 @@ public class SpecialDealLogicService {
String specialSearchField = getSpecialSearchFieldFromProduct(productIBO);
productIBO.setSpecialSearchField(specialSearchField);
// 3、处理forbiddenPageIds
String forbiddenPageIds = forbiddenPageIdsLogicService.getSknForbiddenPageIds(productIBO);
productIBO.setForbiddenPageIds(forbiddenPageIds);
// // 3、处理forbiddenPageIds
// String forbiddenPageIds =
// forbiddenPageIdsLogicService.getSknForbiddenPageIds(productIBO);
// productIBO.setForbiddenPageIds(forbiddenPageIds);
// 4、处理物理分类对应的销售分类
List<Integer> physicalChannels = salesCategoryLogicService.getPhysicalChannelsBySmallSortId(productIBO.getSmallSortId());
productIBO.setPhysicalChannels(StringUtils.join(physicalChannels, ","));
... ...