|
|
@@ -26,8 +26,11 @@ import com.storlead.trade.mapper.MarketEmailsMapper;
|
|
|
import com.storlead.trade.service.*;
|
|
|
import com.storlead.trade.vo.*;
|
|
|
import org.apache.commons.lang.time.DateUtils;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -85,6 +88,10 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
@Resource
|
|
|
private LiaisonTradeService liaisonTradeService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ private RedissonClient redissonClient;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Result<Object> getList(MarketEmailsDTO dto) {
|
|
|
@@ -1142,6 +1149,28 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
|
|
|
@Override
|
|
|
public void sendAgain() {
|
|
|
+ String lockKey = "market-emails:send-again:lock";
|
|
|
+ RLock lock = redissonClient.getLock(lockKey);
|
|
|
+ boolean acquired = false;
|
|
|
+ try {
|
|
|
+ // 尝试获取锁,最多等 0 秒(抢不到直接放弃,避免当前执行实例被阻塞)
|
|
|
+ acquired = lock.tryLock(0, 2, java.util.concurrent.TimeUnit.MINUTES);
|
|
|
+ if (!acquired) {
|
|
|
+ log.info("[sendAgain] 锁未获取到,当前有其他实例在执行,跳过本次");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ doSendAgain(lockKey);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ log.warn("[sendAgain] 获取锁被中断: {}", e.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (acquired && lock.isHeldByCurrentThread()) {
|
|
|
+ lock.unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doSendAgain(String lockKey) {
|
|
|
LambdaQueryWrapper<MarketEmailsEntity> marketEmailHasFirstQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
marketEmailHasFirstQueryWrapper.eq(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
|
|
|
marketEmailHasFirstQueryWrapper.eq(MarketEmailsEntity::getHasFirst, 2);
|
|
|
@@ -1206,6 +1235,9 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
Date expectSendTime = DateUtils.addMinutes(new Date(), 30);
|
|
|
newMarketEmail.setExpectSendTime(expectSendTime);
|
|
|
newMarketEmail.setHasFirst(2);
|
|
|
+ newMarketEmail.setHasProtect(0);
|
|
|
+ newMarketEmail.setHasReader(0);
|
|
|
+ newMarketEmail.setHasReply(0);
|
|
|
|
|
|
newMarketEmailList.add(newMarketEmail);
|
|
|
}
|