refactor(系统设置): 类名优化

This commit is contained in:
AgAngle 2024-08-28 17:10:43 +08:00 committed by Craftsman
parent 4192b7dfe5
commit 86581e4580
14 changed files with 35 additions and 35 deletions

View File

@ -6,7 +6,7 @@ import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
@Data @Data
public class CustomFieldDao extends CustomField implements Serializable { public class CustomFieldDTO extends CustomField implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -4,7 +4,7 @@ package io.metersphere.system.resolver.field;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -20,13 +20,13 @@ public abstract class AbstractCustomFieldResolver {
* @param customField * @param customField
* @param value * @param value
*/ */
abstract public void validate(CustomFieldDao customField, Object value); abstract public void validate(CustomFieldDTO customField, Object value);
protected void throwValidateException(String name) { protected void throwValidateException(String name) {
throw new MSException(FIELD_VALIDATE_ERROR, Translator.getWithArgs(FIELD_VALIDATE_ERROR.getMessage(), name)); throw new MSException(FIELD_VALIDATE_ERROR, Translator.getWithArgs(FIELD_VALIDATE_ERROR.getMessage(), name));
} }
protected void validateRequired(CustomFieldDao customField, Object value) { protected void validateRequired(CustomFieldDTO customField, Object value) {
if (!customField.getRequired()) { if (!customField.getRequired()) {
return; return;
} }
@ -37,7 +37,7 @@ public abstract class AbstractCustomFieldResolver {
} }
} }
protected void validateArrayRequired(CustomFieldDao customField, Object value) { protected void validateArrayRequired(CustomFieldDTO customField, Object value) {
if (!customField.getRequired()) { if (!customField.getRequired()) {
return; return;
} }

View File

@ -2,13 +2,13 @@ package io.metersphere.system.resolver.field;
import io.metersphere.sdk.util.DateUtils; import io.metersphere.sdk.util.DateUtils;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
public class CustomFieldDateResolver extends AbstractCustomFieldResolver { public class CustomFieldDateResolver extends AbstractCustomFieldResolver {
@Override @Override
public void validate(CustomFieldDao customField, Object value) { public void validate(CustomFieldDTO customField, Object value) {
validateRequired(customField, value); validateRequired(customField, value);
validateString(customField.getName(), value); validateString(customField.getName(), value);
try { try {

View File

@ -2,13 +2,13 @@ package io.metersphere.system.resolver.field;
import io.metersphere.sdk.util.DateUtils; import io.metersphere.sdk.util.DateUtils;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
public class CustomFieldDateTimeResolver extends AbstractCustomFieldResolver { public class CustomFieldDateTimeResolver extends AbstractCustomFieldResolver {
@Override @Override
public void validate(CustomFieldDao customField, Object value) { public void validate(CustomFieldDTO customField, Object value) {
validateRequired(customField, value); validateRequired(customField, value);
try { try {
if (value != null && StringUtils.isNotBlank(value.toString())) { if (value != null && StringUtils.isNotBlank(value.toString())) {

View File

@ -1,12 +1,12 @@
package io.metersphere.system.resolver.field; package io.metersphere.system.resolver.field;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
public class CustomFieldFloatResolver extends AbstractCustomFieldResolver { public class CustomFieldFloatResolver extends AbstractCustomFieldResolver {
@Override @Override
public void validate(CustomFieldDao customField, Object value) { public void validate(CustomFieldDTO customField, Object value) {
validateRequired(customField, value); validateRequired(customField, value);
if (value != null && !(value instanceof Number)) { if (value != null && !(value instanceof Number)) {
throwValidateException(customField.getName()); throwValidateException(customField.getName());

View File

@ -1,10 +1,10 @@
package io.metersphere.system.resolver.field; package io.metersphere.system.resolver.field;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
public class CustomFieldIntegerResolver extends AbstractCustomFieldResolver { public class CustomFieldIntegerResolver extends AbstractCustomFieldResolver {
@Override @Override
public void validate(CustomFieldDao customField, Object value) { public void validate(CustomFieldDTO customField, Object value) {
validateRequired(customField, value); validateRequired(customField, value);
if (value != null && !(value instanceof Integer)) { if (value != null && !(value instanceof Integer)) {
throwValidateException(customField.getName()); throwValidateException(customField.getName());

View File

@ -1,12 +1,12 @@
package io.metersphere.system.resolver.field; package io.metersphere.system.resolver.field;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
public class CustomFieldMemberResolver extends AbstractCustomFieldResolver { public class CustomFieldMemberResolver extends AbstractCustomFieldResolver {
@Override @Override
public void validate(CustomFieldDao customField, Object value) { public void validate(CustomFieldDTO customField, Object value) {
validateRequired(customField, value); validateRequired(customField, value);
validateString(customField.getName(), value); validateString(customField.getName(), value);
} }

View File

@ -2,12 +2,12 @@ package io.metersphere.system.resolver.field;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
public class CustomFieldMultipleMemberResolver extends CustomFieldMemberResolver { public class CustomFieldMultipleMemberResolver extends CustomFieldMemberResolver {
@Override @Override
public void validate(CustomFieldDao customField, Object value) { public void validate(CustomFieldDTO customField, Object value) {
validateArrayRequired(customField, value); validateArrayRequired(customField, value);
validateArray(customField.getName(), value); validateArray(customField.getName(), value);
} }

View File

@ -3,7 +3,7 @@ package io.metersphere.system.resolver.field;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.domain.CustomFieldOption; import io.metersphere.system.domain.CustomFieldOption;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -12,7 +12,7 @@ import java.util.stream.Collectors;
public class CustomFieldMultipleSelectResolver extends CustomFieldSelectResolver { public class CustomFieldMultipleSelectResolver extends CustomFieldSelectResolver {
@Override @Override
public void validate(CustomFieldDao customField, Object value) { public void validate(CustomFieldDTO customField, Object value) {
validateArrayRequired(customField, value); validateArrayRequired(customField, value);
validateArray(customField.getName(), value); validateArray(customField.getName(), value);
List<CustomFieldOption> options = getOptions(customField.getId()); List<CustomFieldOption> options = getOptions(customField.getId());

View File

@ -2,13 +2,13 @@ package io.metersphere.system.resolver.field;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
public class CustomFieldMultipleTextResolver extends AbstractCustomFieldResolver { public class CustomFieldMultipleTextResolver extends AbstractCustomFieldResolver {
@Override @Override
public void validate(CustomFieldDao customField, Object value) { public void validate(CustomFieldDTO customField, Object value) {
validateArrayRequired(customField, value); validateArrayRequired(customField, value);
validateArray(customField.getName(), value); validateArray(customField.getName(), value);
} }

View File

@ -3,7 +3,7 @@ package io.metersphere.system.resolver.field;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.system.domain.CustomFieldOption; import io.metersphere.system.domain.CustomFieldOption;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
import io.metersphere.system.service.BaseCustomFieldOptionService; import io.metersphere.system.service.BaseCustomFieldOptionService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -14,7 +14,7 @@ import java.util.stream.Collectors;
public class CustomFieldSelectResolver extends AbstractCustomFieldResolver { public class CustomFieldSelectResolver extends AbstractCustomFieldResolver {
@Override @Override
public void validate(CustomFieldDao customField, Object value) { public void validate(CustomFieldDTO customField, Object value) {
validateRequired(customField, value); validateRequired(customField, value);
if (value == null) { if (value == null) {
return; return;

View File

@ -1,11 +1,11 @@
package io.metersphere.system.resolver.field; package io.metersphere.system.resolver.field;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
public class CustomFieldTextResolver extends AbstractCustomFieldResolver { public class CustomFieldTextResolver extends AbstractCustomFieldResolver {
@Override @Override
public void validate(CustomFieldDao customField, Object value) { public void validate(CustomFieldDTO customField, Object value) {
validateRequired(customField, value); validateRequired(customField, value);
validateString(customField.getName(), value); validateString(customField.getName(), value);
} }

View File

@ -4,7 +4,7 @@ import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.system.domain.CustomField; import io.metersphere.system.domain.CustomField;
import io.metersphere.system.domain.TemplateCustomField; import io.metersphere.system.domain.TemplateCustomField;
import io.metersphere.system.domain.TemplateCustomFieldExample; import io.metersphere.system.domain.TemplateCustomFieldExample;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
import io.metersphere.system.dto.sdk.request.TemplateCustomFieldRequest; import io.metersphere.system.dto.sdk.request.TemplateCustomFieldRequest;
import io.metersphere.system.mapper.TemplateCustomFieldMapper; import io.metersphere.system.mapper.TemplateCustomFieldMapper;
import io.metersphere.system.resolver.field.AbstractCustomFieldResolver; import io.metersphere.system.resolver.field.AbstractCustomFieldResolver;
@ -106,11 +106,11 @@ public class BaseTemplateCustomFieldService {
private String parseDefaultValue(TemplateCustomFieldRequest field) { private String parseDefaultValue(TemplateCustomFieldRequest field) {
CustomField customField = baseCustomFieldService.getWithCheck(field.getFieldId()); CustomField customField = baseCustomFieldService.getWithCheck(field.getFieldId());
AbstractCustomFieldResolver customFieldResolver = CustomFieldResolverFactory.getResolver(customField.getType()); AbstractCustomFieldResolver customFieldResolver = CustomFieldResolverFactory.getResolver(customField.getType());
CustomFieldDao customFieldDao = BeanUtils.copyBean(new CustomFieldDao(), customField); CustomFieldDTO customFieldDTO = BeanUtils.copyBean(new CustomFieldDTO(), customField);
customFieldDao.setRequired(false); customFieldDTO.setRequired(false);
if (BooleanUtils.isNotFalse(validateDefaultValue.get())) { if (BooleanUtils.isNotFalse(validateDefaultValue.get())) {
// 创建项目时不校验默认值 // 创建项目时不校验默认值
customFieldResolver.validate(customFieldDao, field.getDefaultValue()); customFieldResolver.validate(customFieldDTO, field.getDefaultValue());
} }
return customFieldResolver.parse2String(field.getDefaultValue()); return customFieldResolver.parse2String(field.getDefaultValue());
} }

View File

@ -6,7 +6,7 @@ import io.metersphere.sdk.constants.TemplateScene;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.system.domain.CustomField; import io.metersphere.system.domain.CustomField;
import io.metersphere.system.dto.CustomFieldDao; import io.metersphere.system.dto.CustomFieldDTO;
import io.metersphere.system.dto.sdk.request.CustomFieldOptionRequest; import io.metersphere.system.dto.sdk.request.CustomFieldOptionRequest;
import io.metersphere.system.resolver.field.AbstractCustomFieldResolver; import io.metersphere.system.resolver.field.AbstractCustomFieldResolver;
import io.metersphere.system.resolver.field.CustomFieldResolverFactory; import io.metersphere.system.resolver.field.CustomFieldResolverFactory;
@ -129,8 +129,8 @@ public class BaseCustomFieldTestService {
AbstractCustomFieldResolver customFieldResolver = CustomFieldResolverFactory.getResolver(customFieldType.name()); AbstractCustomFieldResolver customFieldResolver = CustomFieldResolverFactory.getResolver(customFieldType.name());
CustomField customField = getCustomFields().get(customFieldType); CustomField customField = getCustomFields().get(customFieldType);
CustomFieldDao customFieldDao = BeanUtils.copyBean(new CustomFieldDao(), customField); CustomFieldDTO customFieldDTO = BeanUtils.copyBean(new CustomFieldDTO(), customField);
customFieldDao.setRequired(true); customFieldDTO.setRequired(true);
String valueStr = customFieldResolver.parse2String(objectValueMap.get(customFieldType)); String valueStr = customFieldResolver.parse2String(objectValueMap.get(customFieldType));
Object objectValue = customFieldResolver.parse2Value(valueStr); Object objectValue = customFieldResolver.parse2Value(valueStr);
// 校验 parse2String parse2Value 是否正确 // 校验 parse2String parse2Value 是否正确
@ -157,8 +157,8 @@ public class BaseCustomFieldTestService {
private void invokeValidate(Map<CustomFieldType, Object> valueMap, CustomFieldType customFieldType) { private void invokeValidate(Map<CustomFieldType, Object> valueMap, CustomFieldType customFieldType) {
AbstractCustomFieldResolver customFieldResolver = CustomFieldResolverFactory.getResolver(customFieldType.name()); AbstractCustomFieldResolver customFieldResolver = CustomFieldResolverFactory.getResolver(customFieldType.name());
CustomField customField = getCustomFields().get(customFieldType); CustomField customField = getCustomFields().get(customFieldType);
CustomFieldDao customFieldDao = BeanUtils.copyBean(new CustomFieldDao(), customField); CustomFieldDTO customFieldDTO = BeanUtils.copyBean(new CustomFieldDTO(), customField);
customFieldDao.setRequired(true); customFieldDTO.setRequired(true);
customFieldResolver.validate(customFieldDao, valueMap.get(customFieldType)); customFieldResolver.validate(customFieldDTO, valueMap.get(customFieldType));
} }
} }