Преглед изворни кода

fix:“修复支付成功多次回调发送多次MQ导致多次做糖问题”

soobin пре 1 година
родитељ
комит
54b2fad0bf

+ 42 - 15
src/main/java/com/szwl/controller/TOrderController.java

@@ -2021,8 +2021,12 @@ public class TOrderController {
                     }
                 }
             }else {
-                equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("pay_success", kindData.toString()).toString());
-            }
+                if (!order.getIsNotified().equals("1")) {
+                    String paySuccess = equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("pay_success", kindData.toString()).toString());
+                    if (paySuccess.equals("success")) {
+                        order.setIsNotified("1");
+                    }
+                }            }
             orderService.updateById(order);
 //            equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("pay_success", kindData.toString()).toString());
             try {
@@ -2033,14 +2037,19 @@ public class TOrderController {
             }catch (Exception e) {
                 e.printStackTrace();
             }
-            try {
+            //            try {
+            LambdaQueryWrapper<TOrderTask> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(TOrderTask::getSn, sn);
+            TOrderTask oldOrderTask = orderTaskService.getOne(queryWrapper);
+            if (oldOrderTask == null) {
                 TOrderTask orderTask = new TOrderTask();
                 BeanUtils.copyPropertiesIgnoreNull(order, orderTask, true);
                 orderTask.setAgencyId(order.getId());
                 orderTaskService.save(orderTask);
-            }catch (Exception e) {
-                e.printStackTrace();
             }
+//            }catch (Exception e) {
+//                e.printStackTrace();
+//            }
             //传送数据
             sentJingZhun(order);
             return R.ok("支付成功");
@@ -2049,8 +2058,12 @@ public class TOrderController {
             String gtClientId = equipment.getGtClientId();
             JSONObject kindData = new JSONObject();
             kindData.put("sn", order.getSn());
-            equipmentService.sentMessage(equipment.getClientId(),PushUtils.buildJson("pay_faile", kindData.toString()).toString());
-            order.setNote(gtClientId + "支付失败");
+            if (!order.getIsNotified().equals("2")) {
+                String payFail = equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("pay_faile", kindData.toString()).toString());
+                if (payFail.equals("success")) {
+                    order.setIsNotified("2");
+                }
+            }            order.setNote(gtClientId + "支付失败");
             orderService.updateById(order);
             return R.fail(ResponseCodesEnum.A0001,"支付失败");
         }
@@ -2063,7 +2076,7 @@ public class TOrderController {
      */
     @RequestMapping(value = "/notify", method = RequestMethod.GET)
     @ResponseBody
-    public Object refund(HttpServletRequest request) {
+    public String notify(HttpServletRequest request) {
 
         String r6_Status = request.getParameter("r6_Status");
 
@@ -2152,7 +2165,12 @@ public class TOrderController {
                     }
                 }
             }else {
-                equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("pay_success", kindData.toString()).toString());
+                if (!order.getIsNotified().equals("1")) {
+                    String paySuccess = equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("pay_success", kindData.toString()).toString());
+                    if (paySuccess.equals("success")) {
+                        order.setIsNotified("1");
+                    }
+                }
             }
             orderService.updateById(order);
 
@@ -2164,14 +2182,19 @@ public class TOrderController {
             }catch (Exception e) {
                 e.printStackTrace();
             }
-            try {
+//            try {
+            LambdaQueryWrapper<TOrderTask> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(TOrderTask::getSn, sn);
+            TOrderTask oldOrderTask = orderTaskService.getOne(queryWrapper);
+            if (oldOrderTask == null) {
                 TOrderTask orderTask = new TOrderTask();
                 BeanUtils.copyPropertiesIgnoreNull(order, orderTask, true);
                 orderTask.setAgencyId(order.getId());
                 orderTaskService.save(orderTask);
-            }catch (Exception e) {
-                e.printStackTrace();
             }
+//            }catch (Exception e) {
+//                e.printStackTrace();
+//            }
             //传送数据
             sentJingZhun(order);
             return "success";
@@ -2180,12 +2203,16 @@ public class TOrderController {
             String gtClientId = byClientId.getGtClientId();
             JSONObject kindData = new JSONObject();
             kindData.put("sn", order.getSn());
-            equipmentService.sentMessage(byClientId.getClientId(),PushUtils.buildJson("pay_faile", kindData.toString()).toString());
+            if (!order.getIsNotified().equals("2")) {
+                String payFail = equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("pay_faile", kindData.toString()).toString());
+                if (payFail.equals("success")) {
+                    order.setIsNotified("2");
+                }
+            }
             order.setNote(gtClientId + "支付失败");
             orderService.updateById(order);
+            return "success";
         }
-
-        return "success";
     }
 
     //发送两次mq

Разлика између датотеке није приказан због своје велике величине
+ 2 - 1
src/main/java/com/szwl/mapper/xml/TOrderMapper.xml


+ 3 - 0
src/main/java/com/szwl/model/entity/TOrder.java

@@ -157,5 +157,8 @@ public class TOrder implements Serializable {
     @ApiModelProperty(value = "设备类型,0:棉花糖,1,爆米花")
     private String machineType;
 
+    @ApiModelProperty(value = "是否通知MQ,0:未通知,1:通知支付成功做糖,2:通知支付失败")
+    private String isNotified;
+
 
 }

+ 3 - 1
src/main/java/com/szwl/service/impl/TEquipmentServiceImpl.java

@@ -45,6 +45,7 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
         if(StringUtils.isEmpty(channel)||channel.equals("1")||StringUtils.isEmpty(equimentType)){
             //用个推
             PushUtils.push(equipment.getGtClientId(), "", "", json);
+            return "success";
         }
         if(StringUtils.isNotEmpty(channel)&&channel.equals("2")&&StringUtils.isNotEmpty(equimentType)){
             //用Mq
@@ -55,8 +56,9 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
             amqpTemplate.send(equimentType, clientId, message);
             System.out.println("mq发送成功,clientId="+clientId+"&json="+json);
 
+            return "success";
         }
-        return "success";
+        return "error";
     }
 
 }