tongz
This commit is contained in:
@@ -95,6 +95,12 @@ public class NotificationsController extends BaseController
|
||||
public AjaxResult publish(@PathVariable("id") Long id) {
|
||||
return notificationsService.publishNotification(id);
|
||||
}
|
||||
// 发送全部
|
||||
@Log(title = "发送全部通知", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/sendAll/{id}")
|
||||
public AjaxResult sendAll(@PathVariable("id") Long id) {
|
||||
return notificationsService.publishSendAll(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
|
||||
@@ -49,12 +49,13 @@ public class ClientShopUserController {
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/shopLogin")
|
||||
public AjaxResult shopLogin(@RequestBody ShopUserResq userResq)
|
||||
{
|
||||
public AjaxResult shopLogin(@RequestBody ShopUserResq userResq) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ShopUser shopUser = shopUserService.login(userResq);
|
||||
if (shopUser == null || shopUser.getMsg() != null){
|
||||
if (shopUser == null) {
|
||||
return new AjaxResult(999, "登录失败");
|
||||
} else if (shopUser.getMsg() != null) {
|
||||
return new AjaxResult(999, shopUser.getMsg());
|
||||
} else {
|
||||
// 生成令牌
|
||||
String token = loginService.shopUserLogin(shopUser.getUsername(), shopUser.getPassword());
|
||||
@@ -66,6 +67,7 @@ public class ClientShopUserController {
|
||||
|
||||
/**
|
||||
* 修改个人信息
|
||||
*
|
||||
* @param shopUser 个人信息
|
||||
* @return 成功
|
||||
*/
|
||||
@@ -81,6 +83,7 @@ public class ClientShopUserController {
|
||||
|
||||
/**
|
||||
* 获取个人信息
|
||||
*
|
||||
* @return 个人信息
|
||||
*/
|
||||
@GetMapping("/getUserInfo")
|
||||
@@ -105,6 +108,7 @@ public class ClientShopUserController {
|
||||
|
||||
/**
|
||||
* 根据用户ID获取个人信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 个人信息
|
||||
*/
|
||||
@@ -126,7 +130,6 @@ public class ClientShopUserController {
|
||||
return AjaxResult.success(shopUser);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/user/file")
|
||||
public AjaxResult addConfigFile(
|
||||
@RequestParam("file") MultipartFile file
|
||||
|
||||
@@ -10,5 +10,6 @@ public class PushMsgInfo {
|
||||
private String title;
|
||||
private String text;
|
||||
private String ticker;
|
||||
private String deviceIds;
|
||||
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
"eyJvIjoiaU9TIiwiayI6ImJNSGJwMktVdjhVaE5zOW1wQWhwYlwvWCtVRTlqcnZKeXhjb091N3BDdVlqcHNEc2RKM3A2M0pJZ056U0JrdlY5UlFPSHo3U25ZMmNcL3ZpbUI3ZHN2THFwQXlkbmRJeDB4NHhLSytFR2p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MlhkczAwY3hZa2s5Q29zeVdWVUdGUkVDMjdjUUFURU9PMWp2TzdlMHEwOTRLZjdnaEx2UFJadlo2bFIxSUxmTTJxeWlQc0V5dmRiSUJyaG1yVEtJOWdqRW5Qc3U2dEZPc1RiZ0oxaVwvNGZBRFBKWDhOczF1Ym9taVl2KzZnVGsyNzlZTmQ3WU9OT21mMzlTOG05RktrNEN3Uk1QT1wvcVVSMGRJN25HbER4U1wvWEFFbWNHU0wxcDllczN0U0lsVUIrbHNcL3luWWZFNWNicDIwRE9NV3ZcL0xLa0I2cXA5RkVtaXV6eDY2MWYzZE9hZnk2WUJ2V2dsQnljU05TSkdDNkpYeTZnWHEwR1wvNE9XTkRPdjFhakIxMnhGRk9PK1dhbUVKcG9Takxic0FFV0V5eEtDb3pXaU9meG0ydEJ0bHdoM2hwXC9Vb3RyRCtIbkY2Z1NOOGtCblVtYnJRU3FzYUdsM2g3WDZSZUREbXdRSmMzSzY0QkxNcCJ9", "IOS");
|
||||
//umengConfig.sendAndroidBroadcast();
|
||||
// umengConfig.sendAndroidColumnOn("ArQoP2TkOFOCc11xP_biFmEO_DLfdKO0PZ4lvoWp5enm");
|
||||
// umengConfig.sendAndroidColumnOn("ApqqKzPuBZdgILvIrX0Hq099e3qN_Z8ub_P0qoIvwEdi");
|
||||
// System.out.println(DeviceTypeEnum.ANDROID.name());
|
||||
// UmResp sss1 = umengConfig.send(
|
||||
// "eyJvIjoiaU9TIiwiayI6ImJNSGJwMktVdjhVaE5zOW1wQWhwYlwvWCtVRTlqcnZKeXhjb091N3BDdVlqcHNEc2RKM3A2M0pJZ056U0JrdlY5UlFPSHo3U25ZMmNcL3ZpbUI3ZHN2THFwQXlkbmRJeDB4NHhLSytFR2pvVEF4eU1oUnpUVHlrNHYzZThCSjNIajJOamJoK0VPdUtRTXV3N2pnS0dIdHJoT3FJRFF4QXJ0NisrUTI1ODhhQWdEVnp5TUVZdmxpTFhKeDUwS1wvZWI5VjdSb1VoNkMzc2E5Mm1xcH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wvNGZBRFBKWDhOczF1Ym9taVl2KzZnVGsyNzlZTmQ3WU9OT21mMzlTOG05RktrNEN3Uk1QT1wvcVVSMGRJN25HbER4U1wvWEFFbWNHU0wxcDllczN0U0lsVUIrbHNcL3luWWZFNWNicDIwRE9NV3ZcL0xLa0I2cXA5RkVtaXV6eDY2MWYzZE9hZnk2WUJ2V2dsQnljU05TSkdDNkpYeTZnWHEwR1wvNE9XTkRPdjFhakIxMnhGRk9PK1dhbUVKcG9Takxic0FFV0V5eEtDb3pXaU9meG0ydEJ0bHdoM2hwXC9Vb3RyRCtIbkY2Z1NOOGtCblVtYnJRU3FzYUdsM2g3WDZSZUREbXdRSmMzSzY0QkxNcCJ9", "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";
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,23 +22,7 @@ public class Demo {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
@@ -68,4 +68,6 @@ public interface INotificationsService
|
||||
* @return 结果
|
||||
*/
|
||||
public AjaxResult publishNotification(Long id);
|
||||
|
||||
AjaxResult publishSendAll(Long id);
|
||||
}
|
||||
|
||||
@@ -143,6 +143,8 @@ public class CShopUserServiceImpl implements ShopUserService {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 修改外设id
|
||||
shopUserMapper.updateDeviceIdByPhone(shopUser);
|
||||
return member;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,10 +118,10 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
|
||||
|
||||
// 打印用户列表信息
|
||||
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();
|
||||
@@ -149,14 +149,14 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
|
||||
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;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ public class NotificationRecordsServiceImpl implements INotificationRecordsServi
|
||||
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++;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -207,7 +204,28 @@ public class NotificationsServiceImpl implements INotificationsService
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,7 +235,7 @@ public class NotificationsServiceImpl implements INotificationsService
|
||||
* @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);
|
||||
umengConfig.sendAndroidColumnOn(pushMsgInfo);
|
||||
umengConfig.sendIOSColumnOn(pushMsgInfo);
|
||||
log.info("发送通知批次 {}/{}, 本批次包含 {} 个手机号",
|
||||
(i / 499) + 1, (phones.size() + 498) / 499, phoneBatch.size());
|
||||
(i / 499) + 1, (deviceIds.size() + 498) / 499, phoneBatch.size());
|
||||
}
|
||||
// 模拟发送成功
|
||||
return true;
|
||||
|
||||
@@ -226,7 +226,7 @@
|
||||
|
||||
<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>
|
||||
|
||||
<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>
|
||||
Reference in New Issue
Block a user