Browse Source

[POS][修改]:事务修改

release_toaliyun_real
Stormeye Wu 6 years ago
parent
commit
9c049ce288
3 changed files with 59 additions and 16 deletions
  1. +25
    -2
      mallinkPosApi/src/main/java/com/iformall/service/PosService.java
  2. +7
    -14
      mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java
  3. +27
    -0
      mallinkPosApi/src/test/java/com/iformall/pos/test/PosAppTest.java

+ 25
- 2
mallinkPosApi/src/main/java/com/iformall/service/PosService.java View File

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

import com.iformall.domain.po.WxCoupon;
import com.iformall.domain.vo.WxCouponOrderCVo;
import com.iformall.enums.EnumVerifyActionType;
import com.iformall.exception.MallinkException;
import org.springframework.web.bind.annotation.RequestBody;
@@ -22,9 +24,30 @@ public interface PosService {
*/
Map<String, String> checkMember(Map<String, String> params) throws MallinkException;

/**
* 核销动作(check, pre_verify, verify)
* @param params
* @param actionType
* @return
* @throws MallinkException
*/
Map<String, String> couponOrderVerifyDo(@RequestBody Map<String, String> params, EnumVerifyActionType actionType) throws MallinkException;

Map<String, String> couponOrderVerifyListDo(@RequestBody Map<String, String> params, EnumVerifyActionType actionType) throws MallinkException;

/**
* 核销取消(check, pre_verify, verify) for selected_coupon_list
* @param params
* @param actionType
* @return
* @throws MallinkException
*/
Map<String, String> couponOrderVerifyCancel(Map<String, String> params, EnumVerifyActionType actionType) throws MallinkException;

/**
* 核销动作(check, pre_verify, verify) for selected_coupon_list
* @param params
* @param actionType
* @return
* @throws MallinkException
*/
Map<String, String> couponOrderVerifyListDo(@RequestBody Map<String, String> params, EnumVerifyActionType actionType) throws MallinkException;
}

+ 7
- 14
mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java View File

@@ -15,12 +15,10 @@ import com.iformall.mapper.WxOrderMapper;
import com.iformall.pay.WxPayConstant;
import com.iformall.service.*;
import lombok.AllArgsConstructor;
import net.sf.saxon.expr.Component;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

@@ -220,6 +218,7 @@ public class PosServiceImpl implements PosService {
}

