package com.jilongda.manage.utils; import com.jilongda.common.model.TCustomers; import lombok.extern.slf4j.Slf4j; import org.springframework.util.StringUtils; import java.util.Objects; @Slf4j public class GoodsImportValidator { public static boolean validateCustomers(TCustomers customers) { try { return !isValidCustomers(customers); } catch (Exception e) { // 记录日志,提供详细的错误信息 log.error("Validation error in GoodsImportExcel: {}", e.getMessage()); // 可以根据具体情况决定是否需要抛出异常或如何处理这些异常 throw e; } } /** * 校验客户导入Excel数据 * * @param customers 客户导入Excel数据 * @return 校验结果 */ private static boolean isValidCustomers(TCustomers customers) { return hasLength(customers.getCustomerName()) && hasLength(customers.getRecipientPhone()) && hasLength(customers.getCompanyName()) && hasLength(customers.getRecipientName()) && hasLength(customers.getSubsidiaryName()) && hasLength(customers.getRecipientAddress()); } private static boolean hasLength(String str) { return StringUtils.hasLength(str); } private static boolean isNotNull(Object obj) { return Objects.nonNull(obj); } private static boolean isNotNullAndNonNegative(Integer value) { return Objects.nonNull(value) && value >= 0; } // 自定义异常类 class GoodsImportException extends RuntimeException { public GoodsImportException(String message) { super(message); } } }