用户物品

back_recharge
gaojie 2019-01-18 10:10:12 +08:00
parent 5012bc0fd0
commit 7fb418baf6
4 changed files with 64 additions and 20 deletions

View File

@ -1,13 +1,25 @@
package com.ljsd.jieling.handler;
import com.ljsd.jieling.logic.dao.Item;
import com.ljsd.jieling.logic.dao.ItemManager;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.protocols.PlayerInfoProto;
import com.ljsd.jieling.util.CBean2Proto;
import com.ljsd.jieling.util.ItemUtil;
import com.ljsd.jieling.util.MessageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Component
public class GetAllItemHandler extends BaseHandler {
@ -26,9 +38,18 @@ public class GetAllItemHandler extends BaseHandler {
int msgIndex = netData.getIndex();
PlayerInfoProto.PlayerInfo.GetItemInfoRequest getItemInfoRequest
= PlayerInfoProto.PlayerInfo.GetItemInfoRequest.parseFrom(netData.parseClientProtoNetData());
LOGGER.info("processMessage->uid={},token={},msgId={},msgIndex={},messageNum={},messageStr={}",
userId, token,msgId,msgIndex,getItemInfoRequest.getNum(),getItemInfoRequest.getStr());
User user = UserManager.getUserForLogin(userId);
List<CommonProto.Common.Item> itemList = ItemUtil.getAllItem(user);
PlayerInfoProto.PlayerInfo.GetItemInfoResponse getItemInfoResponse = PlayerInfoProto.PlayerInfo.GetItemInfoResponse.newBuilder()
.addAllItemlist(itemList)
.build();
try {
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.GET_ITEMINFO_RESPONSE_VALUE, getItemInfoResponse, true);
LOGGER.info("back to client!");
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -5,9 +5,10 @@ import com.ljsd.jieling.config.SItem;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class ItemManager extends MongoBase {
private Map<Integer, Item> itemMap;
private Map<Integer, Item> itemMap = new ConcurrentHashMap<>();
public ItemManager() {
itemMap = new HashMap();

View File

@ -5,9 +5,12 @@ import com.ljsd.jieling.logic.dao.Item;
import com.ljsd.jieling.logic.dao.ItemManager;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.protocols.CommonProto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ItemUtil {
@ -55,4 +58,17 @@ public class ItemUtil {
}
}
public static List<CommonProto.Common.Item> getAllItem(User user){
List<CommonProto.Common.Item> itemList = new ArrayList<>();
ItemManager itemManager = user.getItemManager();
Map<Integer, Item> itemMap = itemManager.getItemMap();
if (itemMap.size() !=0 ){
for (Map.Entry<Integer, Item> entry :itemMap.entrySet()){
itemList.add(CBean2Proto.getItem(entry.getValue()));
}
}
return itemList;
}
}

View File

@ -72,21 +72,7 @@ public class ExcelUtils {
Cell cell = row.getCell(j);
if (cell == null){
Cell cell1 = row4.getCell(j);
if (cell1==null){
String in = getIn(row2.getCell(j).toString());
if (info.length() == 0){
info = info.append(in);
}else{
info.append("\t").append(in);
}
}else{
cellData = getCellFormatValue(cell1);
if (info.length() == 0){
info = info.append(cellData);
}else{
info.append("\t").append(cellData);
}
}
info = getStringBuilder(row2, info, j, cell1);
}else{
if (getCellFormatValue(row1.getCell(j)).toString().isEmpty()){
continue;
@ -111,6 +97,26 @@ public class ExcelUtils {
out.close();
}
private static StringBuilder getStringBuilder(Row row2, StringBuilder info, int j, Cell cell1) {
Object cellData;
if (cell1==null){
String in = getIn(row2.getCell(j).toString());
if (info.length() == 0){
info = info.append(in);
}else{
info.append("\t").append(in);
}
}else{
cellData = getCellFormatValue(cell1);
if (info.length() == 0){
info = info.append(cellData);
}else{
info.append("\t").append(cellData);
}
}
return info;
}
private static String getIn(String row2) {
String str = "";
switch (row2) {