Commit c523a895 by Lee Munkyeong

GroupAPI修正。

parent d7c71ca2
......@@ -18,6 +18,7 @@ public class GroupListJSON extends AcmsCommonJSON {
public ArrayList<GroupDto> groupList;
public String allGroupLastUpdateDate;
public GroupListJSON(String jsonString) throws AcmsException {
super(jsonString);
......@@ -28,6 +29,7 @@ public class GroupListJSON extends AcmsCommonJSON {
// ルーム一覧情報を取得
if (!json.has(ABookCommConstants.KEY.BODY)) { return; }
if (!json.getJSONObject(ABookCommConstants.KEY.BODY).has(ABookCommConstants.KEY.GROUP_INFO_LIST)) { return; }
JSONArray groupListJsonArray = json.getJSONObject(ABookCommConstants.KEY.BODY).getJSONArray(ABookCommConstants.KEY.GROUP_INFO_LIST);
if (groupListJsonArray == null) { return; }
......@@ -47,7 +49,9 @@ public class GroupListJSON extends AcmsCommonJSON {
}
groupDto.groupName = groupJSON.getString(ABookCommConstants.KEY.GROUP_NAME);
groupDto.delFlg = groupJSON.getInt(ABookCommConstants.KEY.DEL_FLG);
if (groupJSON.has(ABookCommConstants.KEY.GROUP_INFO_LAST_UPDATE_DATE)) {
groupDto.updateDate = groupJSON.getString(ABookCommConstants.KEY.GROUP_INFO_LAST_UPDATE_DATE);
}
if (groupJSON.has(ABookCommConstants.KEY.GROUP_MEMBER_LIST)) {
JSONArray groupMemberJsonArray = groupJSON.getJSONArray(ABookCommConstants.KEY.GROUP_MEMBER_LIST);
ArrayList<ShopMemberDto> groupMembers = new ArrayList<ShopMemberDto>();
......@@ -69,6 +73,10 @@ public class GroupListJSON extends AcmsCommonJSON {
}
groupList.add(groupDto);
}
if (json.getJSONObject(ABookCommConstants.KEY.BODY).has(ABookCommConstants.KEY.GROUP_INFO_LAST_UPDATE_DATE)) {
allGroupLastUpdateDate = json.getJSONObject(ABookCommConstants.KEY.BODY).getString(ABookCommConstants.KEY.GROUP_INFO_LAST_UPDATE_DATE);
}
}
}
......@@ -57,6 +57,13 @@ public class RoomListJSON extends AcmsCommonJSON {
chatMessageDto.chatMessageId = lastMessageInfoJSON.getInt(ABookCommConstants.KEY.MESSAGE_ID);
chatRoomDto.lastMessageInfo = chatMessageDto;
}
JSONArray attendUsers = roomListJsonArray.getJSONObject(listCount).getJSONArray(ABookCommConstants.KEY.ATTEND_USERS);
ArrayList<Integer> attendUserList = new ArrayList<Integer>();
for (int attendUserCount = 0; attendUserCount < attendUsers.length(); attendUserCount++) {
attendUserList.add((Integer) attendUsers.get(attendUserCount));
}
chatRoomDto.attendUsers = attendUserList;
roomList.add(chatRoomDto);
}
}
......
......@@ -6,6 +6,8 @@ package jp.agentec.abook.abv.bl.common.constant;
public interface ABookCommConstants {
String TAG ="ABookComm";
//AbookComm専用の共通インターフェース
interface KEY {
String CHAT_ROOM_ID = "chatRoomId";
......@@ -51,6 +53,8 @@ public interface ABookCommConstants {
String LAST_MESSAGE_INFO = "lastMessageInfo";
String FAVORITE_USER_IDS = "favoriteUserIds";
String FAVORITE_GROUP_IDS = "favoriteGroupIds";
String GROUP_INFO_LAST_UPDATE_DATE = "groupInfoLastUpdateDate";
String ROOT_GROUP_ID = "rootGroupId";
......
......@@ -81,7 +81,7 @@ public class ChatRoomDao extends AbstractDao {
sql.append(" ON cr.chat_room_id = cm.chat_room_id ");
sql.append(" WHERE cr.type =? ");
sql.append(" GROUP BY cr.chat_room_id ");
sql.append(" ORDER BY unread_count, cm.insert_date DESC ");
sql.append(" ORDER BY CASE WHEN unread_count = 0 THEN 0 ELSE 1 END DESC, cm.insert_date DESC ");
List<ChatRoomDto> list = rawQueryGetDtoList(sql.toString(), new String[]{""+ roomType}, ChatRoomDto.class);
return list;
}
......@@ -103,6 +103,7 @@ public class ChatRoomDao extends AbstractDao {
beginTransaction();
for (ChatRoomDto chatRoomDto : chatRoomDtoList) {
insertChatRoom(chatRoomDto);
insertChatRoomUsers(chatRoomDto.attendUsers, chatRoomDto.chatRoomId);
}
commit();
} catch (Exception e) {
......@@ -112,6 +113,12 @@ public class ChatRoomDao extends AbstractDao {
}
}
public void insertChatRoomUsers(List<Integer> attendUsers, Integer chatRoomId) {
for (Integer attendUserId : attendUsers) {
insert("insert or replace into r_chat_room_shop_member (chat_room_id, shop_member_id) values (?,?)", new Integer[]{chatRoomId, attendUserId});
}
}
public boolean updateChatRoom(ChatRoomDto dto) {
long count = update("update t_chat_room set chat_room_name=?, type=?, unread_count=?, user_count=?, favorite_register_date=? where chat_room_id=?", dto.getUpdateValues());
return count > 0;
......
......@@ -99,6 +99,20 @@ public class ShopMemberDao extends AbstractDao {
return rawQueryGetDto("select * from m_shop_member where self_flg = 1", null, ShopMemberDto.class);
}
public List<ShopMemberDto> getUserInRoom(Integer chatRoomId) {
StringBuffer sql = new StringBuffer();
sql.append(" SELECT sm.* ");
sql.append(" FROM ");
sql.append(" m_shop_member AS sm ");
sql.append(" INNER JOIN r_chat_room_shop_member AS rrm ");
sql.append(" ON sm.shop_member_id = rrm.shop_member_id ");
sql.append(" WHERE rrm.chat_room_id =?");
sql.append(" AND sm.self_flg != 1");
sql.append(" ORDER BY sm.shop_member_name DESC ");
List<ShopMemberDto> list = rawQueryGetDtoList(sql.toString(), new String[]{""+ chatRoomId}, ShopMemberDto.class);
return list;
}
public List<ShopMemberDto> getfavoriteUserList() {
return rawQueryGetDtoList("select * from m_shop_member where favorite_register_date NOT NULL", null, ShopMemberDto.class);
}
......
package jp.agentec.abook.abv.bl.dto;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -15,6 +16,7 @@ public class ChatRoomDto extends AbstractDto {
public Integer messageType;
public String insertDate;
public ChatMessageDto lastMessageInfo;
public ArrayList<Integer> attendUsers;
@Override
public Object[] getInsertValues() {
......
......@@ -22,6 +22,7 @@ public class GroupDto extends AbstractDto {
public int delFlg;
public List<ShopMemberDto> groupMembers;
public List<String> groupPathList;
public String updateDate;
public GroupDto() {
}
......
......@@ -58,6 +58,20 @@ public class CommunicationLogic extends AbstractLogic {
chatRoomMap.put(ABookCommConstants.KEY.MESSAGE_TYPE, chatRoomDto.messageType);
chatRoomMap.put(ABookCommConstants.KEY.INSERT_DATE, chatRoomDto.insertDate);
chatRoomMap.put(ABookCommConstants.KEY.USER_COUNT, chatRoomDto.userCount);
//ルームの参加者リスト取得。
List<ShopMemberDto> userList = shopMemberDao.getUserInRoom(chatRoomDto.chatRoomId);
JSONArray attendUsers = new JSONArray();
for (ShopMemberDto user : userList) {
Map<String, Object> userMap = new HashMap<String, Object>();
userMap.put(ABookCommConstants.KEY.INSERT_DATE, user.shopMemberId);
userMap.put(ABookCommConstants.KEY.INSERT_DATE, user.profileUrl);
userMap.put(ABookCommConstants.KEY.INSERT_DATE, user.shopMemberName);
JSONObject jsonObject = new JSONObject(userMap);
attendUsers.put(jsonObject);
}
chatRoomMap.put(ABookCommConstants.KEY.ATTEND_USERS, attendUsers);
JSONObject jsonObject = new JSONObject(chatRoomMap);
resultJsonArray.put(jsonObject);
}
......@@ -314,6 +328,11 @@ public class CommunicationLogic extends AbstractLogic {
Map<String, Object> groupTreeMap = new HashMap<String, Object>();
groupTreeMap.put(ABookCommConstants.KEY.GROUP_NAME, group.groupName);
groupTreeMap.put(ABookCommConstants.KEY.GROUP_ID, group.groupId);
if(StringUtil.isNullOrEmpty(group.favoriteRegisterDate)) {
groupTreeMap.put(ABookCommConstants.KEY.IS_FAVORITE, false);
} else {
groupTreeMap.put(ABookCommConstants.KEY.IS_FAVORITE, true);
}
JSONObject jsonObject = new JSONObject(groupTreeMap);
childGroupJSONArray.put(jsonObject);
}
......@@ -406,6 +425,7 @@ public class CommunicationLogic extends AbstractLogic {
continue;
}
insertShopMember(groupDto.groupMembers);
}
groupDao.insertGroupList(insertGroupList);
groupDao.updateGroupList(updateGroupList);
......
......@@ -8,6 +8,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
......@@ -66,6 +67,8 @@ import jp.agentec.abook.abv.ui.common.util.ABVToastUtil;
import jp.agentec.abook.abv.ui.common.util.AlertDialogUtil;
import jp.agentec.abook.abv.ui.home.helper.ActivityHandlingHelper;
import jp.agentec.abook.abv.ui.viewer.activity.ParentWebViewActivity;
import jp.agentec.adf.util.CollectionUtil;
import jp.agentec.adf.util.StringUtil;
import static org.chromium.net.NetError.ERR_FAILED;
......@@ -933,8 +936,28 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
}
private void updateGroupInfoFromServer(String groupIds) throws NetworkDisconnectedException, AcmsException {
GroupListJSON resultJson = AcmsClient.getInstance(ABVEnvironment.getInstance().networkAdapter).getGroupInfo(sid,groupIds,DEFAULT_CHECKSUM);
communicationLogic.updateGroup(resultJson.groupList);
ArrayList<String> checkSumList = new ArrayList<String>();
SharedPreferences pref = getSharedPreferences(ABookCommConstants.TAG,MODE_PRIVATE);
for (String groupId : groupIds.split(",")) {
checkSumList.add(pref.getString(groupId,DEFAULT_CHECKSUM));
}
String checkSumListStr = StringUtil.join(",",checkSumList);
GroupListJSON resultJson = AcmsClient.getInstance(ABVEnvironment.getInstance().networkAdapter).getGroupInfo(sid,groupIds,checkSumListStr);
if (CollectionUtil.isNotEmpty(resultJson.groupList)) {
SharedPreferences.Editor editor = pref.edit();
communicationLogic.updateGroup(resultJson.groupList);
if (groupIds.equals(ABookCommConstants.FLAG.GROUP_REQUEST_ALL.toString())) {
editor.putString(ABookCommConstants.FLAG.GROUP_REQUEST_ALL.toString(),resultJson.allGroupLastUpdateDate);
} else {
for (GroupDto groupDto : resultJson.groupList) {
editor.putString(Integer.toString(groupDto.groupId),groupDto.updateDate);
}
}
editor.commit();
}
}
private void updateFavoriteUser() throws NetworkDisconnectedException, AcmsException {
......@@ -950,6 +973,7 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
private void updateAllGroupInfo() throws NetworkDisconnectedException, AcmsException {
updateGroupInfoFromServer(ABookCommConstants.FLAG.GROUP_REQUEST_ALL.toString());
List<GroupDto> groupList = communicationLogic.getAllGroup();
for (GroupDto group : groupList) {
updateGroupInfoFromServer(Integer.toString(group.groupId));
}
......
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