Commit d392f7f1 by 杨卫

feat:1047852:导入代码优化

1 parent 005d716f
...@@ -6,7 +6,7 @@ import lombok.Data; ...@@ -6,7 +6,7 @@ import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.LinkedHashMap;
/** /**
* 门店毛利率导入实体 * 门店毛利率导入实体
...@@ -24,7 +24,7 @@ public class MerchantProfitRecordImportDTO implements Serializable { ...@@ -24,7 +24,7 @@ public class MerchantProfitRecordImportDTO implements Serializable {
* 导入数据 * 导入数据
*/ */
@NotEmpty(message = "导入数据不能为空") @NotEmpty(message = "导入数据不能为空")
private Map<Integer, MerchantProfitRecordImportDataDTO> data; private LinkedHashMap<Integer, MerchantProfitRecordImportDataDTO> data;
/** /**
* 操作人 * 操作人
......
...@@ -231,7 +231,9 @@ public class BiAnalyseBackgroundService { ...@@ -231,7 +231,9 @@ public class BiAnalyseBackgroundService {
// 如果有门店名称就要校验门店名称 // 如果有门店名称就要校验门店名称
Map<Integer, String> merchantIdMapName = MapUtil.<Integer, String>builder().build(); Map<Integer, String> merchantIdMapName = MapUtil.<Integer, String>builder().build();
if (values.stream().anyMatch(merchantProfitRecord -> StrUtil.isNotBlank(merchantProfitRecord.getStoreName()))) { if (values.stream().anyMatch(merchantProfitRecord -> StrUtil.isNotBlank(merchantProfitRecord.getStoreName()))) {
List<MerchantNameResponse> merchantNameResponses = searchMerchantName(values.stream().map(ele -> ele.getStoreId().intValue()).collect(Collectors.toList())); List<MerchantNameResponse> merchantNameResponses = searchMerchantName(values.stream()
.filter(ele -> ObjectUtil.isNotNull(ele.getStoreId()))
.map(ele -> ele.getStoreId().intValue()).collect(Collectors.toList()));
merchantIdMapName = merchantNameResponses.stream().collect( merchantIdMapName = merchantNameResponses.stream().collect(
Collectors.toMap(MerchantNameResponse::getMerchantId, MerchantNameResponse::getMerchantName, (pre, next) -> pre)); Collectors.toMap(MerchantNameResponse::getMerchantId, MerchantNameResponse::getMerchantName, (pre, next) -> pre));
} }
...@@ -253,6 +255,11 @@ public class BiAnalyseBackgroundService { ...@@ -253,6 +255,11 @@ public class BiAnalyseBackgroundService {
if (CollUtil.isEmpty(checks)) { if (CollUtil.isEmpty(checks)) {
return uniqueKeyMapMerchantProfitRecord; return uniqueKeyMapMerchantProfitRecord;
} }
// 唯一键不为空的才进行查询
checks = checks.stream().filter(ele -> ObjectUtil.isNotNull(ele.getStoreId())
&& StrUtil.isNotBlank(ele.getBusinessType())
&& StrUtil.isNotBlank(ele.getMonthYear()))
.collect(Collectors.toList());
// or 拼接sql不能过长,影响性能同时mysql对sql语句的字节大小存在限制,故需分批查询 // or 拼接sql不能过长,影响性能同时mysql对sql语句的字节大小存在限制,故需分批查询
List<MerchantProfitRecord> merchantProfitRecords = Lists.newArrayList(); List<MerchantProfitRecord> merchantProfitRecords = Lists.newArrayList();
...@@ -316,20 +323,26 @@ public class BiAnalyseBackgroundService { ...@@ -316,20 +323,26 @@ public class BiAnalyseBackgroundService {
List<String> errors = Lists.newArrayList(); List<String> errors = Lists.newArrayList();
// 月份校验 // 月份校验
if (merchantProfitRecordOperationDTO.getMonthYear().compareTo(nowMonth) > 0) { String monthYear = merchantProfitRecordOperationDTO.getMonthYear();
if (StrUtil.isNotBlank(monthYear)) {
if (monthYear.compareTo(nowMonth) > 0) {
errors.add("无效月份"); errors.add("无效月份");
} }
}
// 重复校验 // 重复校验
String uniqueKey = StrUtil.join(SymbolConstants.UNDERLINE, merchantProfitRecordOperationDTO.getStoreId(), Long storeId = merchantProfitRecordOperationDTO.getStoreId();
merchantProfitRecordOperationDTO.getBusinessType(), merchantProfitRecordOperationDTO.getMonthYear()); String businessType = merchantProfitRecordOperationDTO.getBusinessType();
if (ObjectUtil.isNotNull(storeId) && StrUtil.isNotBlank(businessType) && StrUtil.isNotBlank(monthYear)) {
String uniqueKey = StrUtil.join(SymbolConstants.UNDERLINE, storeId, businessType, monthYear);
if (uniqueKeyMapMerchantProfitRecord.containsKey(uniqueKey)) { if (uniqueKeyMapMerchantProfitRecord.containsKey(uniqueKey)) {
errors.add("已存在"); errors.add("已存在");
} }
}
// 无效商户 // 无效商户
String storeName = merchantProfitRecordOperationDTO.getStoreName(); String storeName = merchantProfitRecordOperationDTO.getStoreName();
if (StrUtil.isNotBlank(storeName)) { if (StrUtil.isNotBlank(storeName) && ObjectUtil.isNotNull(storeId)) {
String merchantName = merchantIdMapName.get(merchantProfitRecordOperationDTO.getStoreId().intValue()); String merchantName = merchantIdMapName.get(merchantProfitRecordOperationDTO.getStoreId().intValue());
if (StrUtil.isBlank(merchantName) || !StrUtil.equalsIgnoreCase(merchantName, storeName)) { if (StrUtil.isBlank(merchantName) || !StrUtil.equalsIgnoreCase(merchantName, storeName)) {
errors.add("无效商户"); errors.add("无效商户");
...@@ -418,7 +431,7 @@ public class BiAnalyseBackgroundService { ...@@ -418,7 +431,7 @@ public class BiAnalyseBackgroundService {
// 获取成功和失败数据 // 获取成功和失败数据
Map<Boolean, Map<Integer, MerchantProfitRecordImportDataDTO>> partitioning = data.entrySet().stream().collect(Collectors.partitioningBy(entry -> Map<Boolean, Map<Integer, MerchantProfitRecordImportDataDTO>> partitioning = data.entrySet().stream().collect(Collectors.partitioningBy(entry ->
CollUtil.isEmpty(entry.getValue().getErrors()), CollUtil.isEmpty(entry.getValue().getErrors()),
Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1, () -> MapUtil.newHashMap(true)))
); );
Map<Integer, MerchantProfitRecordImportDataDTO> successData = partitioning.get(true); Map<Integer, MerchantProfitRecordImportDataDTO> successData = partitioning.get(true);
Map<Integer, MerchantProfitRecordImportDataDTO> failData = partitioning.get(false); Map<Integer, MerchantProfitRecordImportDataDTO> failData = partitioning.get(false);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!