Authored by zhaoqing

砍价

@@ -11,4 +11,5 @@ public interface CutDownPriceActivityMapper { @@ -11,4 +11,5 @@ public interface CutDownPriceActivityMapper {
11 11
12 List<CutDownPriceActivity> selectCutDownPriceActivityList(@Param("list") List<Integer> activityId); 12 List<CutDownPriceActivity> selectCutDownPriceActivityList(@Param("list") List<Integer> activityId);
13 13
  14 + void updateCutDownPriceActivity(@Param("params") CutDownPriceActivity cutDownPriceActivity);
14 } 15 }
1 package com.yoho.activity.dal; 1 package com.yoho.activity.dal;
2 2
3 -import com.yoho.activity.dal.model.CutDownPriceActivity;  
4 import com.yoho.activity.dal.model.CutDownPriceProduct; 3 import com.yoho.activity.dal.model.CutDownPriceProduct;
5 import com.yoho.activity.dal.model.CutDownPriceUserRecord; 4 import com.yoho.activity.dal.model.CutDownPriceUserRecord;
6 import org.apache.ibatis.annotations.Param; 5 import org.apache.ibatis.annotations.Param;
@@ -13,4 +12,7 @@ public interface CutDownPriceProductMapper { @@ -13,4 +12,7 @@ public interface CutDownPriceProductMapper {
13 12
14 List<CutDownPriceProduct> selectCutDownPriceProductList(@Param("list") List<CutDownPriceUserRecord> records); 13 List<CutDownPriceProduct> selectCutDownPriceProductList(@Param("list") List<CutDownPriceUserRecord> records);
15 14
  15 + void updateCutDownPriceProductStatus(@Param("productSkn")Integer productSkn, @Param("status")Integer status);
  16 +
  17 + void updateCutDownPriceProduct(@Param("list") List<CutDownPriceProduct> cutDownPriceProductList);
16 } 18 }
1 package com.yoho.activity.dal.model; 1 package com.yoho.activity.dal.model;
2 2
3 -import java.math.BigDecimal;  
4 -  
5 public class CutDownPriceActivity { 3 public class CutDownPriceActivity {
6 private Integer id; 4 private Integer id;
7 private Integer activityId; 5 private Integer activityId;
@@ -11,6 +11,7 @@ public class CutDownPriceProduct { @@ -11,6 +11,7 @@ public class CutDownPriceProduct {
11 private Integer joinNum; 11 private Integer joinNum;
12 private BigDecimal highPrice; 12 private BigDecimal highPrice;
13 private BigDecimal lowPrice; 13 private BigDecimal lowPrice;
  14 + private Integer status;
14 15
15 public Integer getId() { 16 public Integer getId() {
16 return id; 17 return id;
@@ -75,4 +76,12 @@ public class CutDownPriceProduct { @@ -75,4 +76,12 @@ public class CutDownPriceProduct {
75 public void setLowPrice(BigDecimal lowPrice) { 76 public void setLowPrice(BigDecimal lowPrice) {
76 this.lowPrice = lowPrice; 77 this.lowPrice = lowPrice;
77 } 78 }
  79 +
  80 + public Integer getStatus() {
  81 + return status;
  82 + }
  83 +
  84 + public void setStatus(Integer status) {
  85 + this.status = status;
  86 + }
78 } 87 }
@@ -31,4 +31,93 @@ @@ -31,4 +31,93 @@
31 #{item} 31 #{item}
32 </foreach> 32 </foreach>
33 </select> 33 </select>
  34 +
  35 + <insert id="updateCollageActivity">
  36 + INSERT INTO cutdown_price_activity
  37 + <trim prefix="(" suffix=")" suffixOverrides=",">
  38 + <if test="params.activityId != null and params.activityId != ''">
  39 + activity_id,
  40 + </if>
  41 + <if test="params.activityName != null and params.activityName != ''">
  42 + activity_name,
  43 + </if>
  44 + <if test="params.beginTime != null and params.beginTime != ''">
  45 + begin_time,
  46 + </if>
  47 + <if test="params.endTime != null and params.endTime != ''">
  48 + end_time,
  49 + </if>
  50 + <if test="params.createTime != null and params.createTime != ''">
  51 + create_time,
  52 + </if>
  53 + <if test="params.updateTime != null and params.updateTime != ''">
  54 + update_time,
  55 + </if>
  56 + <if test="params.banner != null and params.banner != ''">
  57 + banner,
  58 + </if>
  59 + <if test="params.jumpUrl != null and params.jumpUrl != ''">
  60 + jump_url,
  61 + </if>
  62 + <if test="params.status != null and params.status != ''">
  63 + status,
  64 + </if>
  65 + </trim>
  66 + <trim prefix="values (" suffix=")" suffixOverrides=",">
  67 + <if test="params.activityId != null and params.activityId != ''">
  68 + #{params.activityId},
  69 + </if>
  70 + <if test="params.activityName != null and params.activityName != ''">
  71 + #{params.activityName,jdbcType=VARCHAR},
  72 + </if>
  73 + <if test="params.beginTime != null and params.beginTime != ''">
  74 + #{params.beginTime,jdbcType=INTEGER},
  75 + </if>
  76 + <if test="params.endTime != null and params.endTime != ''">
  77 + #{params.endTime,jdbcType=INTEGER},
  78 + </if>
  79 + <if test="params.createTime != null and params.createTime != ''">
  80 + #{params.createTime,jdbcType=INTEGER},
  81 + </if>
  82 + <if test="params.updateTime != null and params.updateTime != ''">
  83 + #{params.updateTime,jdbcType=INTEGER},
  84 + </if>
  85 + <if test="params.banner != null and params.banner != ''">
  86 + #{params.banner,jdbcType=VARCHAR},
  87 + </if>
  88 + <if test="params.jumpUrl != null and params.jumpUrl != ''">
  89 + #{params.jumpUrl,jdbcType=VARCHAR},
  90 + </if>
  91 + <if test="params.status != null and params.status != ''">
  92 + #{params.status},
  93 + </if>
  94 + </trim>
  95 + ON DUPLICATE KEY UPDATE
  96 + <trim suffixOverrides=",">
  97 + <if test="params.activityName != null and params.activityName != ''">
  98 + activity_name = VALUES(activity_name),
  99 + </if>
  100 + <if test="params.updateTime != null and params.updateTime != ''">
  101 + update_time = VALUES(update_time),
  102 + </if>
  103 + <if test="params.beginTime != null and params.beginTime != ''">
  104 + begin_time = VALUES(begin_time),
  105 + </if>
  106 + <if test="params.endTime != null and params.endTime != ''">
  107 + end_time = VALUES(end_time),
  108 + </if>
  109 + <if test="params.status != null and params.status != ''">
  110 + status = VALUES(status),
  111 + </if>
  112 + <if test="params.banner != null and params.banner != ''">
  113 + banner = VALUES(banner),
  114 + </if>
  115 + <if test="params.jumpUrl != null and params.jumpUrl != ''">
  116 + jump_url = VALUES(jump_url)
  117 + </if>
  118 + <if test="params.status != null and params.status != ''">
  119 + status = VALUES(status),
  120 + </if>
  121 + </trim>
  122 + </insert>
34 </mapper> 123 </mapper>
@@ -33,4 +33,41 @@ @@ -33,4 +33,41 @@
33 (activity_id=#{item.activityId,jdbcType=INTEGER} and product_skn=#{item.productSkn,jdbcType=INTEGER}) 33 (activity_id=#{item.activityId,jdbcType=INTEGER} and product_skn=#{item.productSkn,jdbcType=INTEGER})
34 </foreach> 34 </foreach>
35 </select> 35 </select>
  36 +
  37 + <update id="updateCutDownPriceProductStatus" >
  38 + update cutdown_price_product set status = #{status,jdbcType=INTEGER}
  39 + where product_skn = #{productSkn,jdbcType=INTEGER}
  40 + </update>
  41 +
  42 + <insert id="updateCutDownPriceProduct">
  43 + INSERT INTO cutdown_price_product
  44 + <![CDATA[
  45 + (activity_id,
  46 + product_skn,
  47 + join_num,
  48 + high_price,
  49 + low_price,
  50 + create_time,
  51 + update_time,
  52 + status)
  53 + VALUES
  54 + ]]>
  55 + <foreach item="item" collection="list" separator=",">
  56 + ( #{item.activityId},
  57 + #{item.productSkn},
  58 + #{item.joinNum},
  59 + #{item.highPrice},
  60 + #{item.lowPrice},
  61 + #{item.createTime},
  62 + #{item.updateTime},
  63 + #{item.status})
  64 + </foreach>
  65 + ON DUPLICATE KEY UPDATE
  66 + product_skn = VALUES(product_skn),
  67 + join_num = VALUES(join_num),
  68 + update_time = VALUES(update_time),
  69 + high_price = VALUES(high_price),
  70 + low_price = VALUES(low_price),
  71 + status = VALUES(status))
  72 + </insert>
36 </mapper> 73 </mapper>
@@ -30,6 +30,18 @@ @@ -30,6 +30,18 @@
30 <groupId>com.yoho.core</groupId> 30 <groupId>com.yoho.core</groupId>
31 <artifactId>yoho-core-rabbitmq</artifactId> 31 <artifactId>yoho-core-rabbitmq</artifactId>
32 </dependency> 32 </dependency>
  33 + <dependency>
  34 + <groupId>com.yoho.dsf.yhactivity</groupId>
  35 + <artifactId>yohobuy-activity-common</artifactId>
  36 + </dependency>
  37 + <dependency>
  38 + <groupId>com.yoho.dsf.yhactivity</groupId>
  39 + <artifactId>yohobuy-activity-dal</artifactId>
  40 + </dependency>
  41 + <dependency>
  42 + <groupId>com.yoho.dsf.yhactivity</groupId>
  43 + <artifactId>yohobuy-activity-queue</artifactId>
  44 + </dependency>
33 </dependencies> 45 </dependencies>
34 46
35 <build> 47 <build>
1 package com.yoho.dsf.mqapi.consumer; 1 package com.yoho.dsf.mqapi.consumer;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
  4 +import com.yoho.activity.common.redis.CacheKeyEnum;
  5 +import com.yoho.activity.common.redis.RedisValueCache;
  6 +import com.yoho.activity.dal.CutDownPriceActivityMapper;
  7 +import com.yoho.activity.dal.model.CutDownPriceActivity;
4 import com.yoho.core.rabbitmq.YhConsumer; 8 import com.yoho.core.rabbitmq.YhConsumer;
5 import com.yoho.dsf.mqapi.constants.MqConstants; 9 import com.yoho.dsf.mqapi.constants.MqConstants;
6 -import com.yoho.dsf.mqapi.model.CutDownPriceActivity;  
7 -import com.yoho.dsf.mqapi.service.CutDownPriceActivityService;  
8 import org.slf4j.Logger; 10 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
10 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
@@ -13,9 +15,11 @@ import org.springframework.stereotype.Service; @@ -13,9 +15,11 @@ import org.springframework.stereotype.Service;
13 @Service(value="collageActivityConsumer") 15 @Service(value="collageActivityConsumer")
14 public class CutDownPriceActivityConsumer implements YhConsumer { 16 public class CutDownPriceActivityConsumer implements YhConsumer {
15 private static final Logger LOGGER = LoggerFactory.getLogger(CutDownPriceActivityConsumer.class); 17 private static final Logger LOGGER = LoggerFactory.getLogger(CutDownPriceActivityConsumer.class);
16 - 18 +
  19 + @Autowired
  20 + private CutDownPriceActivityMapper cutDownPriceActivityMapper;
17 @Autowired 21 @Autowired
18 - private CutDownPriceActivityService cutDownPriceActivityService; 22 + private RedisValueCache redisValueCache;
19 23
20 @Override 24 @Override
21 public void handleMessage(Object message) { 25 public void handleMessage(Object message) {
@@ -23,7 +27,12 @@ public class CutDownPriceActivityConsumer implements YhConsumer { @@ -23,7 +27,12 @@ public class CutDownPriceActivityConsumer implements YhConsumer {
23 try { 27 try {
24 CutDownPriceActivity cutDownPriceActivity = JSONObject.parseObject(String.valueOf(message), CutDownPriceActivity.class); 28 CutDownPriceActivity cutDownPriceActivity = JSONObject.parseObject(String.valueOf(message), CutDownPriceActivity.class);
25 if (null != cutDownPriceActivity){ 29 if (null != cutDownPriceActivity){
26 - cutDownPriceActivityService.updateCutDownPriceActivity(cutDownPriceActivity); 30 + cutDownPriceActivityMapper.updateCutDownPriceActivity(cutDownPriceActivity);
  31 + //更新的时候清除缓存
  32 + if (cutDownPriceActivity.getActivityId() != null){
  33 + String redisKeySuffix = cutDownPriceActivity.getActivityId() + "";
  34 + redisValueCache.delete(CacheKeyEnum.CUTDOWN_PRICE_ACTIVITYBO_INFO,redisKeySuffix);
  35 + }
27 } 36 }
28 } catch (Exception e) { 37 } catch (Exception e) {
29 LOGGER.warn("handle CutDownPriceActivityConsumer info message failed!! message is " + String.valueOf(message),e); 38 LOGGER.warn("handle CutDownPriceActivityConsumer info message failed!! message is " + String.valueOf(message),e);
@@ -2,10 +2,12 @@ package com.yoho.dsf.mqapi.consumer; @@ -2,10 +2,12 @@ package com.yoho.dsf.mqapi.consumer;
2 2
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.google.common.collect.Lists; 4 import com.google.common.collect.Lists;
  5 +import com.yoho.activity.common.redis.CacheKeyEnum;
  6 +import com.yoho.activity.common.redis.RedisValueCache;
  7 +import com.yoho.activity.dal.CutDownPriceProductMapper;
5 import com.yoho.core.rabbitmq.YhConsumer; 8 import com.yoho.core.rabbitmq.YhConsumer;
6 import com.yoho.dsf.mqapi.constants.MqConstants; 9 import com.yoho.dsf.mqapi.constants.MqConstants;
7 -import com.yoho.dsf.mqapi.model.CutDownPriceProduct;  
8 -import com.yoho.dsf.mqapi.service.CutDownPriceProductService; 10 +import com.yoho.activity.dal.model.CutDownPriceProduct;
9 import org.apache.commons.collections.CollectionUtils; 11 import org.apache.commons.collections.CollectionUtils;
10 import org.apache.commons.lang3.StringUtils; 12 import org.apache.commons.lang3.StringUtils;
11 import org.slf4j.Logger; 13 import org.slf4j.Logger;
@@ -20,7 +22,10 @@ public class CutDownPriceProductConsumer implements YhConsumer { @@ -20,7 +22,10 @@ public class CutDownPriceProductConsumer implements YhConsumer {
20 private static final Logger LOGGER = LoggerFactory.getLogger(CutDownPriceProductConsumer.class); 22 private static final Logger LOGGER = LoggerFactory.getLogger(CutDownPriceProductConsumer.class);
21 23
22 @Autowired 24 @Autowired
23 - private CutDownPriceProductService cutDownPriceProductService; 25 + private CutDownPriceProductMapper cutDownPriceProductMapper;
  26 +
  27 + @Autowired
  28 + private RedisValueCache redisValueCache;
24 29
25 @Override 30 @Override
26 public void handleMessage(Object message) { 31 public void handleMessage(Object message) {
@@ -30,10 +35,16 @@ public class CutDownPriceProductConsumer implements YhConsumer { @@ -30,10 +35,16 @@ public class CutDownPriceProductConsumer implements YhConsumer {
30 if (CollectionUtils.isEmpty(cutDownPriceProductList)) { 35 if (CollectionUtils.isEmpty(cutDownPriceProductList)) {
31 return; 36 return;
32 } 37 }
33 - if (null == cutDownPriceProductList.get(0).getActivityId()){  
34 - cutDownPriceProductService.updateCutDownPriceProductStatus(cutDownPriceProductList.get(0).getProductSkn(),cutDownPriceProductList.get(0).getStatus()); 38 + if (null != cutDownPriceProductList.get(0).getStatus() && cutDownPriceProductList.get(0).getStatus() == 2){
  39 + cutDownPriceProductMapper.updateCutDownPriceProductStatus(cutDownPriceProductList.get(0).getProductSkn(),cutDownPriceProductList.get(0).getStatus());
35 }else{ 40 }else{
36 - cutDownPriceProductService.updateCutDownPriceProduct(cutDownPriceProductList); 41 + cutDownPriceProductMapper.updateCutDownPriceProduct(cutDownPriceProductList);
  42 + }
  43 + if (null != cutDownPriceProductList.get(0).getActivityId()){
  44 + for (CutDownPriceProduct cutDownPriceProduct : cutDownPriceProductList){
  45 + String redisKeySuffix = cutDownPriceProduct.getActivityId() + ":" + cutDownPriceProduct.getProductSkn();
  46 + redisValueCache.delete(CacheKeyEnum.CUTDOWN_PRICE_PRODUCTBO_INFO, redisKeySuffix);
  47 + }
37 } 48 }
38 } catch (Exception e) { 49 } catch (Exception e) {
39 LOGGER.warn("handle CutDownPriceProductConsumer info message failed!! message is " + String.valueOf(message),e); 50 LOGGER.warn("handle CutDownPriceProductConsumer info message failed!! message is " + String.valueOf(message),e);
1 -package com.yoho.dsf.mqapi.model;  
2 -  
3 -/**  
4 - * Created by qing.zhao on 2018/1/15.  
5 - */  
6 -public class CutDownPriceActivity {  
7 - private Integer activityId;  
8 - private String activityName;  
9 - private Integer status;  
10 - private Integer beginTime;  
11 - private Integer endTime;  
12 - private Integer createTime;  
13 - private Integer updateTime;  
14 - private String banner;  
15 - private String jumpUrl;  
16 -  
17 - public Integer getActivityId() {  
18 - return activityId;  
19 - }  
20 -  
21 - public void setActivityId(Integer activityId) {  
22 - this.activityId = activityId;  
23 - }  
24 -  
25 - public String getActivityName() {  
26 - return activityName;  
27 - }  
28 -  
29 - public void setActivityName(String activityName) {  
30 - this.activityName = activityName;  
31 - }  
32 -  
33 - public Integer getStatus() {  
34 - return status;  
35 - }  
36 -  
37 - public void setStatus(Integer status) {  
38 - this.status = status;  
39 - }  
40 -  
41 - public Integer getBeginTime() {  
42 - return beginTime;  
43 - }  
44 -  
45 - public void setBeginTime(Integer beginTime) {  
46 - this.beginTime = beginTime;  
47 - }  
48 -  
49 - public Integer getEndTime() {  
50 - return endTime;  
51 - }  
52 -  
53 - public void setEndTime(Integer endTime) {  
54 - this.endTime = endTime;  
55 - }  
56 -  
57 - public Integer getCreateTime() {  
58 - return createTime;  
59 - }  
60 -  
61 - public void setCreateTime(Integer createTime) {  
62 - this.createTime = createTime;  
63 - }  
64 -  
65 - public Integer getUpdateTime() {  
66 - return updateTime;  
67 - }  
68 -  
69 - public void setUpdateTime(Integer updateTime) {  
70 - this.updateTime = updateTime;  
71 - }  
72 -  
73 - public String getBanner() {  
74 - return banner;  
75 - }  
76 -  
77 - public void setBanner(String banner) {  
78 - this.banner = banner;  
79 - }  
80 -  
81 - public String getJumpUrl() {  
82 - return jumpUrl;  
83 - }  
84 -  
85 - public void setJumpUrl(String jumpUrl) {  
86 - this.jumpUrl = jumpUrl;  
87 - }  
88 -}  
1 -package com.yoho.dsf.mqapi.model;  
2 -  
3 -import java.math.BigDecimal;  
4 -  
5 -/**  
6 - * Created by qing.zhao on 2018/1/15.  
7 - */  
8 -public class CutDownPriceProduct {  
9 - private Integer id;  
10 - private Integer activityId;  
11 - private Integer productSkn;  
12 - private BigDecimal highPrice;  
13 - private BigDecimal lowPrice;  
14 - private Integer joinNum;  
15 - private Integer createTime;  
16 - private Integer updateTime;  
17 - private Integer status;  
18 -  
19 - public Integer getId() {  
20 - return id;  
21 - }  
22 -  
23 - public void setId(Integer id) {  
24 - this.id = id;  
25 - }  
26 -  
27 - public Integer getJoinNum() {  
28 - return joinNum;  
29 - }  
30 -  
31 - public void setJoinNum(Integer joinNum) {  
32 - this.joinNum = joinNum;  
33 - }  
34 -  
35 - public Integer getActivityId() {  
36 - return activityId;  
37 - }  
38 -  
39 - public void setActivityId(Integer activityId) {  
40 - this.activityId = activityId;  
41 - }  
42 -  
43 - public Integer getProductSkn() {  
44 - return productSkn;  
45 - }  
46 -  
47 - public void setProductSkn(Integer productSkn) {  
48 - this.productSkn = productSkn;  
49 - }  
50 -  
51 - public BigDecimal getHighPrice() {  
52 - return highPrice;  
53 - }  
54 -  
55 - public void setHighPrice(BigDecimal highPrice) {  
56 - this.highPrice = highPrice;  
57 - }  
58 -  
59 - public BigDecimal getLowPrice() {  
60 - return lowPrice;  
61 - }  
62 -  
63 - public void setLowPrice(BigDecimal lowPrice) {  
64 - this.lowPrice = lowPrice;  
65 - }  
66 -  
67 - public Integer getCreateTime() {  
68 - return createTime;  
69 - }  
70 -  
71 - public void setCreateTime(Integer createTime) {  
72 - this.createTime = createTime;  
73 - }  
74 -  
75 - public Integer getUpdateTime() {  
76 - return updateTime;  
77 - }  
78 -  
79 - public void setUpdateTime(Integer updateTime) {  
80 - this.updateTime = updateTime;  
81 - }  
82 -  
83 - public Integer getStatus() {  
84 - return status;  
85 - }  
86 -  
87 - public void setStatus(Integer status) {  
88 - this.status = status;  
89 - }  
90 -  
91 -}