diff --git a/pom.xml b/pom.xml index f5145ee..4ff0679 100644 --- a/pom.xml +++ b/pom.xml @@ -71,14 +71,33 @@ json 20150729 + + + org.springframework.boot + spring-boot-starter-data-redis + 1.5.2.RELEASE + + + com.google.code.gson + gson + 2.2.4 + + + + org.springframework.boot + spring-boot-starter-web + - org.springframework.boot spring-boot-maven-plugin + + org.springframework.boot + spring-boot-maven-plugin + \ No newline at end of file diff --git a/src/main/java/com/html/deliveryGoods.html b/src/main/java/com/html/deliveryGoods.html deleted file mode 100644 index 565deeb..0000000 --- a/src/main/java/com/html/deliveryGoods.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - 发货机 - - -
- 用  户  Id: 

- 礼包类型: -

- 物品数量:

- -
- - \ No newline at end of file diff --git a/src/main/java/com/jmfy/Application.java b/src/main/java/com/jmfy/Application.java index 5f7faee..74d2c42 100644 --- a/src/main/java/com/jmfy/Application.java +++ b/src/main/java/com/jmfy/Application.java @@ -2,8 +2,10 @@ package com.jmfy; import com.jmfy.Handler.BaseHandler; import com.jmfy.Handler.ManagerManager; +import com.jmfy.redisProperties.RedisAutoConfiguration; import com.jmfy.thrift.pool.ThriftPoolUtils; import com.jmfy.util.KProducer; +import com.jmfy.util.RedisUtil; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; @@ -22,6 +24,9 @@ public class Application { // ManagerManager handlerManager = ManagerManager.getInstance(); KProducer kProducer = configurableApplicationContext.getBean(KProducer.class); KProducer.init(); + //redis初始化 + RedisAutoConfiguration redisAutoConfiguration = configurableApplicationContext.getBean(RedisAutoConfiguration.class); + RedisUtil.getInstence().init(redisAutoConfiguration.getRedisProperties()); // Map commandHanderMap = configurableApplicationContext.getBeansOfType(BaseHandler.class); // for (BaseHandler handler : commandHanderMap.values()){ // handlerManager.addHandler(handler); diff --git a/src/main/java/com/jmfy/controller/HealthController.java b/src/main/java/com/jmfy/controller/HealthController.java index 227b1e0..8a3519e 100644 --- a/src/main/java/com/jmfy/controller/HealthController.java +++ b/src/main/java/com/jmfy/controller/HealthController.java @@ -2,17 +2,16 @@ package com.jmfy.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; -@RestController +@Controller public class HealthController { private static final Logger LOGGER = LoggerFactory.getLogger(HealthController.class); - - @GetMapping(value = "/health") + @RequestMapping(value = "health") public String getStatus(){ - return "ok"; + return "deliveryGoods.html"; } } diff --git a/src/main/java/com/jmfy/controller/ManagerController.java b/src/main/java/com/jmfy/controller/ManagerController.java index 99c3a1f..be648f2 100644 --- a/src/main/java/com/jmfy/controller/ManagerController.java +++ b/src/main/java/com/jmfy/controller/ManagerController.java @@ -1,6 +1,8 @@ package com.jmfy.controller; +import com.jmfy.dto.CUserDao; import com.jmfy.dto.JsonResult; +import com.jmfy.model.CUser; import com.jmfy.thrift.idl.RPCRequestIFace; import com.jmfy.thrift.idl.Result; import com.jmfy.thrift.pool.ClientAdapterPo; @@ -12,6 +14,7 @@ import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.Enumeration; import java.util.HashMap; @@ -20,7 +23,8 @@ import java.util.HashMap; public class ManagerController { private static final Logger LOGGER = LoggerFactory.getLogger(ManagerController.class); - + @Resource + private CUserDao cuserDao; @RequestMapping(value = "/manager") public JsonResult deliveryGoods(HttpServletRequest request){ try { @@ -99,23 +103,25 @@ public class ManagerController { String channel_id = map.get("channel_id"); String token = map.get("token"); - - //TODO 根据大区id和小区id从redis找到对应服的 IP和 Port - String ip = "127.0.0.1"; - String port = "7900"; - - + CUser cUser = cuserDao.findUserInfo(gameServer,userId); + String ip; + String port; //TODO RPC 发货 Result result = null; - ClientAdapterPo rPCClient = null; - String serviceKey = getServiceKey(ServiceKey.RPCCore,ip,port); - try { - rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey); - result = rPCClient.getClient().deliveryGood(openid,userId,payitem,billno,amt,channel_id,token,serverOrder); - } catch (Exception e) { - e.printStackTrace(); - } finally { - rPCClient.returnObject(serviceKey); + if (cUser != null){ + String[] split = cUser.getCoreAddress().split(":"); + ip = split[0]; + port = split[1]; + ClientAdapterPo rPCClient = null; + String serviceKey = getServiceKey(ServiceKey.RPCCore,ip,port); + try { + rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey); + result = rPCClient.getClient().deliveryGood(openid,userId,payitem,billno,amt,channel_id,token,serverOrder); + } catch (Exception e) { + e.printStackTrace(); + } finally { + rPCClient.returnObject(serviceKey); + } } JsonResult jsonResult = new JsonResult(); diff --git a/src/main/java/com/jmfy/controller/TestController.java b/src/main/java/com/jmfy/controller/TestController.java index 73eebf9..f7cb8ca 100644 --- a/src/main/java/com/jmfy/controller/TestController.java +++ b/src/main/java/com/jmfy/controller/TestController.java @@ -1,6 +1,8 @@ package com.jmfy.controller; +import com.jmfy.dto.CUserDao; import com.jmfy.dto.JsonResult; +import com.jmfy.model.CUser; import com.jmfy.thrift.idl.RPCRequestIFace; import com.jmfy.thrift.idl.Result; import com.jmfy.thrift.pool.ClientAdapterPo; @@ -10,41 +12,47 @@ import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @RestController public class TestController { - private static final Logger LOGGER = LoggerFactory.getLogger(TestController.class); - + @Resource + private CUserDao cuserDao; @RequestMapping(value = "/test") public JsonResult deliveryGoods(HttpServletRequest request){ + int serverId = Integer.parseInt(request.getParameter("serverId")); int userId = Integer.parseInt(request.getParameter("userId")); - int itemType = Integer.parseInt(request.getParameter("itemType")); - String num = request.getParameter("itemNum"); + String payitem = request.getParameter("payitem"); + JsonResult jsonResult = new JsonResult(); + CUser cUser = cuserDao.findUserInfo(serverId,userId); + if (cUser != null){ + String[] split = cUser.getCoreAddress().split(":"); + String ip = split[0]; + String port = split[1]; + //TODO RPC 发货 + Result result = null; + ClientAdapterPo rPCClient = null; + String serviceKey = getServiceKey(ServiceKey.RPCCore,ip,port); + try { + rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey); + result = rPCClient.getClient().testdeliveryGood(userId,payitem); + } catch (Exception e) { + e.printStackTrace(); + } finally { + rPCClient.returnObject(serviceKey); + } + jsonResult.setRet(result.getResultCode()); + jsonResult.setMsg(result.getResultMsg()); + }else{ + jsonResult.setRet(100); + jsonResult.setMsg("NO user !!!!"); - int itemNum = Integer.parseInt(String.valueOf("".equals(num) ?0:num)); - - //TODO 根据大区id和小区id从redis找到对应服的 IP和 Port - String ip = "127.0.0.1"; - String port = "7900"; - //TODO RPC 发货 - Result result = null; - ClientAdapterPo rPCClient = null; - String serviceKey = getServiceKey(ServiceKey.RPCCore,ip,port); - try { - rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey); - result = rPCClient.getClient().testdeliveryGood(userId,itemType,itemNum); - } catch (Exception e) { - e.printStackTrace(); - } finally { - rPCClient.returnObject(serviceKey); } - JsonResult jsonResult = new JsonResult(); - jsonResult.setRet(result.getResultCode()); - jsonResult.setMsg(result.getResultMsg()); return jsonResult; + } public static String getServiceKey(String serviceName, String host, String port) { diff --git a/src/main/java/com/jmfy/dto/CUserDao.java b/src/main/java/com/jmfy/dto/CUserDao.java new file mode 100644 index 0000000..5c7029a --- /dev/null +++ b/src/main/java/com/jmfy/dto/CUserDao.java @@ -0,0 +1,8 @@ +package com.jmfy.dto; + +import com.jmfy.model.CUser; + +public interface CUserDao { + + CUser findUserInfo(int serverId, int userId); +} diff --git a/src/main/java/com/jmfy/dto/impl/CUserDaoImpl.java b/src/main/java/com/jmfy/dto/impl/CUserDaoImpl.java new file mode 100644 index 0000000..d7000b9 --- /dev/null +++ b/src/main/java/com/jmfy/dto/impl/CUserDaoImpl.java @@ -0,0 +1,15 @@ +package com.jmfy.dto.impl; + +import com.jmfy.dto.CUserDao; +import com.jmfy.model.CUser; +import com.jmfy.util.RedisUtil; +import org.springframework.stereotype.Component; + +@Component +public class CUserDaoImpl implements CUserDao { + @Override + public CUser findUserInfo(int serverId, int userId) { + CUser cUser= RedisUtil.getInstence().getObject(serverId + ":CUser_Key", Integer.toString(userId), CUser.class, 3600 * 24 * 7); + return cUser; + } +} diff --git a/src/main/java/com/jmfy/model/CUser.java b/src/main/java/com/jmfy/model/CUser.java new file mode 100644 index 0000000..d12bc79 --- /dev/null +++ b/src/main/java/com/jmfy/model/CUser.java @@ -0,0 +1,616 @@ +package com.jmfy.model; + +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; +import org.springframework.data.mongodb.core.mapping.Field; + +import java.util.Map; +import java.util.Set; + +/** + * Created by justin on 14-7-28. + * 用户信息实例化 + * 对应mongodb中的Document + */ +@Document(collection = "c_user") +public class CUser { + + @Id + private int id; + + @Field(value = "userName") + + private String userName; + + @Field(value = "sUserId") + private int sUserId;//模板id + + @Field(value = "permission") + private int permission; + /** + * 玩家的权限 + */ + + @Field(value = "level") + private int level;//用户等级 + + @Field(value = "exp") + private int exp;//当前经验 + + @Field(value = "vipLevel") + private int vipLevel; //用户vip等级 + + @Field(value = "img") + private String img;//头像 + + @Field(value = "createTime") + private long createTime; //创建时间 + + @Field(value = "lastLoginTime") + private long lastLoginTime; //最近一次登录 + + @Field(value = "cumulative_online_time") + private long cumulativeOnlineTime; //总累计时间 + + @Field(value = "day_online_time") + private long dayOnlineTime; //当日累计时间 + + @Field(value = "QQ_batch_time") + private long QQBatchTime;//用于QQ关怀统计时间每5分钟更新一次 + + + @Field(value = "curStamina") + private int curStamina;//体力 + + @Field(value = "maxStamina") + private int maxStamina;//体力 + + @Field(value = "gold") + private int gold;//金币 + + @Field(value = "gem") + private int gem;//宝石 + + @Field(value = "sys_gem") + private int sysGem;//宝石 + + @Field(value = "honorPoint") + private int honorPoint; // 荣誉点 + + @Field(value = "friendHeart") + private int friendHeart;//友情点 + + @Field(value = "banTime") + private long banTime;//禁言时间 + + @Field(value = "banReason") + private String banReason;//禁言原因 + + @Field(value = "vip_flush_time") + private long vipFlushTime; + + @Field(value = "systemSetting") // 保存系统设置 + private String systemSetting; + + @Field(value = "totalForces") + private int totalForces; // 总战斗力 + + @Field(value = "award_level_set") + private Set awardLevelSet; + + @Field(value = "medal") + private int medal; + + @Field(value = "area_id") + private int areaId; + + @Field(value = "shield") + private int shield; //0:未封号 1:永久封号 2:至封号时间期间封号 + + @Field(value = "shield_time") + private long shieldTime; + + @Field(value = "shield_cause") + private String shieldCause; + + @Field(value = "award_stamina_time") + private long awardStaminaTime;//获取体力值得最后时间 + + @Field(value = "vip_award_set") + private Set vipAwardSet;//vip已领取等级集合 + + @Field(value = "population_upper_limit") + private int populationUpperLimit;//关卡人口上限 + + @Field(value = "is_first_fail") + private int isFirstFail; //0:未触发 1:已触发 + + @Field(value = "novice_guide_id") + private String noviceGuideId; //新手引导BI记录Id + + @Field(value = "danmu") + private String danmu; // 是否显示弹幕 "1" 显示, "0"不显示 + + @Field(value = "take_stamina_map") + private Map takeStaminaMap; + + @Field(value = "captain_id") + private String captainId; // 设为队长的英雄id + + @Field(value = "skip_newer") + private int skipNewer; // 跳过剧情==1 + + @Field(value = "cum_login_time") + private int CumLoginTime; + + @Field(value = "online")//1在线 0不在线 + private int online; + + @Field(value = "draw_daily_time") + private int drawDailyTime;//每日抽签累计领取次数 + + @Field(value = "draw_daily_state") + private int drawDailyState;//每日抽签1可领取 0不可领取 + + @Field(value = "is_privilege") + private int isPrivilege; + + @Field(value = "privilegedLoginTime") + private long privilegedLoginTime; + + @Field(value = "recall") + private int recall; + + @Field(value = "cumulative_recharge") + private int cumulativeRecharge; + + @Field(value = "skinGold") + private int skinGold; + + @Field(value = "head") + private int head; + + @Field(value = "headFrame") + private int headFrame; + + @Field(value = "clientVersion") + private String clientVersion; + + @Field(value = "recNoticeTime") + private long recNoticeTime; + + @Field(value = "core_address") + private String coreAddress; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public int getsUserId() { + return sUserId; + } + + public void setsUserId(int sUserId) { + this.sUserId = sUserId; + } + + public int getPermission() { + return permission; + } + + public void setPermission(int permission) { + this.permission = permission; + } + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + public int getExp() { + return exp; + } + + public void setExp(int exp) { + this.exp = exp; + } + + public int getVipLevel() { + return vipLevel; + } + + public void setVipLevel(int vipLevel) { + this.vipLevel = vipLevel; + } + + public String getImg() { + return img; + } + + public void setImg(String img) { + this.img = img; + } + + public long getCreateTime() { + return createTime; + } + + public void setCreateTime(long createTime) { + this.createTime = createTime; + } + + public long getLastLoginTime() { + return lastLoginTime; + } + + public void setLastLoginTime(long lastLoginTime) { + this.lastLoginTime = lastLoginTime; + } + + public long getCumulativeOnlineTime() { + return cumulativeOnlineTime; + } + + public void setCumulativeOnlineTime(long cumulativeOnlineTime) { + this.cumulativeOnlineTime = cumulativeOnlineTime; + } + + public long getDayOnlineTime() { + return dayOnlineTime; + } + + public void setDayOnlineTime(long dayOnlineTime) { + this.dayOnlineTime = dayOnlineTime; + } + + public long getQQBatchTime() { + return QQBatchTime; + } + + public void setQQBatchTime(long QQBatchTime) { + this.QQBatchTime = QQBatchTime; + } + + public int getCurStamina() { + return curStamina; + } + + public void setCurStamina(int curStamina) { + this.curStamina = curStamina; + } + + public int getMaxStamina() { + return maxStamina; + } + + public void setMaxStamina(int maxStamina) { + this.maxStamina = maxStamina; + } + + public int getGold() { + return gold; + } + + public void setGold(int gold) { + this.gold = gold; + } + + public int getGem() { + return gem; + } + + public void setGem(int gem) { + this.gem = gem; + } + + public int getSysGem() { + return sysGem; + } + + public void setSysGem(int sysGem) { + this.sysGem = sysGem; + } + + public int getHonorPoint() { + return honorPoint; + } + + public void setHonorPoint(int honorPoint) { + this.honorPoint = honorPoint; + } + + public int getFriendHeart() { + return friendHeart; + } + + public void setFriendHeart(int friendHeart) { + this.friendHeart = friendHeart; + } + + public long getBanTime() { + return banTime; + } + + public void setBanTime(long banTime) { + this.banTime = banTime; + } + + public String getBanReason() { + return banReason; + } + + public void setBanReason(String banReason) { + this.banReason = banReason; + } + + public long getVipFlushTime() { + return vipFlushTime; + } + + public void setVipFlushTime(long vipFlushTime) { + this.vipFlushTime = vipFlushTime; + } + + public String getSystemSetting() { + return systemSetting; + } + + public void setSystemSetting(String systemSetting) { + this.systemSetting = systemSetting; + } + + public int getTotalForces() { + return totalForces; + } + + public void setTotalForces(int totalForces) { + this.totalForces = totalForces; + } + + public Set getAwardLevelSet() { + return awardLevelSet; + } + + public void setAwardLevelSet(Set awardLevelSet) { + this.awardLevelSet = awardLevelSet; + } + + public int getMedal() { + return medal; + } + + public void setMedal(int medal) { + this.medal = medal; + } + + public int getAreaId() { + return areaId; + } + + public void setAreaId(int areaId) { + this.areaId = areaId; + } + + public int getShield() { + return shield; + } + + public void setShield(int shield) { + this.shield = shield; + } + + public long getShieldTime() { + return shieldTime; + } + + public void setShieldTime(long shieldTime) { + this.shieldTime = shieldTime; + } + + public String getShieldCause() { + return shieldCause; + } + + public void setShieldCause(String shieldCause) { + this.shieldCause = shieldCause; + } + + public long getAwardStaminaTime() { + return awardStaminaTime; + } + + public void setAwardStaminaTime(long awardStaminaTime) { + this.awardStaminaTime = awardStaminaTime; + } + + public Set getVipAwardSet() { + return vipAwardSet; + } + + public void setVipAwardSet(Set vipAwardSet) { + this.vipAwardSet = vipAwardSet; + } + + public int getPopulationUpperLimit() { + return populationUpperLimit; + } + + public void setPopulationUpperLimit(int populationUpperLimit) { + this.populationUpperLimit = populationUpperLimit; + } + + public int getIsFirstFail() { + return isFirstFail; + } + + public void setIsFirstFail(int isFirstFail) { + this.isFirstFail = isFirstFail; + } + + public String getNoviceGuideId() { + return noviceGuideId; + } + + public void setNoviceGuideId(String noviceGuideId) { + this.noviceGuideId = noviceGuideId; + } + + public String getDanmu() { + return danmu; + } + + public void setDanmu(String danmu) { + this.danmu = danmu; + } + + public Map getTakeStaminaMap() { + return takeStaminaMap; + } + + public void setTakeStaminaMap(Map takeStaminaMap) { + this.takeStaminaMap = takeStaminaMap; + } + + public String getCaptainId() { + return captainId; + } + + public void setCaptainId(String captainId) { + this.captainId = captainId; + } + + public int getSkipNewer() { + return skipNewer; + } + + public void setSkipNewer(int skipNewer) { + this.skipNewer = skipNewer; + } + + public int getCumLoginTime() { + return CumLoginTime; + } + + public void setCumLoginTime(int cumLoginTime) { + CumLoginTime = cumLoginTime; + } + + public int getOnline() { + return online; + } + + public void setOnline(int online) { + this.online = online; + } + + public int getDrawDailyTime() { + return drawDailyTime; + } + + public void setDrawDailyTime(int drawDailyTime) { + this.drawDailyTime = drawDailyTime; + } + + public int getDrawDailyState() { + return drawDailyState; + } + + public void setDrawDailyState(int drawDailyState) { + this.drawDailyState = drawDailyState; + } + + public int getIsPrivilege() { + return isPrivilege; + } + + public void setIsPrivilege(int isPrivilege) { + this.isPrivilege = isPrivilege; + } + + public long getPrivilegedLoginTime() { + return privilegedLoginTime; + } + + public void setPrivilegedLoginTime(long privilegedLoginTime) { + this.privilegedLoginTime = privilegedLoginTime; + } + + public int getRecall() { + return recall; + } + + public void setRecall(int recall) { + this.recall = recall; + } + + public int getCumulativeRecharge() { + return cumulativeRecharge; + } + + public void setCumulativeRecharge(int cumulativeRecharge) { + this.cumulativeRecharge = cumulativeRecharge; + } + + public int getSkinGold() { + return skinGold; + } + + public void setSkinGold(int skinGold) { + this.skinGold = skinGold; + } + + public int getHead() { + return head; + } + + public void setHead(int head) { + this.head = head; + } + + public int getHeadFrame() { + return headFrame; + } + + public void setHeadFrame(int headFrame) { + this.headFrame = headFrame; + } + + public String getClientVersion() { + return clientVersion; + } + + public void setClientVersion(String clientVersion) { + this.clientVersion = clientVersion; + } + + public long getRecNoticeTime() { + return recNoticeTime; + } + + public void setRecNoticeTime(long recNoticeTime) { + this.recNoticeTime = recNoticeTime; + } + + public String getCoreAddress() { + return coreAddress; + } + + public void setCoreAddress(String coreAddress) { + this.coreAddress = coreAddress; + } +} diff --git a/src/main/java/com/jmfy/redisProperties/RedisAutoConfiguration.java b/src/main/java/com/jmfy/redisProperties/RedisAutoConfiguration.java new file mode 100644 index 0000000..ca71b9a --- /dev/null +++ b/src/main/java/com/jmfy/redisProperties/RedisAutoConfiguration.java @@ -0,0 +1,24 @@ +package com.jmfy.redisProperties; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * Created by Administrator on 2016/3/17. + */ +@Configuration(value = "redisAutoConfiguration") +@EnableConfigurationProperties(RedisProperties.class) +public class RedisAutoConfiguration { + + @Autowired + private com.jmfy.redisProperties.RedisProperties RedisProperties; + + public com.jmfy.redisProperties.RedisProperties getRedisProperties() { + return RedisProperties; + } + + public void setRedisProperties(com.jmfy.redisProperties.RedisProperties RedisProperties) { + RedisProperties = RedisProperties; + } +} diff --git a/src/main/java/com/jmfy/redisProperties/RedisProperties.java b/src/main/java/com/jmfy/redisProperties/RedisProperties.java new file mode 100644 index 0000000..9b0bb10 --- /dev/null +++ b/src/main/java/com/jmfy/redisProperties/RedisProperties.java @@ -0,0 +1,189 @@ +package com.jmfy.redisProperties; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Created by Administrator on 2016/3/17. + */ +@ConfigurationProperties(prefix = "spring.redis") +public class RedisProperties { + + private String host; + + private int port; + + private String password; + + private int expireTime; // 过期时间,单位分钟 + private int database ; + //连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true + private boolean blockWhenExhausted; + //是否启用pool的jmx管理功能, 默认true + private boolean jmxEnabled; + //是否启用后进先出, 默认true + private boolean lifo; + //最大空闲连接数, 默认8个 + private int maxIdle; + //最大连接数, 默认8个 + private int maxTotal; + //获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 + private int maxWaitMillis; + //逐出连接的最小空闲时间 默认1800000毫秒(30分钟) + private long minEvictableIdleTimeMillis; + //最小空闲连接数, 默认0 + private int minIdle; + //每次逐出检查时 逐出的最大数目 如果为负数就是 : 1/abs(n), 默认3 + private int numTestsPerEvictionRun; + //对象空闲多久后逐出, 当空闲时间>该值 且 空闲连接>最大空闲数 时直接逐出,不再根据MinEvictableIdleTimeMillis判断 (默认逐出策略) + private long softMinEvictableIdleTimeMillis; + //在获取连接的时候检查有效性, 默认false + private boolean testOnBorrow; + //在空闲时检查有效性, 默认false + private boolean testWhileIdle; + //逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1 + private int timeBetweenEvictionRunsMillis; + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getPassword() { + return password; + } + + public int getExpireTime() { + return expireTime; + } + + public void setExpireTime(int expireTime) { + this.expireTime = expireTime; + } + + public void setPassword(String password) { + this.password = password; + } + + public boolean isBlockWhenExhausted() { + return blockWhenExhausted; + } + + public void setBlockWhenExhausted(boolean blockWhenExhausted) { + this.blockWhenExhausted = blockWhenExhausted; + } + + public boolean isJmxEnabled() { + return jmxEnabled; + } + + public void setJmxEnabled(boolean jmxEnabled) { + this.jmxEnabled = jmxEnabled; + } + + public boolean isLifo() { + return lifo; + } + + public void setLifo(boolean lifo) { + this.lifo = lifo; + } + + public int getMaxIdle() { + return maxIdle; + } + + public void setMaxIdle(int maxIdle) { + this.maxIdle = maxIdle; + } + + public int getMaxTotal() { + return maxTotal; + } + + public void setMaxTotal(int maxTotal) { + this.maxTotal = maxTotal; + } + + public int getMaxWaitMillis() { + return maxWaitMillis; + } + + public void setMaxWaitMillis(int maxWaitMillis) { + this.maxWaitMillis = maxWaitMillis; + } + + public long getMinEvictableIdleTimeMillis() { + return minEvictableIdleTimeMillis; + } + + public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) { + this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; + } + + public int getMinIdle() { + return minIdle; + } + + public void setMinIdle(int minIdle) { + this.minIdle = minIdle; + } + + public int getNumTestsPerEvictionRun() { + return numTestsPerEvictionRun; + } + + public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) { + this.numTestsPerEvictionRun = numTestsPerEvictionRun; + } + + public long getSoftMinEvictableIdleTimeMillis() { + return softMinEvictableIdleTimeMillis; + } + + public void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) { + this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis; + } + + public boolean isTestOnBorrow() { + return testOnBorrow; + } + + public void setTestOnBorrow(boolean testOnBorrow) { + this.testOnBorrow = testOnBorrow; + } + + public boolean isTestWhileIdle() { + return testWhileIdle; + } + + public void setTestWhileIdle(boolean testWhileIdle) { + this.testWhileIdle = testWhileIdle; + } + + public int getTimeBetweenEvictionRunsMillis() { + return timeBetweenEvictionRunsMillis; + } + + public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) { + this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; + } + + public int getDatabase() { + return database; + } + + public void setDatabase(int database) { + this.database = database; + } +} diff --git a/src/main/java/com/jmfy/redisProperties/RedisUserKey.java b/src/main/java/com/jmfy/redisProperties/RedisUserKey.java new file mode 100644 index 0000000..325ce32 --- /dev/null +++ b/src/main/java/com/jmfy/redisProperties/RedisUserKey.java @@ -0,0 +1,34 @@ +package com.jmfy.redisProperties; + +public class RedisUserKey { + + public final static String Delimiter_colon = ":"; + public final static String Delimiter_len = "|"; + public final static String Delimiter_code = "#"; + public final static String CUser_Key = "CUser_Key"; + public final static String CItem_Key = "CItem_Key"; + public final static String KICK_Old_key = "Kick_Old_Key"; + public final static String CMail_Key = "CMail_Key"; + public final static String Barage_Key = "Barage_Key"; + public final static String Title_Key = "Title_Key"; + public final static String Clear_Chat_Key = "Clear_Chat_Key"; + public final static String SendAllSVR_key = "SendAllSVR_key"; + public final static String Clight_Key = "Clight_Key"; + public final static String Notice_key = "Notice_key"; + public final static String HeroRandSwitch = "HeroRandSwitch"; + public final static String Server_GM = "Server_GM"; + /** value key:roleUid,value:CBanInfo*/ + public final static String CBanInfo_Key = "CBanInfo_Key"; + + public final static String BlackList_key = "BlackList_key"; + public final static String UserInfo_key = "UserInfo_key"; + public final static String CTeam_Pos_Key = "CTeam_Pos_Key"; + /** + * hash key:roleUid,hashKey:heroUid,value:cHero + */ + public final static String CHero_Key = "CHero_Key"; + + public final static String Shero_Rand_Switch = "Shero_Rand_Switch"; + public final static String Shero_Rand_Template = "Shero_Rand_Template"; + public final static String Login_Server_Info = "Login_Server_Info"; +} diff --git a/src/main/java/com/jmfy/util/RedisUtil.java b/src/main/java/com/jmfy/util/RedisUtil.java new file mode 100644 index 0000000..fc68ef3 --- /dev/null +++ b/src/main/java/com/jmfy/util/RedisUtil.java @@ -0,0 +1,282 @@ +package com.jmfy.util; + +import com.google.gson.Gson; +import com.jmfy.redisProperties.RedisProperties; +import com.jmfy.redisProperties.RedisUserKey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.redis.RedisConnectionFailureException; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.redis.core.StringRedisTemplate; +import redis.clients.jedis.JedisPoolConfig; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + + +/** + * 用来储存返回改前端的respose的实体 当断线重连时下次请求直接返回缓存中的数据 + *

+ * 添加储存玩家常用数据 + */ +public class RedisUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(RedisUtil.class); + + private static String separator = "_"; + + private final static String Disconnected = "Disconnected_"; + + private StringRedisTemplate redisObjectTemplate; + private RedisUtil() { + } + + private static RedisUtil redisUtil; + private Gson gson = new Gson(); + public static RedisUtil getInstence() { + if (redisUtil == null) { + redisUtil = InnerClass.SINGLETON; + } + return redisUtil; + } + + public Set getKeys(String key) { + return redisObjectTemplate.keys("*"+key+ "*"); + } + + + private static class InnerClass { + private static final RedisUtil SINGLETON = new RedisUtil(); + } + + public void init(RedisProperties redisProperties) { + try { + //initStringCacheDb(0, redisProperties); + initUserCacheDb(0,redisProperties); + LOGGER.info("redis init .."); + + } catch (Exception e) { + LOGGER.error("------------------Redis 未启动------------------"); + } + + + } + + private void initUserCacheDb(int dbIndex, RedisProperties redisProperties) { + //实例化链接工厂 + JedisConnectionFactory connectionFactory = new JedisConnectionFactory(); + //设置host + connectionFactory.setHostName(redisProperties.getHost()); + //设置端口 + connectionFactory.setPort(redisProperties.getPort()); + // 分库 + connectionFactory.setDatabase(dbIndex); + //设置密码 + connectionFactory.setPassword(redisProperties.getPassword()); + // 设置参数 + JedisPoolConfig config = new JedisPoolConfig(); + //连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true + config.setBlockWhenExhausted(true); + //设置的逐出策略类名, 默认DefaultEvictionPolicy(当连接超过最大空闲时间,或连接数超过最大空闲连接数) + config.setEvictionPolicyClassName("org.apache.commons.pool2.impl.DefaultEvictionPolicy"); + //是否启用pool的jmx管理功能, 默认true + config.setJmxEnabled(true); + //MBean ObjectName = new ObjectName("org.apache.commons.pool2:type=GenericObjectPool,name=" + "pool" + i); 默 认为"pool", JMX不熟,具体不知道是干啥的...默认就好. + config.setJmxNamePrefix("pool"); + //是否启用后进先出, 默认true + config.setLifo(true); + //最大空闲连接数, 默认8个 + config.setMaxIdle(8); + //最大连接数, 默认8个 + config.setMaxTotal(1000); + //获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 + config.setMaxWaitMillis(-1); + //逐出连接的最小空闲时间 默认1800000毫秒(30分钟) + config.setMinEvictableIdleTimeMillis(1800000); + //最小空闲连接数, 默认0 + config.setMinIdle(0); + //每次逐出检查时 逐出的最大数目 如果为负数就是 : 1/abs(n), 默认3 + config.setNumTestsPerEvictionRun(3); + //对象空闲多久后逐出, 当空闲时间>该值 且 空闲连接>最大空闲数 时直接逐出,不再根据MinEvictableIdleTimeMillis判断 (默认逐出策略) + config.setSoftMinEvictableIdleTimeMillis(1800000); + //在获取连接的时候检查有效性, 默认false + config.setTestOnBorrow(false); + //在空闲时检查有效性, 默认false + config.setTestWhileIdle(false); + //逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1 + config.setTimeBetweenEvictionRunsMillis(-1); + + connectionFactory.setPoolConfig(config); + + //初始化connectionFactory + connectionFactory.afterPropertiesSet(); + //实例化 + redisObjectTemplate = new StringRedisTemplate(connectionFactory); +// redisObjectTemplate.setConnectionFactory(connectionFactory); + redisObjectTemplate.afterPropertiesSet(); + } + /** + * 获取Object + * + * @param key + * @return + */ + public T getObject(String type, String key, Class clazz, int expireTime) { + try { + String valueStr = redisObjectTemplate.opsForValue().get(type + RedisUserKey.Delimiter_colon + key); + if (valueStr == null) { + return null; + } + if(expireTime > 0){ + redisObjectTemplate.expire(type+key, expireTime, TimeUnit.SECONDS); + } + return gson.fromJson(valueStr, clazz); + } catch (RedisConnectionFailureException e) { + LOGGER.error("------------------Redis 连接失败------------------"); + } + return null; + } + public void delHash(String type, int key, String mapId) { + redisObjectTemplate.opsForHash().delete(type+":"+key, mapId); + } + /** + * 更新Object + * + * @param key + * @param value + */ + public void putObject(String type, String key, T value, int expireTime) { + try { + String valueStr = gson.toJson(value); + redisObjectTemplate.opsForValue().set(type + RedisUserKey.Delimiter_colon + key, valueStr); + if (expireTime > 0) { + redisObjectTemplate.expire(type + RedisUserKey.Delimiter_colon + key, expireTime, TimeUnit.SECONDS); + } + } catch (RedisConnectionFailureException e) { + LOGGER.error("------------------Redis 连接失败------------------"); + delObject(type, key); + return; + } + } + /** + * 更新Map某hashKey + * + * @param type + * @param key + * @param mapKey + * @param value + */ + public void putMapEntry(String type, String key, String mapKey, T value, int expireTime) { + try { + String valueStr = gson.toJson(value); + redisObjectTemplate.opsForHash().put(type + RedisUserKey.Delimiter_colon + key, mapKey, valueStr); + if (expireTime > 0) { + redisObjectTemplate.expire(type + RedisUserKey.Delimiter_colon + key, expireTime, TimeUnit.SECONDS); + } + } catch (RedisConnectionFailureException e) { + LOGGER.error("------------------Redis 连接失败------------------"); + delObject(type, key); + } + } + /** + * 删除Map中某hashKey值 + * + * @param type + * @param key + * @param mapKey + */ + public void delMapKey(String type, String key, String... mapKey) { + try { + redisObjectTemplate.opsForHash().delete(type + RedisUserKey.Delimiter_colon + key, mapKey); + } catch (RedisConnectionFailureException e) { + LOGGER.error("------------------Redis 连接失败------------------"); + } + } + /** + * 删除Object + * + * @param type + * @param key + */ + public void delObject(String type, String key) { + try { + redisObjectTemplate.delete(type + RedisUserKey.Delimiter_colon + key); + } catch (RedisConnectionFailureException e) { + LOGGER.error("------------------Redis 连接失败------------------"); + } catch (Exception e) { + redisObjectTemplate.delete(type + RedisUserKey.Delimiter_colon + key); + } + } + /** + * 获取Map + * + * @param key + * @return + */ + public Map getMap(String key, Class clazz,int expireTime) { + try { + Map reslut = new HashMap<>(); + Map map = redisObjectTemplate.opsForHash().entries(key); + for (Map.Entry entry : map.entrySet()) { + reslut.put((String) entry.getKey(), gson.fromJson((String) entry.getValue(), clazz)); + } + if(expireTime > 0){ + redisObjectTemplate.expire(key, expireTime, TimeUnit.SECONDS); + } + return reslut; + } catch (RedisConnectionFailureException e) { + LOGGER.error("------------------Redis 连接失败------------------"); + } + return null; + } + /** + * 获取Map中某hashKey值 + * + * @param type + * @param key + * @param mapKey + * @return + */ + public T getMapValue(String type, String key, String mapKey, Class clazz, int expireTime) { + try { + String valueStr = (String) redisObjectTemplate.opsForHash().get(type+key, mapKey); + if (valueStr == null) { + return null; + } +// if(expireTime > 0){ +// redisObjectTemplate.expire(getKey(type, key), expireTime, TimeUnit.SECONDS); +// } + return gson.fromJson(valueStr, clazz); + } catch (RedisConnectionFailureException e) { + e.printStackTrace(); + LOGGER.error("------------------Redis 连接失败------------------"); + } + return null; + } + /** + * 更新Map + * + * @param type + * @param key + * @param value + */ + public void putMap(String type, String key, Map value, int expireTime) { + try { + Map map = new HashMap<>(); + for (Map.Entry entry : value.entrySet()) { + String valueStr = gson.toJson(entry.getValue()); + map.put(entry.getKey(), valueStr); + } + redisObjectTemplate.opsForHash().putAll(type+key, map); +// if (expireTime > 0) { +// redisObjectTemplate.expire(getKey(type, key), expireTime, TimeUnit.SECONDS); +// } + } catch (RedisConnectionFailureException e) { + e.printStackTrace(); + LOGGER.error("------------------Redis 连接失败------------------"); + delObject(type, key); + } + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 5a06eb8..4673417 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,6 +2,13 @@ server.port=9991 ##contextPath server.context-path=/delivery + + +# redis config +spring.redis.host = 192.168.0.169 +spring.redis.port = 6379 +spring.redis.password = +spring.redis.expireTime = -1 # #spring.data.mongodb.host=192.168.0.170 #spring.data.mongodb.port=27017 @@ -11,4 +18,4 @@ server.context-path=/delivery #spring.data.mongodb.username=game #spring.data.mongodb.password=ysj0912 #spring.data.mongodb.authentication-database=admin -#spring.data.mongodb.grid-fs-database=ysj-pr1-game \ No newline at end of file +#spring.data.mongodb.grid-fs-database=ysj-pr1-game diff --git a/src/main/resources/static/deliveryGoods.html b/src/main/resources/static/deliveryGoods.html new file mode 100644 index 0000000..325a56d --- /dev/null +++ b/src/main/resources/static/deliveryGoods.html @@ -0,0 +1,15 @@ + + + + + 发货机 + + +

+ 服务器id:

+ 用  户  Id: 

+ 礼包内容:注意格式:itemid#itemNum#itemType|itemid#itemNum#itemType...

+ +
+ + \ No newline at end of file diff --git a/src/main/thrift/idl/core.thrift b/src/main/thrift/idl/core.thrift index 2e13c05..bd20b12 100644 --- a/src/main/thrift/idl/core.thrift +++ b/src/main/thrift/idl/core.thrift @@ -10,5 +10,5 @@ service RPCRequestIFace{ Result deliveryGood(1:string openid, 2:i32 userId, 3:string payitem, 4:string billno, 5:string amt, 6:string channel_id, 7:string token, 8:string serverOrder) throws (1:common.InvalidOperException ouch); - Result testdeliveryGood(1:i32 userId, 2:i32 itemType ,3:i32 itemNum) throws (1:common.InvalidOperException ouch); + Result testdeliveryGood(1:i32 userId, 2:string payitem) throws (1:common.InvalidOperException ouch); } \ No newline at end of file