From e8d08ebdd187f99f793cd839038dd5c392cdfbd8 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 09 二月 2026 17:56:36 +0800
Subject: [PATCH] fix: 修改人员薪资接口
---
src/main/java/com/ruoyi/project/system/service/impl/UnipushService.java | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 200 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/project/system/service/impl/UnipushService.java b/src/main/java/com/ruoyi/project/system/service/impl/UnipushService.java
new file mode 100644
index 0000000..7284ace
--- /dev/null
+++ b/src/main/java/com/ruoyi/project/system/service/impl/UnipushService.java
@@ -0,0 +1,200 @@
+package com.ruoyi.project.system.service.impl;
+
+import com.getui.push.v2.sdk.ApiHelper;
+import com.getui.push.v2.sdk.GtApiConfiguration;
+import com.getui.push.v2.sdk.api.PushApi;
+import com.getui.push.v2.sdk.common.ApiResult;
+import com.getui.push.v2.sdk.dto.req.Audience;
+import com.getui.push.v2.sdk.dto.req.message.PushChannel;
+import com.getui.push.v2.sdk.dto.req.message.PushDTO;
+import com.getui.push.v2.sdk.dto.req.message.PushMessage;
+import com.getui.push.v2.sdk.dto.req.message.android.AndroidDTO;
+import com.getui.push.v2.sdk.dto.req.message.android.ThirdNotification;
+import com.getui.push.v2.sdk.dto.req.message.android.Ups;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.project.system.domain.GetuiConfig;
+import com.ruoyi.project.system.domain.SysMenu;
+import com.ruoyi.project.system.domain.SysNotice;
+import com.ruoyi.project.system.domain.SysUserClient;
+import com.ruoyi.project.system.mapper.SysMenuMapper;
+import com.ruoyi.project.system.service.SysUserClientService;
+import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.NotNull;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * APP娑堟伅鎺ㄩ�佹湇鍔�
+ *
+ * @author deslrey
+ * @version 1.4
+ * @since 2026/2/9
+ */
+@Slf4j
+@Component
+public class UnipushService {
+
+ @Autowired
+ private SysMenuMapper sysMenuMapper;
+
+ @Autowired
+ private GetuiConfig getuiConfig;
+
+ @Autowired
+ private SysUserClientService userClientService;
+
+ private PushApi pushApi;
+
+ private static final String DEFAULT_APP_PAGE = "pages/index";
+
+ @PostConstruct
+ public void init() {
+ GtApiConfiguration config = new GtApiConfiguration();
+ config.setAppId(getuiConfig.getAppId());
+ config.setAppKey(getuiConfig.getAppKey());
+ config.setMasterSecret(getuiConfig.getMasterSecret());
+ config.setDomain(getuiConfig.getDomain());
+ ApiHelper apiHelper = ApiHelper.build(config);
+ this.pushApi = apiHelper.creatApi(PushApi.class);
+ }
+
+ /**
+ * 鎵归噺鍙戦�侀�氱煡鍏憡鍒扮Щ鍔ㄧ
+ */
+ @Async
+ public void sendClientMessage(List<SysNotice> sysNoticeList) {
+ if (sysNoticeList == null || sysNoticeList.isEmpty()) {
+ return;
+ }
+
+ for (SysNotice sysNotice : sysNoticeList) {
+ SysUserClient client = userClientService.getById(sysNotice.getConsigneeId());
+ if (client == null || StringUtils.isEmpty(client.getCid())) {
+ log.warn("鐢ㄦ埛 {} 鏈粦瀹氱Щ鍔ㄧ CID,璺宠繃鎺ㄩ��", sysNotice.getConsigneeId());
+ continue;
+ }
+
+ // 杞崲璺緞
+ String appPath = convertWebPathToAppPath(sysNotice.getJumpPath());
+
+ // 鎺ㄩ��
+ sendRoutingPush(
+ client.getCid(),
+ sysNotice.getNoticeTitle(),
+ sysNotice.getRemark() != null ? sysNotice.getRemark() : sysNotice.getNoticeContent(),
+ appPath
+ );
+ }
+ }
+
+ /**
+ * 灏� Web 绔垎灞傚叏璺緞杞崲涓� App 绔粍浠惰矾鐢�
+ */
+ private String convertWebPathToAppPath(String webPath) {
+ if (StringUtils.isEmpty(webPath)) {
+ return DEFAULT_APP_PAGE;
+ }
+
+ String pathOnly = webPath;
+ String queryString = "";
+ if (webPath.contains("?")) {
+ int index = webPath.indexOf("?");
+ pathOnly = webPath.substring(0, index);
+ queryString = webPath.substring(index);
+ }
+
+ String lastSegment;
+ int lastSlashIndex = pathOnly.lastIndexOf("/");
+ if (lastSlashIndex != -1) {
+ lastSegment = pathOnly.substring(lastSlashIndex + 1);
+ } else {
+ lastSegment = pathOnly;
+ }
+
+ if (StringUtils.isEmpty(lastSegment)) {
+ return DEFAULT_APP_PAGE;
+ }
+
+ SysMenu menu = sysMenuMapper.selectMenuByPath(lastSegment);
+
+ if (menu != null && StringUtils.isNotEmpty(menu.getAppComponent())) {
+ String appPath = menu.getAppComponent();
+
+ if (appPath.startsWith("/")) {
+ appPath = appPath.substring(1);
+ }
+
+ // 鎷兼帴 Web 绔師濮嬪弬鏁板苟杩斿洖
+ return appPath + queryString;
+ }
+
+ return DEFAULT_APP_PAGE;
+ }
+
+ /**
+ * 鍙戦�佸崟浜鸿矾鐢辨帹閫�
+ */
+ private void sendRoutingPush(String cid, String title, String content, String targetPath) {
+ log.info("鍑嗗鎺ㄩ�佹秷鎭�: CID={}, Title={}, TargetPath={}", cid, title, targetPath);
+
+ PushDTO<Audience> pushDTO = new PushDTO<>();
+ pushDTO.setRequestId("REQ_" + System.currentTimeMillis());
+
+ // 鍦ㄧ嚎閫忎紶鍐呭
+ PushMessage pushMessage = new PushMessage();
+ String transmissionContent = String.format(
+ "{\"title\":\"%s\",\"content\":\"%s\",\"payload\":\"%s\"}",
+ title, content, targetPath
+ );
+ pushMessage.setTransmission(transmissionContent);
+ pushDTO.setPushMessage(pushMessage);
+
+ // 鎺ユ敹浜�
+ Audience audience = new Audience();
+ audience.addCid(cid);
+ pushDTO.setAudience(audience);
+
+ // 绂荤嚎鎺ㄩ�侀�氶亾
+ pushDTO.setPushChannel(getPushChannel(title, content, targetPath));
+
+ try {
+ ApiResult<Map<String, Map<String, String>>> result = pushApi.pushToSingleByCid(pushDTO);
+ if (result.isSuccess()) {
+ log.info("Unipush 鎺ㄩ�佹垚鍔�: CID={}", cid);
+ } else {
+ log.error("Unipush 鎺ㄩ�佸け璐�: CID={}, Code={}, Msg={}", cid, result.getCode(), result.getMsg());
+ }
+ } catch (Exception e) {
+ log.error("Unipush 鎺ㄩ�佸紓甯�: ", e);
+ }
+ }
+
+ @NotNull
+ private PushChannel getPushChannel(String title, String content, String targetPath) {
+ PushChannel pushChannel = new PushChannel();
+ AndroidDTO androidDTO = new AndroidDTO();
+ Ups ups = new Ups();
+ ThirdNotification thirdNotification = new ThirdNotification();
+ thirdNotification.setTitle(title);
+ thirdNotification.setBody(content);
+ thirdNotification.setClickType("intent");
+
+ String intent = "intent:#Intent;launchFlags=0x04000000;"
+ + "component=" + getuiConfig.getIntentComponent() + ";"
+ + "S.UP-OL-P9=true;"
+ + "S.path=" + targetPath + ";"
+ + "S.payload=" + targetPath + ";"
+ + "end";
+ thirdNotification.setIntent(intent);
+
+ ups.setNotification(thirdNotification);
+ androidDTO.setUps(ups);
+ pushChannel.setAndroid(androidDTO);
+ return pushChannel;
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.3