123
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package com.ruoyi.cai.enums.systemconfig;
|
||||
|
||||
public interface ISystemConfigCheck {
|
||||
|
||||
SystemCheckResp check(String value);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.ruoyi.cai.enums.systemconfig;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
public class NumberSystemConfigCheck implements ISystemConfigCheck{
|
||||
@Override
|
||||
public SystemCheckResp check(String value) {
|
||||
if(StringUtils.isEmpty(value)){
|
||||
return SystemCheckResp.fail("该配置必填");
|
||||
}
|
||||
boolean b = NumberUtil.isLong(value);
|
||||
if(!b){
|
||||
return SystemCheckResp.fail("请填写正确的整数");
|
||||
}
|
||||
Long of = Long.valueOf(value);
|
||||
if(of < 0){
|
||||
return SystemCheckResp.fail("请填写整数,不要填负数");
|
||||
}
|
||||
return SystemCheckResp.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.ruoyi.cai.enums.systemconfig;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
public class RankSystemConfigCheck implements ISystemConfigCheck{
|
||||
@Override
|
||||
public SystemCheckResp check(String value) {
|
||||
if(StringUtils.isEmpty(value)){
|
||||
return SystemCheckResp.fail("该配置必填");
|
||||
}
|
||||
boolean b = SystemConfigCheckUtil.checkArrayListLong(value, 10);
|
||||
if(!b){
|
||||
return SystemCheckResp.fail("请填写逗号分割的数字,且需要超过10个!");
|
||||
}
|
||||
return SystemCheckResp.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.ruoyi.cai.enums.systemconfig;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class RateSystemConfigCheck implements ISystemConfigCheck{
|
||||
@Override
|
||||
public SystemCheckResp check(String value) {
|
||||
if(StringUtils.isEmpty(value)){
|
||||
return SystemCheckResp.fail("该配置必填");
|
||||
}
|
||||
boolean b = NumberUtil.isDouble(value);
|
||||
if(!b){
|
||||
return SystemCheckResp.fail("请填写[0-1)之间的数字,两位小数点");
|
||||
}
|
||||
BigDecimal bigDecimal = new BigDecimal(value);
|
||||
boolean in = NumberUtil.isIn(bigDecimal, BigDecimal.ZERO, BigDecimal.ONE);
|
||||
if(!in){
|
||||
return SystemCheckResp.fail("请填写[0-1)之间的数字,两位小数点");
|
||||
}
|
||||
if(bigDecimal.scale() > 2){
|
||||
return SystemCheckResp.fail("小数点位数只能配置两位");
|
||||
}
|
||||
return SystemCheckResp.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.ruoyi.cai.enums.systemconfig;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SystemCheckResp {
|
||||
private boolean success;
|
||||
private String message;
|
||||
|
||||
public static SystemCheckResp ok(){
|
||||
SystemCheckResp resp = new SystemCheckResp();
|
||||
resp.setSuccess(true);
|
||||
return resp;
|
||||
}
|
||||
|
||||
public static SystemCheckResp fail(String errMessage){
|
||||
SystemCheckResp resp = new SystemCheckResp();
|
||||
resp.setSuccess(false);
|
||||
resp.setMessage(errMessage);
|
||||
return resp;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.ruoyi.cai.enums.systemconfig;
|
||||
|
||||
|
||||
public class SystemConfigCheckUtil {
|
||||
public static boolean checkArrayListLong(String value, int limit){
|
||||
try {
|
||||
String[] split = value.split(",");
|
||||
for (String s : split) {
|
||||
Long.valueOf(s);
|
||||
}
|
||||
return split.length > limit;
|
||||
}catch (Exception e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user