@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> couponOrderVerifyDo(@RequestBody Map<String, String> params, EnumVerifyActionType actionType) throws MallinkException {
Map<String, String> retMap = new HashMap<>();

@@ -322,6 +321,7 @@ public class PosServiceImpl implements PosService {
}

@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> couponOrderVerifyListDo(@RequestBody Map<String, String> params, EnumVerifyActionType actionType) throws MallinkException {
Map<String, String> retMap = new HashMap<>();

@@ -558,7 +558,6 @@ public class PosServiceImpl implements PosService {
retMap.put(WxPayConstant.PRE_VERIFY, "true");
retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(couponOrderCVo.getPrice()));
retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(posAmount - couponOrderCVo.getPrice()));
posAmount = posAmount - couponOrderCVo.getPrice();
return retMap;
}
if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode())) {
@@ -569,7 +568,6 @@ public class PosServiceImpl implements PosService {
retMap.put(WxPayConstant.PRE_VERIFY, "true");
retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(couponOrderCVo.getPrice()));
retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(posAmount - couponOrderCVo.getPrice()));
posAmount = posAmount - couponOrderCVo.getPrice();
return retMap;
} catch (MallinkException e) {
logger.error(e.getMessage());
@@ -634,7 +632,6 @@ public class PosServiceImpl implements PosService {
retMap.put(WxPayConstant.VERIFY, "true");
retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(couponOrderCVo.getPrice()));
retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(posAmount - couponOrderCVo.getPrice()));
posAmount = posAmount - couponOrderCVo.getPrice();
return retMap;
} catch (MallinkException e) {
logger.error(e.getMessage());
@@ -652,6 +649,7 @@ public class PosServiceImpl implements PosService {
}

@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> couponOrderVerifyCancel(Map<String, String> params, EnumVerifyActionType actionType) {
Map<String, String> retMap = new HashMap<>();

@@ -740,7 +738,7 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL);
}
try {
cancelPreVerify(couponOrderCVo, buUserId, posOrderId);
cancelPreVerify(couponOrderCVo, posOrderId);
return retMap;
} catch (MallinkException e) {
logger.error(e.getMessage());
@@ -776,7 +774,6 @@ public class PosServiceImpl implements PosService {
* @param couponOrderCVo
* @param posOrderId
*/
@Transactional(rollbackFor = Exception.class)
public void doPreVerify(WxCouponOrderCVo couponOrderCVo, Long buUserId, Long posOrderId) {
int num = 0;
// 1. insert posOrderId
@@ -817,11 +814,9 @@ public class PosServiceImpl implements PosService {
/**
* 预核销回退
* @param couponOrderCVo
* @param buUserId
* @param posOrderId
*/
@Transactional(rollbackFor = Exception.class)
public void cancelPreVerify(WxCouponOrderCVo couponOrderCVo, Long buUserId, Long posOrderId) {
public void cancelPreVerify(WxCouponOrderCVo couponOrderCVo, Long posOrderId) {
int num = 0;
// 1. update posOrderId
PosCouponOrderVerify posCouponOrderVerify = new PosCouponOrderVerify();
@@ -864,7 +859,7 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage());
}
if (num != 1) {
logger.error("核销异常:updatete num " + num);
logger.error("核销异常:updatete num " + num);
throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), "updatete num " + num);
}
logger.info("预核销已取消: " + couponOrderCVo.getId());
@@ -877,7 +872,6 @@ public class PosServiceImpl implements PosService {
* @param buUserId
* @param posOrderId
*/
@Transactional(rollbackFor = Exception.class)
public void doVerify(WxCouponOrderCVo couponOrderCVo, WxCoupon coupon, Long merchantId, Long buUserId, Long posOrderId, Map<String, String> retMap) {
int num = 0;
// 1. insert posOrderId
@@ -913,7 +907,7 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage());
}
if (num != 1) {
logger.error("核销异常:updatete num " + num);
logger.error("核销异常:update num " + num);
throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), "updatete num " + num);
}

@@ -957,7 +951,6 @@ public class PosServiceImpl implements PosService {
* @param buUserId
* @param posOrderId
*/
@Transactional(rollbackFor = Exception.class)
public void cancelVerify(WxCouponOrderCVo couponOrderCVo, Long buUserId, Long posOrderId) {
// 1. 积分历史回退
try {


+ 27
- 0
mallinkPosApi/src/test/java/com/iformall/pos/test/PosAppTest.java View File

@@ -284,4 +284,31 @@ public class PosAppTest {
System.out.println("response sign: " + resSigned);
Assert.assertEquals(resSigned, true);
}

@Test
public void couponOrderPayVerifyListTest() throws Exception {
Map<String, String> reqObj = new HashMap<>();
reqObj.put(WxPayConstant.DEV_ID, devId);
reqObj.put(WxPayConstant.TENANT_ID, "456");
reqObj.put(WxPayConstant.MERCHANT_ID, "317109453987631104");
reqObj.put(WxPayConstant.BUSER_ID, "317111133332426752");
reqObj.put(WxPayConstant.SELECTED_COUPON_ORDER_LIST, "[\"318978990426783744\"]");
reqObj.put(WxPayConstant.NONCE_STR, "1");
reqObj.put(WxPayConstant.POS_ORDER_ID, "1");
reqObj.put(WxPayConstant.POS_AMOUNT, "200");
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey));
String reqJsonStr = JSONObject.toJSONString(reqObj);
RequestBuilder request = MockMvcRequestBuilders.post("/couponOrderPayVerifyList")
.contentType(MediaType.APPLICATION_JSON)
.content(reqJsonStr);
MvcResult result = mockMvc.perform(request).andReturn();
String responseStr = result.getResponse().getContentAsString();
System.out.println(responseStr);

ObjectMapper mapper = new ObjectMapper();
Map<String,String> respMap = mapper.readValue(responseStr, Map.class);
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey);
System.out.println("response sign: " + resSigned);
Assert.assertEquals(resSigned, true);
}
}

Loading…
Cancel
Save