Browse Source

tt

release_toaliyun_real
xhxu 5 years ago
parent
commit
4ae861d5df
3 changed files with 42 additions and 40 deletions
  1. +2
    -5
      mallinkPublicApi/src/main/java/com/iformall/controller/UserThirdCircleOrderController.java
  2. +3
    -2
      mallinkService/src/main/java/com/iformall/service/WxThirdPartyOrdersService.java
  3. +37
    -33
      mallinkService/src/main/java/com/iformall/service/impl/WxThirdPartyOrdersServiceImpl.java

+ 2
- 5
mallinkPublicApi/src/main/java/com/iformall/controller/UserThirdCircleOrderController.java View File

@@ -107,7 +107,7 @@ public class UserThirdCircleOrderController extends BaseController {
thirdPartyOrders.setPayAmount(Integer.parseInt(amount));
thirdPartyOrders.setSummary(summary);
try{
thirdPartyOrdersService.createOrder(thirdPartyOrders);
return thirdPartyOrdersService.createOrder(thirdPartyOrders);
}catch(MallinkException e){
logger.error(e.getMessage());
return new ResultData(e.getErrorCode(), e.getMessage());
@@ -116,7 +116,6 @@ public class UserThirdCircleOrderController extends BaseController {
return new ResultData(ErrorCode.SYS_SERVER_ERROR);
}

return new ResultData();
}

/**
@@ -180,7 +179,7 @@ public class UserThirdCircleOrderController extends BaseController {
thirdPartyOrders.setRefundId(refundId);

try{
thirdPartyOrdersService.insertRefundNoticeOrder(thirdPartyOrders);
return thirdPartyOrdersService.insertRefundNoticeOrder(thirdPartyOrders);
}catch(MallinkException e){
logger.error(e.getMessage());
return new ResultData(e.getErrorCode(), e.getMessage());
@@ -188,8 +187,6 @@ public class UserThirdCircleOrderController extends BaseController {
logger.error("异常:" + e);
return new ResultData(ErrorCode.SYS_SERVER_ERROR);
}

return new ResultData();
}




+ 3
- 2
mallinkService/src/main/java/com/iformall/service/WxThirdPartyOrdersService.java View File

@@ -1,6 +1,7 @@
package com.iformall.service;

import com.github.pagehelper.PageInfo;
import com.iformall.common.ResultData;
import com.iformall.domain.po.WxThirdPartyOrders;
import com.iformall.domain.po.base.TenantEntity;
import com.iformall.enums.EnumThirdOrderType;
@@ -38,9 +39,9 @@ public interface WxThirdPartyOrdersService {
List<WxThirdPartyOrders> getRefundOrderByTransactionId(EnumThirdOrderType orderType, String transactionId, String tenantId);


void createOrder(WxThirdPartyOrders record);
ResultData createOrder(WxThirdPartyOrders record);

void insertRefundNoticeOrder(WxThirdPartyOrders record);
ResultData insertRefundNoticeOrder(WxThirdPartyOrders record);

/**
* 积分


+ 37
- 33
mallinkService/src/main/java/com/iformall/service/impl/WxThirdPartyOrdersServiceImpl.java View File

@@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode;
import com.iformall.common.IdWorker;
import com.iformall.common.ResultData;
import com.iformall.domain.po.*;
import com.iformall.domain.po.base.TenantEntity;
import com.iformall.enums.*;
@@ -109,7 +110,7 @@ public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService

@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public void createOrder(WxThirdPartyOrders record) {
public ResultData createOrder(WxThirdPartyOrders record) {
String lockKey = StringUtils.join(THIRD_CIRCLE_KEY,record.getTransactionId(), ":",EnumYesOrNo.NO.getCode(),":", "lock");
long time = System.currentTimeMillis() + 2000;
String timeStr = String.valueOf(time);
@@ -166,7 +167,7 @@ public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService

if(record.getCUserId() == null){
redisLock.unlock(lockKey, timeStr);
return;
return new ResultData(0);
}
Integer businessId = EnumBusiness.BUSINESS_ID6.getCode();
if(wxMerchant != null){
@@ -191,7 +192,7 @@ public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService
}
if(creditNum == 0){
redisLock.unlock(lockKey, timeStr);
return;
return new ResultData(0);
}
record.setIncreasedPoints(creditNum);
record.setPointsUpdateTime(creditHistory.getCreateDate());
@@ -200,12 +201,13 @@ public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService
try {
wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.B_MICROPAY, record,EnumPayWay.PAY_WAY_NOT_UNPAY_B_MA);
} catch (Exception e) {
logger.error("B端刷卡支付发券: " + e.getMessage());
logger.error("支付发券: " + e.getMessage());
}
}

redisLock.unlock(lockKey, timeStr);
return new ResultData(creditNum);
}

redisLock.unlock(lockKey, timeStr);
}else {
logger.debug("CacheAspect 读库等待中, key:{}: " + lockKey);
try {
@@ -215,28 +217,30 @@ public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService
}finally {
redisLock.unlock(lockKey, timeStr);
}
return new ResultData(ErrorCode.SYS_REPEAT_SUBMIT_EXCEPTION);
}


}


@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public void insertRefundNoticeOrder(WxThirdPartyOrders record) {
public ResultData insertRefundNoticeOrder(WxThirdPartyOrders record) {
WxThirdPartyOrders order = this.getOrderByTransactionId(EnumThirdOrderType.RMB_PAY,record.getTransactionId(),record.getTenantId());
if(order == null){
logger.error("--第三方退款--付款消息未找到--transactionId="+record.getTransactionId());
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "付款消息未找到");
}else{
WxThirdPartyOrders refundOrder = this.getRefundOrderByRefundId(EnumThirdOrderType.RMB_PAY,record.getRefundId(),record.getTenantId());
if(refundOrder != null){
logger.error("--第三方退款--退款消息已存在---RefundId="+record.getRefundId());
}else{
String lockKey = StringUtils.join(THIRD_CIRCLE_KEY,record.getRefundId(), ":",EnumYesOrNo.YES.getCode(),":", "lock");
long time = System.currentTimeMillis() + 2000;
String timeStr = String.valueOf(time);
if (redisLock.lock2(lockKey, timeStr)) {
String lockKey = StringUtils.join(THIRD_CIRCLE_KEY,record.getRefundId(), ":",EnumYesOrNo.YES.getCode(),":", "lock");
long time = System.currentTimeMillis() + 2000;
String timeStr = String.valueOf(time);
if (redisLock.lock2(lockKey, timeStr)) {
WxThirdPartyOrders refundOrder = this.getRefundOrderByRefundId(EnumThirdOrderType.RMB_PAY,record.getRefundId(),record.getTenantId());
if(refundOrder != null){
logger.error("--第三方退款--退款消息已存在---RefundId="+record.getRefundId());
redisLock.unlock(lockKey, timeStr);
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "退款数据已存在");
}else{
List<WxThirdPartyOrders> refundOrders = this.getRefundOrderByTransactionId(EnumThirdOrderType.RMB_PAY,record.getTransactionId(),record.getTenantId());
Integer amount = order.getPayAmount();
Integer increasedPoints = order.getIncreasedPoints();
@@ -291,6 +295,7 @@ public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService
order.setUpdateTime(now);
wxThirdPartyOrdersMapper.updateOrderStatus(order);

int creditNum = 0;
if(order.getEarnPoints().equals(EnumYesOrNo.YES.getCode())){
WxCreditHistory creditHistory = new WxCreditHistory();
creditHistory.setTenantId(record.getFinalTenantId());
@@ -315,32 +320,31 @@ public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService
creditHistory.setSpend(0-record.getRefundAmount());
creditHistory.setChangePurpose(record.getSourceAppName()+"·消费退款:商户["+record.getShopName()+"] ("+record.getRefundAmountStr()+"元) ");
creditHistory = wxCreditHistoryService.saveOrUpdate(creditHistory,record.getTenantId());
Integer creditNum = 0;
if (creditHistory.getCreditNum() != null) {
creditNum = creditHistory.getCreditNum();
}
if(creditNum == 0){
redisLock.unlock(lockKey, timeStr);
return;
if(creditNum != 0){
record.setIncreasedPoints(creditNum);
record.setPointsUpdateTime(creditHistory.getCreateDate());
this.updatePoints(record);
}

record.setIncreasedPoints(creditNum);
record.setPointsUpdateTime(creditHistory.getCreateDate());
this.updatePoints(record);
}
redisLock.unlock(lockKey, timeStr);
return new ResultData(creditNum);
}

}
}else {
logger.debug("CacheAspect 读库等待中, key:{}: " + lockKey);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}finally {
redisLock.unlock(lockKey, timeStr);
}else {
logger.debug("CacheAspect 读库等待中, key:{}: " + lockKey);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}finally {
redisLock.unlock(lockKey, timeStr);
}
}
return new ResultData(ErrorCode.SYS_REPEAT_SUBMIT_EXCEPTION);
}
}



Loading…
Cancel
Save