Authored by zhaoqing

砍价

  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +
  3 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <parent>
  6 + <artifactId>yohobuy-activity</artifactId>
  7 + <groupId>com.yoho.dsf</groupId>
  8 + <version>1.0.0-SNAPSHOT</version>
  9 + </parent>
  10 + <modelVersion>4.0.0</modelVersion>
  11 +
  12 + <artifactId>yohobuy-activity-mq</artifactId>
  13 +
  14 + <name>yohobuy-activity-mq</name>
  15 +
  16 + <properties>
  17 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  18 + <maven.compiler.source>1.7</maven.compiler.source>
  19 + <maven.compiler.target>1.7</maven.compiler.target>
  20 + </properties>
  21 +
  22 + <dependencies>
  23 + <dependency>
  24 + <groupId>junit</groupId>
  25 + <artifactId>junit</artifactId>
  26 + <version>4.11</version>
  27 + <scope>test</scope>
  28 + </dependency>
  29 + <dependency>
  30 + <groupId>com.yoho.core</groupId>
  31 + <artifactId>yoho-core-rabbitmq</artifactId>
  32 + </dependency>
  33 + </dependencies>
  34 +
  35 + <build>
  36 + <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
  37 + <plugins>
  38 + <plugin>
  39 + <artifactId>maven-clean-plugin</artifactId>
  40 + <version>3.0.0</version>
  41 + </plugin>
  42 + <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
  43 + <plugin>
  44 + <artifactId>maven-resources-plugin</artifactId>
  45 + <version>3.0.2</version>
  46 + </plugin>
  47 + <plugin>
  48 + <artifactId>maven-compiler-plugin</artifactId>
  49 + <version>3.7.0</version>
  50 + </plugin>
  51 + <plugin>
  52 + <artifactId>maven-surefire-plugin</artifactId>
  53 + <version>2.20.1</version>
  54 + </plugin>
  55 + <plugin>
  56 + <artifactId>maven-jar-plugin</artifactId>
  57 + <version>3.0.2</version>
  58 + </plugin>
  59 + <plugin>
  60 + <artifactId>maven-install-plugin</artifactId>
  61 + <version>2.5.2</version>
  62 + </plugin>
  63 + <plugin>
  64 + <artifactId>maven-deploy-plugin</artifactId>
  65 + <version>2.8.2</version>
  66 + </plugin>
  67 + </plugins>
  68 + </pluginManagement>
  69 + </build>
  70 +</project>
  1 +package com.yoho.dsf.mqapi.constants;
  2 +
  3 +public interface MqConstants {
  4 +
  5 + String MQ_SYN_CUTDOWNPRICE_ACTIVITY = "platform.cutDownPrice.activity";
  6 + String MQ_SYN_CUTDOWNPRICE_PRODUCT = "platform.cutDownPrice.product";
  7 +}
  1 +package com.yoho.dsf.mqapi.consumer;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.yoho.core.rabbitmq.YhConsumer;
  5 +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;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.stereotype.Service;
  12 +
  13 +@Service(value="collageActivityConsumer")
  14 +public class CutDownPriceActivityConsumer implements YhConsumer {
  15 + private static final Logger LOGGER = LoggerFactory.getLogger(CutDownPriceActivityConsumer.class);
  16 +
  17 + @Autowired
  18 + private CutDownPriceActivityService cutDownPriceActivityService;
  19 +
  20 + @Override
  21 + public void handleMessage(Object message) {
  22 + LOGGER.info("begin CutDownPriceActivityConsumer.handleMessage message is:{}, topic is:{}", MqConstants.MQ_SYN_CUTDOWNPRICE_ACTIVITY);
  23 + try {
  24 + CutDownPriceActivity cutDownPriceActivity = JSONObject.parseObject(String.valueOf(message), CutDownPriceActivity.class);
  25 + if (null != cutDownPriceActivity){
  26 + cutDownPriceActivityService.updateCutDownPriceActivity(cutDownPriceActivity);
  27 + }
  28 + } catch (Exception e) {
  29 + LOGGER.warn("handle CutDownPriceActivityConsumer info message failed!! message is " + String.valueOf(message),e);
  30 + }
  31 + }
  32 +
  33 +}
  1 +package com.yoho.dsf.mqapi.consumer;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.google.common.collect.Lists;
  5 +import com.yoho.core.rabbitmq.YhConsumer;
  6 +import com.yoho.dsf.mqapi.constants.MqConstants;
  7 +import com.yoho.dsf.mqapi.model.CutDownPriceProduct;
  8 +import com.yoho.dsf.mqapi.service.CutDownPriceProductService;
  9 +import org.apache.commons.collections.CollectionUtils;
  10 +import org.apache.commons.lang3.StringUtils;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.stereotype.Service;
  15 +
  16 +import java.util.List;
  17 +
  18 +@Service(value="collageProductConsumer")
  19 +public class CutDownPriceProductConsumer implements YhConsumer {
  20 + private static final Logger LOGGER = LoggerFactory.getLogger(CutDownPriceProductConsumer.class);
  21 +
  22 + @Autowired
  23 + private CutDownPriceProductService cutDownPriceProductService;
  24 +
  25 + @Override
  26 + public void handleMessage(Object message) {
  27 + LOGGER.info("begin CutDownPriceProductConsumer.handleMessage message is:{}, topic is:{}", MqConstants.MQ_SYN_CUTDOWNPRICE_PRODUCT);
  28 + try {
  29 + List<CutDownPriceProduct> cutDownPriceProductList = getCutDownPriceProductList(message);
  30 + if (CollectionUtils.isEmpty(cutDownPriceProductList)) {
  31 + return;
  32 + }
  33 + if (null == cutDownPriceProductList.get(0).getActivityId()){
  34 + cutDownPriceProductService.updateCutDownPriceProductStatus(cutDownPriceProductList.get(0).getProductSkn(),cutDownPriceProductList.get(0).getStatus());
  35 + }else{
  36 + cutDownPriceProductService.updateCutDownPriceProduct(cutDownPriceProductList);
  37 + }
  38 + } catch (Exception e) {
  39 + LOGGER.warn("handle CutDownPriceProductConsumer info message failed!! message is " + String.valueOf(message),e);
  40 + }
  41 + }
  42 +
  43 + private List<CutDownPriceProduct> getCutDownPriceProductList(Object message) {
  44 + // 如果是单个变价,则是以 {字符 开始 否则是以 [ 字符开始
  45 + String value = String.valueOf(message);
  46 + if (StringUtils.startsWith(value, "[")) {
  47 + return JSON.parseArray(value, CutDownPriceProduct.class);
  48 + } else {
  49 + return Lists.newArrayList(JSON.parseObject(value, CutDownPriceProduct.class));
  50 + }
  51 + }
  52 +
  53 +}
  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 +}
