Showing
4 changed files
with
110 additions
and
1 deletions
1 | package com.yoho.order.model; | 1 | package com.yoho.order.model; |
2 | 2 | ||
3 | +import com.alibaba.fastjson.JSONObject; | ||
4 | + | ||
3 | public class QiniuLiveRecord { | 5 | public class QiniuLiveRecord { |
4 | private Integer id; | 6 | private Integer id; |
5 | 7 | ||
@@ -160,4 +162,9 @@ public class QiniuLiveRecord { | @@ -160,4 +162,9 @@ public class QiniuLiveRecord { | ||
160 | public void setProductId(Integer productId) { | 162 | public void setProductId(Integer productId) { |
161 | this.productId = productId; | 163 | this.productId = productId; |
162 | } | 164 | } |
165 | + | ||
166 | + @Override | ||
167 | + public String toString() { | ||
168 | + return JSONObject.toJSONString(this); | ||
169 | + } | ||
163 | } | 170 | } |
1 | +package com.yoho.ufo.order.service.event; | ||
2 | + | ||
3 | +import com.google.common.collect.Lists; | ||
4 | +import com.yoho.order.dal.QiniuLiveRecordMapper; | ||
5 | +import com.yoho.order.dal.SellerOrderGoodsMapper; | ||
6 | +import com.yoho.order.model.QiniuLiveRecord; | ||
7 | +import com.yoho.order.model.SellerOrderGoods; | ||
8 | +import com.yoho.ufo.util.DateUtil; | ||
9 | +import org.apache.commons.collections.CollectionUtils; | ||
10 | +import org.slf4j.Logger; | ||
11 | +import org.slf4j.LoggerFactory; | ||
12 | +import org.springframework.beans.factory.annotation.Autowired; | ||
13 | +import org.springframework.context.ApplicationListener; | ||
14 | +import org.springframework.stereotype.Component; | ||
15 | + | ||
16 | +import java.util.List; | ||
17 | + | ||
18 | +/** | ||
19 | + * Created by li.ma on 2018/12/18. | ||
20 | + */ | ||
21 | +@Component | ||
22 | +public class LiveEventsListener implements ApplicationListener<QiniuLiveRecordEvent> { | ||
23 | + private static final Logger LOGGER = LoggerFactory.getLogger(LiveEventsListener.class); | ||
24 | + | ||
25 | + @Autowired | ||
26 | + private SellerOrderGoodsMapper sellerOrderGoodsMapper; | ||
27 | + | ||
28 | + @Autowired | ||
29 | + private QiniuLiveRecordMapper qiniuLiveRecordMapper; | ||
30 | + | ||
31 | + /** | ||
32 | + * seller_order_code = #{sellerOrderCode,jdbcType=BIGINT}, | ||
33 | + update_time = #{updateTime,jdbcType=INTEGER}, | ||
34 | + storage_id = #{storageId,jdbcType=INTEGER}, | ||
35 | + goods_id = #{goodsId,jdbcType=INTEGER}, | ||
36 | + product_id = #{productId,jdbcType=INTEGER} | ||
37 | + * @param event | ||
38 | + */ | ||
39 | + @Override | ||
40 | + public void onApplicationEvent(QiniuLiveRecordEvent event) { | ||
41 | + LOGGER.info("LiveEventsListener.onApplicationEvent method in. param is {}", event); | ||
42 | + QiniuLiveRecord record = event.getRecord(); | ||
43 | + List<SellerOrderGoods> sellerOrderGoodses = sellerOrderGoodsMapper.selectByIds(Lists.newArrayList(record.getSkup())); | ||
44 | + if (CollectionUtils.isEmpty(sellerOrderGoodses)) { | ||
45 | + return; | ||
46 | + } | ||
47 | + SellerOrderGoods sellerOrderGoods = sellerOrderGoodses.get(0); | ||
48 | + | ||
49 | + record.setSellerOrderCode(0L); | ||
50 | + record.setUpdateTime(DateUtil.getCurrentTimeSeconds()); | ||
51 | + record.setStorageId(sellerOrderGoods.getStorageId()); | ||
52 | + record.setGoodsId(0); | ||
53 | + record.setProductId(sellerOrderGoods.getProductId()); | ||
54 | + qiniuLiveRecordMapper.updateProductBySkup(record); | ||
55 | + | ||
56 | + LOGGER.info("LiveEventsListener.onApplicationEvent method out. skup is {}", event.getRecord().getSkup()); | ||
57 | + } | ||
58 | +} |
1 | +package com.yoho.ufo.order.service.event; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSONObject; | ||
4 | +import com.yoho.order.model.QiniuLiveRecord; | ||
5 | +import org.springframework.context.ApplicationEvent; | ||
6 | + | ||
7 | +/** | ||
8 | + * Created by li.ma on 2018/12/18. | ||
9 | + */ | ||
10 | +public class QiniuLiveRecordEvent extends ApplicationEvent { | ||
11 | + private QiniuLiveRecord record; | ||
12 | + /** | ||
13 | + * Create a new ApplicationEvent. | ||
14 | + * | ||
15 | + * @param source the object on which the event initially occurred (never {@code null}) | ||
16 | + */ | ||
17 | + public QiniuLiveRecordEvent(QiniuLiveRecord record) { | ||
18 | + super(record); | ||
19 | + this.record = record; | ||
20 | + } | ||
21 | + | ||
22 | + public QiniuLiveRecord getRecord() { | ||
23 | + return record; | ||
24 | + } | ||
25 | + | ||
26 | + public void setRecord(QiniuLiveRecord record) { | ||
27 | + this.record = record; | ||
28 | + } | ||
29 | + | ||
30 | + @Override | ||
31 | + public String toString() { | ||
32 | + return JSONObject.toJSONString(this); | ||
33 | + } | ||
34 | +} |
@@ -15,6 +15,8 @@ import org.apache.commons.lang3.StringUtils; | @@ -15,6 +15,8 @@ import org.apache.commons.lang3.StringUtils; | ||
15 | import org.slf4j.Logger; | 15 | import org.slf4j.Logger; |
16 | import org.slf4j.LoggerFactory; | 16 | import org.slf4j.LoggerFactory; |
17 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
18 | +import org.springframework.context.ApplicationContext; | ||
19 | +import org.springframework.context.ApplicationContextAware; | ||
18 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
19 | 21 | ||
20 | import java.util.List; | 22 | import java.util.List; |
@@ -23,7 +25,7 @@ import java.util.List; | @@ -23,7 +25,7 @@ import java.util.List; | ||
23 | * Created by li.ma on 2018/12/13. | 25 | * Created by li.ma on 2018/12/13. |
24 | */ | 26 | */ |
25 | @Service | 27 | @Service |
26 | -public class UfoLiveService { | 28 | +public class UfoLiveService implements ApplicationContextAware { |
27 | private static final Logger LOGGER = LoggerFactory.getLogger(UfoLiveService.class); | 29 | private static final Logger LOGGER = LoggerFactory.getLogger(UfoLiveService.class); |
28 | 30 | ||
29 | @Autowired | 31 | @Autowired |
@@ -32,6 +34,12 @@ public class UfoLiveService { | @@ -32,6 +34,12 @@ public class UfoLiveService { | ||
32 | @Autowired | 34 | @Autowired |
33 | private QiniuLiveRecordMapper qiniuLiveRecordMapper; | 35 | private QiniuLiveRecordMapper qiniuLiveRecordMapper; |
34 | 36 | ||
37 | + private ApplicationContext context; | ||
38 | + | ||
39 | + public void setApplicationContext(ApplicationContext applicationContext) { | ||
40 | + this.context = applicationContext; | ||
41 | + } | ||
42 | + | ||
35 | @Database(ForceMaster = true) | 43 | @Database(ForceMaster = true) |
36 | public void generateMp4(QNliveReq req) throws PlatformException { | 44 | public void generateMp4(QNliveReq req) throws PlatformException { |
37 | LOGGER.info("method UfoLiveService.generateMp4 in, QNliveReq is {}", req); | 45 | LOGGER.info("method UfoLiveService.generateMp4 in, QNliveReq is {}", req); |
@@ -66,6 +74,8 @@ public class UfoLiveService { | @@ -66,6 +74,8 @@ public class UfoLiveService { | ||
66 | record.setStatus(0); | 74 | record.setStatus(0); |
67 | record.setVedioFileUrl(fileName + ".mp4"); | 75 | record.setVedioFileUrl(fileName + ".mp4"); |
68 | qiniuLiveRecordMapper.insert(record); | 76 | qiniuLiveRecordMapper.insert(record); |
77 | + | ||
78 | + context.publishEvent(record); // 异步补充记录的卖家订单号,商品信息 | ||
69 | } | 79 | } |
70 | 80 | ||
71 | public String queryMp4Vedio(QNliveReq req) throws PlatformException { | 81 | public String queryMp4Vedio(QNliveReq req) throws PlatformException { |
-
Please register or login to post a comment