Commit c4a8cda9 by Lee Munkyeong

メッセージ検索

parent 712afa1f
package jp.agentec.abook.abv.bl.data.dao;
import java.util.ArrayList;
import java.util.List;
import jp.agentec.abook.abv.bl.common.db.Cursor;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.dto.ChatMessageDto;
import jp.agentec.abook.abv.bl.dto.ChatRoomDto;
import jp.agentec.adf.util.StringUtil;
public class ChatMessageDao extends AbstractDao {
......@@ -99,6 +101,44 @@ public class ChatMessageDao extends AbstractDao {
return list;
}
public List<ChatMessageDto> searchChatMessage(int chatRoomId, String[] keywords, String userList) {
StringBuffer sql = new StringBuffer();
sql.append(" SELECT ");
sql.append(" cm.chat_message_id ");
sql.append(" ,cm.chat_room_id ");
sql.append(" ,cm.shop_member_id ");
sql.append(" ,cm.message ");
sql.append(" ,cm.message_type ");
sql.append(" ,cm.image_name ");
sql.append(" ,cm.download_file_name ");
sql.append(" ,cm.save_path ");
sql.append(" ,cm.insert_date ");
sql.append(" ,sm.shop_member_name ");
sql.append(" ,sm.profile_url ");
sql.append(" ,sm.self_flg ");
sql.append(" FROM ");
sql.append(" t_chat_message AS cm ");
sql.append(" INNER JOIN ");
sql.append(" m_shop_member AS sm ");
sql.append(" ON cm.shop_member_id = sm.shop_member_id ");
sql.append(" WHERE cm.message_type = 0 ");
List<String> whereSqlList = new ArrayList<String>();
for (String keyword : keywords) {
whereSqlList.add("cm.message LIKE '%" + keyword + "%'");
}
String whereSql = StringUtil.join(" OR ", whereSqlList);
if (!StringUtil.isNullOrEmpty(whereSql)) {
sql.append("AND (" + whereSql + ")");
}
if (!StringUtil.isNullOrEmpty(userList)) {
sql.append(" AND cm.shop_member_id IN (" + userList + ") ");
}
sql.append("AND cm.chat_room_id = ? ");
sql.append("ORDER BY cm.insert_date DESC ");
List<ChatMessageDto> list = rawQueryGetDtoList(sql.toString(), new String[]{""+ chatRoomId}, ChatMessageDto.class);
return list;
}
public void insertChatMessage(ChatMessageDto dto) {
insert("insert or replace into t_chat_message (chat_message_id, chat_room_id, shop_member_id, message, message_type, image_name, download_file_name, save_path, insert_date) values (?,?,?,?,?,?,?,?,?)", dto.getInsertValues());
}
......
......@@ -122,6 +122,28 @@ public class CommunicationLogic extends AbstractLogic {
return messageListStr;
}
public String searMessages(Integer roomId, String keyword, String userList) {
String[] replacedKeyword = keyword.replaceAll(" ", " ").split(" ");
List<ChatMessageDto> chatMessageDtoList = chatMessageDao.searchChatMessage(roomId, replacedKeyword, userList);
JSONArray resultJsonArray = new JSONArray();
for (ChatMessageDto chatMessageDto : chatMessageDtoList) {
Map<String, Object> chatMessageMap = new HashMap<String, Object>();
chatMessageMap.put(ABookCommConstants.KEY.CHAT_ROOM_ID, chatMessageDto.chatRoomId);
chatMessageMap.put(ABookCommConstants.KEY.LOGIN_ID, chatMessageDto.shopMemberName);
chatMessageMap.put(ABookCommConstants.KEY.SHOP_MEMBER_ID, chatMessageDto.shopMemberId);
chatMessageMap.put(ABookCommConstants.KEY.MESSAGE, chatMessageDto.message);
chatMessageMap.put(ABookCommConstants.KEY.MESSAGE_TYPE, chatMessageDto.messageType);
chatMessageMap.put(ABookCommConstants.KEY.INSERT_DATE, chatMessageDto.insertDate);
chatMessageMap.put(ABookCommConstants.KEY.PROFILE_URL, chatMessageDto.profileUrl);
chatMessageMap.put(ABookCommConstants.KEY.SELF_FLG, chatMessageDto.selfFlg);
JSONObject jsonObject = new JSONObject(chatMessageMap);
resultJsonArray.put(jsonObject);
}
String messageListStr = resultJsonArray.toString();
return messageListStr;
}
public String getNameCardInfo(Integer shopMemberId) {
JSONObject resultJson = new JSONObject();
ShopMemberDto shopMemberDto = shopMemberDao.getShopMember(shopMemberId);
......@@ -437,6 +459,10 @@ public class CommunicationLogic extends AbstractLogic {
chatRoomDao.insertChatRoom(chatRoomDto);
}
public void insertChatMessage(ChatMessageDto chatMessageDto) {
chatMessageDao.insertChatMessage(chatMessageDto);
}
public void updateChatRoomName(String roomName, Integer roomId) {
chatRoomDao.updateChatRoomName(roomName, roomId);
}
......
......@@ -17,6 +17,7 @@ import java.util.Map;
import jp.agentec.abook.abv.bl.common.exception.ABVException;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.dto.ChatMessageDto;
import jp.agentec.abook.abv.bl.dto.MemberInfoDto;
import jp.agentec.abook.abv.bl.logic.AbstractLogic;
import jp.agentec.abook.abv.bl.logic.UserAuthenticateLogic;
......@@ -64,6 +65,10 @@ public class ABVFcmListenerService extends FirebaseMessagingService {
String roomName = "";
String pushSendLoginId = "";
long pushSendDate = 0;
Integer insertId = 0;
Integer messageType = 0;
Integer messageId = 0;
Log.d(TAG,"tempMsg : "+ tempMsg);
if (tempMsg.indexOf("pushSendLoginId") > 0) {
......@@ -77,6 +82,12 @@ public class ABVFcmListenerService extends FirebaseMessagingService {
pushSendDate = json.getLong("pushSendDate");
pushMsg = json.getString("message");
//TODO pushメッセージが到着した際、新着メッセージかルーム招待か判別してDB格納が必要
//insertId = json.getString("insertId");
//ChatMessageDto chatMessageDto = new ChatMessageDto();
//chatMessageDto.chatRoomId =
//chatRoomId shopMemberId messge messageType insertDate
if (pushMsg.length() > 0) {
tempMsg = pushMsg;
}
......
......@@ -185,7 +185,7 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
//ページをロード
if(roomId != 0 && roomName != null) { // by push message
String parameterData = "sid=" + sid + "&loginId=" + loginId + "&shopName=" + shopName + "&roomId=" + roomId + "&roomName=" + roomName + fixedParam;
mChatWebView.postUrl(chatWebviewUrl, parameterData.getBytes());
mChatWebView.postUrl(CHAT_ROOM_PAGE_URL, parameterData.getBytes());
}
else { // Chat
if (lastRoomName.length() > 0 && lastRoomId.length() > 0) {
......@@ -794,6 +794,12 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
}
@JavascriptInterface
public String searchMessages(String keyword, String userList) {
String messageListStr = communicationLogic.searMessages(roomId.intValue(), keyword, userList);
return messageListStr;
}
@JavascriptInterface
public String getFavoriteUsers() {
String favoriteUsersStr = communicationLogic.getFavoriteUsers();
return favoriteUsersStr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment