| 
 
 | 
1
 | 
+package com.lframework.xingyun.sc.excel.customerCredit;
 | 
| 
 
 | 
2
 | 
+
 | 
| 
 
 | 
3
 | 
+import com.alibaba.excel.context.AnalysisContext;
 | 
| 
 
 | 
4
 | 
+import com.lframework.starter.common.exceptions.impl.DefaultClientException;
 | 
| 
 
 | 
5
 | 
+import com.lframework.starter.common.utils.StringUtil;
 | 
| 
 
 | 
6
 | 
+import com.lframework.starter.web.core.components.excel.ExcelImportListener;
 | 
| 
 
 | 
7
 | 
+import com.lframework.starter.web.core.utils.ApplicationUtil;
 | 
| 
 
 | 
8
 | 
+import com.lframework.xingyun.sc.entity.CorePersonnel;
 | 
| 
 
 | 
9
 | 
+import com.lframework.xingyun.sc.entity.CustomerCredit;
 | 
| 
 
 | 
10
 | 
+import com.lframework.xingyun.sc.service.customer.CorePersonnelService;
 | 
| 
 
 | 
11
 | 
+import com.lframework.xingyun.sc.service.customer.CustomerCreditService;
 | 
| 
 
 | 
12
 | 
+import com.lframework.xingyun.sc.vo.customer.credit.QueryCorePersonnelVo;
 | 
| 
 
 | 
13
 | 
+import com.lframework.xingyun.sc.vo.customer.credit.QueryCustomerCreditVo;
 | 
| 
 
 | 
14
 | 
+import com.lframework.xingyun.sc.vo.customer.credit.UpdateCorePersonnelVo;
 | 
| 
 
 | 
15
 | 
+import com.lframework.xingyun.sc.vo.customer.credit.UpdateCustomerCreditVo;
 | 
| 
 
 | 
16
 | 
+import lombok.extern.slf4j.Slf4j;
 | 
| 
 
 | 
17
 | 
+import org.springframework.beans.BeanUtils;
 | 
| 
 
 | 
18
 | 
+import org.apache.commons.collections.CollectionUtils;
 | 
| 
 
 | 
19
 | 
+
 | 
| 
 
 | 
20
 | 
+import java.util.ArrayList;
 | 
| 
 
 | 
21
 | 
+import java.util.Arrays;
 | 
| 
 
 | 
22
 | 
+import java.util.List;
 | 
| 
 
 | 
23
 | 
+
 | 
| 
 
 | 
24
 | 
+@Slf4j
 | 
| 
 
 | 
25
 | 
