|
@@ -10,12 +10,16 @@ import com.incubator.core.net.ws.WSRequest;
|
|
import com.incubator.core.net.ws.WSResponse;
|
|
import com.incubator.core.net.ws.WSResponse;
|
|
import com.incubator.game.constant.RedisKeyConstant;
|
|
import com.incubator.game.constant.RedisKeyConstant;
|
|
import com.incubator.game.data.jedis.RedisUtil;
|
|
import com.incubator.game.data.jedis.RedisUtil;
|
|
|
|
+import com.incubator.game.data.po.ZjClubMemberPo;
|
|
import com.incubator.game.data.po.ZjClubPo;
|
|
import com.incubator.game.data.po.ZjClubPo;
|
|
import com.incubator.game.data.po.ZjUserLobbyPo;
|
|
import com.incubator.game.data.po.ZjUserLobbyPo;
|
|
import com.incubator.game.util.UtilCore;
|
|
import com.incubator.game.util.UtilCore;
|
|
import com.incubator.message.proto.CommonProto;
|
|
import com.incubator.message.proto.CommonProto;
|
|
|
|
|
|
|
|
+import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Optional;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Author: xhb
|
|
* Author: xhb
|
|
@@ -30,12 +34,15 @@ public class CreateClub extends NetHandler {
|
|
response.setCmd(CommonProto.Cmd.CreateClubRes_VALUE);
|
|
response.setCmd(CommonProto.Cmd.CreateClubRes_VALUE);
|
|
|
|
|
|
String userId = request.getDataValue("userId", String.class, "");
|
|
String userId = request.getDataValue("userId", String.class, "");
|
|
|
|
+ String userInfo = RedisUtil.get(RedisKeyConstant.USER_BASE + userId);
|
|
|
|
+ JSONObject userObject = JSONUtil.parseObj(userInfo);
|
|
String clubInfo = request.getDataValue("clubInfo", String.class, "");
|
|
String clubInfo = request.getDataValue("clubInfo", String.class, "");
|
|
|
|
+ ZjClubPo club = JSONUtil.parseObj(clubInfo).toBean(ZjClubPo.class);
|
|
|
|
+ JSONObject jsonObject = getClubListFromRedis();
|
|
|
|
+ JSONArray clubArray = jsonObject.getJSONArray("clubList");
|
|
|
|
+ List<ZjClubPo> clubList = clubArray.toList(ZjClubPo.class);
|
|
|
|
|
|
- try {
|
|
|
|
- JSONObject jsonObject = getClubListFromRedis();
|
|
|
|
- JSONArray clubArray = jsonObject.getJSONArray("clubList");
|
|
|
|
- List<ZjClubPo> clubList = clubArray.toList(ZjClubPo.class);
|
|
|
|
|
|
+ if (club.getClubId()==null){
|
|
|
|
|
|
if (isUserAlreadyCreatedClub(clubList, userId)) {
|
|
if (isUserAlreadyCreatedClub(clubList, userId)) {
|
|
response.setCode(CommonProto.Code.PARAMETER_ERR_VALUE);
|
|
response.setCode(CommonProto.Code.PARAMETER_ERR_VALUE);
|
|
@@ -43,17 +50,46 @@ public class CreateClub extends NetHandler {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- ZjClubPo newClub = createNewClub(clubInfo, userId);
|
|
|
|
- addClubToRedis(jsonObject, clubArray, newClub);
|
|
|
|
|
|
+ ZjClubPo newClub = createNewClub(club, userId);
|
|
|
|
+ addClubToRedis(jsonObject, clubArray, newClub);//添加俱乐部到redis
|
|
|
|
+
|
|
|
|
+ addClubMemberToRedis(userObject, newClub);//添加俱乐部成员到redis
|
|
|
|
|
|
- updateUserLobbyClub(jsonObject, userId, newClub);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- // 处理异常,例如记录日志或返回错误响应
|
|
|
|
- response.setCode(CommonProto.Code.SYSTEM_ERR_VALUE);
|
|
|
|
- response.setMessage("创建俱乐部时发生错误");
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ updateUserLobbyClub(userId, newClub);//设置主俱乐部
|
|
|
|
+ }else {
|
|
|
|
+ Optional<ZjClubPo> existingClub = clubList.stream()
|
|
|
|
+ .filter(clubPo -> clubPo.getClubId().equals(club.getClubId()))
|
|
|
|
+ .findFirst();
|
|
|
|
+ existingClub.ifPresent(c -> {
|
|
|
|
+ c.setClubName(club.getClubName());
|
|
|
|
+ c.setClubImg(club.getClubImg());
|
|
|
|
+ c.setClubDescription(club.getClubDescription());
|
|
|
|
+ c.setClubAddress(club.getClubAddress());
|
|
|
|
+ });
|
|
|
|
+ jsonObject.put("clubList", clubList);
|
|
|
|
+ RedisUtil.set(RedisKeyConstant.CLUB_BASE, jsonObject.toString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void addClubMemberToRedis(JSONObject userObject, ZjClubPo newClub) {
|
|
|
|
+ Object lobbyUserObj = userObject.get("lobbyUser");
|
|
|
|
+ ZjUserLobbyPo lobbyUser = JSONUtil.toBean((JSONObject) lobbyUserObj, ZjUserLobbyPo.class);
|
|
|
|
+ ZjClubMemberPo zjClubMemberPo = new ZjClubMemberPo();
|
|
|
|
+ zjClubMemberPo.setMemberId(UtilCore.getDateRandomId());
|
|
|
|
+ zjClubMemberPo.setUserId(lobbyUser.getUserId());
|
|
|
|
+ zjClubMemberPo.setClubId(newClub.getClubId());
|
|
|
|
+ zjClubMemberPo.setIsMain("Y");
|
|
|
|
+ zjClubMemberPo.setIsMaster("Y");
|
|
|
|
+ zjClubMemberPo.setMemberStatus("1");
|
|
|
|
+ zjClubMemberPo.setAvatarUrl(lobbyUser.getAvatarUrl());
|
|
|
|
+ zjClubMemberPo.setNickName(lobbyUser.getNickName());
|
|
|
|
+ zjClubMemberPo.setJoinTime(new Date());
|
|
|
|
+ zjClubMemberPo.setSevenDayMasterScore((Integer) userObject.get("sevenScore"));
|
|
|
|
+ zjClubMemberPo.setRequestExplain("掌门人");
|
|
|
|
+ zjClubMemberPo.setRequestChannel("2");
|
|
|
|
+ RedisUtil.set(RedisKeyConstant.CLUB_MEMBER + newClub.getClubId(), zjClubMemberPo);
|
|
|
|
+ }
|
|
|
|
+
|
|
private JSONObject getClubListFromRedis() {
|
|
private JSONObject getClubListFromRedis() {
|
|
String clubListStr = RedisUtil.get(RedisKeyConstant.CLUB_BASE);
|
|
String clubListStr = RedisUtil.get(RedisKeyConstant.CLUB_BASE);
|
|
return JSONUtil.parseObj(clubListStr);
|
|
return JSONUtil.parseObj(clubListStr);
|
|
@@ -63,8 +99,7 @@ public class CreateClub extends NetHandler {
|
|
return clubList.stream().anyMatch(club -> club.getClubCreator().equals(userId));
|
|
return clubList.stream().anyMatch(club -> club.getClubCreator().equals(userId));
|
|
}
|
|
}
|
|
|
|
|
|
- private ZjClubPo createNewClub(String clubInfo, String userId) {
|
|
|
|
- ZjClubPo newClub = JSONUtil.parseObj(clubInfo).toBean(ZjClubPo.class);
|
|
|
|
|
|
+ private ZjClubPo createNewClub(ZjClubPo newClub , String userId) {
|
|
newClub.setClubId(UtilCore.getDateRandomId());
|
|
newClub.setClubId(UtilCore.getDateRandomId());
|
|
newClub.setClubCreator(userId);
|
|
newClub.setClubCreator(userId);
|
|
newClub.setOnlineCount(1);
|
|
newClub.setOnlineCount(1);
|
|
@@ -79,9 +114,9 @@ public class CreateClub extends NetHandler {
|
|
RedisUtil.set(RedisKeyConstant.CLUB_BASE, jsonObject.toString());
|
|
RedisUtil.set(RedisKeyConstant.CLUB_BASE, jsonObject.toString());
|
|
}
|
|
}
|
|
|
|
|
|
- private void updateUserLobbyClub(JSONObject userObject, String userId, ZjClubPo newClub) {
|
|
|
|
|
|
+ private void updateUserLobbyClub(String userId, ZjClubPo newClub) {
|
|
String userInfo = RedisUtil.get(RedisKeyConstant.USER_BASE + userId);
|
|
String userInfo = RedisUtil.get(RedisKeyConstant.USER_BASE + userId);
|
|
- userObject = JSONUtil.parseObj(userInfo);
|
|
|
|
|
|
+ JSONObject userObject = JSONUtil.parseObj(userInfo);
|
|
Object lobbyUserObj = userObject.get("lobbyUser");
|
|
Object lobbyUserObj = userObject.get("lobbyUser");
|
|
ZjUserLobbyPo lobbyUser = JSONUtil.toBean((JSONObject) lobbyUserObj, ZjUserLobbyPo.class);
|
|
ZjUserLobbyPo lobbyUser = JSONUtil.toBean((JSONObject) lobbyUserObj, ZjUserLobbyPo.class);
|
|
lobbyUser.setUserClub(newClub.getClubId());
|
|
lobbyUser.setUserClub(newClub.getClubId());
|