Authored by zhaoqing

砍价

... ... @@ -11,4 +11,5 @@ public interface CutDownPriceActivityMapper {
List<CutDownPriceActivity> selectCutDownPriceActivityList(@Param("list") List<Integer> activityId);
void updateCutDownPriceActivity(@Param("params") CutDownPriceActivity cutDownPriceActivity);
}
... ...
package com.yoho.activity.dal;
import com.yoho.activity.dal.model.CutDownPriceActivity;
import com.yoho.activity.dal.model.CutDownPriceProduct;
import com.yoho.activity.dal.model.CutDownPriceUserRecord;
import org.apache.ibatis.annotations.Param;
... ... @@ -13,4 +12,7 @@ public interface CutDownPriceProductMapper {
List<CutDownPriceProduct> selectCutDownPriceProductList(@Param("list") List<CutDownPriceUserRecord> records);
void updateCutDownPriceProductStatus(@Param("productSkn")Integer productSkn, @Param("status")Integer status);
void updateCutDownPriceProduct(@Param("list") List<CutDownPriceProduct> cutDownPriceProductList);
}
... ...
package com.yoho.activity.dal.model;
import java.math.BigDecimal;
public class CutDownPriceActivity {
private Integer id;
private Integer activityId;
... ...
... ... @@ -11,6 +11,7 @@ public class CutDownPriceProduct {
private Integer joinNum;
private BigDecimal highPrice;
private BigDecimal lowPrice;
private Integer status;
public Integer getId() {
return id;
... ... @@ -75,4 +76,12 @@ public class CutDownPriceProduct {
public void setLowPrice(BigDecimal lowPrice) {
this.lowPrice = lowPrice;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}
... ...
... ... @@ -31,4 +31,93 @@
#{item}
</foreach>
</select>
<insert id="updateCollageActivity">
INSERT INTO cutdown_price_activity
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="params.activityId != null and params.activityId != ''">
activity_id,
</if>
<if test="params.activityName != null and params.activityName != ''">
activity_name,
</if>
<if test="params.beginTime != null and params.beginTime != ''">
begin_time,
</if>
<if test="params.endTime != null and params.endTime != ''">
end_time,
</if>
<if test="params.createTime != null and params.createTime != ''">
create_time,
</if>
<if test="params.updateTime != null and params.updateTime != ''">
update_time,
</if>
<if test="params.banner != null and params.banner != ''">
banner,
</if>
<if test="params.jumpUrl != null and params.jumpUrl != ''">
jump_url,
</if>
<if test="params.status != null and params.status != ''">
status,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="params.activityId != null and params.activityId != ''">
#{params.activityId},
</if>
<if test="params.activityName != null and params.activityName != ''">
#{params.activityName,jdbcType=VARCHAR},
</if>
<if test="params.beginTime != null and params.beginTime != ''">
#{params.beginTime,jdbcType=INTEGER},
</if>
<if test="params.endTime != null and params.endTime != ''">
#{params.endTime,jdbcType=INTEGER},
</if>
<if test="params.createTime != null and params.createTime != ''">
#{params.createTime,jdbcType=INTEGER},
</if>
<if test="params.updateTime != null and params.updateTime != ''">
#{params.updateTime,jdbcType=INTEGER},
</if>
<if test="params.banner != null and params.banner != ''">
#{params.banner,jdbcType=VARCHAR},
</if>
<if test="params.jumpUrl != null and params.jumpUrl != ''">
#{params.jumpUrl,jdbcType=VARCHAR},
</if>
<if test="params.status != null and params.status != ''">
#{params.status},
</if>
</trim>
ON DUPLICATE KEY UPDATE
<trim suffixOverrides=",">
<if test="params.activityName != null and params.activityName != ''">
activity_name = VALUES(activity_name),
</if>
<if test="params.updateTime != null and params.updateTime != ''">
update_time = VALUES(update_time),
</if>
<if test="params.beginTime != null and params.beginTime != ''">
begin_time = VALUES(begin_time),
</if>
<if test="params.endTime != null and params.endTime != ''">
end_time = VALUES(end_time),
</if>
<if test="params.status != null and params.status != ''">
status = VALUES(status),
</if>
<if test="params.banner != null and params.banner != ''">
banner = VALUES(banner),
</if>
<if test="params.jumpUrl != null and params.jumpUrl != ''">
jump_url = VALUES(jump_url)
</if>
<if test="params.status != null and params.status != ''">
status = VALUES(status),
</if>
</trim>
</insert>
</mapper>
\ No newline at end of file
... ...
... ... @@ -33,4 +33,41 @@
(activity_id=#{item.activityId,jdbcType=INTEGER} and product_skn=#{item.productSkn,jdbcType=INTEGER})
</foreach>
</select>
<update id="updateCutDownPriceProductStatus" >
update cutdown_price_product set status = #{status,jdbcType=INTEGER}
where product_skn = #{productSkn,jdbcType=INTEGER}
</update>
<insert id="updateCutDownPriceProduct">
INSERT INTO cutdown_price_product
<![CDATA[
(activity_id,
product_skn,
join_num,
high_price,
low_price,
create_time,
update_time,
status)
VALUES
]]>
<foreach item="item" collection="list" separator=",">
( #{item.activityId},
#{item.productSkn},
#{item.joinNum},
#{item.highPrice},
#{item.lowPrice},
#{item.createTime},
#{item.updateTime},
#{item.status})
</foreach>
ON DUPLICATE KEY UPDATE
product_skn = VALUES(product_skn),
join_num = VALUES(join_num),
update_time = VALUES(update_time),
high_price = VALUES(high_price),
low_price = VALUES(low_price),
status = VALUES(status))
</insert>
</mapper>
\ No newline at end of file
... ...
... ... @@ -30,6 +30,18 @@
<groupId>com.yoho.core</groupId>
<artifactId>yoho-core-rabbitmq</artifactId>
</dependency>
<dependency>
<groupId>com.yoho.dsf.yhactivity</groupId>
<artifactId>yohobuy-activity-common</artifactId>
</dependency>
<dependency>
<groupId>com.yoho.dsf.yhactivity</groupId>
<artifactId>yohobuy-activity-dal</artifactId>
</dependency>
<dependency>
<groupId>com.yoho.dsf.yhactivity</groupId>
<artifactId>yohobuy-activity-queue</artifactId>
</dependency>
</dependencies>
<build>
... ...
package com.yoho.dsf.mqapi.consumer;
import com.alibaba.fastjson.JSONObject;
import com.yoho.activity.common.redis.CacheKeyEnum;
import com.yoho.activity.common.redis.RedisValueCache;
import com.yoho.activity.dal.CutDownPriceActivityMapper;
import com.yoho.activity.dal.model.CutDownPriceActivity;
import com.yoho.core.rabbitmq.YhConsumer;
import com.yoho.dsf.mqapi.constants.MqConstants;
import com.yoho.dsf.mqapi.model.CutDownPriceActivity;
import com.yoho.dsf.mqapi.service.CutDownPriceActivityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -13,9 +15,11 @@ import org.springframework.stereotype.Service;
@Service(value="collageActivityConsumer")
public class CutDownPriceActivityConsumer implements YhConsumer {
private static final Logger LOGGER = LoggerFactory.getLogger(CutDownPriceActivityConsumer.class);
@Autowired
private CutDownPriceActivityMapper cutDownPriceActivityMapper;
@Autowired
private CutDownPriceActivityService cutDownPriceActivityService;
private RedisValueCache redisValueCache;
@Override
public void handleMessage(Object message) {
... ... @@ -23,7 +27,12 @@ public class CutDownPriceActivityConsumer implements YhConsumer {
try {
CutDownPriceActivity cutDownPriceActivity = JSONObject.parseObject(String.valueOf(message), CutDownPriceActivity.class);
if (null != cutDownPriceActivity){
cutDownPriceActivityService.updateCutDownPriceActivity(cutDownPriceActivity);
cutDownPriceActivityMapper.updateCutDownPriceActivity(cutDownPriceActivity);
//更新的时候清除缓存
if (cutDownPriceActivity.getActivityId() != null){
String redisKeySuffix = cutDownPriceActivity.getActivityId() + "";
redisValueCache.delete(CacheKeyEnum.CUTDOWN_PRICE_ACTIVITYBO_INFO,redisKeySuffix);
}
}
} catch (Exception e) {
LOGGER.warn("handle CutDownPriceActivityConsumer info message failed!! message is " + String.valueOf(message),e);
... ...
... ... @@ -2,10 +2,12 @@ package com.yoho.dsf.mqapi.consumer;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.yoho.activity.common.redis.CacheKeyEnum;
import com.yoho.activity.common.redis.RedisValueCache;
import com.yoho.activity.dal.CutDownPriceProductMapper;
import com.yoho.core.rabbitmq.YhConsumer;
import com.yoho.dsf.mqapi.constants.MqConstants;
import com.yoho.dsf.mqapi.model.CutDownPriceProduct;
import com.yoho.dsf.mqapi.service.CutDownPriceProductService;
import com.yoho.activity.dal.model.CutDownPriceProduct;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -20,7 +22,10 @@ public class CutDownPriceProductConsumer implements YhConsumer {
private static final Logger LOGGER = LoggerFactory.getLogger(CutDownPriceProductConsumer.class);
@Autowired
private CutDownPriceProductService cutDownPriceProductService;
private CutDownPriceProductMapper cutDownPriceProductMapper;
@Autowired
private RedisValueCache redisValueCache;
@Override
public void handleMessage(Object message) {
... ... @@ -30,10 +35,16 @@ public class CutDownPriceProductConsumer implements YhConsumer {
if (CollectionUtils.isEmpty(cutDownPriceProductList)) {
return;
}
if (null == cutDownPriceProductList.get(0).getActivityId()){
cutDownPriceProductService.updateCutDownPriceProductStatus(cutDownPriceProductList.get(0).getProductSkn(),cutDownPriceProductList.get(0).getStatus());
if (null != cutDownPriceProductList.get(0).getStatus() && cutDownPriceProductList.get(0).getStatus() == 2){
cutDownPriceProductMapper.updateCutDownPriceProductStatus(cutDownPriceProductList.get(0).getProductSkn(),cutDownPriceProductList.get(0).getStatus());
}else{
cutDownPriceProductService.updateCutDownPriceProduct(cutDownPriceProductList);
cutDownPriceProductMapper.updateCutDownPriceProduct(cutDownPriceProductList);
}
if (null != cutDownPriceProductList.get(0).getActivityId()){
for (CutDownPriceProduct cutDownPriceProduct : cutDownPriceProductList){
String redisKeySuffix = cutDownPriceProduct.getActivityId() + ":" + cutDownPriceProduct.getProductSkn();
redisValueCache.delete(CacheKeyEnum.CUTDOWN_PRICE_PRODUCTBO_INFO, redisKeySuffix);
}
}
} catch (Exception e) {
LOGGER.warn("handle CutDownPriceProductConsumer info message failed!! message is " + String.valueOf(message),e);
... ...
package com.yoho.dsf.mqapi.model;
/**
* Created by qing.zhao on 2018/1/15.
*/
public class CutDownPriceActivity {
private Integer activityId;
private String activityName;
private Integer status;
private Integer beginTime;
private Integer endTime;
private Integer createTime;
private Integer updateTime;
private String banner;
private String jumpUrl;
public Integer getActivityId() {
return activityId;
}
public void setActivityId(Integer activityId) {
this.activityId = activityId;
}
public String getActivityName() {
return activityName;
}
public void setActivityName(String activityName) {
this.activityName = activityName;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getBeginTime() {
return beginTime;
}
public void setBeginTime(Integer beginTime) {
this.beginTime = beginTime;
}
public Integer getEndTime() {
return endTime;
}
public void setEndTime(Integer endTime) {
this.endTime = endTime;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public String getBanner() {
return banner;
}
public void setBanner(String banner) {
this.banner = banner;
}
public String getJumpUrl() {
return jumpUrl;
}
public void setJumpUrl(String jumpUrl) {
this.jumpUrl = jumpUrl;
}
}
package com.yoho.dsf.mqapi.model;
import java.math.BigDecimal;
/**
* Created by qing.zhao on 2018/1/15.
*/
public class CutDownPriceProduct {
private Integer id;
private Integer activityId;
private Integer productSkn;
private BigDecimal highPrice;
private BigDecimal lowPrice;
private Integer joinNum;
private Integer createTime;
private Integer updateTime;
private Integer status;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getJoinNum() {
return joinNum;
}
public void setJoinNum(Integer joinNum) {
this.joinNum = joinNum;
}
public Integer getActivityId() {
return activityId;
}
public void setActivityId(Integer activityId) {
this.activityId = activityId;
}
public Integer getProductSkn() {
return productSkn;
}
public void setProductSkn(Integer productSkn) {
this.productSkn = productSkn;
}
public BigDecimal getHighPrice() {
return highPrice;
}
public void setHighPrice(BigDecimal highPrice) {
this.highPrice = highPrice;
}
public BigDecimal getLowPrice() {
return lowPrice;
}
public void setLowPrice(BigDecimal lowPrice) {
this.lowPrice = lowPrice;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}