app message sending api update

master
yixian 6 years ago
parent b22ecb893e
commit 5ea3a11d87

@ -4,7 +4,6 @@ import au.com.royalpay.payment.manage.pushMessage.bean.AppManagerMessageBuilder;
import au.com.royalpay.payment.manage.pushMessage.bean.AppMessageType;
import au.com.royalpay.payment.tools.device.message.AppMessage;
import au.com.royalpay.payment.tools.env.RequestEnvironment;
import au.com.royalpay.payment.tools.permission.enums.PartnerRole;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
@ -16,13 +15,13 @@ import java.util.Date;
public class RetailAppMessage {
private String title;
private String body;
private PartnerRole role = PartnerRole.ADMIN;
private JSONObject data;
public JSONObject forSave(String appid, int clientId) {
JSONObject msg = new JSONObject();
msg.put("appid", appid);
msg.put("client_id", clientId);
msg.put("role", role.getCode());
msg.put("role", "admin");
msg.put("title", title);
msg.put("body", body);
msg.put("send_time", new Date());
@ -38,7 +37,7 @@ public class RetailAppMessage {
managerMsg.put("title", title);
managerMsg.put("body", body);
managerMsg.put("type", sendType);
managerMsg.put("data", new JSONObject());
managerMsg.put("data", data == null ? new JSONObject() : data);
managerMsg.put("msgType", AppMessageType.MESSAGE.name());
return new AppManagerMessageBuilder(managerMsg).buildMessage();
}
@ -61,16 +60,12 @@ public class RetailAppMessage {
return this;
}
public PartnerRole getRole() {
return role;
public JSONObject getData() {
return data;
}
public RetailAppMessage setRole(PartnerRole role) {
this.role = role;
public RetailAppMessage setData(JSONObject data) {
this.data = data;
return this;
}
public boolean acceptRole(int roleNumber) {
return role.getCode() <= roleNumber;
}
}

@ -2221,6 +2221,7 @@ public class RetailAppServiceImp implements RetailAppService {
}
stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).set(codeKeyValue + "&" + nationCode + "&" + phoneNumber, Long.parseLong(expireMin), TimeUnit.MINUTES);
}
@Override
public void sendUnbindAccountPhone(JSONObject device) {
String codeKey = device.getString("account_id");
@ -2600,8 +2601,6 @@ public class RetailAppServiceImp implements RetailAppService {
}
public JSONObject complianceFilesNotice(JSONObject client, JSONObject account) {
JSONObject complianceFilesNotice = new JSONObject();
@ -2855,14 +2854,9 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject msg = message.forSave(appid, clientId);
authAppMessageMapper.save(msg);
String msgId = msg.getString("message_id");
List<JSONObject> tokens = clientDeviceTokenMapper.listTokensByClient_id(clientId);
List<JSONObject> tokens = clientDeviceTokenMapper.listTokensByAccountId(device.getString("account_id"));
final String[] supportedClientTypes = {"android", "iphone", "ipad"};
long successCount = tokens.parallelStream().filter(devToken -> ArrayUtils.contains(supportedClientTypes, devToken.getString("client_type")))
.filter(devToken -> StringUtils.isNoneEmpty(devToken.getString("account_id"), devToken.getString("token")))
.filter(devToken -> {
JSONObject account = clientAccountMapper.findById(devToken.getString("account_id"));
return account != null && message.acceptRole(account.getIntValue("role"));
})
.filter(devToken -> {
String token = devToken.getString("token");
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), AppMessageType.MESSAGE.name(), token,

@ -24,6 +24,8 @@ public interface ClientDeviceTokenMapper {
List<JSONObject> listTokensByClient_id(@Param("client_id") int client_id);
List<JSONObject> listTokensByAccountId(@Param("client_id") String accountId);
List<JSONObject> listAllTokens(JSONObject devToken);
@AutoSql(type = SqlType.SELECT)

@ -13,6 +13,16 @@
GROUP BY token
</select>
<select id="listTokensByAccountId" resultType="com.alibaba.fastjson.JSONObject">
SELECT t.*,
d.client_type,
d.account_id
FROM sys_clients_devices_token t
INNER JOIN sys_clients_devices d ON t.dev_id = d.dev_id and d.account_id=#{account_id} and d.is_offline=0
WHERE t.is_valid = 1
GROUP BY token
</select>
<select id="listAllTokensByClient_id" resultType="com.alibaba.fastjson.JSONObject">
SELECT t.*,
d.client_type

Loading…
Cancel
Save