Пример #1
0
  @Override
  @Transactional
  public void sign(Long userId) throws Exception {
    UserInfo user = infoDao.findOne(userId);
    if (user == null) {
      GeneralExceptionHandler.handle("用户不存在");
    }
    Date lsd = user.getLastSignDate();

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date now = df.parse(df.format(new Date()));

    String[] signArr = user.getSign().split("\\|");
    Long continueCount = Long.valueOf(signArr[0]); // 连续签到次数
    Long totalCount = Long.valueOf(signArr[1]); // 总共签到次数

    if (lsd != null) {
      Long day = (now.getTime() - lsd.getTime()) / (1000 * 3600 * 24);
      if (day < 1) {
        GeneralExceptionHandler.handle("今天已经签到过了");
      }
      if (day > 1) {
        continueCount = 0l;
      }
    }
    user.setLastSignDate(new Date());
    user.setSign((continueCount + 1) + "|" + (totalCount + 1));
    infoDao.save(user);
  }
Пример #2
0
  /**
   * 注册
   *
   * @param userInfo
   * @param password
   * @param ipAddress
   * @return
   */
  @Override
  @Transactional
  public UserInfo create(UserInfo userInfo, String password, String ipAddress) {
    // 新增登录
    UserLogin userLogin = new UserLogin();
    userLogin.setUsername(userInfo.getMobile());
    userLogin.setPassword(password);
    userLogin.setIp_address(ipAddress);
    UserLogin ul = loginDao.save(userLogin);

    // 新增用户
    userInfo.setUserLogin(ul);
    userInfo.setGender(0);
    userInfo.setIntegral(0);
    userInfo.setYm(0);
    userInfo.setLevel(1);
    userInfo.setSign("0|0");
    UserInfo u = infoDao.save(userInfo);
    return u;
  }
Пример #3
0
 @Override
 public UserInfo findOne(UserInfo userInfo) throws Exception {
   Specification<UserInfo> spec = buildSpecification(userInfo);
   UserInfo user = infoDao.findOne(spec);
   return user;
 }
Пример #4
0
 @Override
 public Page<UserInfo> findAll(Integer currentPage, Integer pageSize) throws Exception {
   return infoDao.findAll(
       new PageRequest(currentPage - 1, pageSize, Sort.Direction.DESC, "integral"));
 }
Пример #5
0
 @Override
 public UserInfo findByLoginId(Long loginId) {
   return infoDao.findByLoginId(loginId);
 }