Merge remote-tracking branch 'origin/1130-查验接口加上幂等校验' into release

# Conflicts:
#	dxhy-erp/pom.xml
#	dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java
release
wangrangrang 2 years ago
commit 7c31e89e4d
  1. 4
      dxhy-erp/pom.xml
  2. 31
      dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java

@ -156,6 +156,10 @@
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

@ -12,7 +12,6 @@ import com.dxhy.common.exception.BaseException;
import com.dxhy.common.util.InvoiceUtil;
import com.dxhy.common.utils.Base64Encoding;
import com.dxhy.common.utils.R;
import com.dxhy.erp.dao.*;
import com.dxhy.erp.entity.*;
import com.dxhy.erp.entity.sdny.*;
import com.dxhy.erp.model.InvoiceDetailInfo;
@ -21,11 +20,14 @@ import com.dxhy.erp.utils.Base64;
import com.dxhy.erp.utils.HmacSHA1Util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -86,6 +88,9 @@ public class SDNYMainProcessController extends AbstractController {
@Autowired
private ImageSubmitService imageSubmitService;
@Resource
private RedissonClient redisson;
/**
* 查验发票
*/
@ -489,6 +494,18 @@ public class SDNYMainProcessController extends AbstractController {
@SysLog("发票查验")
public ResponseEntity<String> singleInvoiceCheck(@RequestBody Map<String, String> pramsMap) throws Exception {
log.info("传入的参数为:{}", pramsMap);
String param = JSONObject.toJSONString(pramsMap);
//加分布式锁
String lockKey = Base64Utils.encodeToString(param.getBytes());
boolean isLock = false;
RLock lock = redisson.getLock(lockKey);
try {
isLock = lock.tryLock();
if (!isLock) {
log.info("当前已有线程获取到锁");
} else {
String dbName = "business";
JSONObject checkInvoiceResult = null;
@ -725,6 +742,18 @@ public class SDNYMainProcessController extends AbstractController {
return ResponseEntity.ok(JSONObject.toJSONString(R.error().put("data", checkInvoiceResult)));
}
}catch (Exception e) {
e.printStackTrace();
return ResponseEntity.ok(JSONObject.toJSONString(R.error().put("data", "")));
}
finally {
//关锁
if (isLock) {
lock.unlock();
}
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error().put("data", "请求正在处理,不要重复提交")));
}
@Async
void saveCheckLog(Map<String, String> pramsMap, JSONObject checkInvoice) {

Loading…
Cancel
Save