Sfoglia il codice sorgente

feature 代码提交

xiahan 1 anno fa
parent
commit
7d82a0661d

+ 16 - 0
bs-common/src/main/java/com/rongwei/safecommon/fegin/CXCommonFeginClient.java

@@ -0,0 +1,16 @@
+package com.rongwei.safecommon.fegin;
+
+import com.rongwei.rwcommon.base.R;
+import com.rongwei.rwcommonentity.commonservers.vo.SysNotifyAnnounceVo;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.multipart.MultipartFile;
+
+@FeignClient(value = "rw-common-server",fallback = CXHysitx.class)
+public interface CXCommonFeginClient {
+    @PostMapping("sys/sysnotifyannounce/saveOrUpdate")
+    void sendNotify(@RequestBody SysNotifyAnnounceVo sysNotifyAnnounceVo);
+}

+ 22 - 0
bs-common/src/main/java/com/rongwei/safecommon/fegin/CXHysitx.java

@@ -0,0 +1,22 @@
+package com.rongwei.safecommon.fegin;
+
+import com.rongwei.rwcommonentity.commonservers.vo.SysNotifyAnnounceVo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * Hysitx class
+ *
+ * @author XH
+ * @date 2023/05/30
+ */
+@Component
+public class CXHysitx implements CXCommonFeginClient {
+    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
+
+    @Override
+    public void sendNotify(SysNotifyAnnounceVo sysNotifyAnnounceVo) {
+        log.error("发送消息通知失败!通知内容为:{}", sysNotifyAnnounceVo);
+    }
+}

+ 72 - 0
bs-common/src/main/java/com/rongwei/safecommon/utils/CXCommonUtils.java

@@ -0,0 +1,72 @@
+package com.rongwei.safecommon.utils;
+
+import com.rongwei.commonservice.service.RedisService;
+import com.rongwei.rwcommon.utils.SecurityUtil;
+import com.rongwei.rwcommon.utils.StringUtils;
+import com.rongwei.rwcommonentity.commonservers.vo.SysNotifyAnnounceVo;
+import com.rongwei.safecommon.fegin.CXCommonFeginClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * CXCommonUtils class
+ *
+ * @author XH
+ * @date 2023/12/15
+ */
+@Component
+public class CXCommonUtils {
+    private static final Logger log = LoggerFactory.getLogger(CXCommonUtils.class.getName());
+    @Autowired
+    private RedisService autoRedisService;
+    @Autowired
+    private CXCommonFeginClient autoCommonFeginClient;
+    private static RedisService redisService;
+
+    private static CXCommonFeginClient commonFeginClient;
+
+    @PostConstruct
+    public void info(){
+        redisService = autoRedisService;
+        commonFeginClient = autoCommonFeginClient;
+    }
+
+    /**
+     * 发送通知信息
+     */
+    public static void sendNotify(String title, String content, String remark, List<String> recipientIds) {
+        sendNotify(title, content, remark, recipientIds, null);
+    }
+
+    /**
+     * 发送通知信息
+     */
+    public static void sendNotify(String title, String content, String remark,
+                                  List<String> recipientIds, String roption) {
+        if (recipientIds == null || recipientIds.isEmpty()) {
+            log.debug("接收人ID为空");
+            return;
+        }
+        SysNotifyAnnounceVo sysNotifyAnnounceVo = new SysNotifyAnnounceVo();
+        sysNotifyAnnounceVo.setId(SecurityUtil.getUUID());
+        sysNotifyAnnounceVo.setSenderid("8672bf72ab274bec83052868ae336b38");
+        sysNotifyAnnounceVo.setNotifytype("notify");
+        sysNotifyAnnounceVo.setNotifystatus("3");
+        sysNotifyAnnounceVo.setNotifytitle(title);
+        sysNotifyAnnounceVo.setNotifycontent(content);
+        sysNotifyAnnounceVo.setRemark(remark);
+        // 特殊处理
+        if (StringUtils.isNotBlank(roption)) {
+            sysNotifyAnnounceVo.setRoption(roption);
+        }
+        sysNotifyAnnounceVo.setUserid(recipientIds.stream().distinct().collect(Collectors.joining(",")));
+        log.debug("开始通过fegin发送消息通知: {}", sysNotifyAnnounceVo);
+        commonFeginClient.sendNotify(sysNotifyAnnounceVo);
+    }
+}