This commit is contained in:
menxipeng
2025-10-14 23:15:44 +08:00
parent f2ad14d43e
commit 2fa7f9be20
14 changed files with 332 additions and 167 deletions

View File

@@ -7,9 +7,13 @@ import com.ruoyi.common.core.domain.UmResp;
import com.ruoyi.common.core.domain.entity.PushMsgInfo;
import com.ruoyi.common.enums.DeviceTypeEnum;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.system.config.push.AndroidColumnOn;
import com.ruoyi.system.config.push.AndroidNotification;
import com.ruoyi.system.config.push.IOSColumnOn;
import com.ruoyi.system.config.push.PushClient;
import com.ruoyi.system.config.push.android.AndroidBroadcast;
import com.ruoyi.system.config.push.android.AndroidCustomizedcast;
import com.ruoyi.system.config.push.ios.IOSBroadcast;
import com.ruoyi.system.config.push.ios.IOSCustomizedcast;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
@@ -158,12 +162,101 @@ public class UmengConfig {
client.send(customizedcast);
}
public void sendIOSBroadcast(PushMsgInfo pushMsgInfo) throws Exception {
IOSBroadcast broadcast = new IOSBroadcast(AliKeyConfig.UMApp_IOS_Key,AliKeyConfig.IOS_SECRET);
//alert值设置为字符串
//broadcast.setAlert("IOS 广播测试");
//alert的值设置为字典
broadcast.setAlert(pushMsgInfo.getTitle());
broadcast.setBadge(0);
broadcast.setSound( "default");
// TODO set 'production_mode' to 'true' if your app is under production mode
broadcast.setTestMode();
// Set customized fields
broadcast.setCustomizedField(pushMsgInfo.getTitle(), pushMsgInfo.getText());
client.send(broadcast);
}
public void sendIOSColumnOn(PushMsgInfo pushMsgInfo) throws Exception {
// 自定义实体类, 附有代码
IOSColumnOn columnOn = new IOSColumnOn(AliKeyConfig.UMApp_IOS_Key,AliKeyConfig.IOS_SECRET);
columnOn.setDeviceToken(pushMsgInfo.getDeviceIds());
// 列播中 传入的deviceToken类似于 1,2,3,4,5
columnOn.setDeviceToken(pushMsgInfo.getDeviceIds());
columnOn.setAlert(pushMsgInfo.getTicker());
columnOn.setBadge(0);
columnOn.setSound("default");
// 点击"通知"的后续行为默认为打开app。
columnOn.setTestMode();
columnOn.setCustomizedField(pushMsgInfo.getTitle(), pushMsgInfo.getText());
client.send(columnOn);
}
public void sendAndroidBroadcast(PushMsgInfo pushMsgInfo) throws Exception {
//"68a9988ce563686f4288e26d","vxq4qfnb3jbb3jahrcxpbtpjgcuu7dtm"
AndroidBroadcast broadcast = new AndroidBroadcast(AliKeyConfig.UMApp_Android_Key,AliKeyConfig.Android_SECRET);
broadcast.setTicker(pushMsgInfo.getTicker());
broadcast.setTitle(pushMsgInfo.getTitle());
broadcast.setText(pushMsgInfo.getText());
broadcast.goAppAfterOpen();
broadcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
broadcast.setProductionMode();
// Set customized fields
//broadcast.setExtraField("test", "helloworld");
//厂商通道相关参数
// broadcast.setChannelActivity("your channel activity");
// broadcast.setChannelProperties("abc");
client.send(broadcast);
}
/**
* 列播推送
*
* @param deviceToken 多个device_tokens是用英文逗号间隔, 不能超过五百个
*/
public void sendAndroidColumnOn(PushMsgInfo pushMsgInfo) throws Exception {
// 自定义实体类, 附有代码
AndroidColumnOn columnOn = new AndroidColumnOn(AliKeyConfig.UMApp_Android_Key,AliKeyConfig.Android_SECRET);
// 列播中 传入的deviceToken类似于 1,2,3,4,5
columnOn.setDeviceToken(pushMsgInfo.getDeviceIds());
// 当你没有下拉通知栏的时候, 写入的文字会在顶端翻转显示, 有的可以显示有的不可以显示, 看你设置和设备的允许情况
columnOn.setTicker(pushMsgInfo.getTicker());
// 标题
columnOn.setTitle(pushMsgInfo.getTitle());
// 内容
columnOn.setText(pushMsgInfo.getText());
// 点击"通知"的后续行为默认为打开app。
columnOn.goAppAfterOpen();
/**
* NOTIFICATION 是友盟做处理在通知栏上显示通知内容
* MESSAGE 是传给应用自身进行解析处理
*/
columnOn.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// 测试模式使用false, 正式模式使用true
columnOn.setProductionMode();
// Set customized fields
columnOn.setExtraField("test", "helloworld");
// 自定义的一些东西
columnOn.setChannelActivity("your channel activity");
columnOn.setChannelProperties("abc");
client.send(columnOn);
}
public static void main(String[] args) throws Exception {
UmengConfig umengConfig = new UmengConfig();
System.out.println(DeviceTypeEnum.ANDROID.name());
UmResp sss1 = umengConfig.send(
"eyJvIjoiaU9TIiwiayI6ImJNSGJwMktVdjhVaE5zOW1wQWhwYlwvWCtVRTlqcnZKeXhjb091N3BDdVlqcHNEc2RKM3A2M0pJZ056U0JrdlY5UlFPSHo3U25ZMmNcL3ZpbUI3ZHN2THFwQXlkbmRJeDB4NHhLSytFR2pvVEF4eU1oUnpUVHlrNHYzZThCSjNIajJOamJoK0VPdUtRTXV3N2pnS0dIdHJoT3FJRFF4QXJ0NisrUTI1ODhhQWdEVnp5TUVZdmxpTFhKeDUwS1wvZWI5VjdSb1VoNkMzc2E5Mm1xcHI1S3FxMm9KZHk3THoyYkVPQUVnM1hvWHJWVlwvcmtOMFluV1AyMVBZb0xrVFgxXC84TWZhVXZJRkY2aWJldDVaYkNzMVNhZU9LVU1rcnlicVpINHBMNlF5TzBFRjkrUHljT01hOGlVTjZabVZ6dm1HOFJHK3BjQjF1amVpSVpRN2N5bDRPOGxnPT0iLCJjIjoiSW02VTJVV3IxYTlDTkpmN29WR2FpRGxCZ3RSamQ5djUwaENCajJMWXd5N2Y3dzV2SndnWHFSXC8zeTlWYzFpSDFITnFHN1wvcUZpN2cxXC94cGQ5RGNsVjE0SXFKYmsxSHppZkNcL0JSU0NaeGpFTm5qWndTR3l1K1VnR3luajhnMWlHbkFhOHRmVWRUN0lGNWdrOGpVSVlteTZBNllkXC92Z2RXXC9wa1krcE9pczVWZEUrTjhXMjhEXC9idXhjQm1Wbm5obHpMWmdzRHUrdWcwQ0FMY2M0V3JybWdGdFcyOWN4Mkh5SGNNZ3AwY2xuOW5GQnNaS20zbDV3QWZIeUd2WkRpU1R3Q0lp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Mm1OUEFpTDVwb3ZkZEp0QmY4TDZmb3B1NWl4a0FnVzBUdFM2OHN3Y3BaeWhuT25zRks0dXI2OHc3YWIySWJPNWpZMnhLTHZvb1NjMmRcLzhcL2JSTmxFM0txUUFLcDRGQUpxdWJ2bjhQRzdPcGN2bXhuSkF4bTJYNTFkQUZtaTdsSjZuZlc0MlJSNDRZWDBtMlhkczAwY3hZa2s5Q29zeVdWVUdGUkVDMjdjUUFURU9PMWp2TzdlMHEwOTRLZjdnaEx2UFJadlo2bFIxSUxmTTJxeWlQc0V5dmRiSUJyaG1yVEtJOWdqRW5Qc3U2dEZPc1RiZ0oxaVwvNGZBRFBKWDhOczF1Ym9taVl2KzZnVGsyNzlZTmQ3WU9OT21mMzlTOG05RktrNEN3Uk1QT1wvcVVSMGRJN25HbER4U1wvWEFFbWNHU0wxcDllczN0U0lsVUIrbHNcL3luWWZFNWNicDIwRE9NV3ZcL0xLa0I2cXA5RkVtaXV6eDY2MWYzZE9hZnk2WUJ2V2dsQnljU05TSkdDNkpYeTZnWHEwR1wvNE9XTkRPdjFhakIxMnhGRk9PK1dhbUVKcG9Takxic0FFV0V5eEtDb3pXaU9meG0ydEJ0bHdoM2hwXC9Vb3RyRCtIbkY2Z1NOOGtCblVtYnJRU3FzYUdsM2g3WDZSZUREbXdRSmMzSzY0QkxNcCJ9", "IOS");
// String sss;
// sss = "{\"success\":true,\"data\":{\"mobile\":\"18518753918\",\"score\":null,\"activeScore\":null,\"aesEncryptKey\":null},\"code\":2001,\"message\":\"gain mobile's result success\",\"requestId\":\"0E87E249-42A0-42C0-94D3-7424D45E571E\"}\n";

View File

@@ -0,0 +1,18 @@
package com.ruoyi.system.config.push;
/**
* 列播要求不超过500个device_token 用英文逗号隔开
*/
public class AndroidColumnOn extends AndroidNotification {
public AndroidColumnOn(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", "listcast"); // type = listcast 是群体发送
}
public void setDeviceToken(String token) throws Exception {
setPredefinedKeyValue("device_tokens", token);
}
}

View File

@@ -11,7 +11,7 @@ public class Demo {
private String appMasterSecret = null;
private String timestamp = null;
private PushClient client = new PushClient();
public Demo(String key, String secret) {
try {
appkey = key;
@@ -21,25 +21,9 @@ public class Demo {
System.exit(1);
}
}
public void sendAndroidBroadcast() throws Exception {
AndroidBroadcast broadcast = new AndroidBroadcast(appkey,appMasterSecret);
broadcast.setTicker( "Android broadcast ticker");
broadcast.setTitle( "中文的title");
broadcast.setText( "Android broadcast text");
broadcast.goAppAfterOpen();
broadcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
broadcast.setProductionMode();
// Set customized fields
broadcast.setExtraField("test", "helloworld");
//厂商通道相关参数
broadcast.setChannelActivity("your channel activity");
broadcast.setChannelProperties("abc");
client.send(broadcast);
}
public void sendAndroidUnicast() throws Exception {
AndroidUnicast unicast = new AndroidUnicast(appkey,appMasterSecret);
// TODO Set your device token
@@ -49,7 +33,7 @@ public class Demo {
unicast.setText( "Android unicast text");
unicast.goAppAfterOpen();
unicast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// TODO Set 'production_mode' to 'false' if it's a test device.
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
unicast.setProductionMode();
// Set customized fields
@@ -58,14 +42,14 @@ public class Demo {
unicast.setChannelProperties("abc");
client.send(unicast);
}
public void sendAndroidGroupcast() throws Exception {
AndroidGroupcast groupcast = new AndroidGroupcast(appkey,appMasterSecret);
/* TODO
* Construct the filter condition:
* "where":
* "where":
* {
* "and":
* "and":
* [
* {"tag":"test"},
* {"tag":"Test"}
@@ -91,7 +75,7 @@ public class Demo {
groupcast.goAppAfterOpen();
groupcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
groupcast.setChannelActivity("your channel activity");
// TODO Set 'production_mode' to 'false' if it's a test device.
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
groupcast.setProductionMode();
//厂商通道相关参数
@@ -99,7 +83,7 @@ public class Demo {
groupcast.setChannelProperties("abc");
client.send(groupcast);
}
// public void sendAndroidCustomizedcast() throws Exception {
// AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey,appMasterSecret);
// // TODO Set your alias here, and use comma to split them if there are multiple alias.
@@ -119,11 +103,11 @@ public class Demo {
// customizedcast.setChannelProperties("abc");
// client.send(customizedcast);
// }
public void sendAndroidCustomizedcastFile() throws Exception {
AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey,appMasterSecret);
// TODO Set your alias here, and use comma to split them if there are multiple alias.
// And if you have many alias, you can also upload a file containing these alias, then
// And if you have many alias, you can also upload a file containing these alias, then
// use file_id to send customized notification.
String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb"+"\n"+"alias");
customizedcast.setFileId(fileId, "alias_type");
@@ -132,7 +116,7 @@ public class Demo {
customizedcast.setText( "Android customizedcast text");
customizedcast.goAppAfterOpen();
customizedcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// TODO Set 'production_mode' to 'false' if it's a test device.
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
customizedcast.setProductionMode();
//厂商通道相关参数
@@ -140,10 +124,10 @@ public class Demo {
customizedcast.setChannelProperties("abc");
client.send(customizedcast);
}
public void sendAndroidFilecast() throws Exception {
AndroidFilecast filecast = new AndroidFilecast(appkey,appMasterSecret);
// TODO upload your device tokens, and use '\n' to split them if there are multiple tokens
// TODO upload your device tokens, and use '\n' to split them if there are multiple tokens
String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb");
filecast.setFileId( fileId);
filecast.setTicker( "Android filecast ticker");
@@ -156,7 +140,7 @@ public class Demo {
filecast.setChannelProperties("abc");
client.send(filecast);
}
public void sendIOSBroadcast() throws Exception {
IOSBroadcast broadcast = new IOSBroadcast(appkey,appMasterSecret);
//alert值设置为字符串
@@ -171,7 +155,7 @@ public class Demo {
broadcast.setCustomizedField("test", "helloworld");
client.send(broadcast);
}
public void sendIOSUnicast() throws Exception {
IOSUnicast unicast = new IOSUnicast(appkey,appMasterSecret);
// TODO Set your device token
@@ -189,14 +173,14 @@ public class Demo {
client.send(unicast);
}
public void sendIOSGroupcast() throws Exception {
IOSGroupcast groupcast = new IOSGroupcast(appkey,appMasterSecret);
/* TODO
* Construct the filter condition:
* "where":
* "where":
* {
* "and":
* "and":
* [
* {"tag":"iostest"}
* ]
@@ -211,7 +195,7 @@ public class Demo {
whereJson.put("and", tagArray);
filterJson.put("where", whereJson);
System.out.println(filterJson.toString());
// Set filter condition into rootJson
groupcast.setFilter(filterJson);
//groupcast.setAlert("IOS 组播测试");
@@ -223,11 +207,11 @@ public class Demo {
groupcast.setTestMode();
client.send(groupcast);
}
public void sendIOSCustomizedcast() throws Exception {
IOSCustomizedcast customizedcast = new IOSCustomizedcast(appkey,appMasterSecret);
// TODO Set your alias and alias_type here, and use comma to split them if there are multiple alias.
// And if you have many alias, you can also upload a file containing these alias, then
// And if you have many alias, you can also upload a file containing these alias, then
// use file_id to send customized notification.
customizedcast.setAlias("alias", "alias_type");
//customizedcast.setAlert("IOS 个性化测试");
@@ -239,10 +223,10 @@ public class Demo {
customizedcast.setTestMode();
client.send(customizedcast);
}
public void sendIOSFilecast() throws Exception {
IOSFilecast filecast = new IOSFilecast(appkey,appMasterSecret);
// TODO upload your device tokens, and use '\n' to split them if there are multiple tokens
// TODO upload your device tokens, and use '\n' to split them if there are multiple tokens
String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb");
filecast.setFileId( fileId);
//filecast.setAlert("IOS 文件播测试");
@@ -254,7 +238,7 @@ public class Demo {
filecast.setTestMode();
client.send(filecast);
}
public static void main(String[] args) {
// TODO set your appkey and master secret here
Demo demo = new Demo("your appkey", "your master secret");
@@ -267,7 +251,7 @@ public class Demo {
* demo.sendAndroidGroupcast();
* demo.sendAndroidCustomizedcast();
* demo.sendAndroidFilecast();
*
*
* demo.sendIOSBroadcast();
* demo.sendIOSUnicast();
* demo.sendIOSGroupcast();
@@ -278,6 +262,6 @@ public class Demo {
ex.printStackTrace();
}
}
}

View File

@@ -0,0 +1,21 @@
package com.ruoyi.system.config.push;
/**
* 描述:
*
* @author MXP by 2025/10/14
*/
public class IOSColumnOn extends IOSNotification{
public IOSColumnOn(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", "listcast"); // type = listcast 是群体发送
}
public void setDeviceToken(String token) throws Exception {
setPredefinedKeyValue("device_tokens", token);
}
}

View File

@@ -2,6 +2,7 @@ package com.ruoyi.system.config.push;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;
@@ -11,19 +12,19 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
public class PushClient {
// The user agent
protected final String USER_AGENT = "Mozilla/5.0";
// This object is used for sending the post request to Umeng
protected HttpClient client = new DefaultHttpClient();
// The host
protected static final String host = "http://msg.umeng.com";
// The upload path
protected static final String uploadPath = "/upload";
// The post path
protected static final String postPath = "/api/send";
@@ -32,7 +33,7 @@ public class PushClient {
msg.setPredefinedKeyValue("timestamp", timestamp);
String url = host + postPath;
String postBody = msg.getPostBody();
String sign = DigestUtils.md5Hex(("POST" + url + postBody + msg.getAppMasterSecret()).getBytes("utf8"));
String sign = DigestUtils.md5Hex(("POST" + url + postBody + msg.getAppMasterSecret()).getBytes(StandardCharsets.UTF_8));
url = url + "?sign=" + sign;
HttpPost post = new HttpPost(url);
post.setHeader("User-Agent", USER_AGENT);
@@ -93,7 +94,7 @@ public class PushClient {
JSONObject data = respJson.getJSONObject("data");
String fileId = data.getString("file_id");
// Set file_id into rootJson using setPredefinedKeyValue
return fileId;
}

View File

@@ -1,6 +1,7 @@
package com.ruoyi.system.mapper;
import com.ruoyi.common.core.domain.entity.ShopUser;
import com.ruoyi.common.core.domain.entity.ShopUserResq;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@@ -69,7 +70,7 @@ public interface ShopUserMapper {
* @return 结果
*/
public int deleteShopUserByIds(String[] ids);
/**
* 更新用户在线时长
*
@@ -77,7 +78,7 @@ public interface ShopUserMapper {
* @return 结果
*/
public int updateUserOnlineTime(ShopUser shopUser);
/**
* 查询用户的音乐标签
*
@@ -88,5 +89,9 @@ public interface ShopUserMapper {
List<String> selectPhoneShopUserByUserIds(List<Long> userIds);
List<String> selectDeviceIdShopUserByUserIds(List<Long> userIds);
int updateShopUserId(ShopUser shopUser);
}
int updateDeviceIdByPhone(ShopUserResq shopUser);
}

View File

@@ -7,15 +7,15 @@ import java.util.List;
/**
* 【请填写功能名称】Service接口
*
*
* @author ruoyi
* @date 2025-08-23
*/
public interface INotificationsService
public interface INotificationsService
{
/**
* 查询【请填写功能名称】
*
*
* @param id 【请填写功能名称】主键
* @return 【请填写功能名称】
*/
@@ -23,7 +23,7 @@ public interface INotificationsService
/**
* 查询【请填写功能名称】列表
*
*
* @param notifications 【请填写功能名称】
* @return 【请填写功能名称】集合
*/
@@ -31,7 +31,7 @@ public interface INotificationsService
/**
* 新增【请填写功能名称】
*
*
* @param notifications 【请填写功能名称】
* @return 结果
*/
@@ -39,7 +39,7 @@ public interface INotificationsService
/**
* 修改【请填写功能名称】
*
*
* @param notifications 【请填写功能名称】
* @return 结果
*/
@@ -47,7 +47,7 @@ public interface INotificationsService
/**
* 批量删除【请填写功能名称】
*
*
* @param ids 需要删除的【请填写功能名称】主键集合
* @return 结果
*/
@@ -55,17 +55,19 @@ public interface INotificationsService
/**
* 删除【请填写功能名称】信息
*
*
* @param id 【请填写功能名称】主键
* @return 结果
*/
public int deleteNotificationsById(Long id);
/**
* 发布通知
*
*
* @param id 通知ID
* @return 结果
*/
public AjaxResult publishNotification(Long id);
AjaxResult publishSendAll(Long id);
}

View File

@@ -51,7 +51,7 @@ public class CShopUserServiceImpl implements ShopUserService {
// 验证码
String code = redisCache.getCacheObject("sms_code:"+shopUser.getPhone());
// TODO:写死
// String code="9527";
//String code="9527";
String reqCode = shopUser.getCode();
if (code != null && code.equals(reqCode)){
// 登录
@@ -143,6 +143,8 @@ public class CShopUserServiceImpl implements ShopUserService {
return null;
}
}
// 修改外设id
shopUserMapper.updateDeviceIdByPhone(shopUser);
return member;
}

View File

@@ -15,20 +15,20 @@ import java.util.stream.Collectors;
/**
* 【请填写功能名称】Service业务层处理
*
*
* @author ruoyi
* @date 2025-08-23
*/
@Transactional
@Service
public class NotificationRecordsServiceImpl implements INotificationRecordsService
public class NotificationRecordsServiceImpl implements INotificationRecordsService
{
@Autowired
private NotificationRecordsMapper notificationRecordsMapper;
/**
* 查询【请填写功能名称】
*
*
* @param id 【请填写功能名称】主键
* @return 【请填写功能名称】
*/
@@ -40,7 +40,7 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
/**
* 查询【请填写功能名称】列表
*
*
* @param notificationRecords 【请填写功能名称】
* @return 【请填写功能名称】
*/
@@ -52,7 +52,7 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
/**
* 新增【请填写功能名称】
*
*
* @param notificationRecords 【请填写功能名称】
* @return 结果
*/
@@ -65,7 +65,7 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
/**
* 修改【请填写功能名称】
*
*
* @param notificationRecords 【请填写功能名称】
* @return 结果
*/
@@ -78,7 +78,7 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
/**
* 批量删除【请填写功能名称】
*
*
* @param ids 需要删除的【请填写功能名称】主键
* @return 结果
*/
@@ -90,7 +90,7 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
/**
* 删除【请填写功能名称】信息
*
*
* @param id 【请填写功能名称】主键
* @return 结果
*/
@@ -99,7 +99,7 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
{
return notificationRecordsMapper.deleteNotificationRecordsById(id);
}
/**
* 绑定用户到通知记录
*
@@ -110,22 +110,22 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
@Transactional
public void bind(Long id, List<ShopUser> shopUsers) {
System.out.println("开始绑定用户通知ID: " + id + ", 用户数量: " + (shopUsers != null ? shopUsers.size() : 0));
if (id == null || shopUsers == null || shopUsers.isEmpty()) {
System.out.println("通知ID为空或用户列表为空无法绑定");
return;
}
// 打印用户列表信息
System.out.println("用户列表详情:");
for (ShopUser user : shopUsers) {
System.out.println("用户ID: " + (user != null ? user.getUserId() : "null") +
", 类型: " + (user != null && user.getUserId() != null ? user.getUserId().getClass().getName() : "null"));
}
// for (ShopUser user : shopUsers) {
// System.out.println("用户ID: " + (user != null ? user.getUserId() : "null") +
// ", 类型: " + (user != null && user.getUserId() != null ? user.getUserId().getClass().getName() : "null"));
// }
// 获取当前时间
Date now = DateUtils.getNowDate();
// 查询该通知已经绑定的用户ID列表
NotificationRecords query = new NotificationRecords();
query.setNotificationId(id);
@@ -134,33 +134,33 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
.map(NotificationRecords::getUserId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
System.out.println("已绑定用户数量: " + existingUserIds.size());
// 创建通知记录列表
List<NotificationRecords> recordsList = new ArrayList<>();
// 遍历用户列表,为每个用户创建通知记录(排除已绑定的用户)
int validUserCount = 0;
int invalidUserCount = 0;
int duplicateUserCount = 0;
for (ShopUser user : shopUsers) {
try {
// 验证用户ID是否有效
if (user == null || user.getUserId() == null) {
System.out.println("用户或用户ID为空跳过");
//System.out.println("用户或用户ID为空跳过");
invalidUserCount++;
continue;
}
if (existingUserIds.contains(user.getUserId())) {
System.out.println("用户ID: " + user.getUserId() + " 已绑定,跳过");
// System.out.println("用户ID: " + user.getUserId() + " 已绑定,跳过");
duplicateUserCount++;
continue;
}
// 创建通知记录
NotificationRecords record = new NotificationRecords();
record.setUserId(user.getUserId());
@@ -172,19 +172,19 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
record.setNotificationId(id);
recordsList.add(record);
validUserCount++;
System.out.println("添加用户ID: " + user.getUserId() + " 到待绑定列表");
} catch (Exception e) {
// 记录错误日志,但继续处理其他用户
System.err.println("处理用户ID时出错: " + (user != null ? user.getUserId() : "null") + ", 错误: " + e.getMessage());
//lo.error("处理用户ID时出错: " + (user != null ? user.getUserId() : "null") + ", 错误: " + e.getMessage());
e.printStackTrace();
invalidUserCount++;
}
}
System.out.println("有效用户数: " + validUserCount + ", 无效用户数: " + invalidUserCount + ", 重复用户数: " + duplicateUserCount);
System.out.println("待插入记录数: " + recordsList.size());
// 批量插入通知记录
if (!recordsList.isEmpty()) {
try {
@@ -199,7 +199,7 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
System.out.println("没有需要插入的记录");
}
}
/**
* 获取通知已绑定的用户列表
*
@@ -211,25 +211,25 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
if (notificationId == null) {
return new ArrayList<>();
}
// 创建查询条件
NotificationRecords query = new NotificationRecords();
query.setNotificationId(notificationId);
// 查询通知记录
List<NotificationRecords> records = notificationRecordsMapper.selectNotificationRecordsList(query);
// 提取用户ID列表
List<Long> userIds = records.stream()
.map(NotificationRecords::getUserId)
.filter(Objects::nonNull)
.collect(Collectors.toList());
// 如果没有绑定用户,返回空列表
if (userIds.isEmpty()) {
return new ArrayList<>();
}
// 查询用户信息
// 这里需要调用ShopUserMapper来查询用户信息
// 由于没有提供ShopUserMapper这里简单处理将用户ID封装成ShopUser对象返回
@@ -239,7 +239,7 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
user.setUserId(userId);
users.add(user);
}
return users;
}
}

View File

@@ -22,19 +22,19 @@ import java.util.stream.Collectors;
/**
* 【请填写功能名称】Service业务层处理
*
*
* @author ruoyi
* @date 2025-08-23
*/
@Transactional
@Service
public class NotificationsServiceImpl implements INotificationsService
public class NotificationsServiceImpl implements INotificationsService
{
private static final Logger log = LoggerFactory.getLogger(NotificationsServiceImpl.class);
@Autowired
private NotificationsMapper notificationsMapper;
@Autowired
private NotificationRecordsMapper notificationRecordsMapper;
@@ -46,7 +46,7 @@ public class NotificationsServiceImpl implements INotificationsService
/**
* 查询【请填写功能名称】
*
*
* @param id 【请填写功能名称】主键
* @return 【请填写功能名称】
*/
@@ -58,7 +58,7 @@ public class NotificationsServiceImpl implements INotificationsService
/**
* 查询【请填写功能名称】列表
*
*
* @param notifications 【请填写功能名称】
* @return 【请填写功能名称】
*/
@@ -70,7 +70,7 @@ public class NotificationsServiceImpl implements INotificationsService
/**
* 新增【请填写功能名称】
*
*
* @param notifications 【请填写功能名称】
* @return 结果
*/
@@ -83,7 +83,7 @@ public class NotificationsServiceImpl implements INotificationsService
/**
* 修改【请填写功能名称】
*
*
* @param notifications 【请填写功能名称】
* @return 结果
*/
@@ -95,7 +95,7 @@ public class NotificationsServiceImpl implements INotificationsService
/**
* 批量删除【请填写功能名称】
*
*
* @param ids 需要删除的【请填写功能名称】主键
* @return 结果
*/
@@ -107,7 +107,7 @@ public class NotificationsServiceImpl implements INotificationsService
/**
* 删除【请填写功能名称】信息
*
*
* @param id 【请填写功能名称】主键
* @return 结果
*/
@@ -116,10 +116,10 @@ public class NotificationsServiceImpl implements INotificationsService
{
return notificationsMapper.deleteNotificationsById(id);
}
/**
* 发布通知
*
*
* @param id 通知ID
* @return 结果
*/
@@ -133,7 +133,7 @@ public class NotificationsServiceImpl implements INotificationsService
{
return AjaxResult.error("通知不存在");
}
// 查询该通知的所有记录
NotificationRecords query = new NotificationRecords();
query.setNotificationId(id);
@@ -145,14 +145,11 @@ public class NotificationsServiceImpl implements INotificationsService
{
return AjaxResult.error("该通知没有绑定任何用户,请先绑定用户");
}
List<String> phones = shopUserMapper.selectPhoneShopUserByUserIds(userIds);
List<String> deviceIds = shopUserMapper.selectDeviceIdShopUserByUserIds(userIds);
// 当前时间
Date now = DateUtils.getNowDate();
int successCount = 0;
int failCount = 0;
sendNotificationToThirdParty(notification, phones);
sendNotificationToThirdParty(notification, deviceIds);
query.setStatus("sent");
notificationRecordsMapper.updateNotificationRecords(query);
@@ -201,23 +198,44 @@ public class NotificationsServiceImpl implements INotificationsService
// }
// }
// }
// 更新通知状态为已发布
// notification.setStatus("published");
// notification.setPublishTime(now);
// notificationsMapper.updateNotifications(notification);
return AjaxResult.success("通知发布完成,成功" + successCount + ",失败:" + failCount);
return AjaxResult.success("通知发布完成,成功");
}
@Override
public AjaxResult publishSendAll(Long id) {
// 查询通知信息
Notifications notification = notificationsMapper.selectNotificationsById(id);
sendAllToThirdParty(notification);
return AjaxResult.success("通知发布完成");
}
private void sendAllToThirdParty(Notifications notification) {
PushMsgInfo pushMsgInfo = new PushMsgInfo();
pushMsgInfo.setTitle(notification.getTitle());
pushMsgInfo.setText(notification.getContent());
pushMsgInfo.setTicker(notification.getTitle());
try {
umengConfig.sendAndroidBroadcast(pushMsgInfo);
umengConfig.sendIOSBroadcast(pushMsgInfo);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 调用第三方接口发送通知
*
*
* @param notification 通知信息
* @param record 通知记录
* @return 发送结果
*/
private boolean sendNotificationToThirdParty(Notifications notification, List<String> phones)
private boolean sendNotificationToThirdParty(Notifications notification, List<String> deviceIds)
{
try
{
@@ -227,18 +245,18 @@ public class NotificationsServiceImpl implements INotificationsService
// notification.getId(), record.getUserId(), notification.getTitle(), notification.getContent());
//
// 按照499个手机号一组进行分批处理
for (int i = 0; i < phones.size(); i += 499) {
int endIndex = Math.min(i + 499, phones.size());
List<String> phoneBatch = phones.subList(i, endIndex);
String phoneS = String.join(",", phoneBatch);
for (int i = 0; i < deviceIds.size(); i += 499) {
int endIndex = Math.min(i + 499, deviceIds.size());
List<String> phoneBatch = deviceIds.subList(i, endIndex);
String deviceIdS = String.join(",", phoneBatch);
PushMsgInfo pushMsgInfo = new PushMsgInfo();
pushMsgInfo.setAlias(phoneS);
pushMsgInfo.setDeviceIds(deviceIdS);
pushMsgInfo.setTitle(notification.getTitle());
pushMsgInfo.setText(notification.getContent());
umengConfig.sendAndroidCustomizedcast(pushMsgInfo);
umengConfig.sendIOSCustomizedcast(pushMsgInfo);
log.info("发送通知批次 {}/{}, 本批次包含 {} 个手机号",
(i / 499) + 1, (phones.size() + 498) / 499, phoneBatch.size());
umengConfig.sendAndroidColumnOn(pushMsgInfo);
umengConfig.sendIOSColumnOn(pushMsgInfo);
log.info("发送通知批次 {}/{}, 本批次包含 {} 个手机号",
(i / 499) + 1, (deviceIds.size() + 498) / 499, phoneBatch.size());
}
// 模拟发送成功
return true;

View File

@@ -204,7 +204,7 @@
<include refid="selectShopUserVo"/>
where shop_user.user_id = #{userId}
</select>
<!-- 更新用户在线时长 -->
<update id="updateUserOnlineTime" parameterType="ShopUser">
update shop_user
@@ -214,19 +214,19 @@
</set>
where user_id = #{userId}
</update>
<!-- 查询用户的音乐标签 -->
<select id="selectUserMusicTags" parameterType="String" resultType="String">
SELECT mi.label FROM user_history uh
SELECT mi.label FROM user_history uh
LEFT JOIN music_info mi on uh.music_id = mi.music_id
LEFT JOIN shop_user su on uh.user_id = su.user_id
LEFT JOIN shop_user su on uh.user_id = su.user_id
WHERE su.user_id = #{userId} AND mi.label IS NOT NULL AND mi.label != ''
GROUP BY mi.label
</select>
<select id="selectPhoneShopUserByUserIds" resultType="java.lang.String">
SELECT phone from shop_user where user_id in
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
<foreach collection="list" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
</select>
@@ -256,4 +256,15 @@
</trim>
where shop_user.id = #{id}
</update>
</mapper>
<update id="updateDeviceIdByPhone">
update shop_user set device_id = #{deviceId} where shop_user.phone = #{phone}
</update>
<select id="selectDeviceIdShopUserByUserIds" resultType="java.lang.String">
SELECT device_id from shop_user where user_id in
<foreach collection="list" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
</select>
</mapper>