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. 35
      dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java

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

@ -12,7 +12,6 @@ import com.dxhy.common.exception.BaseException;
import com.dxhy.common.util.InvoiceUtil; import com.dxhy.common.util.InvoiceUtil;
import com.dxhy.common.utils.Base64Encoding; import com.dxhy.common.utils.Base64Encoding;
import com.dxhy.common.utils.R; import com.dxhy.common.utils.R;
import com.dxhy.erp.dao.*;
import com.dxhy.erp.entity.*; import com.dxhy.erp.entity.*;
import com.dxhy.erp.entity.sdny.*; import com.dxhy.erp.entity.sdny.*;
import com.dxhy.erp.model.InvoiceDetailInfo; import com.dxhy.erp.model.InvoiceDetailInfo;
@ -21,11 +20,14 @@ import com.dxhy.erp.utils.Base64;
import com.dxhy.erp.utils.HmacSHA1Util; import com.dxhy.erp.utils.HmacSHA1Util;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; 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.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -86,6 +88,9 @@ public class SDNYMainProcessController extends AbstractController {
@Autowired @Autowired
private ImageSubmitService imageSubmitService; private ImageSubmitService imageSubmitService;
@Resource
private RedissonClient redisson;
/** /**
* 查验发票 * 查验发票
*/ */
@ -489,6 +494,18 @@ public class SDNYMainProcessController extends AbstractController {
@SysLog("发票查验") @SysLog("发票查验")
public ResponseEntity<String> singleInvoiceCheck(@RequestBody Map<String, String> pramsMap) throws Exception { public ResponseEntity<String> singleInvoiceCheck(@RequestBody Map<String, String> pramsMap) throws Exception {
log.info("传入的参数为:{}", pramsMap); 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"; String dbName = "business";
JSONObject checkInvoiceResult = null; JSONObject checkInvoiceResult = null;
@ -558,7 +575,7 @@ public class SDNYMainProcessController extends AbstractController {
//如果购方名称为空,则查验之后补充购销方相关信息 //如果购方名称为空,则查验之后补充购销方相关信息
String gfName = checkInvoiceByUuid.getGfName(); String gfName = checkInvoiceByUuid.getGfName();
String gfAddressAndPhone = checkInvoiceByUuid.getGfAddressAndPhone(); String gfAddressAndPhone = checkInvoiceByUuid.getGfAddressAndPhone();
if(StringUtils.isEmpty(gfName) || StringUtils.isEmpty(gfAddressAndPhone)){ if (StringUtils.isEmpty(gfName) || StringUtils.isEmpty(gfAddressAndPhone)) {
log.info("购方名称为空,查验补充信息"); log.info("购方名称为空,查验补充信息");
checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap, null); checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap, null);
@ -608,7 +625,7 @@ public class SDNYMainProcessController extends AbstractController {
JSONObject checkInvoice = (JSONObject) JSONObject.toJSON(checkInvoiceByUuid); JSONObject checkInvoice = (JSONObject) JSONObject.toJSON(checkInvoiceByUuid);
JSONArray checkInvoiceDetail = (JSONArray) JSONObject.toJSON(baseTDxRecordInvoiceDetail); JSONArray checkInvoiceDetail = (JSONArray) JSONObject.toJSON(baseTDxRecordInvoiceDetail);
JSONObject vehicleDetail = new JSONObject(); JSONObject vehicleDetail = new JSONObject();
if(vehicleList != null && vehicleList.size() > 0) { if (vehicleList != null && vehicleList.size() > 0) {
vehicleDetail = (JSONObject) JSONObject.toJSON(vehicleList.get(0)); vehicleDetail = (JSONObject) JSONObject.toJSON(vehicleList.get(0));
} }
@ -725,6 +742,18 @@ public class SDNYMainProcessController extends AbstractController {
return ResponseEntity.ok(JSONObject.toJSONString(R.error().put("data", checkInvoiceResult))); 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 @Async
void saveCheckLog(Map<String, String> pramsMap, JSONObject checkInvoice) { void saveCheckLog(Map<String, String> pramsMap, JSONObject checkInvoice) {

Loading…
Cancel
Save