直播间留言推送修改

This commit is contained in:
谢洪龙 2017-07-28 13:38:10 +08:00
parent 6ef5739727
commit 61bce4c26a
2 changed files with 97 additions and 3 deletions

View File

@ -19,7 +19,8 @@ public enum PushTypeEnum {
offline_push("offline_push", "离线通知"),
send_report("send_report", "看护报告"),
shops_push("shops_push", "看护通知"),
all_push("all_push", "所有用户推送");
all_push("all_push", "所有用户推送"),
pinglun_push("pinglun_push","直播间评论");
private PushTypeEnum(String key, String value) {
this.key = key;

View File

@ -5,6 +5,7 @@
*/
package com.ifish.helper;
import com.ifish.API.JiGuangPush;
import com.ifish.Interceptor.IfishException;
import com.ifish.bean.LiveRoomPageInfo;
import com.ifish.bean.PageResult;
@ -12,7 +13,9 @@ import com.ifish.bean.Tbl_Device_User;
import com.ifish.bean.Tbl_Live_Message;
import com.ifish.bean.Tbl_Live_Room;
import com.ifish.bean.Tbl_Live_Watch;
import com.ifish.bean.Tbl_Push_List;
import com.ifish.bean.Tbl_User;
import com.ifish.enums.PushTypeEnum;
import com.ifish.enums.ResultEnum;
import com.ifish.mapper.Tbl_Live_Room_Mapper;
import com.ifish.util.IfishUtil;
@ -51,6 +54,12 @@ public class LiveRoomHelper implements LiveRoomHelperI {
@Autowired
private RedisKeyHelperI redisKeyHelperI;
@Autowired
private JiGuangPush jiGuangPush;
@Autowired
private PushMessageHelperI pushMessageHelperI;
/**
* 新增直播间
*
@ -246,8 +255,7 @@ public class LiveRoomHelper implements LiveRoomHelperI {
try {
Integer roomId = liveMessage.getRoomId();
Integer userId = liveMessage.getUserId();
String messageContent = new String(liveMessage.getMessageContent().getBytes("ISO-8859-1"), "UTF-8");
liveMessage.setMessageContent(messageContent);
String messageContent = liveMessage.getMessageContent();
if (roomId != null && userId != null && StringUtils.isNotBlank(messageContent)) {
Tbl_Live_Room live_Room = getTbl_Live_RoomByRoomId(roomId);
Tbl_User user = userHelperI.getUserById(userId);
@ -266,14 +274,40 @@ public class LiveRoomHelper implements LiveRoomHelperI {
if (asUser != null) {
liveMessage.setAsUserName(asUser.getNickName());
if (!asUserId.equals(userId)) {
String timestamp = IfishUtil.format(new Date());
//发送云信消息给所@的用户
//neteaseIM.sendMsg(userId.toString(), asUserId.toString(), "来自爱鱼看看的回复:" + messageContent, "");
//基本参数
Map<String, String> baseMap = new HashMap<String, String>();
baseMap.put("title", PushTypeEnum.pinglun_push.getValue());
baseMap.put("content", "来自爱鱼看看的回复:" + messageContent);
baseMap.put("user_id", asUserId.toString());
baseMap.put("loginType", asUser.getLoginType());
//推送参数
Map<String, String> pushMap = new HashMap<String, String>();
pushMap.put("timestamp", timestamp);
pushMap.put("msg_type", PushTypeEnum.pinglun_push.getKey());
//推送消息
jPushNotifcation(baseMap, pushMap);
}
} else {
Integer roomUserId = live_Room.getUserId();
if (!roomUserId.equals(userId)) {
//发送云信消息给房主
//neteaseIM.sendMsg(userId.toString(), roomUserId.toString(), "来自爱鱼看看的留言:" + messageContent, "");
String timestamp = IfishUtil.format(new Date());
//基本参数
Map<String, String> baseMap = new HashMap<String, String>();
baseMap.put("title", PushTypeEnum.pinglun_push.getValue());
baseMap.put("content", "来自爱鱼看看的回复:" + messageContent);
baseMap.put("user_id", user.getUserId().toString());
baseMap.put("loginType", user.getLoginType());
//推送参数
Map<String, String> pushMap = new HashMap<String, String>();
pushMap.put("timestamp", timestamp);
pushMap.put("msg_type", PushTypeEnum.pinglun_push.getKey());
//推送消息
jPushNotifcation(baseMap, pushMap);
}
}
}
@ -513,4 +547,63 @@ public class LiveRoomHelper implements LiveRoomHelperI {
}
return IfishUtil.toJson(ResultEnum.fail101.getKey(), "");
}
/**
* 极光推送
*
* @param userId
*/
public boolean jPushNotifcation(Map<String, String> baseMap, Map<String, String> pushMap) {
try {
//登录类型
String loginType = baseMap.get("loginType");
if (loginType != null) {
//推送消息类型
String msgType = pushMap.get("msg_type");
String userId = baseMap.get("user_id");
String title = baseMap.get("title");
String content = baseMap.get("content");
boolean result = false;
if (loginType.equals("ios")) {
result = jiGuangPush.pushMessageByIOS(title, content, userId, pushMap);
} else if (loginType.equals("android")) {
result = jiGuangPush.pushMessageByAndroid(title, content, userId, pushMap);
}
//推送记录
Tbl_Push_List pushList = new Tbl_Push_List();
if (msgType.equals(PushTypeEnum.remove_device.getKey())) {
pushList.setUserId(Integer.valueOf(userId));
pushList.setDeviceId(Integer.valueOf(pushMap.get("device_id")));
pushList.setPhoneType(loginType);
pushList.setShowName(pushMap.get("showName"));
pushList.setPushType(msgType);
pushList.setPushTitle(title);
pushList.setPushContext(content);
pushList.setJpushStatus(result ? "1" : "0");
pushList.setCreateTime(new Date());
pushMessageHelperI.save(pushList);
return true;
} //发送看护报告推送
else if (msgType.equals(PushTypeEnum.send_report.getKey())) {
String reportId = baseMap.get("reportId");
if (reportId != null) {
pushList.setReportId(Integer.valueOf(reportId));
}
pushList.setUserId(Integer.valueOf(userId));
pushList.setPhoneType(loginType);
pushList.setPushType(msgType);
pushList.setPushTitle(title);
pushList.setPushContext(content);
pushList.setPushLink(pushMap.get("push_link"));
pushList.setJpushStatus(result ? "1" : "0");
pushList.setCreateTime(new Date());
pushMessageHelperI.save(pushList);
return true;
}
}
} catch (Exception e) {
throw new RuntimeException();
}
return false;
}
}