1 changed files with 66 additions and 25 deletions
@ -1,35 +1,76 @@ |
|||||
package com.epmet.modules.support; |
package com.epmet.modules.support; |
||||
|
|
||||
|
import com.epmet.commons.tools.constant.NumConstant; |
||||
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
||||
|
import com.epmet.commons.tools.exception.RenException; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
|
||||
|
import java.util.concurrent.atomic.AtomicBoolean; |
||||
|
import java.util.concurrent.atomic.AtomicInteger; |
||||
|
|
||||
/** |
/** |
||||
* 小组等级积分工具类 |
* 小组等级积分工具类 |
||||
* |
* |
||||
* @author zhaoqifeng |
* @author zhaoqifeng |
||||
* @date 2021/4/21 10:22 |
* @date 2021/4/21 10:22 |
||||
*/ |
*/ |
||||
|
@Slf4j |
||||
public class GroupLevelUtils { |
public class GroupLevelUtils { |
||||
/** |
|
||||
* 根据等级算出升级所需的积分 |
/** |
||||
* |
* 根据等级算出升级所需的积分 |
||||
* @param level |
* |
||||
* @return java.lang.Integer |
* @param level |
||||
* @author zhaoqifeng |
* @return java.lang.Integer |
||||
* @date 2021/4/21 10:25 |
* @author zhaoqifeng |
||||
*/ |
* @date 2021/4/21 10:25 |
||||
public static Integer getPoint(Integer level) { |
* @remark 通项公式:an=n(n-1)/2+2n-2(n∈N+) -3+n(n-1)/2(需要特殊处理,所以引用前面的) |
||||
Integer point = 0; |
*/ |
||||
return point; |
public static Integer getPoint(Integer level) { |
||||
} |
if (level == null || level < NumConstant.ONE) { |
||||
|
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode()); |
||||
/** |
} |
||||
* 根据积分算出当前的等级 |
Integer point = (level * (level - NumConstant.ONE) / NumConstant.TWO + NumConstant.TWO * level - NumConstant.TWO) * NumConstant.ONE_HUNDRED; |
||||
* |
log.info("getPoint level:{},point:{}", level, point); |
||||
* @param point |
return point; |
||||
* @return java.lang.Integer |
} |
||||
* @author zhaoqifeng |
|
||||
* @date 2021/4/21 10:25 |
/** |
||||
*/ |
* 根据积分算出当前的等级 |
||||
public static Integer getLevel(Integer point) { |
* |
||||
Integer level = 0; |
* @param point |
||||
return level; |
* @return java.lang.Integer |
||||
} |
* @author zhaoqifeng |
||||
|
* @date 2021/4/21 10:25 |
||||
|
*/ |
||||
|
public static Integer getLevel(Integer point) { |
||||
|
if (point == null || point < NumConstant.ZERO) { |
||||
|
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode()); |
||||
|
} |
||||
|
//如果是0 则返回等级1
|
||||
|
if (point == NumConstant.ZERO) { |
||||
|
return NumConstant.ONE; |
||||
|
} |
||||
|
AtomicBoolean flag = new AtomicBoolean(false); |
||||
|
AtomicInteger initLevel = new AtomicInteger(1); |
||||
|
do { |
||||
|
Integer point1 = getPoint(initLevel.incrementAndGet()); |
||||
|
if (point < point1) { |
||||
|
int i = initLevel.decrementAndGet(); |
||||
|
log.info("getLevel level:{},point:{}", i, point); |
||||
|
return i; |
||||
|
} |
||||
|
|
||||
|
} while (!flag.get()); |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
for (int i = 1; i < 10; i++) { |
||||
|
System.out.println("lv" + i + ":" + getPoint(i)); |
||||
|
} |
||||
|
System.out.println(getLevel(3300)); |
||||
|
System.out.println(getLevel(299)); |
||||
|
|
||||
|
} |
||||
} |
} |
||||
|
Loading…
Reference in new issue