+public class CustomerCreditImportListener extends ExcelImportListener<CustomerCreditImportModel> {
 | 
| 
 
 | 
26
 | 
+
 | 
| 
 
 | 
27
 | 
+
 | 
| 
 
 | 
28
 | 
+  private List<String> checkList = new ArrayList<>();
 | 
| 
 
 | 
29
 | 
+
 | 
| 
 
 | 
30
 | 
+  @Override
 | 
| 
 
 | 
31
 | 
+  protected void doInvoke(CustomerCreditImportModel data, AnalysisContext context) {
 | 
| 
 
 | 
32
 | 
+    List<String> validValues = Arrays.asList("AAA", "AA", "A", "BBB", "BB", "B", "C", "D");
 | 
| 
 
 | 
33
 | 
+    if (StringUtil.isBlank(data.getCode())) {
 | 
| 
 
 | 
34
 | 
+      throw new DefaultClientException(
 | 
| 
 
 | 
35
 | 
+          "第" + context.readRowHolder().getRowIndex() + "行“编号”不能为空");
 | 
| 
 
 | 
36
 | 
+    }
 | 
| 
 
 | 
37
 | 
+    if (checkList.contains(data.getCode())) {
 | 
| 
 
 | 
38
 | 
+      throw new DefaultClientException(
 | 
| 
 
 | 
39
 | 
+          "第" + context.readRowHolder().getRowIndex() + "行“编号”与第" + (checkList.indexOf(data.getCode()) + 1) + "行重复");
 | 
| 
 
 | 
40
 | 
+    }
 | 
| 
 
 | 
41
 | 
+    checkList.add(data.getCode());
 | 
| 
 
 | 
42
 | 
+    QueryCustomerCreditVo vo = new QueryCustomerCreditVo();
 | 
| 
 
 | 
43
 | 
+    vo.setSerialNumber(data.getCode());
 | 
| 
 
 | 
44
 | 
+    CustomerCreditService customerCreditService = ApplicationUtil.getBean(CustomerCreditService.class);
 | 
| 
 
 | 
45
 | 
+    List<CustomerCredit> query = customerCreditService.query(vo);
 | 
| 
 
 | 
46
 | 
+    if (CollectionUtils.isEmpty(query)) {
 | 
| 
 
 | 
47
 | 
+      throw new DefaultClientException(
 | 
| 
 
 | 
48
 | 
+              "第" + context.readRowHolder().getRowIndex() + "行“编号”不存在");
 | 
| 
 
 | 
49
 | 
+    }
 | 
| 
 
 | 
50
 | 
+
 | 
| 
 
 | 
51
 | 
+    if (StringUtil.isNotEmpty(data.getCompanySuggestedCategory()) && !validValues.contains(data.getCompanySuggestedCategory())) {
 | 
| 
 
 | 
52
 | 
+      throw new DefaultClientException(
 | 
| 
 
 | 
53
 | 
+              "第" + context.readRowHolder().getRowIndex() + "行“客户分类”只能为:AAA、AA、A、BBB、BB、B、C、D");
 | 
| 
 
 | 
54
 | 
+    }
 | 
| 
 
 | 
55
 | 
+  }
 | 
| 
 
 | 
56
 | 
+
 | 
| 
 
 | 
57
 | 
+  @Override
 | 
| 
 
 | 
58
 | 
+  protected void afterAllAnalysed(AnalysisContext context) {
 | 
| 
 
 | 
59
 | 
+    CorePersonnelService corePersonnelService = ApplicationUtil.getBean(CorePersonnelService.class);
 | 
| 
 
 | 
60
 | 
+    CustomerCreditService customerCreditService = ApplicationUtil.getBean(CustomerCreditService.class);
 | 
| 
 
 | 
61
 | 
+    List<CustomerCreditImportModel> datas = this.getDatas();
 | 
| 
 
 | 
62
 | 
+    for (int i = 0; i < datas.size(); i++) {
 | 
| 
 
 | 
63
 | 
+      CustomerCreditImportModel data = datas.get(i);
 | 
| 
 
 | 
64
 | 
+      QueryCustomerCreditVo vo = new QueryCustomerCreditVo();
 | 
| 
 
 | 
65
 | 
+      vo.setSerialNumber(data.getCode());
 | 
| 
 
 | 
66
 | 
+      List<CustomerCredit> query = customerCreditService.query(vo);
 | 
| 
 
 | 
67
 | 
+      if (CollectionUtils.isNotEmpty(query)) {
 | 
| 
 
 | 
68
 | 
+        CustomerCredit customerCredit = query.get(0);
 | 
| 
 
 | 
69
 | 
+
 | 
| 
 
 | 
70
 | 
+        UpdateCustomerCreditVo updateCustomerCreditVo = new UpdateCustomerCreditVo();
 | 
| 
 
 | 
71
 | 
+//        updateCustomerCreditVo.setId(customerCredit.getId());
 | 
| 
 
 | 
72
 | 
+
 | 
| 
 
 | 
73
 | 
+        BeanUtils.copyProperties(customerCredit, updateCustomerCreditVo);
 | 
| 
 
 | 
74
 | 
+        //客户分类
 | 
| 
 
 | 
75
 | 
+        if (StringUtil.isNotEmpty(data.getCompanySuggestedCategory())) {
 | 
| 
 
 | 
76
 | 
+          updateCustomerCreditVo.setCompanySuggestedCategory(data.getCompanySuggestedCategory());
 | 
| 
 
 | 
77
 | 
+        }
 | 
| 
 
 | 
78
 | 
+        //授信额度
 | 
| 
 
 | 
79
 | 
+        if (StringUtil.isNotEmpty(data.getCompanyCreditLimit())) {
 | 
| 
 
 | 
80
 | 
+          updateCustomerCreditVo.setCompanyCreditLimit(data.getCompanyCreditLimit());
 | 
| 
 
 | 
81
 | 
+        }
 | 
| 
 
 | 
82
 | 
+        //加工操作方案
 | 
| 
 
 | 
83
 | 
+        if (StringUtil.isNotEmpty(data.getCompanyMaterialSupplyPlan())) {
 | 
| 
 
 | 
84
 | 
+          updateCustomerCreditVo.setCompanyMaterialSupplyPlan(data.getCompanyMaterialSupplyPlan());
 | 
| 
 
 | 
85
 | 
+        }
 | 
| 
 
 | 
86
 | 
+        //结算期限
 | 
| 
 
 | 
87
 | 
+        if (StringUtil.isNotEmpty(data.getCompanySettlementPeriod())) {
 | 
| 
 
 | 
88
 | 
+          updateCustomerCreditVo.setCompanySettlementPeriod(data.getCompanySettlementPeriod());
 | 
| 
 
 | 
89
 | 
+        }
 | 
| 
 
 | 
90
 | 
+        //核心人员(不填更新的时候会被删除)
 | 
| 
 
 | 
91
 | 
+        QueryCorePersonnelVo queryCorePersonnelVo = new QueryCorePersonnelVo();
 | 
| 
 
 | 
92
 | 
+        queryCorePersonnelVo.setCreditId(customerCredit.getId());
 | 
| 
 
 | 
93
 | 
+        List<CorePersonnel> corePersonnelList = corePersonnelService.query(queryCorePersonnelVo);
 | 
| 
 
 | 
94
 | 
+        if (CollectionUtils.isNotEmpty(corePersonnelList)) {
 | 
| 
 
 | 
95
 | 
+          List<UpdateCorePersonnelVo> results = new ArrayList<>();
 | 
| 
 
 | 
96
 | 
+          for (CorePersonnel corePersonnel : corePersonnelList) {
 | 
| 
 
 | 
97
 | 
+            UpdateCorePersonnelVo personnelVo = new UpdateCorePersonnelVo();
 | 
| 
 
 | 
98
 | 
+            personnelVo.setId(corePersonnel.getId());
 | 
| 
 
 | 
99
 | 
+            personnelVo.setCreditId(corePersonnel.getCreditId());
 | 
| 
 
 | 
100
 | 
+            if (!StringUtil.isBlank(corePersonnel.getPersonId())) {
 | 
| 
 
 | 
101
 | 
+              personnelVo.setPersonId(corePersonnel.getPersonId());
 | 
| 
 
 | 
102
 | 
+            }
 | 
| 
 
 | 
103
 | 
+            if (!StringUtil.isBlank(corePersonnel.getName())) {
 | 
| 
 
 | 
104
 | 
+              personnelVo.setName(corePersonnel.getName());
 | 
| 
 
 | 
105
 | 
+            }
 | 
| 
 
 | 
106
 | 
+            if (!StringUtil.isBlank(corePersonnel.getSex())) {
 | 
| 
 
 | 
107
 | 
+              personnelVo.setSex(corePersonnel.getSex());
 | 
| 
 
 | 
108
 | 
+            }
 | 
| 
 
 | 
109
 | 
+            if (!StringUtil.isBlank(corePersonnel.getNativePlace())) {
 | 
| 
 
 | 
110
 | 
+              personnelVo.setNativePlace(corePersonnel.getNativePlace());
 | 
| 
 
 | 
111
 | 
+            }
 | 
| 
 
 | 
112
 | 
+            if (!StringUtil.isBlank(corePersonnel.getAge())) {
 | 
| 
 
 | 
113
 | 
+              personnelVo.setAge(corePersonnel.getAge());
 | 
| 
 
 | 
114
 | 
+            }
 | 
| 
 
 | 
115
 | 
+            if (!StringUtil.isBlank(corePersonnel.getPosition())) {
 | 
| 
 
 | 
116
 | 
+              personnelVo.setPosition(corePersonnel.getPosition());
 | 
| 
 
 | 
117
 | 
+            }
 | 
| 
 
 | 
118
 | 
+            if (!StringUtil.isBlank(corePersonnel.getMobile())) {
 | 
| 
 
 | 
119
 | 
+              personnelVo.setMobile(corePersonnel.getMobile());
 | 
| 
 
 | 
120
 | 
+            }
 | 
| 
 
 | 
121
 | 
+            if (!StringUtil.isBlank(corePersonnel.getPhone())) {
 | 
| 
 
 | 
122
 | 
+              personnelVo.setPhone(corePersonnel.getPhone());
 | 
| 
 
 | 
123
 | 
+            }
 | 
| 
 
 | 
124
 | 
+            if (!StringUtil.isBlank(corePersonnel.getEmail())) {
 | 
| 
 
 | 
125
 | 
+              personnelVo.setEmail(corePersonnel.getEmail());
 | 
| 
 
 | 
126
 | 
+            }
 | 
| 
 
 | 
127
 | 
+            if (!StringUtil.isBlank(corePersonnel.getAddress())) {
 | 
| 
 
 | 
128
 | 
+              personnelVo.setAddress(corePersonnel.getAddress());
 | 
| 
 
 | 
129
 | 
+            }
 | 
| 
 
 | 
130
 | 
+            results.add(personnelVo);
 | 
| 
 
 | 
131
 | 
+          }
 | 
| 
 
 | 
132
 | 
+          updateCustomerCreditVo.setCorePersonnelList(results);
 | 
| 
 
 | 
133
 | 
+        }
 | 
| 
 
 | 
134
 | 
+        customerCreditService.update(updateCustomerCreditVo);
 | 
| 
 
 | 
135
 | 
+        customerCreditService.cleanCacheByKey(customerCredit.getId());
 | 
| 
 
 | 
136
 | 
+
 | 
| 
 
 | 
137
 | 
+        this.setSuccessProcess(i);
 | 
| 
 
 | 
138
 | 
+      }
 | 
| 
 
 | 
139
 | 
+    }
 | 
| 
 
 | 
140
 | 
+  }
 | 
| 
 
 | 
141
 | 
+
 | 
| 
 
 | 
142
 | 
+  @Override
 | 
| 
 
 | 
143
 | 
+  protected void doComplete() {
 | 
| 
 
 | 
144
 | 
+  }
 | 
| 
 
 | 
145
 | 
+} | 
...
 | 
...
 | 
 |