Kaynağa Gözat

修复自调用 事务不生效的问题

xdd 2 ay önce
ebeveyn
işleme
d4cf6c6271

+ 6 - 0
fs-service-system/src/main/java/com/fs/store/service/IFsStoreOrderService.java

@@ -276,4 +276,10 @@ public interface IFsStoreOrderService
      */
     R payRemain(FsStoreOrderPayParam param);
 
+    /**
+     * 完成订单
+     * @param orderId 订单id
+     * @return R
+     */
+    R finishStoreOrder(Long orderId);
 }

+ 21 - 47
fs-service-system/src/main/java/com/fs/store/service/impl/FsStoreOrderServiceImpl.java

@@ -14,7 +14,6 @@ import java.util.stream.Collectors;
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 import cn.hutool.core.collection.CollectionUtil;
-import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.net.URLDecoder;
 import cn.hutool.core.util.IdUtil;
@@ -28,7 +27,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.fs.api.param.OrderListParam;
 import com.fs.api.vo.OrderListVO;
 import com.fs.api.vo.ProductListVO;
-import com.fs.common.annotation.DataScope;
 import com.fs.common.config.FSSysConfig;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
@@ -74,32 +72,26 @@ import com.fs.store.service.handler.PaymentHandler;
 import com.fs.store.service.handler.PaymentHandlerHolder;
 import com.fs.store.service.handler.param.PayProcessContext;
 import com.fs.store.vo.*;
-import com.fs.pay.service.IPayService;
-import com.fs.pay.service.dto.RefundDTO;
-import com.fs.system.domain.SysConfig;
 import com.fs.system.service.ISysConfigService;
 import com.fs.tzBank.TzBankService;
 import com.fs.tzBank.utils.TzConfigUtils;
 import com.fs.wx.miniapp.config.WxMaConfiguration;
 import com.fs.wx.miniapp.config.WxMaProperties;
-import com.fs.wx.pay.config.WxPayProperties;
-import com.hc.openapi.tool.util.Ids;
 import lombok.Synchronized;
 import me.chanjar.weixin.common.error.WxErrorException;
 import org.apache.commons.collections4.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.aop.framework.AopContext;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationEventPublisher;
-import org.springframework.scheduling.annotation.Async;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
-import javax.swing.plaf.TableHeaderUI;
-
 import static com.fs.store.constants.StoreConstants.DELIVERY;
 
 /**
@@ -109,6 +101,7 @@ import static com.fs.store.constants.StoreConstants.DELIVERY;
  * @date 2022-03-15
  */
 @Service
+@EnableAspectJAutoProxy(proxyTargetClass = true,exposeProxy = true)
 public class FsStoreOrderServiceImpl implements IFsStoreOrderService
 {
 
@@ -136,7 +129,7 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
     private IFsUserBillService billService;
 
     @Autowired
-    RedisCache redisCache;
+    private RedisCache redisCache;
 
     @Autowired
     private IFsStoreCartService cartService;
@@ -156,15 +149,15 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
     @Autowired
     private FSSysConfig sysConfig;
     @Autowired
-    IErpOrderService erpOrderService;
+    private IErpOrderService erpOrderService;
     @Autowired
-    IFsStorePaymentService paymentService;
+    private IFsStorePaymentService paymentService;
 
     @Autowired
-    IFsStoreProductPackageService productPackageService;
+    private IFsStoreProductPackageService productPackageService;
 
     @Autowired
-    ICompanyUserService companyUserService;
+    private ICompanyUserService companyUserService;
     @Autowired
     private IFsStoreProductAttrValueService attrValueService;
     @Autowired
@@ -186,17 +179,17 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
     @Autowired
     private FsStoreOrderItemMapper fsStoreOrderItemMapper;
     @Autowired
-    ICompanyDeptService companyDeptService;
+    private ICompanyDeptService companyDeptService;
     @Autowired
-    IFsPrescribeService prescribeService;
+    private IFsPrescribeService prescribeService;
 
     @Autowired
-    PayService ybPayService;
+    private PayService ybPayService;
     @Autowired
-    HuiFuService huiFuService;
+    private HuiFuService huiFuService;
 
     @Autowired
-    TzBankService tzBankService;
+    private TzBankService tzBankService;
 
     @Autowired
     private IFsCouponScheduleService fsCouponScheduleService;
@@ -407,8 +400,6 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
                     vo.setItems(items);
                 }
             }
-            //List<FsStoreOrderItemVO> items=storeOrderItemService.selectFsStoreOrderItemListByOrderId(vo.getId());
-            //vo.setItems(items);
         }
         return list;
     }
@@ -878,6 +869,7 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
 
     //未支付取消订单
     @Override
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public void cancelOrder(Long orderId) {
         FsStoreOrder order= fsStoreOrderMapper.selectFsStoreOrderById(orderId);
         if(order.getStatus()==OrderInfoEnum.STATUS_0.getValue()){
@@ -894,14 +886,6 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
             //添加记录
             orderStatusService.create(order.getId(), OrderLogEnum.CANCEL_ORDER.getValue(),
                     OrderLogEnum.CANCEL_ORDER.getDesc());
-//            if(order.getPaid()==1){
-//                //更新OMS
-//                ErpRefundUpdateRequest request=new ErpRefundUpdateRequest();
-//                request.setTid(order.getOrderCode());
-//                request.setOid(order.getOrderCode());
-//                request.setRefund_state(1);
-//                erpOrderService.refundUpdate(request);
-//            }
             TemplateBean templateBean = TemplateBean.builder()
                     .orderId(order.getId().toString())
                     .orderCode(order.getOrderCode().toString())
@@ -914,7 +898,7 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
     }
 
     @Override
-    @Transactional
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public void refundPrescribeOrder(Long orderId) {
         FsStoreOrder order= fsStoreOrderMapper.selectFsStoreOrderById(orderId);
         if(order!=null&&order.getStatus()==OrderInfoEnum.STATUS_1.getValue()&&order.getRefundStatus()==0){
@@ -957,18 +941,6 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
                             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                             return;
                         }
-
-                        //小雨点退款
-//                        RefundDTO refundDTO=new RefundDTO();
-//                        refundDTO.setMerchOrderNo(Ids.oid());
-//                        refundDTO.setAmount(payment.getPayMoney().toString());
-//                        if(payment.getIsPayRemain()!=null&&payment.getIsPayRemain().equals(1)){
-//                            refundDTO.setOrigMerchOrderNo("store_remain-"+payment.getPayCode());
-//                        }
-//                        else{
-//                            refundDTO.setOrigMerchOrderNo("store-"+payment.getPayCode());
-//                        }
-//                        payService.refundOrder(refundDTO);
                     }
                 }
             }
@@ -1446,12 +1418,14 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
     }
 
     @Override
-    public synchronized  R finishOrder(Long orderId) {
-        return finishStoreOrder(orderId);
+    public synchronized R finishOrder(Long orderId) {
+        IFsStoreOrderService fsStoreOrderService = (IFsStoreOrderService) AopContext.currentProxy();
+        return fsStoreOrderService.finishStoreOrder(orderId);
     }
 
-    @Transactional
-    R finishStoreOrder(Long orderId){
+   @Override
+   @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
+   public R finishStoreOrder(Long orderId){
         FsStoreOrder order= fsStoreOrderMapper.selectFsStoreOrderById(orderId);
         if(order.getStatus()==OrderInfoEnum.STATUS_2.getValue()){
             order.setFinishTime(new Date());