@Override protected void onPostExecute(List<Player> result) { super.onPostExecute(result); if (result.size() != 0 && result != null) { List<PlayerInTeam> teamMebList = new ArrayList<PlayerInTeam>(); for (Player item : result) { PlayerInTeam response = new PlayerInTeam(); response.setPlayer(item); teamMebList.add(response); } adapter.setMemberList(teamMebList); } }
@Override protected Void doInBackground(List<PlayerInTeam>... params) { // TODO Auto-generated method stub PlayerDao playerDao = CustomApplcation.getDaoSession(mContext).getPlayerDao(); TeamPlayerDao tpDao = CustomApplcation.getDaoSession(mContext).getTeamPlayerDao(); Query<TeamPlayer> tpQuery = CustomApplcation.getDaoSession(mContext) .getTeamPlayerDao() .queryBuilder() .where( TeamPlayerDao.Properties.Player_id.eq(""), TeamPlayerDao.Properties.Team_id.eq("")) .build(); // (1)、将球队成员数据放入到Player表中 List<PlayerInTeam> teamMebList = params[0]; for (PlayerInTeam teamRe : teamMebList) { // 去掉了数据库表Player的自增长ID之后,才能使用insertOrReplace方法 playerDao.insertOrReplace(teamRe.getPlayer()); // (2)、同时,在成员Player与球队Team关联表TeamPlayer表中,也要添加相对应的数据 TeamPlayer team_player = new TeamPlayer(); team_player.setPlayer_id(teamRe.getPlayer().getUuid()); team_player.setTeam_id(onlyTeam.getUuid()); team_player.setCreator(teamRe.isCreator()); // 1创建者 team_player.setType(teamRe.getType()); tpQuery.setParameter(0, teamRe.getPlayer().getUuid()); tpQuery.setParameter(1, onlyTeam.getUuid()); TeamPlayer teamPlayerSearch = tpQuery.unique(); if (teamPlayerSearch != null) { team_player.setId(teamPlayerSearch.getId()); // 找到已有的teamplayer映射的id tpDao.insertOrReplace(team_player); } else { tpDao.insertOrReplace(team_player); } } return null; }