@@ -202,6 +202,7 @@ @@ -202,6 +202,7 @@
202 <module>service</module> 202 <module>service</module>
203 <module>other</module> 203 <module>other</module>
204 <module>controller</module> 204 <module>controller</module>
205 - </modules> 205 + <module>mq</module>
  206 + </modules>
206 207
207 </project> 208 </project>
  1 +<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xmlns:rabbit="http://www.springframework.org/schema/rabbit"
  3 + xmlns="http://www.springframework.org/schema/beans" xmlns:util="http://www.springframework.org/schema/util"
  4 + xsi:schemaLocation="http://www.springframework.org/schema/rabbit
  5 + http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
  6 + http://www.springframework.org/schema/beans
  7 + http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
  8 +
  9 +
  10 + <bean id="simpleMessageConverter-common" class="org.springframework.amqp.support.converter.SimpleMessageConverter"/>
  11 +</beans>
  1 +consumer:
  2 + - address: ${rabbit_common}
  3 + username: ${rabbit_common_user}
  4 + password: ${rabbit_common_password}
  5 + consumers:
  6 + - class: com.yoho.product.syschronize.mq.consumer.CutDownPriceActivityConsumer
  7 + topic: platform.cutDownPrice.activity
  8 + - class: com.yoho.product.syschronize.mq.consumer.CutDownPriceProductConsumer
  9 + topic: platform.cutDownPrice.product
  10 +
  11 +
  12 +producer:
  13 + - address: ${rabbit_common}
  14 + username: ${rabbit_common_user}
  15 + password: ${rabbit_common_password}
  16 + producers:
  17 + - bean: producer1
@@ -28,5 +28,6 @@ @@ -28,5 +28,6 @@
28 <generate template="META-INF/autoconf/logback.xml" destfile="WEB-INF/classes/logback.xml" /> 28 <generate template="META-INF/autoconf/logback.xml" destfile="WEB-INF/classes/logback.xml" />
29 <generate template="META-INF/autoconf/services.yml" destfile="WEB-INF/classes/services.yml" /> 29 <generate template="META-INF/autoconf/services.yml" destfile="WEB-INF/classes/services.yml" />
30 <generate template="META-INF/autoconf/redis-config.yml" destfile="WEB-INF/classes/redis-config.yml" /> 30 <generate template="META-INF/autoconf/redis-config.yml" destfile="WEB-INF/classes/redis-config.yml" />
  31 + <generate template="META-INF/autoconf/rabbitmq.yml" destfile="WEB-INF/classes/rabbitmq.yml"/>
31 </script> 32 </script>
32 </config> 33 </config>
  1 +consumer:
  2 + - address: ${rabbit_common}
  3 + username: ${rabbit_common_user}
  4 + password: ${rabbit_common_password}
  5 + consumers:
  6 + - class: com.yoho.product.syschronize.mq.consumer.CutDownPriceActivityConsumer
  7 + topic: platform.cutDownPrice.activity
  8 + - class: com.yoho.product.syschronize.mq.consumer.CutDownPriceProductConsumer
  9 + topic: platform.cutDownPrice.product
  10 +
  11 +
  12 +producer:
  13 + - address: ${rabbit_common}
  14 + username: ${rabbit_common_user}
  15 + password: ${rabbit_common_password}
  16 + producers:
  17 + - bean: producer1