feature 1.还源代码

release
zhenghaiyang@ele-cloud.com 2 years ago
parent f17032b1b4
commit 7a75cb538a
  1. 80
      order-management-invoice/src/main/java/com/dxhy/order/invoice/config/RedissonConfig.java
  2. 30
      order-management-invoice/src/main/java/com/dxhy/order/invoice/module/invoice/service/impl/OrderInvoiceInfoServiceImpl.java

@ -1,40 +1,40 @@
package com.dxhy.order.invoice.config; //package com.dxhy.order.invoice.config;
//
import org.apache.commons.lang3.StringUtils; //import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson; //import org.redisson.Redisson;
import org.redisson.api.RedissonClient; //import org.redisson.api.RedissonClient;
import org.redisson.config.Config; //import org.redisson.config.Config;
import org.redisson.config.ReadMode; //import org.redisson.config.ReadMode;
import org.redisson.config.SentinelServersConfig; //import org.redisson.config.SentinelServersConfig;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties; //import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
//
import javax.annotation.Resource; //import javax.annotation.Resource;
import java.util.List; //import java.util.List;
//
public class RedissonConfig { //public class RedissonConfig {
//
@Resource // @Resource
private RedisProperties redisProperties; // private RedisProperties redisProperties;
//
//哨兵模式配置 // //哨兵模式配置
@Bean // @Bean
RedissonClient redissonSentinel() { // RedissonClient redissonSentinel() {
Config config = new Config(); // Config config = new Config();
RedisProperties.Sentinel sentinel = redisProperties.getSentinel(); // RedisProperties.Sentinel sentinel = redisProperties.getSentinel();
List<String> newNodes = sentinel.getNodes(); // List<String> newNodes = sentinel.getNodes();
newNodes.stream().forEach((index) -> newNodes.add( // newNodes.stream().forEach((index) -> newNodes.add(
index.startsWith("redis://") ? index : "redis://" + index)); // index.startsWith("redis://") ? index : "redis://" + index));
//
SentinelServersConfig serverConfig = config.useSentinelServers() // SentinelServersConfig serverConfig = config.useSentinelServers()
.addSentinelAddress(newNodes.toArray(new String[0])) // .addSentinelAddress(newNodes.toArray(new String[0]))
.setMasterName(sentinel.getMaster()) // .setMasterName(sentinel.getMaster())
.setReadMode(ReadMode.SLAVE); // .setReadMode(ReadMode.SLAVE);
//
if (StringUtils.isNotBlank(redisProperties.getPassword())) { // if (StringUtils.isNotBlank(redisProperties.getPassword())) {
serverConfig.setPassword(redisProperties.getPassword()); // serverConfig.setPassword(redisProperties.getPassword());
} // }
return Redisson.create(config); // return Redisson.create(config);
} // }
//
} //}

@ -1705,8 +1705,8 @@ public class OrderInvoiceInfoServiceImpl implements OrderInvoiceInfoService {
return redInvoiceRespPo; return redInvoiceRespPo;
} }
@Resource // @Resource
private RedissonClient redisson; // private RedissonClient redisson;
@SneakyThrows @SneakyThrows
@Override @Override
@ -1718,12 +1718,12 @@ public class OrderInvoiceInfoServiceImpl implements OrderInvoiceInfoService {
//组装发票报文 //组装发票报文
//金额、数量、税额跟跟换为负数,折扣行要与被折扣行合并 //金额、数量、税额跟跟换为负数,折扣行要与被折扣行合并
//校验重复提交数据覆盖问题 //校验重复提交数据覆盖问题
RLock lock = redisson.getLock(redInvoiceSaveReqPo.getFpqqlsh()); // RLock lock = redisson.getLock(redInvoiceSaveReqPo.getFpqqlsh());
// boolean redRedisLock = redisService.setNx(redInvoiceSaveReqPo.getFpqqlsh(), key, RedisConstant.REDIS_EXPIRE_TIME_2HOUR); // boolean redRedisLock = redisService.setNx(redInvoiceSaveReqPo.getFpqqlsh(), key, RedisConstant.REDIS_EXPIRE_TIME_2HOUR);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
try { // try {
if(!lock.isLocked()){ // if(!lock.isLocked()){
lock.lock(); // lock.lock();
Map<String, String> paramMap = redisService.pullAllHashMap(key); Map<String, String> paramMap = redisService.pullAllHashMap(key);
if(paramMap != null){ if(paramMap != null){
String value = redisService.pullHashMap(key, innerKey); String value = redisService.pullHashMap(key, innerKey);
@ -1750,16 +1750,16 @@ public class OrderInvoiceInfoServiceImpl implements OrderInvoiceInfoService {
redisService.set(redSyjeKey,syfpje); redisService.set(redSyjeKey,syfpje);
hashMap.put(redItemList.get(0).getId(),syfpje); hashMap.put(redItemList.get(0).getId(),syfpje);
} }
lock.unlock(); // lock.unlock();
return R.ok().put(OrderManagementConstant.DATA,hashMap); return R.ok().put(OrderManagementConstant.DATA,hashMap);
} else { // } else {
Thread.sleep(2000); // Thread.sleep(2000);
log.info("获取redis锁请等待,三次之后还是获取锁失败则返回。。。"); // log.info("获取redis锁请等待,三次之后还是获取锁失败则返回。。。");
} // }
} catch (InterruptedException e) { // } catch (InterruptedException e) {
lock.unlock(); // lock.unlock();
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
} }
return R.ok(); return R.ok();
} }

Loading…
Cancel
Save