无关风月
2025-02-28 2f8e70ad2884d2b6b7443dfae0af11ae9cfc8b99
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
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);
        }
    }
}