记得上下班打卡 | git大法好,push需谨慎

Commit 2dbdf5df authored by 胡佳晨's avatar 胡佳晨

提交 xls 队列 修改 平台券

parent 94bf5d7f
...@@ -111,6 +111,7 @@ public class GoblinRedisConst { ...@@ -111,6 +111,7 @@ public class GoblinRedisConst {
public static final String REDIS_GOBLIN_ORDER_MASTER = PREFIX.concat("order:masterCode:");//用户订单id列表 key:$masterCode public static final String REDIS_GOBLIN_ORDER_MASTER = PREFIX.concat("order:masterCode:");//用户订单id列表 key:$masterCode
public static final String REDIS_GOBLIN_ORDER_OFFCODE = PREFIX.concat("order:offCode:");//用户订单id列表 key:$wtrieOffCode public static final String REDIS_GOBLIN_ORDER_OFFCODE = PREFIX.concat("order:offCode:");//用户订单id列表 key:$wtrieOffCode
public static final String REDIS_GOBLIN_BACK_ORDER_ID = PREFIX.concat("order:backIds:");//用户订单下的退款订单id key:$orderId public static final String REDIS_GOBLIN_BACK_ORDER_ID = PREFIX.concat("order:backIds:");//用户订单下的退款订单id key:$orderId
public static final String REDIS_UN_BUY = PREFIX.concat("unBuy:");//用户订单下的退款订单id key:$skuId:$uid
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
/** /**
* SKU剩余库存 * SKU剩余库存
......
...@@ -39,9 +39,16 @@ public class GoblinAppOrderListVo implements Serializable, Cloneable { ...@@ -39,9 +39,16 @@ public class GoblinAppOrderListVo implements Serializable, Cloneable {
private String marketType; private String marketType;
@ApiModelProperty(value = "正在状态[0-未出货|1-已出货]") @ApiModelProperty(value = "正在状态[0-未出货|1-已出货]")
private Integer zhengzaiStatus; private Integer zhengzaiStatus;
@ApiModelProperty(value = "订单优惠金额")
private BigDecimal priceVoucher;
@ApiModelProperty(value = "实付价格")
private BigDecimal priceActual;
@ApiModelProperty(value = "应付价格")
private BigDecimal priceTotal;
@ApiModelProperty(value = " sku") @ApiModelProperty(value = " sku")
List<GoblinOrderSkuVo> orderSkuVos; List<GoblinOrderSkuVo> orderSkuVos;
private static final GoblinAppOrderListVo obj = new GoblinAppOrderListVo(); private static final GoblinAppOrderListVo obj = new GoblinAppOrderListVo();
public static GoblinAppOrderListVo getNew() { public static GoblinAppOrderListVo getNew() {
try { try {
return (GoblinAppOrderListVo) obj.clone(); return (GoblinAppOrderListVo) obj.clone();
......
...@@ -246,6 +246,7 @@ public class MQConst { ...@@ -246,6 +246,7 @@ public class MQConst {
GOBLIN_ORDER_CLOSE("goblin:stream:order:close", "group.order:close", "订单关闭"), GOBLIN_ORDER_CLOSE("goblin:stream:order:close", "group.order:close", "订单关闭"),
GOBLIN_STORE_ORDER_OPERA("goblin:stream:order:store", "group.order:store", "商铺订单操作"), GOBLIN_STORE_ORDER_OPERA("goblin:stream:order:store", "group.order:store", "商铺订单操作"),
GOBLIN_USER_ORDER_OPERA("goblin:stream:order:user", "group.order:user", "用户订单操作"), GOBLIN_USER_ORDER_OPERA("goblin:stream:order:user", "group.order:user", "用户订单操作"),
GOBLIN_XLS_OPERA("goblin:stream:xls", "group.xls", "xls文件操作"),
; ;
private final String key; private final String key;
......
...@@ -26,6 +26,10 @@ ...@@ -26,6 +26,10 @@
<artifactId>liquidnet-service-goblin-api</artifactId> <artifactId>liquidnet-service-goblin-api</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.liquidnet.service.consumer.goblin.config;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.consumer.goblin.receiver.ConsumerGoblinOrderAGRdsReceiver;
import com.liquidnet.service.consumer.goblin.receiver.ConsumerGoblinXlsRdsReceiver;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
import org.springframework.data.redis.stream.Subscription;
import java.time.Duration;
@Configuration
public class ConsumerGoblinXlsRedisStreamConfig {
@Autowired
ConsumerGoblinXlsRdsReceiver consumerGoblinXlsRdsReceiver;
private StreamMessageListenerContainer<String, MapRecord<String, String, String>> buildStreamMessageListenerContainer(RedisConnectionFactory factory) {
var options = StreamMessageListenerContainer
.StreamMessageListenerContainerOptions
.builder()
.pollTimeout(Duration.ofMillis(1))
.build();
return StreamMessageListenerContainer.create(factory, options);
}
/**
* 缺票登记
*
* @param listenerContainer
* @param t
* @return
*/
private Subscription receiveGoblinXls(StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer, int t) {
return listenerContainer.receiveAutoAck(
Consumer.from(MQConst.GoblinQueue.GOBLIN_XLS_OPERA.getGroup(), MQConst.GoblinQueue.GOBLIN_XLS_OPERA.name() + t),
StreamOffset.create(MQConst.GoblinQueue.GOBLIN_XLS_OPERA.getKey(), ReadOffset.lastConsumed()), consumerGoblinXlsRdsReceiver
);
}
/* —————————————————————————— | —————————————————————————— | —————————————————————————— */
/* -------------------------------------------------------- | 缺票登记 */
@Bean
public Subscription subscriptionGoblinXls1(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveGoblinXls(listenerContainer, 1);
listenerContainer.start();
return subscription;
}
@Bean
public Subscription subscriptionGoblinXls2(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveGoblinXls(listenerContainer, 2);
listenerContainer.start();
return subscription;
}
@Bean
public Subscription subscriptionGoblinXls3(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveGoblinXls(listenerContainer, 3);
listenerContainer.start();
return subscription;
}
/* -------------------------------------------------------- | */
}
package com.liquidnet.service.consumer.goblin.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode
public class PhoneDto {
private String uid;
private String mobile;
}
package com.liquidnet.service.consumer.goblin.receiver;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.fastjson.JSON;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.consumer.goblin.dto.PhoneDto;
import com.liquidnet.service.consumer.goblin.service.IBaseDao;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.stream.StreamListener;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
@Slf4j
public abstract class AbstractXlsRedisReceiver implements StreamListener<String, MapRecord<String, String, String>> {
@Autowired
StringRedisTemplate stringRedisTemplate;
@Autowired
private RedisUtil redisUtil;
@Override
public void onMessage(MapRecord<String, String, String> message) {
log.debug("CONSUMER XLS [streamKey:{},messageId:{},stream:{},body:{}]",
this.getRedisStreamKey(), message.getId(), message.getStream(), message.getValue());
boolean result = this.consumerSqlDaoHandler(message.getValue().get("message"), Integer.parseInt(message.getValue().get("type")), message.getValue().get("skuId"));
log.info("CONSUMER XLS_PATH RESULT:{} ==> MESSAGE_ID:{}", result, message.getId());
try {
stringRedisTemplate.opsForStream().acknowledge(getRedisStreamGroup(), message);
stringRedisTemplate.opsForStream().delete(this.getRedisStreamKey(), message.getId());
} catch (Exception e) {
log.error("#CONSUMER SQL RESULT:{} ==> DEL_REDIS_QUEUE_MSG_EXCEPTION[MESSAGE_ID:{},MSG:{}]", result, message.getId(), JsonUtils.toJson(message), e);
} finally {
try {
stringRedisTemplate.opsForStream().acknowledge(getRedisStreamGroup(), message);
stringRedisTemplate.opsForStream().delete(this.getRedisStreamKey(), message.getId());
} catch (Exception ignored) {
}
}
}
private boolean consumerSqlDaoHandler(String xlsPath, Integer type, String skuId) {
Boolean aBoolean = false;
try {
URL url = new URL(xlsPath);
InputStream is = url.openStream();
EasyExcel.read(is, PhoneDto.class, new PageReadListener<PhoneDto>(dataList -> {
for (PhoneDto data : dataList) {
if(data.getMobile()==null){
continue;
}
String redisKey = GoblinRedisConst.REDIS_UN_BUY.concat(skuId + ":").concat(data.getMobile());
if (type.equals(1)) {//添加
log.debug("添加 读取到一条数据{}", JSON.toJSONString(data));
redisUtil.set(redisKey, 0);
} else {
log.debug("删除 读取到一条数据{}", JSON.toJSONString(data));
redisUtil.del(redisKey);
}
}
})).sheet().doRead();
} catch (Exception e) {
aBoolean = false;
log.error("CONSUMER XLS FAIL ==> {}", e.getMessage(), e);
e.printStackTrace();
} finally {
// if (!aBoolean) {
// HashMap<String, String> map = CollectionUtil.mapStringString();
// map.put("message", xlsPath);
// map.put("skuId", skuId);
// map.put("type", type.toString());
// stringRedisTemplate.opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(this.getRedisStreamKey()));
// }
}
return aBoolean;
}
protected abstract String getRedisStreamKey();
protected abstract String getRedisStreamGroup();
}
\ No newline at end of file
package com.liquidnet.service.consumer.goblin.receiver;
import com.liquidnet.service.base.constant.MQConst;
import org.springframework.stereotype.Component;
@Component
public class ConsumerGoblinXlsRdsReceiver extends AbstractXlsRedisReceiver {
@Override
protected String getRedisStreamKey() {
return MQConst.GoblinQueue.GOBLIN_XLS_OPERA.getKey();
}
@Override
protected String getRedisStreamGroup() {
return MQConst.GoblinQueue.GOBLIN_XLS_OPERA.getGroup();
}
}
...@@ -28,4 +28,8 @@ XGROUP CREATE goblin:stream:order:user group.order:user 0 ...@@ -28,4 +28,8 @@ XGROUP CREATE goblin:stream:order:user group.order:user 0
#---- # #---- #
#---- 购物车 #---- 购物车
XADD goblin:stream:sql.shopcart * 0 0 XADD goblin:stream:sql.shopcart * 0 0
XGROUP CREATE goblin:stream:sql.shopcart group.shop.shopcart 0 XGROUP CREATE goblin:stream:sql.shopcart group.shop.shopcart 0
\ No newline at end of file
#--- xls文件操作
XADD goblin:stream:xls * 0 0
XGROUP CREATE goblin:stream:xls group.xls 0
\ No newline at end of file
...@@ -79,12 +79,13 @@ public class GoblinOrderUtils { ...@@ -79,12 +79,13 @@ public class GoblinOrderUtils {
params.add("content", content); params.add("content", content);
params.add("totalPrice", totalPrice.toString()); params.add("totalPrice", totalPrice.toString());
params.add("goodId", spuId); params.add("goodId", spuId);
params.add("performanceId", null); params.add("performanceId", "null");
params.add("timeId", null); params.add("timeId", "null");
params.add("ticketId", null); params.add("ticketId", "null");
MultiValueMap<String, String> header = CollectionUtil.linkedMultiValueMapStringString(); MultiValueMap<String, String> header = CollectionUtil.linkedMultiValueMapStringString();
header.add("Authorization", "Bearer " + CurrentUtil.getToken()); header.add("Authorization", "Bearer " + CurrentUtil.getToken());
String returnData = HttpUtil.post(candyUrl + "/candy-coupon/use", params, header); header.add("Accept", "application/json;charset=UTF-8");
String returnData = HttpUtil.post("http://172.16.3.71:9009/candy" + "/candy-coupon/use", params, header);
ResponseDto<CandyUseResultVo> innerReturnVo = JsonUtils.fromJson(returnData, new TypeReference<ResponseDto<CandyUseResultVo>>() { ResponseDto<CandyUseResultVo> innerReturnVo = JsonUtils.fromJson(returnData, new TypeReference<ResponseDto<CandyUseResultVo>>() {
}); });
CandyUseResultVo candyUseResultVo = innerReturnVo.getData(); CandyUseResultVo candyUseResultVo = innerReturnVo.getData();
...@@ -117,7 +118,7 @@ public class GoblinOrderUtils { ...@@ -117,7 +118,7 @@ public class GoblinOrderUtils {
} catch (Exception e) { } catch (Exception e) {
log.error("用券ERROR:{}", e); log.error("用券ERROR:{}", e);
hashMap.put("type", -1); hashMap.put("type", -1);
hashMap.put("voucher", -1); hashMap.put("voucher", 0);
return hashMap; return hashMap;
} }
} }
......
package com.liquidnet.service.goblin.util; package com.liquidnet.service.goblin.util;
import com.liquidnet.commons.lang.util.CollectionUtil; import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.service.base.constant.MQConst;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.stream.StreamRecords; import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
...@@ -11,7 +12,7 @@ import java.util.HashMap; ...@@ -11,7 +12,7 @@ import java.util.HashMap;
@Component @Component
public class QueueUtils { public class QueueUtils {
// @Autowired // @Autowired
// private RabbitTemplate rabbitTemplate; // private RabbitTemplate rabbitTemplate;
@Autowired @Autowired
StringRedisTemplate stringRedisTemplate; StringRedisTemplate stringRedisTemplate;
...@@ -38,4 +39,23 @@ public class QueueUtils { ...@@ -38,4 +39,23 @@ public class QueueUtils {
map.put("message", jsonMsg); map.put("message", jsonMsg);
stringRedisTemplate.opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(streamKey)); stringRedisTemplate.opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(streamKey));
} }
/**
* 发送消息 - REDIS [XLS]
*
* @param xlsPath xls 对应的OSS 全量路径
* @param type [1-添加|2-删除]
* @param skuId skuId
*/
public void sendMsgByRedisXls(String xlsPath, String type, String skuId) {
if (xlsPath.equals("") || xlsPath == null || type.equals("") || type == null || skuId.equals("") || skuId == null) {
} else {
HashMap<String, String> map = CollectionUtil.mapStringString();
map.put("message", xlsPath);
map.put("type", type);
map.put("skuId", skuId);
stringRedisTemplate.opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(MQConst.GoblinQueue.GOBLIN_XLS_OPERA.getKey()));
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment