From 87ccf9689e96390311a486f29a7784520db12916 Mon Sep 17 00:00:00 2001 From: yefei Date: Sun, 8 Oct 2023 10:21:01 +0800 Subject: [PATCH] =?UTF-8?q?ariesy=20=20=E9=87=87=E9=9B=86=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E6=95=B0=E6=8D=AE=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dxhy-core/pom.xml | 4 +++ .../com/dxhy/core/config/RedissionConfig.java | 33 +++++++++++++++++++ .../impl/InvoiceInterfaceServiceImpl.java | 24 ++++++++++++-- 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 dxhy-core/src/main/java/com/dxhy/core/config/RedissionConfig.java diff --git a/dxhy-core/pom.xml b/dxhy-core/pom.xml index 45cd4923..a4af582f 100644 --- a/dxhy-core/pom.xml +++ b/dxhy-core/pom.xml @@ -164,6 +164,10 @@ itext-asian 5.2.0 + + org.redisson + redisson-spring-boot-starter + com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config diff --git a/dxhy-core/src/main/java/com/dxhy/core/config/RedissionConfig.java b/dxhy-core/src/main/java/com/dxhy/core/config/RedissionConfig.java new file mode 100644 index 00000000..cbcea2b1 --- /dev/null +++ b/dxhy-core/src/main/java/com/dxhy/core/config/RedissionConfig.java @@ -0,0 +1,33 @@ +package com.dxhy.core.config; + +import org.redisson.Redisson; +import org.redisson.api.RedissonClient; +import org.redisson.config.Config; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class RedissionConfig { + + @Value("${spring.redis.host}") + private String host; + + @Value("${spring.redis.port}") + private String port; + + @Value("${spring.redis.password}") + private String redisPassword; + + @Bean + public RedissonClient getRedisson(){ + + Config config = new Config(); + //单机模式 依次设置redis地址和密码 + config.useSingleServer() + .setAddress("redis://" + host + ":" + port) + .setPassword(redisPassword); + return Redisson.create(config); + } +} + diff --git a/dxhy-core/src/main/java/com/dxhy/core/job/service/impl/InvoiceInterfaceServiceImpl.java b/dxhy-core/src/main/java/com/dxhy/core/job/service/impl/InvoiceInterfaceServiceImpl.java index 841e44f5..45dfde96 100644 --- a/dxhy-core/src/main/java/com/dxhy/core/job/service/impl/InvoiceInterfaceServiceImpl.java +++ b/dxhy-core/src/main/java/com/dxhy/core/job/service/impl/InvoiceInterfaceServiceImpl.java @@ -14,7 +14,10 @@ import javax.crypto.spec.SecretKeySpec; import com.dxhy.core.job.thread.InvoiceParseHandle; import org.apache.commons.lang.StringUtils; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import com.alibaba.fastjson.JSON; @@ -72,6 +75,16 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService { @Resource private Sender sender; + @Resource + private StringRedisTemplate stringRedisTemplate; + + @Resource + private RedissonClient redisson; + + private static final String REDIS_KEY = "redis_oa_01"; + + private static final int MAX_SIZE = 1000; + @Value("${jxjk.collectUrl}") private String collectUrl; @Value("${jxjk.invoiceGet}") @@ -651,10 +664,17 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService { } else { invoiceSelectInfo.setAuthStatus("0"); } + + //加分布式锁 + String lockKey = invoiceSelectInfo.getUuid(); + + RLock lock = redisson.getLock(lockKey); + lock.lock(); + stringRedisTemplate.opsForValue().set(REDIS_KEY, String.valueOf(0)); + // 判断库里是否已经存在,存在则只更新发票状态,状态更新时间,认证状态以及相关字段更新 DynamicContextHolder.push(db + DbConstant.BUSINESS_READ); - TDxRecordInvoiceJobEntity entity = tDxRecordInvoiceJobDao - .findInvoiceByUUid(invoiceSelectInfo.getUuid()); + TDxRecordInvoiceJobEntity entity = tDxRecordInvoiceJobDao.findInvoiceByUUid(invoiceSelectInfo.getUuid()); if (entity != null) { boolean flag = false; if (StringUtils.isBlank(entity.getCheckCode())