Search in sources :

Example 1 with UserService

use of com.code.server.db.Service.UserService in project summer by foxsugar.

the class CenterService method saveUser.

private static void saveUser() {
    Set<String> users = RedisManager.getUserRedisService().getSaveUsers();
    if (users != null) {
        UserService userService = SpringUtil.getBean(UserService.class);
        Set<String> removeList = new HashSet<>();
        users.forEach(userId -> {
            long uid = Long.valueOf(userId);
            UserBean userBean = RedisManager.getUserRedisService().getUserBean(uid);
            User user = GameUserService.userBean2User(userBean);
            // 保存
            userService.save(user);
            removeList.add(userId);
        });
        // 批量删除 需要保存的玩家
        if (removeList.size() > 0) {
            RedisManager.getUserRedisService().removeSaveUser(removeList.toArray());
        }
    }
    // 俱乐部 保存
    ClubManager.getInstance().saveAll();
}
Also used : User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) UserService(com.code.server.db.Service.UserService) HashSet(java.util.HashSet)

Example 2 with UserService

use of com.code.server.db.Service.UserService in project summer by foxsugar.

the class GameRpcHandler method exchange.

@Override
public void exchange(Order order, AsyncMethodCallback<Integer> resultHandler) throws TException {
    long userId = order.getUserId();
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    if (userBean == null) {
        UserService userService = SpringUtil.getBean(UserService.class);
        User user = userService.getUserByUserId(userId);
        user.setMoney(user.getMoney() - order.getNum());
        user.setGold(user.getGold() + order.getNum());
        userService.save(user);
    } else {
        UserRedisService userRedisService = RedisManager.getUserRedisService();
        userRedisService.addUserMoney(userId, -order.getNum());
        RedisManager.addGold(userId, order.getNum());
    }
    resultHandler.onComplete(0);
}
Also used : User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) UserService(com.code.server.db.Service.UserService) UserRedisService(com.code.server.redis.service.UserRedisService)

Example 3 with UserService

use of com.code.server.db.Service.UserService in project summer by foxsugar.

the class GameRpcHandler method getUserInfo.

@Override
public void getUserInfo(long userId, AsyncMethodCallback<com.code.server.rpc.idl.User> resultHandler) throws TException {
    com.code.server.rpc.idl.User userRep = new com.code.server.rpc.idl.User();
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    if (userBean == null) {
        UserService userService = SpringUtil.getBean(UserService.class);
        User user = userService.getUserByUserId(userId);
        if (user != null) {
            userRep.setId(userId);
            userRep.setGold(user.getGold());
            userRep.setMoney(user.getMoney());
            userRep.setUsername(user.getUsername());
        }
    } else {
        userRep.setId(userBean.getId());
        userRep.setGold(userBean.getGold());
        userRep.setMoney(userBean.getMoney());
        userRep.setUsername(userBean.getUsername());
    }
    resultHandler.onComplete(userRep);
}
Also used : com.code.server.rpc.idl(com.code.server.rpc.idl) User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) UserService(com.code.server.db.Service.UserService)

Example 4 with UserService

use of com.code.server.db.Service.UserService in project summer by foxsugar.

the class GameRpcNewHandler method bindReferee.

@Override
public void bindReferee(long userId, int referee, AsyncMethodCallback<Integer> resultHandler) throws TException {
    logger.info("绑定邀请码 userId : " + userId);
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    if (userBean != null) {
        userBean.setReferee(referee);
        RedisManager.getUserRedisService().updateUserBean(userBean.getId(), userBean);
    } else {
        UserService userService = SpringUtil.getBean(UserService.class);
        User user = userService.getUserByUserId(userId);
        user.setReferee(referee);
        userService.save(user);
    }
    resultHandler.onComplete(0);
}
Also used : User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) UserService(com.code.server.db.Service.UserService)

Example 5 with UserService

use of com.code.server.db.Service.UserService in project summer by foxsugar.

the class GameRpcNewHandler method charge.

@Override
public void charge(Order order, AsyncMethodCallback<Integer> resultHandler) throws TException {
    long userId = order.getUserId();
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    UserService userService = SpringUtil.getBean(UserService.class);
    User user = userService.getUserByUserId(userId);
    String name = "";
    if (userBean == null) {
        if (user != null) {
            if (order.getType() == ChargeType.money.getValue()) {
                user.setMoney(user.getMoney() + order.getNum());
            } else if (order.getType() == ChargeType.gold.getValue()) {
                user.setGold(user.getGold() + order.getNum());
            }
            userService.save(user);
            name = user.getUsername();
        } else {
            resultHandler.onComplete(RPCError.NO_USER.getValue());
            return;
        }
    } else {
        // 在redis里
        name = userBean.getUsername();
        if (order.getType() == ChargeType.money.getValue()) {
            double nowMoney = RedisManager.getUserRedisService().addUserMoney(userId, order.getNum());
            user.setMoney(nowMoney);
            userService.save(user);
        } else if (order.getType() == ChargeType.gold.getValue()) {
            double nowGold = RedisManager.getUserRedisService().addUserGold(userId, order.getNum());
            user.setGold(nowGold);
            userService.save(user);
        }
    }
    // 充值记录
    if (order.getAgentId() != 0 && order.getType() == ChargeType.money.getValue()) {
        Charge charge = new Charge();
        charge.setOrderId("" + IdWorker.getDefaultInstance().nextId());
        charge.setUserid(order.getUserId());
        charge.setUsername(name);
        charge.setCreatetime(new Date());
        charge.setCallbacktime(new Date());
        charge.setOrigin(order.getAgentId());
        charge.setMoney(order.getNum());
        charge.setMoney_point(order.getNum());
        charge.setRecharge_source("" + IChargeType.AGENT);
        charge.setStatus(1);
        SpringUtil.getBean(ChargeService.class).save(charge);
    }
    resultHandler.onComplete(0);
}
Also used : User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) UserService(com.code.server.db.Service.UserService) Charge(com.code.server.db.model.Charge) ChargeService(com.code.server.db.Service.ChargeService) Date(java.util.Date)

Aggregations

UserBean (com.code.server.constant.game.UserBean)9 UserService (com.code.server.db.Service.UserService)9 User (com.code.server.db.model.User)9 ChargeService (com.code.server.db.Service.ChargeService)2 Charge (com.code.server.db.model.Charge)2 UserRedisService (com.code.server.redis.service.UserRedisService)2 com.code.server.rpc.idl (com.code.server.rpc.idl)2 Date (java.util.Date)2 HashSet (java.util.HashSet)1