init
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.ruoyi.xq.manager.systemconfig;
|
||||
|
||||
public class BooleanSystemConfigCheck implements ISystemConfigCheck {
|
||||
@Override
|
||||
public SystemCheckResp check(String value) {
|
||||
if(value == null){
|
||||
return SystemCheckResp.fail("该配置必填");
|
||||
}
|
||||
if(!value.equals("1") && !value.equals("0")){
|
||||
return SystemCheckResp.fail("请填写1或者0【1表示确定,0表示否定】");
|
||||
}
|
||||
return SystemCheckResp.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.ruoyi.xq.manager.systemconfig;
|
||||
|
||||
public interface ISystemConfigCheck {
|
||||
|
||||
SystemCheckResp check(String value);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.ruoyi.xq.manager.systemconfig;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class NumberListSystemConfigCheck implements ISystemConfigCheck {
|
||||
private Integer minSize;
|
||||
|
||||
public NumberListSystemConfigCheck(Integer minSize) {
|
||||
this.minSize = minSize;
|
||||
}
|
||||
|
||||
public NumberListSystemConfigCheck() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemCheckResp check(String value) {
|
||||
if(StringUtils.isEmpty(value)){
|
||||
return SystemCheckResp.fail("该配置必填");
|
||||
}
|
||||
String errMessage = String.format("请填写逗号分割的数字,且需要不低于%s个", minSize);
|
||||
List<Long> longList = SystemConfigCheckUtil.getArrayListOfLong(value);
|
||||
if(longList == null){
|
||||
return SystemCheckResp.fail(errMessage);
|
||||
}
|
||||
if(longList.size() < minSize){
|
||||
return SystemCheckResp.fail(errMessage);
|
||||
}
|
||||
return SystemCheckResp.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.ruoyi.xq.manager.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,34 @@
|
||||
package com.ruoyi.xq.manager.systemconfig;
|
||||
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class RangeIntegerSystemConfigCheck implements ISystemConfigCheck {
|
||||
|
||||
private final Integer minNum;
|
||||
private final Integer maxNum;
|
||||
public RangeIntegerSystemConfigCheck(Integer minNum,Integer maxNum) {
|
||||
this.minNum = minNum;
|
||||
this.maxNum = maxNum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemCheckResp check(String value) {
|
||||
if(StringUtils.isEmpty(value)){
|
||||
return SystemCheckResp.fail("该配置必填");
|
||||
}
|
||||
String errorNum = String.format("请填写正确的整数,范围[%s,%s]", minNum, maxNum);
|
||||
boolean b = NumberUtil.isLong(value);
|
||||
if(!b){
|
||||
return SystemCheckResp.fail(errorNum);
|
||||
}
|
||||
int of = Integer.parseInt(value);
|
||||
if(of < minNum || of > maxNum){
|
||||
return SystemCheckResp.fail(errorNum);
|
||||
}
|
||||
return SystemCheckResp.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.ruoyi.xq.manager.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.xq.manager.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,33 @@
|
||||
package com.ruoyi.xq.manager.systemconfig;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SystemConfigCheckUtil {
|
||||
|
||||
public static List<Long> getArrayListOfLong(String value){
|
||||
try {
|
||||
String[] split = value.split(",");
|
||||
List<Long> res = new ArrayList<>();
|
||||
for (String s : split) {
|
||||
res.add(Long.valueOf(s));
|
||||
}
|
||||
return res;
|
||||
}catch (Exception e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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