Commit f4db91dd by Lee Munkyeong

SQL性能改善

parent 6d81f4e4
......@@ -62,11 +62,10 @@ public class GroupListJSON extends AcmsCommonJSON {
if (groupMember.has(ABookCommConstants.KEY.PROFILE_IMAGE_PATH)) {
shopMemberDto.profileUrl = groupMember.getString(ABookCommConstants.KEY.PROFILE_IMAGE_PATH);
}
ArrayList groupIds = new ArrayList();
groupIds.add(groupDto.groupId);
shopMemberDto.groupIdList = groupIds;
// ArrayList groupIds = new ArrayList();
// groupIds.add(groupDto.groupId);
// shopMemberDto.groupIdList = groupIds;
groupMembers.add(shopMemberDto);
}
groupDto.groupMembers = groupMembers;
}
......
......@@ -27,12 +27,12 @@ public class MyInfoJSON extends AcmsCommonJSON {
if (MyInfoJson == null) { return; }
shopMemberDto = new ShopMemberDto();
ArrayList<Integer> groupIdList = new ArrayList<Integer>();
JSONArray groupIdJsonArray = (JSONArray) MyInfoJson.get(ABookCommConstants.KEY.GROUP_ID_LIST);
//ArrayList<Integer> groupIdList = new ArrayList<Integer>();
/*JSONArray groupIdJsonArray = (JSONArray) MyInfoJson.get(ABookCommConstants.KEY.GROUP_ID_LIST);
for (int i = 0; i < groupIdJsonArray.length(); i++) {
groupIdList.add(groupIdJsonArray.getInt(i));
}
shopMemberDto.groupIdList = groupIdList;
}*/
//shopMemberDto.groupIdList = groupIdList;
shopMemberDto.selfFlg = ABookCommConstants.FLAG.SELF_FLAG.ON;
shopMemberDto.profileUrl = MyInfoJson.getString(ABookCommConstants.KEY.PROFILE_IMAGE_PATH);
shopMemberDto.shopMemberId = MyInfoJson.getInt(ABookCommConstants.KEY.SHOP_MEMBER_ID);
......
......@@ -77,6 +77,8 @@ public interface ABookCommConstants {
String COLLABORATION_DEATAIL_ID = "collaborationDetailId";
String MY_SHOPE_MEMBER_ID = "myShopMemberId";
String ROOT_GROUP_ID = "rootGroupId";
String HTTP_STATUS = "httpStatus";
interface API_KIND {
......
......@@ -188,9 +188,15 @@ public class ChatRoomDao extends AbstractCommunicationDao {
}
public void insertChatRoomUsers(List<Integer> attendUsers, Integer chatRoomId) {
if (CollectionUtil.isEmpty(attendUsers)) {
return;
}
String sql = "insert or replace into r_chat_room_shop_member (chat_room_id, shop_member_id) values ";
ArrayList<String> insertAttendUser = new ArrayList<String>();
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});
insertAttendUser.add("(" + chatRoomId + ", " + attendUserId + ")");
}
insert(sql + StringUtil.join(", ", insertAttendUser), new Object[] {});
}
public void deleteChatRoomUsers(Integer chatRoomId) {
......
......@@ -2,6 +2,7 @@ package jp.agentec.abook.abv.bl.data.dao;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import jp.agentec.abook.abv.bl.common.db.Cursor;
......@@ -69,10 +70,11 @@ public class ShopMemberDao extends AbstractCommunicationDao {
try {
beginTransaction();
insert("insert or replace into m_shop_member (shop_member_id, shop_member_name, login_id, profile_url, self_flg, favorite_register_date) values (?,?,?,?,?,(select favorite_register_date from m_shop_member where shop_member_id = ?))", dto.getInsertValues());
update(" delete from r_shop_member_group WHERE shop_member_id = ? ", new Integer[]{dto.shopMemberId});
for (Integer groupId : dto.groupIdList) {
insert("insert or replace into r_shop_member_group (shop_member_id, group_id) values ("+dto.shopMemberId+",?)", new Integer[]{groupId});
if (dto.groupIdList != null && dto.groupIdList.size() > 0) {
update(" delete from r_shop_member_group WHERE shop_member_id = ? ", new Integer[]{dto.shopMemberId});
for (Integer groupId : dto.groupIdList) {
insert("insert or replace into r_shop_member_group (shop_member_id, group_id) values ("+dto.shopMemberId+",?)", new Integer[]{groupId});
}
}
commit();
} catch (Exception e) {
......@@ -102,6 +104,20 @@ public class ShopMemberDao extends AbstractCommunicationDao {
}
}
public void insertShopMemberGroupRelation(Integer groupId, List<ShopMemberDto> dtoList) {
try {
for (ShopMemberDto dto : dtoList) {
insert("insert or replace into r_shop_member_group (shop_member_id, group_id) values ("+dto.shopMemberId+",?)", new Integer[]{groupId});
}
} catch (Exception e) {
rollback();
Logger.e("insertShopMember failed.", e);
throw new RuntimeException(e);
} finally {
}
}
public ShopMemberDto getMyInfo() {
return rawQueryGetDto("select * from m_shop_member where self_flg = 1", null, ShopMemberDto.class);
}
......@@ -400,6 +416,17 @@ public class ShopMemberDao extends AbstractCommunicationDao {
return count > 0;
}
public void updateFavoriteUserList(List<Integer> shopMemberIdList) {
beginTransaction();
for (Integer shopMemberId : shopMemberIdList ) {
ShopMemberDto favoriteUserDto= new ShopMemberDto();
favoriteUserDto.shopMemberId = shopMemberId;
favoriteUserDto.favoriteRegisterDate = DateTimeUtil.toString_yyyyMMddHHmmss_none(new Date(System.currentTimeMillis()));
update("update m_shop_member set favorite_register_date=? where shop_member_id=?", new Object[]{favoriteUserDto.favoriteRegisterDate, favoriteUserDto.shopMemberId});
}
commit();
}
public void deleteShopMember() {
try {
beginTransaction();
......
......@@ -9,6 +9,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import jp.agentec.abook.abv.bl.common.constant.ABookCommConstants;
......@@ -762,7 +763,6 @@ public class CommunicationLogic extends AbstractLogic {
List<ShopMemberDto> deleteList = new ArrayList<ShopMemberDto>();
for (ShopMemberDto shopMemberDto : shopMemberDtoList) {
//TODO ユーザ最新化処理必要
//if (ABookCommConstants.FLAG.DEL_FLAG.EXIST.equals(shopMemberDto.delFlg)) {
if (myInfo.shopMemberId.equals(shopMemberDto.shopMemberId)) {
shopMemberDto.selfFlg = 1;
......@@ -778,6 +778,28 @@ public class CommunicationLogic extends AbstractLogic {
//shopMemberDao.deleteShopMemberByList(deleteList);
}
public void insertShopMemberByMap(HashMap<Integer, List<ShopMemberDto>> shopMemberDtoListMap) {
ShopMemberDto myInfo = shopMemberDao.getMyInfo();
List<ShopMemberDto> insertList = new ArrayList<ShopMemberDto>();
shopMemberDao.beginTransaction();
Set<Integer> groupIds = shopMemberDtoListMap.keySet();
for (Integer groupId : groupIds) {
List<ShopMemberDto> shopMemberDtoList = shopMemberDtoListMap.get(groupId);
for (ShopMemberDto shopMemberDto : shopMemberDtoList) {
if (myInfo.shopMemberId.equals(shopMemberDto.shopMemberId)) {
shopMemberDto.selfFlg = 1;
} else {
shopMemberDto.selfFlg = 0;
}
insertList.add(shopMemberDto);
}
shopMemberDao.insertShopMemberGroupRelation(groupId, shopMemberDtoList);
}
shopMemberDao.commit();
shopMemberDao.insertShopMember(insertList);
}
public void updateArchives(List<ArchiveDto> archiveDtoList) {
List<ArchiveDto> insertList = new ArrayList<ArchiveDto>();
List<ArchiveDto> deleteList = new ArrayList<ArchiveDto>();
......@@ -810,6 +832,7 @@ public class CommunicationLogic extends AbstractLogic {
ArrayList<ChatGroupDto> insertGroupList = new ArrayList<ChatGroupDto>();
ArrayList<ChatGroupDto> deleteGroupList = new ArrayList<ChatGroupDto>();
ArrayList<ChatGroupDto> updateGroupList = new ArrayList<ChatGroupDto>();
HashMap<Integer, List<ShopMemberDto>> groupMembersMap = new HashMap<Integer, List<ShopMemberDto>>();
for (ChatGroupDto chatGroupDto : GroupList) {
if (chatGroupDto.delFlg == 1) {
deleteGroupList.add(chatGroupDto);
......@@ -820,13 +843,14 @@ public class CommunicationLogic extends AbstractLogic {
} else {
updateGroupList.add(chatGroupDto);
}
if (chatGroupDto.groupMembers == null) {
continue;
}
insertShopMember(chatGroupDto.groupMembers);
groupMembersMap.put(chatGroupDto.groupId, chatGroupDto.groupMembers);
//insertShopMember(chatGroupDto.groupMembers);
}
insertShopMemberByMap(groupMembersMap);
chatGroupDao.insertGroupList(insertGroupList);
chatGroupDao.updateGroupList(updateGroupList);
chatGroupDao.deleteGroupList(deleteGroupList);
......@@ -847,12 +871,7 @@ public class CommunicationLogic extends AbstractLogic {
}
public void updateFavoriteUser(List<Integer> favoriteUserIds){
for (Integer favoriteUserId : favoriteUserIds) {
ShopMemberDto favoriteUserDto= new ShopMemberDto();
favoriteUserDto.shopMemberId = favoriteUserId;
favoriteUserDto.favoriteRegisterDate = DateTimeUtil.toString_yyyyMMddHHmmss_none(new Date(System.currentTimeMillis()));
shopMemberDao.updateFavoriteUser(favoriteUserDto);
}
shopMemberDao.updateFavoriteUserList(favoriteUserIds);
}
public void updateFavoriteGroup(List<Integer> favoriteGroupIds){
......
......@@ -247,6 +247,7 @@ public class ChatWebViewActivity extends CommunicationWebViewActivity {
});
closeProgressPopup();
} catch (Exception e) {
e.printStackTrace();
Logger.d("Update error");
}
}
......@@ -1013,7 +1014,6 @@ public class ChatWebViewActivity extends CommunicationWebViewActivity {
public void updateRoomList() throws NetworkDisconnectedException, AcmsException {
Map<String, Object> chatRoomList;
RoomListJSON resultJson = AcmsClient.getInstance(ABVEnvironment.getInstance().networkAdapter).getRoomList(sid);
//communicationLogic.deleteChatRoomList();
communicationLogic.insertChatRoomList(resultJson.roomList);
}
......@@ -1817,6 +1817,7 @@ public class ChatWebViewActivity extends CommunicationWebViewActivity {
for (ChatGroupDto group : groupList) {
updateGroupInfoFromServer(Integer.toString(group.groupId));
}
int test = 1;
}
private void updateFavoriteInfo() throws NetworkDisconnectedException, AcmsException {
......
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