mirror of https://gitee.com/stylefeng/roses
【api】完善api详情接口,增加对注解的校验提示
parent
fead9657d1
commit
e8bd583068
|
@ -45,10 +45,15 @@ public class FieldMetadata {
|
||||||
* 按校验组分的注解集合
|
* 按校验组分的注解集合
|
||||||
* <p>
|
* <p>
|
||||||
* 例如:
|
* 例如:
|
||||||
* key = add, value = [NotBlank,TableUniqueValue]
|
* key = add, value = [不能为空,最大多少位,邮箱类型]
|
||||||
*/
|
*/
|
||||||
private Map<String, Set<String>> groupAnnotations;
|
private Map<String, Set<String>> groupAnnotations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验信息的提示信息
|
||||||
|
*/
|
||||||
|
private String validationMessages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 泛型或object类型的字段的描述
|
* 泛型或object类型的字段的描述
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -132,7 +132,8 @@ public class ClassReflectUtil {
|
||||||
if (annotations == null) {
|
if (annotations == null) {
|
||||||
annotations = new HashSet<>();
|
annotations = new HashSet<>();
|
||||||
}
|
}
|
||||||
annotations.add(fieldAnnotation.annotationType().getSimpleName());
|
String messageTip = invokeAnnotationMethodIgnoreError(fieldAnnotation, "message", String.class);
|
||||||
|
annotations.add(messageTip);
|
||||||
groupAnnotations.put(validateGroupsClass.getSimpleName(), annotations);
|
groupAnnotations.put(validateGroupsClass.getSimpleName(), annotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,4 +160,4 @@ public class ClassReflectUtil {
|
||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package cn.stylefeng.roses.kernel.resource.modular.factory;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.bean.copier.CopyOptions;
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.stylefeng.roses.kernel.resource.api.pojo.resource.FieldMetadata;
|
||||||
import cn.stylefeng.roses.kernel.resource.api.pojo.resource.ResourceDefinition;
|
import cn.stylefeng.roses.kernel.resource.api.pojo.resource.ResourceDefinition;
|
||||||
import cn.stylefeng.roses.kernel.resource.modular.entity.SysResource;
|
import cn.stylefeng.roses.kernel.resource.modular.entity.SysResource;
|
||||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||||
|
@ -10,6 +12,7 @@ import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.parser.Feature;
|
import com.alibaba.fastjson.parser.Feature;
|
||||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,4 +110,61 @@ public class ResourceFactory {
|
||||||
return resourceDefinition;
|
return resourceDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ResourceDefinition转化为api界面的详情信息
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/1/16 16:09
|
||||||
|
*/
|
||||||
|
public static ResourceDefinition fillResourceDetail(ResourceDefinition resourceDefinition) {
|
||||||
|
|
||||||
|
// 这个接口的校验组信息
|
||||||
|
Set<String> validateGroups = resourceDefinition.getValidateGroups();
|
||||||
|
|
||||||
|
// 接口的请求参数信息
|
||||||
|
Set<FieldMetadata> paramFieldDescriptions = resourceDefinition.getParamFieldDescriptions();
|
||||||
|
fillDetailMessage(validateGroups, paramFieldDescriptions);
|
||||||
|
|
||||||
|
// 接口的响应参数信息
|
||||||
|
Set<FieldMetadata> responseFieldDescriptions = resourceDefinition.getResponseFieldDescriptions();
|
||||||
|
fillDetailMessage(validateGroups, responseFieldDescriptions);
|
||||||
|
|
||||||
|
return resourceDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 填充字段里详细的提示信息
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/1/16 18:00
|
||||||
|
*/
|
||||||
|
public static Set<FieldMetadata> fillDetailMessage(Set<String> validateGroups, Set<FieldMetadata> fieldMetadataSet) {
|
||||||
|
if (validateGroups == null || validateGroups.isEmpty()) {
|
||||||
|
return fieldMetadataSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldMetadataSet == null || fieldMetadataSet.isEmpty()) {
|
||||||
|
return fieldMetadataSet;
|
||||||
|
}
|
||||||
|
for (FieldMetadata fieldMetadata : fieldMetadataSet) {
|
||||||
|
StringBuilder finalValidateMessages = new StringBuilder();
|
||||||
|
Map<String, Set<String>> groupAnnotations = fieldMetadata.getGroupAnnotations();
|
||||||
|
if (groupAnnotations != null) {
|
||||||
|
for (String validateGroup : validateGroups) {
|
||||||
|
Set<String> validateMessage = groupAnnotations.get(validateGroup);
|
||||||
|
if (validateMessage != null && !validateMessage.isEmpty()) {
|
||||||
|
finalValidateMessages.append(StrUtil.join(",", validateMessage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldMetadata.setValidationMessages(finalValidateMessages.toString());
|
||||||
|
|
||||||
|
// 递归填充子类型的详细提示信息
|
||||||
|
if (fieldMetadata.getGenericFieldMetadata() != null && !fieldMetadata.getGenericFieldMetadata().isEmpty()) {
|
||||||
|
fillDetailMessage(validateGroups, fieldMetadata.getGenericFieldMetadata());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fieldMetadataSet;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
||||||
import cn.stylefeng.roses.kernel.system.pojo.resource.LayuiApiResourceTreeNode;
|
import cn.stylefeng.roses.kernel.system.pojo.resource.LayuiApiResourceTreeNode;
|
||||||
import cn.stylefeng.roses.kernel.system.pojo.resource.request.ResourceRequest;
|
import cn.stylefeng.roses.kernel.system.pojo.resource.request.ResourceRequest;
|
||||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResourceResponse;
|
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResourceResponse;
|
||||||
import cn.stylefeng.roses.kernel.system.pojo.user.SysUserResponse;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||||
|
@ -121,18 +120,12 @@ public class SysResourceServiceImpl extends ServiceImpl<SysResourceMapper, SysRe
|
||||||
sysResourceLambdaQueryWrapper.eq(SysResource::getResourceCode, resourceRequest.getResourceCode());
|
sysResourceLambdaQueryWrapper.eq(SysResource::getResourceCode, resourceRequest.getResourceCode());
|
||||||
SysResource sysResource = this.getOne(sysResourceLambdaQueryWrapper);
|
SysResource sysResource = this.getOne(sysResourceLambdaQueryWrapper);
|
||||||
if (sysResource != null) {
|
if (sysResource != null) {
|
||||||
ResourceDefinition definition = ResourceFactory.createResourceDefinition(sysResource);
|
|
||||||
|
|
||||||
// 翻译创建人
|
// 实体转化为ResourceDefinition
|
||||||
if (sysResource.getCreateUser().equals(RuleConstants.TREE_ROOT_ID)) {
|
ResourceDefinition resourceDefinition = ResourceFactory.createResourceDefinition(sysResource);
|
||||||
definition.setCreateUser("超级管理员");
|
|
||||||
} else {
|
// 填充具体的提示信息
|
||||||
SysUserResponse userInfo = userServiceApi.getUserInfoByUserId(sysResource.getCreateUser());
|
return ResourceFactory.fillResourceDetail(resourceDefinition);
|
||||||
if (ObjectUtil.isNotEmpty(userInfo)) {
|
|
||||||
definition.setCreateUser(userInfo.getRealName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return definition;
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue