|
|
1
|
+package com.lframework.xingyun.sc.excel.ledger;
|
|
|
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.starter.web.inner.entity.SysDept;
|
|
|
9
|
+import com.lframework.starter.web.inner.service.system.SysDeptService;
|
|
|
10
|
+import com.lframework.xingyun.basedata.entity.Customer;
|
|
|
11
|
+import com.lframework.xingyun.basedata.service.customer.CustomerService;
|
|
|
12
|
+import com.lframework.xingyun.sc.service.ledger.RecapitalizeService;
|
|
|
13
|
+import com.lframework.xingyun.sc.vo.ledger.recapitalize.CreateRecapitalizeVo;
|
|
|
14
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
15
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
16
|
+
|
|
|
17
|
+import java.math.BigDecimal;
|
|
|
18
|
+import java.time.LocalDate;
|
|
|
19
|
+import java.time.format.DateTimeFormatter;
|
|
|
20
|
+import java.time.format.DateTimeParseException;
|
|
|
21
|
+import java.util.List;
|
|
|
22
|
+
|
|
|
23
|
+@Slf4j
|
|
|
24
|
+public class RecapitalizeImportListener extends ExcelImportListener<RecapitalizeImportModel> {
|
|
|
25
|
+
|
|
|
26
|
+ @Override
|
|
|
27
|
+ protected void doInvoke(RecapitalizeImportModel data, AnalysisContext context) {
|
|
|
28
|
+ CustomerService customerService = ApplicationUtil.getBean(CustomerService.class);
|
|
|
29
|
+ SysDeptService sysDeptService = ApplicationUtil.getBean(SysDeptService.class);
|
|
|
30
|
+ if (StringUtil.isBlank(data.getRecapitalizeDateStr())) {
|
|
|
31
|
+ throw new DefaultClientException(
|
|
|
32
|
+ "第" + context.readRowHolder().getRowIndex() + "行“资金回笼日期”不能为空");
|
|
|
33
|
+ } else {
|
|
|
34
|
+ String dateStr = data.getRecapitalizeDateStr().trim();
|
|
|
35
|
+ try {
|
|
|
36
|
+ LocalDate localDate = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
37
|
+ data.setRecapitalizeDate(localDate);
|
|
|
38
|
+ } catch (DateTimeParseException e) {
|
|
|
39
|
+ try {
|
|
|
40
|
+ LocalDate localDate = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy/M/d"));
|
|
|
41
|
+ data.setRecapitalizeDate(localDate);
|
|
|
42
|
+ } catch (DateTimeParseException ex) {
|
|
|
43
|
+ try {
|
|
|
44
|
+ // 支持 "2025年12月3日" 或 "2025年12月03日"
|
|
|
45
|
+ LocalDate localDate = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy'年'M'月'd'日'"));
|
|
|
46
|
+ data.setRecapitalizeDate(localDate);
|
|
|
47
|
+ } catch (DateTimeParseException ex2) {
|
|
|
48
|
+ throw new DefaultClientException(
|
|
|
49
|
+ "第" + context.readRowHolder().getRowIndex() + "行”资金回笼日期“格式错误!");
|
|
|
50
|
+ }
|
|
|
51
|
+ }
|
|
|
52
|
+ }
|
|
|
53
|
+ }
|
|
|
54
|
+
|
|
|
55
|
+ if (StringUtil.isBlank(data.getOrderingUnitName())) {
|
|
|
56
|
+ throw new DefaultClientException(
|
|
|
57
|
+ "第" + context.readRowHolder().getRowIndex() + "行“订货单位名称”不能为空");
|
|
|
58
|
+ } else {
|
|
|
59
|
+ Customer customer = customerService.getByName(data.getOrderingUnitName());
|
|
|
60
|
+ if (customer == null) {
|
|
|
61
|
+ throw new DefaultClientException(
|
|
|
62
|
+ "第" + context.readRowHolder().getRowIndex() + "行“订货单位名称”不存在");
|
|
|
63
|
+ } else {
|
|
|
64
|
+ data.setOrderingUnit(customer.getId());
|
|
|
65
|
+ }
|
|
|
66
|
+ }
|
|
|
67
|
+
|
|
|
68
|
+ if (StringUtil.isBlank(data.getReturnedAmountStr())) {
|
|
|
69
|
+ throw new DefaultClientException(
|
|
|
70
|
+ "第" + context.readRowHolder().getRowIndex() + "行“回笼金额”不能为空");
|
|
|
71
|
+ } else {
|
|
|
72
|
+ try {
|
|
|
73
|
+ BigDecimal bigDecimal = new BigDecimal(data.getReturnedAmountStr());
|
|
|
74
|
+ data.setReturnedAmount(bigDecimal);
|
|
|
75
|
+ } catch (NumberFormatException e) {
|
|
|
76
|
+ throw new DefaultClientException(
|
|
|
77
|
+ "第" + context.readRowHolder().getRowIndex() + "行“回笼金额”格式错误");
|
|
|
78
|
+ }
|
|
|
79
|
+ }
|
|
|
80
|
+
|
|
|
81
|
+ if (StringUtil.isBlank(data.getDeptName())) {
|
|
|
82
|
+ throw new DefaultClientException(
|
|
|
83
|
+ "第" + context.readRowHolder().getRowIndex() + "行“办事处名称”不能为空");
|
|
|
84
|
+ } else {
|
|
|
85
|
+ List<SysDept> deptByName = sysDeptService.getDeptByName(data.getDeptName());
|
|
|
86
|
+ if (CollectionUtils.isEmpty(deptByName)) {
|
|
|
87
|
+ throw new DefaultClientException(
|
|
|
88
|
+ "第" + context.readRowHolder().getRowIndex() + "行“办事处”不存在");
|
|
|
89
|
+ } else {
|
|
|
90
|
+ if (deptByName.size() > 1) {
|
|
|
91
|
+ throw new DefaultClientException(
|
|
|
92
|
+ "第" + context.readRowHolder().getRowIndex() + "行“办事处”存在多个同名区域");
|
|
|
93
|
+ } else {
|
|
|
94
|
+ SysDept sysDept = deptByName.get(0);
|
|
|
95
|
+ data.setDeptId(sysDept.getId());
|
|
|
96
|
+ }
|
|
|
97
|
+ }
|
|
|
98
|
+ }
|
|
|
99
|
+
|
|
|
100
|
+ if (StringUtil.isBlank(data.getFactoryTypeName())) {
|
|
|
101
|
+ throw new DefaultClientException(
|
|
|
102
|
+ "第" + context.readRowHolder().getRowIndex() + "行“厂别”不能为空");
|
|
|
103
|
+ } else {
|
|
|
104
|
+ if (data.getFactoryTypeName().equals("安徽楚江高精铜带有限公司")) {
|
|
|
105
|
+ data.setFactoryType("GJ");
|
|
|
106
|
+ } else if (data.getFactoryTypeName().equals("安徽楚江科技新材料股份有限公司")) {
|
|
|
107
|
+ data.setFactoryType("XC");
|
|
|
108
|
+ } else {
|
|
|
109
|
+ throw new DefaultClientException(
|
|
|
110
|
+ "第" + context.readRowHolder().getRowIndex() + "行“厂别”不存在");
|
|
|
111
|
+ }
|
|
|
112
|
+ }
|
|
|
113
|
+
|
|
|
114
|
+ }
|
|
|
115
|
+
|
|
|
116
|
+ @Override
|
|
|
117
|
+ protected void afterAllAnalysed(AnalysisContext context) {
|
|
|
118
|
+ RecapitalizeService recapitalizeService = ApplicationUtil.getBean(RecapitalizeService.class);
|
|
|
119
|
+ List<RecapitalizeImportModel> datas = this.getDatas();
|
|
|
120
|
+ for (int i = 0; i < datas.size(); i++) {
|
|
|
121
|
+ RecapitalizeImportModel data = datas.get(i);
|
|
|
122
|
+ CreateRecapitalizeVo vo = new CreateRecapitalizeVo();
|
|
|
123
|
+ vo.setRecapitalizeDate(data.getRecapitalizeDate());
|
|
|
124
|
+ vo.setOrderingUnit(data.getOrderingUnit());
|
|
|
125
|
+ vo.setReturnedAmount(data.getReturnedAmount());
|
|
|
126
|
+ vo.setDeptId(data.getDeptId());
|
|
|
127
|
+ vo.setFactoryType(data.getFactoryType());
|
|
|
128
|
+ recapitalizeService.create(vo);
|
|
|
129
|
+ this.setSuccessProcess(i);
|
|
|
130
|
+ }
|
|
|
131
|
+ }
|
|
|
132
|
+
|
|
|
133
|
+ @Override
|
|
|
134
|
+ protected void doComplete() {
|
|
|
135
|
+ }
|
|
|
136
|
+} |
...
|
...
|
|