myjf007
2024-11-04 627b61d17da1dbf02c0363c659b728627dd42890
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package com.nova.sankuai.infra.utils;
 
import com.nova.sankuai.domain.entity.*;
import com.nova.sankuai.infra.mapper.ChannelInfoMapper;
import com.nova.sankuai.service.IApiCompanyRecordService;
import com.nova.sankuai.service.IChannelCompanyConfigService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
 
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
 
/**
 * @author weikangdi
 * @create 2022/4/15
 */
@Component
@AllArgsConstructor
public class ApiCompanyCheckUtil {
 
    private final IApiCompanyRecordService recordService;
 
    private final IChannelCompanyConfigService channelCompanyConfigService;
 
    private static final Logger log = LoggerFactory.getLogger("apiCompanyInfoLogger");
 
    private final ChannelInfoMapper channelInfoMapper;
 
    /**
     * 筛选客户是否满足城市匹配
     *
     * @param apiCompany
     * @param cityId
     * @param provinceId
     * @return
     */
    public boolean checkCity(ApiCompany apiCompany, String cityId, String provinceId) {
        String deliveryCity = apiCompany.getDeliveryCity();
        if (deliveryCity.contains(cityId) || deliveryCity.equals(provinceId)
                || deliveryCity.contains("," + provinceId + ",")
                || deliveryCity.endsWith("," + provinceId)
                || deliveryCity.contains(provinceId + ",")) {
            return true;
        }
        return false;
    }
 
    /**
     * 筛选客户是否满足最低贷款额度
     *
     * @param customer
     * @param apiCompany
     * @return
     */
    public boolean checkLoanAmount(ApiCompany apiCompany, Customer customer) {
        Integer companyMinLoanAmount = apiCompany.getMinLoanAmount();
        Integer customerQuota = customer.parseLoadAmount();
        if (companyMinLoanAmount != null) {
            if ((customerQuota == null || customerQuota < companyMinLoanAmount)) {
                return false;
            }
        }
        return true;
    }
 
    /**
     * 筛选接口公司是否达到达到累计上限
     *
     * @param apiCompany
     * @return
     */
    public boolean checkLimit(ApiCompany apiCompany) {
        Integer count = recordService.lambdaQuery()
                .eq(ApiCompanyRecord::getCompanyId, apiCompany.getId())
                .eq(ApiCompanyRecord::getStatus, ApiCompanyRecord.SUCCESS).count();
        if (apiCompany.getCustomerNum() == null || count < apiCompany.getCustomerNum()) {
            return true;
        }
        return false;
    }
 
