Authored by zhaoqing

砍价

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>yohobuy-activity</artifactId>
<groupId>com.yoho.dsf</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yohobuy-activity-mq</artifactId>
<name>yohobuy-activity-mq</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.yoho.core</groupId>
<artifactId>yoho-core-rabbitmq</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
... ...
package com.yoho.dsf.mqapi.constants;
public interface MqConstants {
String MQ_SYN_CUTDOWNPRICE_ACTIVITY = "platform.cutDownPrice.activity";
String MQ_SYN_CUTDOWNPRICE_PRODUCT = "platform.cutDownPrice.product";
}
... ...
package com.yoho.dsf.mqapi.consumer;
import com.alibaba.fastjson.JSONObject;
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;
import org.springframework.stereotype.Service;
@Service(value="collageActivityConsumer")
public class CutDownPriceActivityConsumer implements YhConsumer {
private static final Logger LOGGER = LoggerFactory.getLogger(CutDownPriceActivityConsumer.class);
@Autowired
private CutDownPriceActivityService cutDownPriceActivityService;
@Override
public void handleMessage(Object message) {
LOGGER.info("begin CutDownPriceActivityConsumer.handleMessage message is:{}, topic is:{}", MqConstants.MQ_SYN_CUTDOWNPRICE_ACTIVITY);
try {
CutDownPriceActivity cutDownPriceActivity = JSONObject.parseObject(String.valueOf(message), CutDownPriceActivity.class);
if (null != cutDownPriceActivity){
cutDownPriceActivityService.updateCutDownPriceActivity(cutDownPriceActivity);
}
} catch (Exception e) {
LOGGER.warn("handle CutDownPriceActivityConsumer info message failed!! message is " + String.valueOf(message),e);
}
}
}
... ...
package com.yoho.dsf.mqapi.consumer;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
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 org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service(value="collageProductConsumer")
public class CutDownPriceProductConsumer implements YhConsumer {
private static final Logger LOGGER = LoggerFactory.getLogger(CutDownPriceProductConsumer.class);
@Autowired
private CutDownPriceProductService cutDownPriceProductService;
@Override
public void handleMessage(Object message) {
LOGGER.info("begin CutDownPriceProductConsumer.handleMessage message is:{}, topic is:{}", MqConstants.MQ_SYN_CUTDOWNPRICE_PRODUCT);
try {
List<CutDownPriceProduct> cutDownPriceProductList = getCutDownPriceProductList(message);
if (CollectionUtils.isEmpty(cutDownPriceProductList)) {
return;
}
if (null == cutDownPriceProductList.get(0).getActivityId()){
cutDownPriceProductService.updateCutDownPriceProductStatus(cutDownPriceProductList.get(0).getProductSkn(),cutDownPriceProductList.get(0).getStatus());
}else{
cutDownPriceProductService.updateCutDownPriceProduct(cutDownPriceProductList);
}
} catch (Exception e) {
LOGGER.warn("handle CutDownPriceProductConsumer info message failed!! message is " + String.valueOf(message),e);
}
}
private List<CutDownPriceProduct> getCutDownPriceProductList(Object message) {
// 如果是单个变价,则是以 {字符 开始 否则是以 [ 字符开始
String value = String.valueOf(message);
if (StringUtils.startsWith(value, "[")) {
return JSON.parseArray(value, CutDownPriceProduct.class);
} else {
return Lists.newArrayList(JSON.parseObject(value, CutDownPriceProduct.class));
}
}
}
... ...
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;
}
}
... ...
... ... @@ -202,6 +202,7 @@
<module>service</module>
<module>other</module>
<module>controller</module>
</modules>
<module>mq</module>
</modules>
</project>
\ No newline at end of file
... ...
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns="http://www.springframework.org/schema/beans" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="simpleMessageConverter-common" class="org.springframework.amqp.support.converter.SimpleMessageConverter"/>
</beans>
\ No newline at end of file
... ...
consumer:
- address: ${rabbit_common}
username: ${rabbit_common_user}
password: ${rabbit_common_password}
consumers:
- class: com.yoho.product.syschronize.mq.consumer.CutDownPriceActivityConsumer
topic: platform.cutDownPrice.activity
- class: com.yoho.product.syschronize.mq.consumer.CutDownPriceProductConsumer
topic: platform.cutDownPrice.product
producer:
- address: ${rabbit_common}
username: ${rabbit_common_user}
password: ${rabbit_common_password}
producers:
- bean: producer1
\ No newline at end of file
... ...
... ... @@ -28,5 +28,6 @@
<generate template="META-INF/autoconf/logback.xml" destfile="WEB-INF/classes/logback.xml" />
<generate template="META-INF/autoconf/services.yml" destfile="WEB-INF/classes/services.yml" />
<generate template="META-INF/autoconf/redis-config.yml" destfile="WEB-INF/classes/redis-config.yml" />
<generate template="META-INF/autoconf/rabbitmq.yml" destfile="WEB-INF/classes/rabbitmq.yml"/>
</script>
</config>
\ No newline at end of file
... ...
consumer:
- address: ${rabbit_common}
username: ${rabbit_common_user}
password: ${rabbit_common_password}
consumers:
- class: com.yoho.product.syschronize.mq.consumer.CutDownPriceActivityConsumer
topic: platform.cutDownPrice.activity
- class: com.yoho.product.syschronize.mq.consumer.CutDownPriceProductConsumer
topic: platform.cutDownPrice.product
producer:
- address: ${rabbit_common}
username: ${rabbit_common_user}
password: ${rabbit_common_password}
producers:
- bean: producer1
\ No newline at end of file
... ...