Search in sources :

Example 11 with DemoChecker

use of com.code.server.login.anotation.DemoChecker in project summer by foxsugar.

the class DemoAction method todayPartnerRecord.

@DemoChecker
@RequestMapping("/todayPartnerRecord")
public AgentResponse todayPartnerRecord(int curPage) {
    if (curPage > 0) {
        curPage--;
    }
    int agentId = (int) AgentUtil.getUserIdByToken(AgentUtil.findTokenInHeader());
    // int agentId = 100027;
    String start = DateUtil.convert2DayString(new Date());
    String end = DateUtil.convert2DayString(new Date());
    Sort sort = new Sort(Sort.Direction.DESC, "date");
    List<String> listA = DateUtil.getDateListIn(end, start);
    Page<AgentRecords> page = homeService.findAllAgentRecords(agentId, listA, new PageRequest(curPage, 20));
    List<AgentRecords> agentRecordsList = page.getContent();
    Map<String, Object> rs = new HashMap<>();
    rs.put("list", agentRecordsList);
    rs.put("count", page.getTotalElements());
    rs.put("userId", agentId);
    AgentResponse agentResponse = new AgentResponse();
    agentResponse.setData(rs);
    return agentResponse;
}
Also used : LocalDate(java.time.LocalDate) PageRequest(org.springframework.data.domain.PageRequest) Sort(org.springframework.data.domain.Sort) DemoChecker(com.code.server.login.anotation.DemoChecker) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with DemoChecker

use of com.code.server.login.anotation.DemoChecker in project summer by foxsugar.

the class DemoAction method doChargeNew.

@DemoChecker
@RequestMapping(value = "/doChargeNew", method = RequestMethod.POST)
public AgentResponse doChargeNew(HttpServletRequest request, long userId, @RequestParam(value = "money", required = true) long money, String type) {
    AgentResponse agentResponse = new AgentResponse();
    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 (type.equals("1")) {
                user.setMoney(user.getMoney() + money);
            } else if (type.equals("2")) {
                user.setGold(user.getGold() + money);
            }
            userService.save(user);
            name = user.getUsername();
        } else {
            agentResponse.setCode(com.code.server.login.action.ErrorCode.ERROR);
            return agentResponse;
        }
    } else {
        // 在redis里
        name = userBean.getUsername();
        if (type.equals("1")) {
            RedisManager.getUserRedisService().addUserMoney(userId, money);
            GameUserService.saveUserBean(userId);
        } else if (type.equals("2")) {
            RedisManager.getUserRedisService().addUserGold(userId, money);
            GameUserService.saveUserBean(userId);
        }
    }
    Charge charge = new Charge();
    charge.setOrderId("" + IdWorker.getDefaultInstance().nextId());
    charge.setUserid(userId);
    charge.setUsername(name);
    charge.setCreatetime(new Date());
    charge.setCallbacktime(new Date());
    charge.setOrigin(1);
    charge.setMoney(money);
    charge.setMoney_point(0);
    charge.setRecharge_source("" + IChargeType.AGENT);
    charge.setStatus(1);
    charge.setChargeType(type == "1" ? 0 : 1);
    SpringUtil.getBean(ChargeService.class).save(charge);
    Map<String, Object> rs = new HashMap<>();
    rs.put("money", money);
    rs.put("type", type);
    agentResponse.setData(rs);
    return agentResponse;
}
Also used : UserBean(com.code.server.constant.game.UserBean) GameUserService(com.code.server.login.service.GameUserService) UserService(com.code.server.db.Service.UserService) ChargeService(com.code.server.db.Service.ChargeService) LocalDate(java.time.LocalDate) DemoChecker(com.code.server.login.anotation.DemoChecker) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with DemoChecker

use of com.code.server.login.anotation.DemoChecker in project summer by foxsugar.

the class DemoAction method downwardDelegate.

