同步BUG修复
This commit is contained in:
parent
bdf6232e15
commit
cdf82b1963
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -36,6 +36,7 @@ import com.nuzar.rtops.log.dto.LogRecordDTO;
|
|||
import com.nuzar.rtops.log.service.EsLogApprovalUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
@ -61,6 +62,7 @@ import java.util.stream.Collectors;
|
|||
@RequestMapping("/spz")
|
||||
@Api(tags = "特保区")
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class FreeTradeHandler implements BaseHandler {
|
||||
|
||||
@Resource
|
||||
|
@ -410,7 +412,7 @@ public class FreeTradeHandler implements BaseHandler {
|
|||
@PostMapping("/import-to-add")
|
||||
public Result<List<JSONObject>> upload(
|
||||
@RequestParam(required = false, defaultValue = "0") String type,
|
||||
MultipartFile file) throws IOException {
|
||||
MultipartFile file) {
|
||||
// 所有读取的数据
|
||||
List<FreeTradeExcel> dataList = new ArrayList<>();
|
||||
|
||||
|
@ -420,96 +422,102 @@ public class FreeTradeHandler implements BaseHandler {
|
|||
// 验证成功的数据
|
||||
List<JSONObject> successDataList = new ArrayList<>();
|
||||
|
||||
EasyExcel.read(file.getInputStream(), FreeTradeExcel.class, new ReadExcelListener<FreeTradeExcel>() {
|
||||
@Override
|
||||
protected void saveData(List<FreeTradeExcel> list) { // 保存数据
|
||||
dataList.addAll(list);
|
||||
try {
|
||||
|
||||
EasyExcel.read(file.getInputStream(), FreeTradeExcel.class, new ReadExcelListener<FreeTradeExcel>() {
|
||||
@Override
|
||||
protected void saveData(List<FreeTradeExcel> list) { // 保存数据
|
||||
dataList.addAll(list);
|
||||
}
|
||||
}).sheet().doRead();
|
||||
|
||||
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
|
||||
Validator validator = vf.getValidator();
|
||||
|
||||
List<FreeTradeExcel> validData = new ArrayList<>();
|
||||
|
||||
// 数据验证
|
||||
dataList.stream().forEach(item -> {
|
||||
Set<ConstraintViolation<FreeTradeExcel>> set = validator.validate(item);
|
||||
if (CollectionUtils.isEmpty(set)) { // 验证通过的
|
||||
validData.add(item);
|
||||
} else { // 验证失败的
|
||||
JSONObject o = JSONObject.from(item);
|
||||
o.put("status", set.stream().map(p -> p.getMessage()).collect(Collectors.joining(",")));
|
||||
errorDataList.add(o);
|
||||
}
|
||||
});
|
||||
|
||||
// 所有数据验证都不通过
|
||||
if (CollectionUtils.isEmpty(validData)) {
|
||||
return ResultUtil.failure(ErrorType.PARAMS_ERROR.id(), "导入失败", errorDataList);
|
||||
}
|
||||
}).sheet().doRead();
|
||||
|
||||
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
|
||||
Validator validator = vf.getValidator();
|
||||
|
||||
List<FreeTradeExcel> validData = new ArrayList<>();
|
||||
|
||||
// 数据验证
|
||||
dataList.stream().forEach(item -> {
|
||||
Set<ConstraintViolation<FreeTradeExcel>> set = validator.validate(item);
|
||||
if (CollectionUtils.isEmpty(set)) { // 验证通过的
|
||||
validData.add(item);
|
||||
} else { // 验证失败的
|
||||
JSONObject o = JSONObject.from(item);
|
||||
o.put("status", set.stream().map(p -> p.getMessage()).collect(Collectors.joining(",")));
|
||||
errorDataList.add(o);
|
||||
// 是否有重复的车架号
|
||||
List<String> repeat = validData.stream().collect(Collectors.groupingBy(FreeTradeExcel::getVin, Collectors.counting()))
|
||||
.entrySet().stream().filter(entry -> entry.getValue() > 1).map(entry -> entry.getKey()).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(repeat)) {
|
||||
errorDataList.addAll(validData.stream().filter(p -> repeat.contains(p.getVin())).map(p -> {
|
||||
JSONObject o = JSONObject.from(p);
|
||||
o.put("status", "车架号重复");
|
||||
return o;
|
||||
}).collect(Collectors.toList()));
|
||||
return ResultUtil.failure(ErrorType.PARAMS_ERROR.id(), "导入失败", errorDataList);
|
||||
}
|
||||
});
|
||||
|
||||
// 所有数据验证都不通过
|
||||
if (CollectionUtils.isEmpty(validData)) {
|
||||
return ResultUtil.failure(ErrorType.PARAMS_ERROR.id(), "导入失败", errorDataList);
|
||||
}
|
||||
List<CustomerFreeTrade> collect = validData.stream().map(item -> {
|
||||
CustomerFreeTrade freeTrade = PoMapper.instance.excel2Entity(item);
|
||||
freeTrade.setApplicantId(UserContext.getUser().getUserId());
|
||||
freeTrade.setIsActivate(ActiveEnum.NO);
|
||||
freeTrade.setApplyTime(new Date());
|
||||
if (StringUtils.equals("1", type)) {
|
||||
freeTrade.setCheckStatus(AuditEnum.AUDIT);
|
||||
} else {
|
||||
freeTrade.setCheckStatus(AuditEnum.SUBMIT);
|
||||
}
|
||||
return freeTrade;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 是否有重复的车架号
|
||||
List<String> repeat = validData.stream().collect(Collectors.groupingBy(FreeTradeExcel::getVin, Collectors.counting()))
|
||||
.entrySet().stream().filter(entry -> entry.getValue() > 1).map(entry -> entry.getKey()).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(repeat)) {
|
||||
errorDataList.addAll(validData.stream().filter(p -> repeat.contains(p.getVin())).map(p -> {
|
||||
JSONObject o = JSONObject.from(p);
|
||||
o.put("status", "车架号重复");
|
||||
return o;
|
||||
}).collect(Collectors.toList()));
|
||||
return ResultUtil.failure(ErrorType.PARAMS_ERROR.id(), "导入失败", errorDataList);
|
||||
}
|
||||
List<String> vins = collect.stream().map(p -> p.getVin()).collect(Collectors.toList());
|
||||
|
||||
List<CustomerFreeTrade> collect = validData.stream().map(item -> {
|
||||
CustomerFreeTrade freeTrade = PoMapper.instance.excel2Entity(item);
|
||||
freeTrade.setApplicantId(UserContext.getUser().getUserId());
|
||||
freeTrade.setIsActivate(ActiveEnum.NO);
|
||||
freeTrade.setApplyTime(new Date());
|
||||
if (StringUtils.equals("1", type)) {
|
||||
freeTrade.setCheckStatus(AuditEnum.AUDIT);
|
||||
} else {
|
||||
freeTrade.setCheckStatus(AuditEnum.SUBMIT);
|
||||
// 验证哪些车架号已经存在了
|
||||
List<CustomerFreeTrade> existCargos = customerFreeTradeService.list(new LambdaQueryWrapper<CustomerFreeTrade>().in(CustomerFreeTrade::getVin, vins));
|
||||
Map<String, ActiveEnum> existVins = existCargos.stream().collect(Collectors.toMap(CustomerFreeTrade::getVin, CustomerFreeTrade::getIsActivate));
|
||||
Map<String, Long> existIdMap = existCargos.stream().collect(Collectors.toMap(CustomerFreeTrade::getVin, CustomerFreeTrade::getId));
|
||||
|
||||
// 已激活不处理的数据
|
||||
List<FreeTradeExcel> activeData = validData.stream().filter(p -> existVins.containsKey(p.getVin()) && existVins.get(p.getVin()) == ActiveEnum.YES).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(activeData)) {
|
||||
errorDataList.addAll(activeData.stream().map(item -> {
|
||||
JSONObject o = JSONObject.from(item);
|
||||
o.put("status", "数据存在并激活");
|
||||
return o;
|
||||
}).collect(Collectors.toList()));
|
||||
|
||||
return ResultUtil.failure(ErrorType.PARAMS_ERROR.id(), "导入失败", errorDataList);
|
||||
}
|
||||
return freeTrade;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
List<String> vins = collect.stream().map(p -> p.getVin()).collect(Collectors.toList());
|
||||
// 需要修改的数据
|
||||
List<CustomerFreeTrade> update = collect.stream().filter(p -> existVins.containsKey(p.getVin()) && existVins.get(p.getVin()) == ActiveEnum.NO).map(p -> {
|
||||
p.setId(existIdMap.get(p.getVin()));
|
||||
p.setIsActivate(ActiveEnum.NO);
|
||||
return p;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 验证哪些车架号已经存在了
|
||||
List<CustomerFreeTrade> existCargos = customerFreeTradeService.list(new LambdaQueryWrapper<CustomerFreeTrade>().in(CustomerFreeTrade::getVin, vins));
|
||||
Map<String, ActiveEnum> existVins = existCargos.stream().collect(Collectors.toMap(CustomerFreeTrade::getVin, CustomerFreeTrade::getIsActivate));
|
||||
Map<String, Long> existIdMap = existCargos.stream().collect(Collectors.toMap(CustomerFreeTrade::getVin, CustomerFreeTrade::getId));
|
||||
List<CustomerFreeTrade> save = collect.stream().filter(p -> !existIdMap.containsKey(p.getVin())).map(p -> {
|
||||
p.setIsActivate(ActiveEnum.NO);
|
||||
return p;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 已激活不处理的数据
|
||||
List<FreeTradeExcel> activeData = validData.stream().filter(p -> existVins.containsKey(p.getVin()) && existVins.get(p.getVin()) == ActiveEnum.YES).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(activeData)) {
|
||||
errorDataList.addAll(activeData.stream().map(item -> {
|
||||
JSONObject o = JSONObject.from(item);
|
||||
o.put("status", "数据存在并激活");
|
||||
return o;
|
||||
}).collect(Collectors.toList()));
|
||||
customerFreeTradeService.updateBatchById(update);
|
||||
|
||||
return ResultUtil.failure(ErrorType.PARAMS_ERROR.id(), "导入失败", errorDataList);
|
||||
customerFreeTradeService.saveBatch(save);
|
||||
|
||||
return ResultUtil.success(errorDataList);
|
||||
} catch (Exception e) {
|
||||
log.error("错误信息", e);
|
||||
return ResultUtil.failure(ErrorType.PARAMS_ERROR.id(), e.getMessage());
|
||||
}
|
||||
|
||||
// 需要修改的数据
|
||||
List<CustomerFreeTrade> update = collect.stream().filter(p -> existVins.containsKey(p.getVin()) && existVins.get(p.getVin()) == ActiveEnum.NO).map(p -> {
|
||||
p.setId(existIdMap.get(p.getVin()));
|
||||
p.setIsActivate(ActiveEnum.NO);
|
||||
return p;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
List<CustomerFreeTrade> save = collect.stream().filter(p -> !existIdMap.containsKey(p.getVin())).map(p -> {
|
||||
p.setIsActivate(ActiveEnum.NO);
|
||||
return p;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
customerFreeTradeService.updateBatchById(update);
|
||||
|
||||
customerFreeTradeService.saveBatch(save);
|
||||
|
||||
return ResultUtil.success(errorDataList);
|
||||
}
|
||||
|
||||
@ApiOperation("导入删除")
|
||||
|
|
|
@ -847,7 +847,7 @@ public class CustomerServiceImpl implements CustomerService {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
CustomerExportInSyncLog log = new CustomerExportInSyncLog();
|
||||
log.setBatchNo(StringUtils.joinWith(",", list.stream().map(p -> p.getBatchNo()).collect(Collectors.toList())));
|
||||
log.setBatchNo(item.getBatchNo());
|
||||
log.setRequestStr(JSONObject.toJSONString(req));
|
||||
log.setResponseStr(e.getMessage());
|
||||
customerExportInSyncLogService.save(log);
|
||||
|
|
Loading…
Reference in New Issue