    public boolean checkChannelConfig(ApiCompany apiCompany, Long channelId) {
        //筛选渠道配置匹配的接口公司
        List<Long> channelIds = channelCompanyConfigService.getChannelsByCompanyId(apiCompany.getId());
        if (!CollectionUtils.isEmpty(channelIds) && !channelIds.contains(channelId)) {
            return false;
        }
        return true;
    }
 
 
    /**
     * 根据机构筛选条件对推送进行筛选,如果不满足条件,则不推送
     *
     * @param customer
     * @param apiCompany
     * @return
     */
    public boolean filterCustomer(Customer customer, ApiCompany apiCompany, ChannelInfo channelInfo, String type) {
        boolean filter = true;
        boolean bool = assetScreening(apiCompany, customer, type, filter);
        filter = bool;
        if (apiCompany.getMinLoanAmount() != null) {
            if ((customer.parseLoadAmount() == null || customer.parseLoadAmount() < apiCompany.getMinLoanAmount())) {
                filter = false;
                log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                        + "错误:该用户的最低贷款额度不满足推送条件");
            }
        }
        Integer count = recordService.lambdaQuery()
                .eq(ApiCompanyRecord::getCompanyId, apiCompany.getId())
                .eq(ApiCompanyRecord::getStatus, ApiCompanyRecord.SUCCESS).count();
        if (apiCompany.getCustomerNum() != null && count >= apiCompany.getCustomerNum()) {
            filter = false;
            log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                    + "错误:该用户的最低贷款额度不满足推送条件");
        }
        if (apiCompany.getAgeLowerLimit() != null) {
            if (customer.getAge() == null || customer.getAge() < apiCompany.getAgeLowerLimit()) {
                filter = false;
                log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                        + "错误:该用户不满足年龄筛选,年龄过小");
            }
        }
        if (apiCompany.getAgeUpperLimit() != null) {
            if (customer.getAge() == null || customer.getAge() > apiCompany.getAgeUpperLimit()) {
                filter = false;
                log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                        + "错误:该用户不满足年龄筛选,年龄过大");
            }
        }
        if (StringUtils.isNotEmpty(apiCompany.getMarriageLimit())) {
            String[] split = apiCompany.getMarriageLimit().split(",");
            if (!Arrays.asList(split).contains(customer.getMaritalStatus())) {
                filter = false;
                log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                        + "错误:该用户不满足婚姻筛选");
            }
        }
        if (apiCompany.getSesameLimit() != null) {
            if (!Objects.equals(apiCompany.getSesameLimit(), customer.getSesame())) {
                filter = false;
                log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                        + "错误:该用户不满足芝麻分筛选");
            }
        }
        if (apiCompany.getCreditCardLimit() != null) {
            if (!Objects.equals(apiCompany.getCreditCardLimit(), customer.getCreditCard())) {
                filter = false;
                log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                        + "错误:该用户不满足信用卡筛选");
            }
        }
        if (apiCompany.getAmountLowerLimit() != null) {
            if (customer.getLoanAmount() == null || customer.getLoanAmount() < apiCompany.getAmountLowerLimit()) {
                filter = false;
                log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                        + "错误:该用户不满足贷款金额筛选,金额过小");
            }
        }
        if (apiCompany.getAmountUpperLimit() != null) {
            if (customer.getLoanAmount() == null || customer.getLoanAmount() > apiCompany.getAmountUpperLimit()) {
                filter = false;
                log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                        + "错误:该用户不满足贷款金额筛选,金额过大");
            }
        }
        if (apiCompany.getMonthlyIncomeLimit() != null) {
            if (!Objects.equals(apiCompany.getMonthlyIncomeLimit(), customer.getMonthlyIncome())) {
                filter = false;
                log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                        + "错误:该用户不满足月收入筛选");
            }
        }
        if (StringUtils.isNotEmpty(apiCompany.getEducationLimit())) {
            String[] split = apiCompany.getEducationLimit().split(",");
            if (!Arrays.asList(split).contains(customer.getEducation())) {
                filter = false;
                log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                        + "错误:该用户不满足教育筛选");
            }
        }
        Integer sourceChannelCustomer = customer.getSourceChannel();
        if (sourceChannelCustomer == null) {
            filter = false;
            log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                    + "错误:该用户不满足渠道筛选,用户渠道为空");
        } else {
            List<Long> channelIds = channelCompanyConfigService.getChannelsByCompanyId(apiCompany.getId());
            if (channelInfo == null) {
                filter = false;
                log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                        + "错误:该用户不满足渠道筛选,渠道为空");
            } else {
                Long sourceChannel = channelInfo.getId();
                if (ApiCompany.CHANNEL_INCLUDE == apiCompany.getChannelConfig()) {
                    if (channelIds == null || channelIds.isEmpty()) {
                        filter = false;
                        log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                                + "错误:该用户不满足渠道筛选,包含渠道列表为空");
                    } else {
                        if (!channelIds.contains(sourceChannel)) {
                            filter = false;
                            log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                                    + "错误:该用户不满足渠道筛选,未包含用户渠道");
                        }
                    }
                } else if (ApiCompany.CHANNEL_UNINCLUDE == apiCompany.getChannelConfig()) {
                    if (channelIds != null && !channelIds.isEmpty()) {
                        if (channelIds.contains(sourceChannel)) {
                            filter = false;
                            log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                                    + "错误:该用户不满足渠道筛选,包含用户渠道");
                        }
                    }
                }
            }
        }
        return filter;
    }
 
    private boolean assetScreening(ApiCompany apiCompany, Customer customer, String type, boolean filter) {
        boolean isAllSatisfy = false;
        if (StringUtils.isNotEmpty(apiCompany.getSocialSecurityLimit())) {
            String[] split = apiCompany.getSocialSecurityLimit().split(",");
            if (customer.getSocialSecurity() == null || !Arrays.asList(split).contains(customer.getSocialSecurity().toString())) {
                filter = false;
            } else {
                isAllSatisfy = true;
            }
        }
        if (StringUtils.isNotEmpty(apiCompany.getProvidentFundLimit())) {
            String[] split = apiCompany.getProvidentFundLimit().split(",");
            if (customer.getProvidentFund() == null || !Arrays.asList(split).contains(customer.getProvidentFund().toString())) {
                filter = false;
            } else {
                isAllSatisfy = true;
            }
        }
        if (StringUtils.isNotEmpty(apiCompany.getHouseLimit())) {
            String[] split = apiCompany.getHouseLimit().split(",");
            if (customer.getHouseStatus() == null || !Arrays.asList(split).contains(customer.getHouseStatus().toString())) {
                filter = false;
            } else {
                isAllSatisfy = true;
            }
        }
        if (StringUtils.isNotEmpty(apiCompany.getCarLimit())) {
            String[] split = apiCompany.getCarLimit().split(",");
            if (customer.getCarStatus() == null || !Arrays.asList(split).contains(customer.getCarStatus().toString())) {
                filter = false;
            } else {
                isAllSatisfy = true;
            }
        }
        if (StringUtils.isNotEmpty(apiCompany.getPolicyLimit())) {
            String[] split = apiCompany.getPolicyLimit().split(",");
            if (customer.getInsurancePolicy() == null || !Arrays.asList(split).contains(customer.getInsurancePolicy().toString())) {
                filter = false;
            } else {
                isAllSatisfy = true;
            }
        }
        if (isAllSatisfy) {
            filter = true;
            log.info(type + apiCompany.getCompanyName() + "成功,用户手机号" + customer.getPhone()
                    + ",5个筛选条件满足其一");
        } else {
            log.info(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                    + ",5个筛选条件均不满足");
        }
        return filter;
    }
}