@DemoChecker
@RequestMapping("/downward")
public AgentResponse downwardDelegate(HttpServletRequest request, long agentId) {
    String token = AgentUtil.findTokenInHeader();
    int self_agentId = (int) AgentUtil.getUserIdByToken(token);
    logger.info("self_id:{}, agent id:{}", self_agentId, agentId);
    AgentUser agentUser = agentUserDao.findOne(self_agentId);
    logger.info("agentUser:{}", agentUser);
    int self_code = 0;
    if (self_agentId != 1) {
        self_code = Integer.parseInt(agentUser.getUsername());
    }
    // 先给个demo
    if (agentId == 0) {
        Map<String, Object> rrss = assDemo();
        AgentResponse agentResponse = new AgentResponse();
        agentResponse.setData(rrss);
        return agentResponse;
    }
    // 如果代理是空的
    if (RedisManager.getAgentRedisService().getAgentBean(agentId) == null) {
        AgentResponse agentResponse = new AgentResponse();
        agentResponse.setCode(com.code.server.login.action.ErrorCode.ERROR);
        agentResponse.setMsg("代理不存在");
        return agentResponse;
    }
    AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
    if (agentBean.getPartnerId() != self_agentId && self_agentId != 1 && agentId != self_code) {
        AgentResponse agentResponse = new AgentResponse();
        agentResponse.setCode(com.code.server.login.action.ErrorCode.ERROR);
        agentResponse.setMsg("没有权限");
        return agentResponse;
    }
    // 直接玩家
    List<Long> aList = new ArrayList<>();
    // 二级代理
    List<Long> bList = new ArrayList<>();
    // 三级代理
    List<Long> cList = new ArrayList<>();
    agentBean.getChildList().stream().forEach(x -> {
        if (RedisManager.getAgentRedisService().isExit(x)) {
            bList.add(x);
        } else {
            aList.add(x);
        }
    });
    bList.stream().forEach(x -> {
        if (RedisManager.getAgentRedisService().isExit(x)) {
            cList.add(x);
        }
    });
    List<User> aUsers = userDao.findUsersByIdIn(aList);
    List<User> bUsers = userDao.findUsersByIdIn(bList);
    Map<String, Object> rs = assembleDelegateRelationship(agentId, aUsers, bUsers);
    AgentResponse agentResponse = new AgentResponse();
    agentResponse.setData(rs);
    System.out.println(agentResponse);
    return agentResponse;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) DemoChecker(com.code.server.login.anotation.DemoChecker) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with DemoChecker

use of com.code.server.login.anotation.DemoChecker in project summer by foxsugar.

the class DemoAction method dissolveRoom.

@DemoChecker
@RequestMapping("/dissolveRoom")
public AgentResponse dissolveRoom(String roomId) {
    System.out.println("admin解散房间");
    Map<String, Object> rs = new HashMap<>();
    AgentResponse agentResponse = new AgentResponse();
    agentResponse.setData(rs);
    String serverId = RedisManager.getRoomRedisService().getServerId(roomId);
    if (serverId == null) {
        rs.put("result", "ok");
        // rs.put("")
        // agentResponse.setMsg("房间不存在");
        // agentResponse.setCode(com.code.server.login.action.ErrorCode.ERROR);
        RedisManager.removeRoomAllInfo(roomId);
        return agentResponse;
    }
    MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
    Map<String, Object> result = new HashMap<>();
    result.put("roomId", roomId);
    KafkaMsgKey msgKey = new KafkaMsgKey();
    msgKey.setUserId(0);
    msgKey.setRoomId(roomId);
    msgKey.setPartition(Integer.valueOf(serverId));
    ResponseVo responseVo = new ResponseVo("roomService", "dissolutionRoom", result);
    msgProducer.send2Partition("roomService", Integer.valueOf(serverId), msgKey, responseVo);
    rs.put("result", "ok");
    return agentResponse;
}
Also used : MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) ResponseVo(com.code.server.constant.response.ResponseVo) DemoChecker(com.code.server.login.anotation.DemoChecker) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with DemoChecker

use of com.code.server.login.anotation.DemoChecker in project summer by foxsugar.

the class DemoAction method fetchAllPlayers.

@DemoChecker
@RequestMapping("/fetchAllPlayers")
public AgentResponse fetchAllPlayers(int pageSize, int curPage, HttpServletRequest request) {
    if (curPage > 0) {
        curPage--;
    }
    Page page = userDao.findAll(new PageRequest(curPage, pageSize));
    List<User> list = page.getContent();
    Map<String, Object> result = new HashMap<>();
    long count = userDao.count();
    result.put("total", count);
    result.put("list", list);
    AgentResponse agentResponse = new AgentResponse();
    agentResponse.setData(result);
    return agentResponse;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) DemoChecker(com.code.server.login.anotation.DemoChecker) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DemoChecker (com.code.server.login.anotation.DemoChecker)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 PageRequest (org.springframework.data.domain.PageRequest)8 LocalDate (java.time.LocalDate)5 GameAgentVo (com.code.server.login.vo.GameAgentVo)4 AgentBean (com.code.server.constant.game.AgentBean)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Sort (org.springframework.data.domain.Sort)2 UserBean (com.code.server.constant.game.UserBean)1 KafkaMsgKey (com.code.server.constant.kafka.KafkaMsgKey)1 ResponseVo (com.code.server.constant.response.ResponseVo)1 ChargeService (com.code.server.db.Service.ChargeService)1 UserService (com.code.server.db.Service.UserService)1 MsgProducer (com.code.server.kafka.MsgProducer)1 GameUserService (com.code.server.login.service.GameUserService)1 ConstantFormVo (com.code.server.login.vo.ConstantFormVo)1 DChargeAdminVo (com.code.server.login.vo.DChargeAdminVo)1 Page (org.springframework.data.domain.Page)1