幸运24-雪花主键-mq-根据insertRow跳出

This commit is contained in:
2025-09-12 11:01:39 +08:00
parent a10a8c393d
commit 33cb7286ae
3 changed files with 26 additions and 15 deletions

View File

@@ -28,6 +28,7 @@ import org.springframework.util.CollectionUtils;
import java.util.Collections;
import java.util.Date;
import java.util.Optional;
@Slf4j
@Service
@@ -96,7 +97,12 @@ public class Lucky24MessageService extends BaseService implements InitializingBe
Gift gift = giftService.getGiftById(giftMessage.getGiftId());
Date createTime = new Date(giftMessage.getCreateTime());
Lucky24Record record = insertRecordV2(giftMessage);
Optional<Lucky24Record> recordOptional = insertRecordIgnore(giftMessage);
if (recordOptional.isEmpty()){
return;
}
Lucky24Record record = recordOptional.get();
log.info("【处理lucky24 mq】 record 插入成功 messId:{} recordId:{} record:{}",
giftMessage.getMessId(), record.getId(), JSON.toJSONString(record));
@@ -159,7 +165,12 @@ public class Lucky24MessageService extends BaseService implements InitializingBe
return record;
}
private Lucky24Record insertRecordV2(Lucky24Message giftMessage) {
private Optional<Lucky24Record> insertRecordIgnore(Lucky24Message giftMessage) {
long startTime = System.currentTimeMillis();
long getPoolTime = 0;
long insertTime = 0;
Lucky24Record record = new Lucky24Record();
if (null == giftMessage.getId()){
@@ -183,6 +194,7 @@ public class Lucky24MessageService extends BaseService implements InitializingBe
if (null != pool){
record.setPoolType(pool.getType());
}
getPoolTime = System.currentTimeMillis();
}
record.setIsSupplement(giftMessage.getIsSupplement());
@@ -192,9 +204,16 @@ public class Lucky24MessageService extends BaseService implements InitializingBe
record.setCreateTime(new Date(giftMessage.getCreateTime()));
record.setStockResult(giftMessage.getStockResult());
recordService.insertRecordIgnore(record);
int insertRow = recordService.insertRecordIgnore(record);
long endTime = System.currentTimeMillis();
return record;
log.info("insertLucky24RecordIgnore row {} performance - getPool: {}ms, insert: {}ms, total: {}ms",
insertRow,
getPoolTime - startTime,
insertTime - getPoolTime,
endTime - startTime);
return Optional.ofNullable(insertRow > 0 ? record : null);
}
@Override

View File

@@ -65,16 +65,8 @@ public class Lucky24RecordService extends ServiceImpl<Lucky24RecordMapper, Lucky
return record;
}
public void insertRecordIgnore(Lucky24Record record) {
long startTime = System.currentTimeMillis();
int insertRow = baseMapper.insertIgnore(record);
long endTime = System.currentTimeMillis();
log.info("insertLucky242RecordIgnore row {} performance - insert: {}ms",
insertRow,
endTime - startTime);
public int insertRecordIgnore(Lucky24Record record) {
return baseMapper.insertIgnore(record);
}
public void insertRecord(Lucky24Record record) {

View File

@@ -57,7 +57,7 @@ public class RocketMQService {
List<Message<String>> messageList = lucky24Messages.stream()
.map(giftMessage -> MessageBuilder.withPayload(JSON.toJSONString(giftMessage)).build())
.collect(Collectors.toList());
mqMessageProducer.send(MqConstant.LUCKY_24_TOPIC, messageList,
mqMessageProducer.send(MqConstant.LUCKY_24_V2_TOPIC, messageList,
sendResult -> log.info("sendLucky24Message success result: {} message: {}", JSON.toJSONString(sendResult), messageList),
throwable -> log.error("sendLucky24Message fail message: {}", messageList, throwable));
}