Quellcode durchsuchen

支付成功推送消息

ZhangWenQiang vor 5 Jahren
Ursprung
Commit
23a6764f41

+ 8 - 1
happy-cloud-system/happy-cloud-system-api/src/main/java/org/jeecg/modules/api/SysBaseRemoteApi.java

@@ -50,5 +50,12 @@ public interface SysBaseRemoteApi {
     @GetMapping("/sys/user/queryTableDictTextByKey")
     String queryTableDictTextByKey(@RequestParam("table") String table, @RequestParam("text") String text, @RequestParam("code") String code, @RequestParam("key") String key);
 
-
+    /**
+     * webSocket单点推送
+     *
+     * @param jsonObject
+     * @return
+     */
+    @PostMapping("/webSocketApi/sendUser")
+    Result<String> sendUserByWebSocket(@RequestBody JSONObject jsonObject);
 }

+ 6 - 0
happy-cloud-system/happy-cloud-system-api/src/main/java/org/jeecg/modules/api/fallback/SysBaseRemoteApiFallbackImpl.java

@@ -41,4 +41,10 @@ public class SysBaseRemoteApiFallbackImpl implements SysBaseRemoteApi {
         log.info("--查询表字典信息异常, table:" + table + ", text:" + text + ", code:" + code + ", key:" + key, cause);
         return null;
     }
+
+    @Override
+    public Result<String> sendUserByWebSocket(JSONObject jsonObject) {
+        log.info("--webSocket单点推送, jsonObject:" + jsonObject.toString(), cause);
+        return null;
+    }
 }

+ 20 - 18
happy-cloud-system/happy-cloud-system-biz/src/main/java/org/jeecg/modules/message/websocket/TestController.java

@@ -13,36 +13,38 @@ import com.alibaba.fastjson.JSONObject;
 @RestController
 @RequestMapping("webSocketApi")
 public class TestController {
-	
+
     @Autowired
     private WebSocket webSocket;
- 
+
     @PostMapping("/sendAll")
     public Result<String> sendAll(@RequestBody JSONObject jsonObject) {
-    	Result<String> result = new Result<String>();
-    	String message = jsonObject.getString("message");
-    	JSONObject obj = new JSONObject();
-    	obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
-		obj.put(WebsocketConst.MSG_ID, "M0001");
-		obj.put(WebsocketConst.MSG_TXT, message);
-    	webSocket.sendAllMessage(obj.toJSONString());
+        Result<String> result = new Result<String>();
+        String message = jsonObject.getString("message");
+        JSONObject obj = new JSONObject();
+        obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
+        obj.put(WebsocketConst.MSG_ID, "M0001");
+        obj.put(WebsocketConst.MSG_TXT, message);
+        webSocket.sendAllMessage(obj.toJSONString());
         result.setResult("群发!");
         return result;
     }
 
     @PostMapping("/sendUser")
     public Result<String> sendUser(@RequestBody JSONObject jsonObject) {
-    	Result<String> result = new Result<String>();
-    	String userId = jsonObject.getString("userId");
-    	String message = jsonObject.getString("message");
-    	JSONObject obj = new JSONObject();
-    	obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
-    	obj.put(WebsocketConst.MSG_USER_ID, userId);
-		obj.put(WebsocketConst.MSG_ID, "M0001");
-		obj.put(WebsocketConst.MSG_TXT, message);
+        Result<String> result = new Result<String>();
+        String userId = jsonObject.getString("userId");
+        String title = jsonObject.getString("title");
+        String message = jsonObject.getString("message");
+        JSONObject obj = new JSONObject();
+        obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
+        obj.put(WebsocketConst.MSG_USER_ID, userId);
+        obj.put(WebsocketConst.MSG_ID, "M0001");
+        obj.put(WebsocketConst.MSG_TITLE, title);
+        obj.put(WebsocketConst.MSG_TXT, message);
         webSocket.sendOneMessage(userId, obj.toJSONString());
         result.setResult("单发");
         return result;
     }
-    
+
 }

+ 36 - 0
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/modules/hlwpayment/service/impl/HlwPaymentServiceImpl.java

@@ -5,12 +5,14 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.businessAccountUtils;
+import org.jeecg.modules.api.SysBaseRemoteApi;
 import org.jeecg.modules.hlwaccount.entity.HlwCompany;
 import org.jeecg.modules.hlwaccount.entity.HlwCompanyAccount;
 import org.jeecg.modules.hlwaccount.entity.HlwCompanyAccountDetail;
@@ -64,6 +66,7 @@ import static org.jeecg.common.util.DateUtils.now;
  * @Date: 2020-07-21
  * @Version: V1.0
  */
+@Slf4j
 @Service
 public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPayment> implements IHlwPaymentService {
 
@@ -95,6 +98,9 @@ public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPaym
     private IHlwOrderService hlwOrderService;
     @Autowired
     private IHlwUserService hlwUserService;
+    @Autowired
+    private SysBaseRemoteApi sysBaseRemoteApi;
+
 
     @Override
     public Page<HlwPayment> pageList(Page<HlwPayment> page, HlwPayment hlwPayment, QueryWrapper<HlwPayment> queryWrapper) {
@@ -470,6 +476,21 @@ public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPaym
                     updateAccountA_B(hlwPayment);
                 }
                 result.success("付款提交成功!等待银行返回结果");
+                try {
+                    /**
+                     * 推送消息
+                     */
+                    JSONObject jsonObject = new JSONObject();
+                    String title = "付款单" + hlwPaymentEntity.getPaymentCode();
+                    String message = "共发放" + hlwPaymentDetailList.size() + "人,合计金额" + totalPayment + "元";
+                    jsonObject.put("userId", "e9ca23d68d884d4ebb19d07889727dae");
+                    jsonObject.put("title", title);
+                    jsonObject.put("message", message);
+                    sysBaseRemoteApi.sendUserByWebSocket(jsonObject);
+                } catch (Exception e) {
+                    log.info("推送异常===,{}", e.getStackTrace());
+                    e.printStackTrace();
+                }
             } else {
                 result.error500("付款提交失败!");
             }
@@ -720,6 +741,21 @@ public class HlwPaymentServiceImpl extends ServiceImpl<HlwPaymentMapper, HlwPaym
                     updateAccountA_B(hlwPayment);
                 }
                 result.success("付款提交成功!等待银行返回结果");
+                try {
+                    /**
+                     * 推送消息
+                     */
+                    JSONObject jsonObject = new JSONObject();
+                    String title = "付款单" + hlwPaymentEntity.getPaymentCode();
+                    String message = "共发放" + hlwPaymentDetailList.size() + "人,合计金额" + totalPayment + "元";
+                    jsonObject.put("userId", "e9ca23d68d884d4ebb19d07889727dae");
+                    jsonObject.put("title", title);
+                    jsonObject.put("message", message);
+                    sysBaseRemoteApi.sendUserByWebSocket(jsonObject);
+                } catch (Exception e) {
+                    log.info("推送异常===,{}", e.getStackTrace());
+                    e.printStackTrace();
+                }
             } else {
                 result.error500("付款提交失败!");
             }