admin
2021-09-30 1a1a315efb1b5dc294013126f35819e36565040c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package org.yeshi.utils.generater.util;
 
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.generater.annotation.admin.form.*;
import org.yeshi.utils.generater.entity.admin.FormVerifyType;
import org.yeshi.utils.generater.exception.AnotationException;
 
/**
 * @author Administrator
 * @title: FormEditValidUtil
 * @description: 验证表单的注解是否正确
 * @date 2021/9/23 15:30
 */
public class FormAnotationValidUtil {
 
    private static void validTitle(String title) throws AnotationException {
        if (StringUtil.isNullOrEmpty(title)) {
            throw new AnotationException("title不能为空");
        }
    }
 
    public static void valid(Text text) throws AnotationException {
        validTitle(text.title());
        //验证长度
        if (text.minLength() > text.maxLength()) {
            throw new AnotationException("最大长度不能小于最小长度");
        }
 
        if (text.verifyType() == FormVerifyType.regex && StringUtil.isNullOrEmpty(text.verifyValue())) {
            throw new AnotationException("验证的输入的正则表达式不能为空");
        }
 
        if (text.verifyType() == FormVerifyType.regex && StringUtil.isNullOrEmpty(text.verifyNotifyMsg())) {
            throw new AnotationException("不满足正则表达式的提示语不能为空");
        }
 
        if (text.inputType() == Text.Type.DATE || text.inputType() == Text.Type.DATETIME) {
            if (StringUtil.isNullOrEmpty(text.dateFormat())) {
                throw new AnotationException("日志格式化表达式不能为空");
            }
        }
    }
 
    public static void valid(TextArea text) throws AnotationException {
        validTitle(text.title());
        //验证长度
        if (text.minLength() > text.maxLength()) {
            throw new AnotationException("最大长度不能小于最小长度");
        }
 
        if (text.verifyType() == FormVerifyType.regex && StringUtil.isNullOrEmpty(text.verifyValue())) {
            throw new AnotationException("验证的输入的正则表达式不能为空");
        }
 
        if (text.verifyType() == FormVerifyType.regex && StringUtil.isNullOrEmpty(text.verifyNotifyMsg())) {
            throw new AnotationException("不满足正则表达式的提示语不能为空");
        }
 
    }
 
 
    public static void valid(CheckBox checkBox) throws AnotationException {
        validTitle(checkBox.title());
        //验证长度
        if (checkBox.values() == null || checkBox.values().length < 1) {
            throw new AnotationException("复选框的内容不能为空");
        }
 
        for (String st : checkBox.values()) {
            if (!st.contains(":")) {
                throw new AnotationException("复选框的内容格式错误,键值对要用:分隔");
            }
        }
    }
 
    public static void valid(Img img) throws AnotationException {
        validTitle(img.title());
    }
 
 
    public static void valid(Password password) throws AnotationException {
        validTitle(password.title());
        //验证长度
        if (password.minLength() > password.maxLength()) {
            throw new AnotationException("最大长度不能小于最小长度");
        }
    }
 
    public static void valid(RadioGroup radioGroup) throws AnotationException {
        validTitle(radioGroup.title());
 
        if (radioGroup.values() == null || radioGroup.values().length < 1) {
            throw new AnotationException("单选框的内容不能为空");
        }
 
        for (String st : radioGroup.values()) {
            if (!st.contains(":")) {
                throw new AnotationException("单选框的内容格式错误,键值对要用:分隔");
            }
        }
 
    }
 
 
    public static void valid(Select select) throws AnotationException {
        validTitle(select.title());
 
        if ((select.values() == null || select.values().length < 1 || (select.values().length == 1 && StringUtil.isNullOrEmpty(select.values()[0])))) {
            if (StringUtil.isNullOrEmpty(select.apiPath())) {
                throw new AnotationException("下拉框的内容不能为空");
            }
        } else {
            for (String st : select.values()) {
                if (!st.contains(":")) {
                    throw new AnotationException("下拉框的内容格式错误,键值对要用:分隔");
                }
            }
        }
    }
 
 
    public static void valid(Switch st) throws AnotationException {
        validTitle(st.title());
    }
 
 
}