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()); } }