package com.jmfy.handler.impl; import com.alibaba.fastjson.JSONObject; import com.jmfy.cenum.CommandEnm; import com.jmfy.dao.GSUserDao; import com.jmfy.dao.ServerListDao; import com.jmfy.dao.ServerRoleInfoDao; import com.jmfy.dao.ServerRoleListDao; import com.jmfy.handler.BaseHandler; import com.jmfy.handler.MarkedInfo; import com.jmfy.model.CoreServerList; import com.jmfy.model.CoreUserInfo; import com.jmfy.model.GSUser; import com.jmfy.modelVo.*; import com.jmfy.util.SDK37Constans; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; import java.util.Map; @Component public class ServerRoleInfoHandler extends BaseHandler { private org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ServerRoleInfoHandler.class); @Resource private ServerRoleInfoDao serverRoleInfoDao; @Resource private GSUserDao gsUserDao; @Resource private ServerListDao serverListDao; @Override public BaseVo execute(JSONObject jsonObject) throws Exception { long time = 0; String uid = ""; String dsid = ""; String roleId = ""; int type = 0; String sign = ""; if (jsonObject.containsKey("timestamp") && jsonObject.containsKey("uid") && jsonObject.containsKey("roleid") && jsonObject.containsKey("partition") && jsonObject.containsKey("type") && jsonObject.containsKey("sign")) { time = jsonObject.getLong("timestamp"); uid = jsonObject.getString("uid"); dsid = jsonObject.getString("partition"); roleId = jsonObject.getString("roleid"); type = jsonObject.getIntValue("type"); sign = jsonObject.getString("sign"); } else { throw new Exception("缺少参数"); } int date = 0; if (type == 0 || type == 2) { if (jsonObject.containsKey("date")) { date = jsonObject.getIntValue("date"); } else { throw new Exception("缺少参数"); } } int begin = 0; int end = 0; if (type == 0 || type == 3 || type == 4) { if (jsonObject.containsKey("begin") && jsonObject.containsKey("end")) { begin = jsonObject.getIntValue("begin"); end = jsonObject.getIntValue("end"); } else { throw new Exception("缺少参数"); } } if (!validSign(String.valueOf(getPid()) + String.valueOf(getGid()) + String.valueOf(time) + String.valueOf(uid) + String.valueOf(dsid) + String.valueOf(roleId) + String.valueOf(type) + SDK37Constans.appkey, sign)) { throw new Exception("签名错误"); } BaseVo baseVo = new BaseVo(); MarkedVo marked = MarkedInfo.getMarkedVo(jsonObject); LOGGER.info("-->areaId={},platId={},openid={},serverId={}", marked.getAreaId(), marked.getPlatId(), marked.getOpenId(), marked.getPartition()); JSONObject jsonObject1 = new JSONObject(); CoreUserInfo coreUserInfo = serverRoleInfoDao.findServerRoleInfo(marked, Integer.valueOf(roleId)); if (coreUserInfo == null) { throw new Exception("帐号不存在"); } else { MarkedVo marked1 = new MarkedVo(); marked1.setOpenId(coreUserInfo.getOpenId()); marked1.setPartition(String.valueOf(coreUserInfo.getServerid())); CoreServerList coreServerList = serverListDao.findServer(marked1); if (null == coreServerList) { throw new Exception("应用不存在"); } GSUser gsUser = gsUserDao.findUserInfo(marked1, coreUserInfo.getUid()); if (null == gsUser) { throw new Exception("帐号不存在"); } jsonObject1.put("dsid", String.valueOf(coreUserInfo.getServerid())); jsonObject1.put("dsname", coreServerList.getName()); jsonObject1.put("droleid", String.valueOf(gsUser.getId())); jsonObject1.put("last_login_time", String.valueOf(gsUser.getPlayerManager().getLoginTime() / 1000)); if (type == 0 || type == 2) { Map onlineTimeOfDay = gsUser.getPlayerManager().getOnlineTimeOfDay(); long sumTime = 0; if (onlineTimeOfDay != null && onlineTimeOfDay.containsKey(date)) { sumTime = onlineTimeOfDay.get(date); } else { sumTime = 0; } jsonObject1.put("online_time", sumTime); //todo 修改记录数据 } jsonObject1.put("paynum", String.valueOf(gsUser.getPlayerManager().getRechargeInfo().getSaveAmt())); if (type == 5) { jsonObject1.put("fight_value", String.valueOf(gsUser.getPlayerManager().getMaxForce())); jsonObject1.put("level", String.valueOf(gsUser.getPlayerManager().getLevel())); } if (type == 6) { jsonObject1.put("level", String.valueOf(gsUser.getPlayerManager().getLevel())); jsonObject1.put("profession", ""); jsonObject1.put("profession_name", ""); } } baseVo.setData(jsonObject1); baseVo.setState(1); baseVo.setMsg("成功"); return baseVo; } @Override public String getRequestURI() { return "serverroleinfo"; } }