Showing
4 changed files
with
83 additions
and
2 deletions
@@ -14,15 +14,18 @@ import com.ash.base.SpringJobBeanFactory; | @@ -14,15 +14,18 @@ import com.ash.base.SpringJobBeanFactory; | ||
14 | import com.ash.base.excelOpt.ExcelCheck; | 14 | import com.ash.base.excelOpt.ExcelCheck; |
15 | import com.ash.base.excelOpt.ExcelErrorMessage; | 15 | import com.ash.base.excelOpt.ExcelErrorMessage; |
16 | import com.ash.base.excelOpt.ValidateAnnotation; | 16 | import com.ash.base.excelOpt.ValidateAnnotation; |
17 | +import com.ash.entity.Case; | ||
17 | import com.ash.entity.dao.CaseMapper; | 18 | import com.ash.entity.dao.CaseMapper; |
18 | import com.ash.excelData.CaseExcelData; | 19 | import com.ash.excelData.CaseExcelData; |
19 | import com.ash.service.CaseService; | 20 | import com.ash.service.CaseService; |
21 | +import com.ash.util.ObjectValueOption; | ||
20 | import com.sun.javafx.binding.StringFormatter; | 22 | import com.sun.javafx.binding.StringFormatter; |
21 | import javafx.beans.binding.StringExpression; | 23 | import javafx.beans.binding.StringExpression; |
22 | import lombok.Getter; | 24 | import lombok.Getter; |
23 | import lombok.extern.slf4j.Slf4j; | 25 | import lombok.extern.slf4j.Slf4j; |
24 | import org.apache.commons.collections.CollectionUtils; | 26 | import org.apache.commons.collections.CollectionUtils; |
25 | import org.apache.commons.lang3.StringUtils; | 27 | import org.apache.commons.lang3.StringUtils; |
28 | +import org.springframework.stereotype.Component; | ||
26 | 29 | ||
27 | import javax.annotation.Resource; | 30 | import javax.annotation.Resource; |
28 | import java.lang.reflect.Field; | 31 | import java.lang.reflect.Field; |
@@ -151,6 +154,7 @@ public class CaseExcelListener extends AnalysisEventListener<CaseExcelData> | @@ -151,6 +154,7 @@ public class CaseExcelListener extends AnalysisEventListener<CaseExcelData> | ||
151 | 154 | ||
152 | @Override | 155 | @Override |
153 | public void doAfterAllAnalysed(AnalysisContext analysisContext) { | 156 | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
157 | + checkRepeat(); | ||
154 | if (CollectionUtils.isNotEmpty(errorList)) { | 158 | if (CollectionUtils.isNotEmpty(errorList)) { |
155 | throw new ExcelAnalysisException("数据校验错误!"); | 159 | throw new ExcelAnalysisException("数据校验错误!"); |
156 | } | 160 | } |
@@ -281,12 +285,16 @@ public class CaseExcelListener extends AnalysisEventListener<CaseExcelData> | @@ -281,12 +285,16 @@ public class CaseExcelListener extends AnalysisEventListener<CaseExcelData> | ||
281 | public void checkRepeat() { | 285 | public void checkRepeat() { |
282 | Map<Field, ValidateAnnotation> repeatFieldMap = fieldMap.entrySet().stream().filter(entry -> !entry.getValue().getExcelCheck().canRepeat()) | 286 | Map<Field, ValidateAnnotation> repeatFieldMap = fieldMap.entrySet().stream().filter(entry -> !entry.getValue().getExcelCheck().canRepeat()) |
283 | .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | 287 | .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); |
288 | + CaseService caseService = SpringJobBeanFactory.getBean(CaseService.class); | ||
284 | repeatFieldMap.forEach((field, annotation) -> { | 289 | repeatFieldMap.forEach((field, annotation) -> { |
285 | //使用iterate方式构建流以获取行号 | 290 | //使用iterate方式构建流以获取行号 |
291 | + List<String> uniqueCodeList = new ArrayList<>(); | ||
286 | Stream.iterate(0, i -> i + 1).limit(list.size()).collect(Collectors.groupingBy(i -> { | 292 | Stream.iterate(0, i -> i + 1).limit(list.size()).collect(Collectors.groupingBy(i -> { |
287 | try { | 293 | try { |
288 | Object value = field.get(list.get(i)); | 294 | Object value = field.get(list.get(i)); |
289 | - return JSON.toJSONString(value); | 295 | + String uc = ObjectValueOption.getObjString(value); |
296 | + uniqueCodeList.add(uc); | ||
297 | + return uc; | ||
290 | } catch (IllegalAccessException e) { | 298 | } catch (IllegalAccessException e) { |
291 | throw new RuntimeException(e); | 299 | throw new RuntimeException(e); |
292 | } | 300 | } |
@@ -301,6 +309,21 @@ public class CaseExcelListener extends AnalysisEventListener<CaseExcelData> | @@ -301,6 +309,21 @@ public class CaseExcelListener extends AnalysisEventListener<CaseExcelData> | ||
301 | } | 309 | } |
302 | } | 310 | } |
303 | }); | 311 | }); |
312 | + if (CollectionUtils.isEmpty(errorList)) { | ||
313 | + List<String> repeatDataList = caseService.listByFeild(field.getName(), uniqueCodeList); | ||
314 | + for (int i = 0; i < list.size(); i++) { | ||
315 | + try { | ||
316 | + Object value = field.get(list.get(i)); | ||
317 | + String uc = ObjectValueOption.getObjString(value); | ||
318 | + if (repeatDataList.contains(uc)) { | ||
319 | + addError(i + 1, annotation.getHeadName() + "字段已存在!"); | ||
320 | + } | ||
321 | + | ||
322 | + } catch (IllegalAccessException e) { | ||
323 | + throw new RuntimeException(e); | ||
324 | + } | ||
325 | + } | ||
326 | + } | ||
304 | }); | 327 | }); |
305 | } | 328 | } |
306 | 329 |
@@ -17,6 +17,7 @@ import com.ash.base.excelOpt.ValidateAnnotation; | @@ -17,6 +17,7 @@ import com.ash.base.excelOpt.ValidateAnnotation; | ||
17 | import com.ash.entity.dao.WarningInstanceMapper; | 17 | import com.ash.entity.dao.WarningInstanceMapper; |
18 | import com.ash.excelData.WarningInstanceExcelData; | 18 | import com.ash.excelData.WarningInstanceExcelData; |
19 | import com.ash.service.WarningInstanceService; | 19 | import com.ash.service.WarningInstanceService; |
20 | +import com.ash.util.ObjectValueOption; | ||
20 | import lombok.Getter; | 21 | import lombok.Getter; |
21 | import lombok.extern.slf4j.Slf4j; | 22 | import lombok.extern.slf4j.Slf4j; |
22 | import org.apache.commons.collections.CollectionUtils; | 23 | import org.apache.commons.collections.CollectionUtils; |
@@ -150,6 +151,7 @@ public class WarningInstanceExcelListener extends AnalysisEventListener<WarningI | @@ -150,6 +151,7 @@ public class WarningInstanceExcelListener extends AnalysisEventListener<WarningI | ||
150 | 151 | ||
151 | @Override | 152 | @Override |
152 | public void doAfterAllAnalysed(AnalysisContext analysisContext) { | 153 | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
154 | + checkRepeat(); | ||
153 | if (CollectionUtils.isNotEmpty(errorList)) { | 155 | if (CollectionUtils.isNotEmpty(errorList)) { |
154 | throw new ExcelAnalysisException("数据校验错误!"); | 156 | throw new ExcelAnalysisException("数据校验错误!"); |
155 | } | 157 | } |
@@ -285,12 +287,16 @@ public class WarningInstanceExcelListener extends AnalysisEventListener<WarningI | @@ -285,12 +287,16 @@ public class WarningInstanceExcelListener extends AnalysisEventListener<WarningI | ||
285 | public void checkRepeat() { | 287 | public void checkRepeat() { |
286 | Map<Field, ValidateAnnotation> repeatFieldMap = fieldMap.entrySet().stream().filter(entry -> !entry.getValue().getExcelCheck().canRepeat()) | 288 | Map<Field, ValidateAnnotation> repeatFieldMap = fieldMap.entrySet().stream().filter(entry -> !entry.getValue().getExcelCheck().canRepeat()) |
287 | .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | 289 | .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); |
290 | + WarningInstanceService warningInstanceService = SpringJobBeanFactory.getBean(WarningInstanceService.class); | ||
288 | repeatFieldMap.forEach((field, annotation) -> { | 291 | repeatFieldMap.forEach((field, annotation) -> { |
289 | //使用iterate方式构建流以获取行号 | 292 | //使用iterate方式构建流以获取行号 |
293 | + List<String> uniqueCodeList = new ArrayList<>(); | ||
290 | Stream.iterate(0, i -> i + 1).limit(list.size()).collect(Collectors.groupingBy(i -> { | 294 | Stream.iterate(0, i -> i + 1).limit(list.size()).collect(Collectors.groupingBy(i -> { |
291 | try { | 295 | try { |
292 | Object value = field.get(list.get(i)); | 296 | Object value = field.get(list.get(i)); |
293 | - return JSON.toJSONString(value); | 297 | + String uc = ObjectValueOption.getObjString(value); |
298 | + uniqueCodeList.add(uc); | ||
299 | + return uc; | ||
294 | } catch (IllegalAccessException e) { | 300 | } catch (IllegalAccessException e) { |
295 | throw new RuntimeException(e); | 301 | throw new RuntimeException(e); |
296 | } | 302 | } |
@@ -305,6 +311,21 @@ public class WarningInstanceExcelListener extends AnalysisEventListener<WarningI | @@ -305,6 +311,21 @@ public class WarningInstanceExcelListener extends AnalysisEventListener<WarningI | ||
305 | } | 311 | } |
306 | } | 312 | } |
307 | }); | 313 | }); |
314 | + if (CollectionUtils.isEmpty(errorList)) { | ||
315 | + List<String> repeatDataList = warningInstanceService.listByFeild(field.getName(), uniqueCodeList); | ||
316 | + for (int i = 0; i < list.size(); i++) { | ||
317 | + try { | ||
318 | + Object value = field.get(list.get(i)); | ||
319 | + String uc = ObjectValueOption.getObjString(value); | ||
320 | + if (repeatDataList.contains(uc)) { | ||
321 | + addError(i + 1, annotation.getHeadName() + "字段已存在!"); | ||
322 | + } | ||
323 | + | ||
324 | + } catch (IllegalAccessException e) { | ||
325 | + throw new RuntimeException(e); | ||
326 | + } | ||
327 | + } | ||
328 | + } | ||
308 | }); | 329 | }); |
309 | } | 330 | } |
310 | 331 |
@@ -16,6 +16,7 @@ import com.ash.listener.CaseExcelListener; | @@ -16,6 +16,7 @@ import com.ash.listener.CaseExcelListener; | ||
16 | import com.ash.util.*; | 16 | import com.ash.util.*; |
17 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 17 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
18 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 18 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
19 | +import com.baomidou.mybatisplus.core.toolkit.support.SFunction; | ||
19 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 20 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
20 | import com.github.yulichang.query.MPJQueryWrapper; | 21 | import com.github.yulichang.query.MPJQueryWrapper; |
21 | import lombok.extern.slf4j.Slf4j; | 22 | import lombok.extern.slf4j.Slf4j; |
@@ -28,6 +29,8 @@ import org.springframework.util.CollectionUtils; | @@ -28,6 +29,8 @@ import org.springframework.util.CollectionUtils; | ||
28 | import org.springframework.web.multipart.MultipartFile; | 29 | import org.springframework.web.multipart.MultipartFile; |
29 | 30 | ||
30 | import javax.annotation.Resource; | 31 | import javax.annotation.Resource; |
32 | +import java.lang.reflect.Field; | ||
33 | +import java.lang.reflect.Method; | ||
31 | import java.text.ParseException; | 34 | import java.text.ParseException; |
32 | import java.text.SimpleDateFormat; | 35 | import java.text.SimpleDateFormat; |
33 | import java.util.*; | 36 | import java.util.*; |
@@ -149,6 +152,23 @@ public class CaseService { | @@ -149,6 +152,23 @@ public class CaseService { | ||
149 | } | 152 | } |
150 | 153 | ||
151 | 154 | ||
155 | + public List<String> listByFeild(String fieldName, List<String> values) { | ||
156 | + QueryWrapper<Case> queryWrapper = new QueryWrapper<>(); | ||
157 | + queryWrapper.in(fieldName,values); | ||
158 | + List<Case> cases = caseMapper.selectList(queryWrapper); | ||
159 | + return Optional.ofNullable(cases).map(all -> all.stream().map(item -> { | ||
160 | + try { | ||
161 | + Field field = Case.class.getDeclaredField(fieldName); | ||
162 | + field.setAccessible(true); | ||
163 | + return String.valueOf(field.get(item)); | ||
164 | + } catch (Exception e) { | ||
165 | + e.printStackTrace(); | ||
166 | + } | ||
167 | + return ""; | ||
168 | + }).filter(StringUtils::isNotBlank).collect(Collectors.toList())).orElse(new ArrayList<>()); | ||
169 | + } | ||
170 | + | ||
171 | + | ||
152 | public List<String> listUnReview(List<String> exceptIds, String area) { | 172 | public List<String> listUnReview(List<String> exceptIds, String area) { |
153 | QueryWrapper<Case> queryWrapper = new QueryWrapper<>(); | 173 | QueryWrapper<Case> queryWrapper = new QueryWrapper<>(); |
154 | LambdaQueryWrapper<Case> lambda = queryWrapper.lambda(); | 174 | LambdaQueryWrapper<Case> lambda = queryWrapper.lambda(); |
@@ -30,6 +30,7 @@ import org.springframework.util.CollectionUtils; | @@ -30,6 +30,7 @@ import org.springframework.util.CollectionUtils; | ||
30 | import org.springframework.web.multipart.MultipartFile; | 30 | import org.springframework.web.multipart.MultipartFile; |
31 | 31 | ||
32 | import javax.annotation.Resource; | 32 | import javax.annotation.Resource; |
33 | +import java.lang.reflect.Field; | ||
33 | import java.text.ParseException; | 34 | import java.text.ParseException; |
34 | import java.text.SimpleDateFormat; | 35 | import java.text.SimpleDateFormat; |
35 | import java.util.*; | 36 | import java.util.*; |
@@ -132,6 +133,22 @@ public class WarningInstanceService { | @@ -132,6 +133,22 @@ public class WarningInstanceService { | ||
132 | return warningInstanceMapper.selectList(queryWrapper); | 133 | return warningInstanceMapper.selectList(queryWrapper); |
133 | } | 134 | } |
134 | 135 | ||
136 | + public List<String> listByFeild(String fieldName, List<String> values) { | ||
137 | + QueryWrapper<WarningInstance> queryWrapper = new QueryWrapper<>(); | ||
138 | + queryWrapper.in(fieldName,values); | ||
139 | + List<WarningInstance> cases = warningInstanceMapper.selectList(queryWrapper); | ||
140 | + return Optional.ofNullable(cases).map(all -> all.stream().map(item -> { | ||
141 | + try { | ||
142 | + Field field = WarningInstance.class.getDeclaredField(fieldName); | ||
143 | + field.setAccessible(true); | ||
144 | + return String.valueOf(field.get(item)); | ||
145 | + } catch (Exception e) { | ||
146 | + e.printStackTrace(); | ||
147 | + } | ||
148 | + return ""; | ||
149 | + }).filter(StringUtils::isNotBlank).collect(Collectors.toList())).orElse(new ArrayList<>()); | ||
150 | + } | ||
151 | + | ||
135 | public List<String> listUnReview(List<String> exceptIds, String area) { | 152 | public List<String> listUnReview(List<String> exceptIds, String area) { |
136 | QueryWrapper<WarningInstance> queryWrapper = new QueryWrapper<>(); | 153 | QueryWrapper<WarningInstance> queryWrapper = new QueryWrapper<>(); |
137 | LambdaQueryWrapper<WarningInstance> lambda = queryWrapper.lambda(); | 154 | LambdaQueryWrapper<WarningInstance> lambda = queryWrapper.lambda(); |