Authored by WN\wangnan

heatvalue

package com.yoho.search.dal;
import com.yoho.search.dal.model.ProductHeatValues;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ProductHeatValuesOneDayMapper {
Integer selectLatestDateId();
Integer selectCount(@Param(value = "dateId") Integer dateId);
List<ProductHeatValues> selectHeatValuesOfLatestDateBySkn(@Param(value = "sknList") List<Integer> sknList, @Param(value = "dateId") Integer dateId);
List<ProductHeatValues> selectHeatValuesOfLatestDate(@Param(value = "dateId") Integer dateId, @Param(value = "offset") Integer offset, @Param(value = "pageSize") Integer pageSize);
List<Long> selectSknByDate(@Param(value = "dateId") String dateId, @Param(value = "pageSize") int pageSize);
void deleteBatch(@Param(value = "sknList") List<Long> sknList, @Param(value = "dateId") String dateId);
}
\ 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.ProductHeatValuesOneDayMapper" >
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.ProductHeatValues" >
<id column="product_skn" property="productSkn" jdbcType="INTEGER" />
<result column="date_id" property="dateId" jdbcType="VARCHAR" />
<result column="shareorder_num" property="shareorderNum" jdbcType="DECIMAL" />
<result column="sale_num" property="saleNum" jdbcType="DECIMAL" />
<result column="cart_num" property="cartNum" jdbcType="DECIMAL" />
<result column="favorite_num" property="favoriteNum" jdbcType="DECIMAL" />
<result column="comments_score" property="commentsScore" jdbcType="DECIMAL" />
<result column="ctr_value" property="ctrValue" jdbcType="DECIMAL" />
<result column="sale_amount" property="saleAmount" jdbcType="DECIMAL" />
<result column="profit_amount" property="profitAmount" jdbcType="DECIMAL" />
<result column="last_update_time" property="lastUpdateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
product_skn, date_id, shareorder_num, sale_num, cart_num, favorite_num, comments_score,
ctr_value, sale_amount, profit_amount, last_update_time
</sql>
<select id="selectHeatValuesOfLatestDateBySkn" resultMap="BaseResultMap" timeout="20000">
<![CDATA[
select * from product_heat_values_oneday p
where
date_id = #{dateId}
and
p.product_skn in
]]>
<foreach item="item" index="index" collection="sknList"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectHeatValuesOfLatestDate" resultMap="BaseResultMap" timeout="20000">
select * from product_heat_values_oneday p
where
date_id = #{dateId}
limit #{offset},#{pageSize}
</select>
<select id="selectLatestDateId" resultType="java.lang.Integer">
select max(date_id) from product_heat_values_oneday
</select>
<select id="selectCount" resultType="java.lang.Integer" timeout="20000">
SELECT count(*) FROM product_heat_values_oneday
where
date_id = #{dateId}
</select>
<select id="selectSknByDate" resultType="java.lang.Long" timeout="20000">
SELECT product_skn FROM product_heat_values_oneday where date_id = #{dateId,jdbcType=VARCHAR} limit #{pageSize}
</select>
<delete id="deleteBatch">
<![CDATA[
DELETE FROM product_heat_values_oneday
WHERE
date_id = #{dateId,jdbcType=VARCHAR}
AND
]]>
product_skn in
<foreach item="item" index="index" collection="sknList" open="(" separator="," close=")">
#{item}
</foreach>
</delete>
</mapper>
\ No newline at end of file
... ...
package com.yoho.search.consumer.service.logic.productIndex;
import com.yoho.search.dal.ProductHeatValuesMapper;
import com.yoho.search.dal.ProductHeatValuesOneDayMapper;
import com.yoho.search.dal.ProductMapper;
import com.yoho.search.dal.model.Product;
import com.yoho.search.dal.model.ProductHeatValues;
... ... @@ -34,6 +35,8 @@ public class ProductHeatValueLogicService {
@Autowired
private ProductHeatValuesMapper productHeatValuesMapper;
@Autowired
private ProductHeatValuesOneDayMapper productHeatValuesOneDayMapper;
@Autowired
private ProductMapper productMapper;
private Integer dateId = null;
... ... @@ -53,16 +56,23 @@ public class ProductHeatValueLogicService {
productSknToIdMap.put(product.getErpProductId(), product.getId());
}
List<ProductHeatValues> productHeatValuesList = productHeatValuesMapper.selectHeatValuesOfLatestDateBySkn(sknList, this.getDateId());
if (CollectionUtils.isEmpty(productHeatValuesList)) {
List<ProductHeatValues> productHeatValuesOneDayList = productHeatValuesOneDayMapper.selectHeatValuesOfLatestDateBySkn(sknList, this.getDateId());
if (CollectionUtils.isEmpty(productHeatValuesList)&&CollectionUtils.isEmpty(productHeatValuesOneDayList)) {
return new HashMap<>();
}
Map<Integer, BigDecimal> result = new HashMap<Integer, BigDecimal>();
for (ProductHeatValues productHeatValues : productHeatValuesList) {
Integer productId = productSknToIdMap.get(productHeatValues.getProductSkn());
if (productId != null) {
result.put(productId, this.countHeatValue(productHeatValues));
}
}
Integer productId = productSknToIdMap.get(productHeatValues.getProductSkn());
if (productId != null) {
result.put(productId, this.countHeatValue(productHeatValues));
}
}
for (ProductHeatValues productHeatValues : productHeatValuesOneDayList) {
Integer productId = productSknToIdMap.get(productHeatValues.getProductSkn());
if (productId != null) {
result.put(productId, result.get(productId).add(this.countHeatValue(productHeatValues)));
}
}
return result;
}
... ...