记得上下班打卡 | git大法好,push需谨慎

Commit cb751a2d authored by 姜秀龙's avatar 姜秀龙

收钱 同步参数校验

parent 1ae61d36
...@@ -73,16 +73,19 @@ public class GoblinStoreMgtSqbGoodsController { ...@@ -73,16 +73,19 @@ public class GoblinStoreMgtSqbGoodsController {
return ResponseDto.failure(ErrorMapping.get("149002")); return ResponseDto.failure(ErrorMapping.get("149002"));
} }
if (CollectionUtils.isEmpty(items)) { if (CollectionUtils.isEmpty(items)) {
return ResponseDto.success(buildAddResult(0, 0, 0)); return ResponseDto.success(buildAddResult(0, 0, 0, Collections.emptyList()));
} }
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("收钱吧商品管理:批量添加:[items={}]", JsonUtils.toJson(items)); log.debug("收钱吧商品管理:批量添加:[items={}]", JsonUtils.toJson(items));
} }
int addSuccess = 0, alreadyExists = 0, addFail = 0; int addSuccess = 0, alreadyExists = 0, addFail = 0;
List<String> invalidReasons = new ArrayList<>();
for (GoblinSqbPerfGoodsVo sqbGoods : items) { for (GoblinSqbPerfGoodsVo sqbGoods : items) {
if (sqbGoods == null || StringUtils.isBlank(sqbGoods.getSpuId()) || StringUtils.isBlank(sqbGoods.getMallSn())) { String invalidReason = validateSqbGoodsForSync(sqbGoods);
if (StringUtils.isNotBlank(invalidReason)) {
addFail++; addFail++;
invalidReasons.add(invalidReason);
continue; continue;
} }
if (existsSqbSpu(sqbGoods.getMallSn(), sqbGoods.getSpuId())) { if (existsSqbSpu(sqbGoods.getMallSn(), sqbGoods.getSpuId())) {
...@@ -109,7 +112,7 @@ public class GoblinStoreMgtSqbGoodsController { ...@@ -109,7 +112,7 @@ public class GoblinStoreMgtSqbGoodsController {
log.error("收钱吧商品管理:批量添加失败, storeId={}, sqbSpuId={}", storeId, sqbGoods.getSpuId(), e); log.error("收钱吧商品管理:批量添加失败, storeId={}, sqbSpuId={}", storeId, sqbGoods.getSpuId(), e);
} }
} }
return ResponseDto.success(buildAddResult(addSuccess, alreadyExists, addFail)); return ResponseDto.success(buildAddResult(addSuccess, alreadyExists, addFail, invalidReasons));
} }
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
...@@ -122,10 +125,11 @@ public class GoblinStoreMgtSqbGoodsController { ...@@ -122,10 +125,11 @@ public class GoblinStoreMgtSqbGoodsController {
return ResponseDto.failure(ErrorMapping.get("149002")); return ResponseDto.failure(ErrorMapping.get("149002"));
} }
if (CollectionUtils.isEmpty(localSpuIds)) { if (CollectionUtils.isEmpty(localSpuIds)) {
return ResponseDto.success(buildEditResult(0, 0, 0, 0)); return ResponseDto.success(buildEditResult(0, 0, 0, 0, Collections.emptyList()));
} }
int editSuccess = 0, notAdded = 0, sqbNotFound = 0, editFail = 0; int editSuccess = 0, notAdded = 0, sqbNotFound = 0, editFail = 0;
List<String> invalidReasons = new ArrayList<>();
for (String localSpuId : localSpuIds) { for (String localSpuId : localSpuIds) {
if (StringUtils.isBlank(localSpuId)) { if (StringUtils.isBlank(localSpuId)) {
editFail++; editFail++;
...@@ -154,6 +158,12 @@ public class GoblinStoreMgtSqbGoodsController { ...@@ -154,6 +158,12 @@ public class GoblinStoreMgtSqbGoodsController {
sqbNotFound++; sqbNotFound++;
continue; continue;
} }
String invalidReason = validateSqbGoodsForSync(sqbGoods);
if (StringUtils.isNotBlank(invalidReason)) {
editFail++;
invalidReasons.add("localSpuId=" + localSpuId + ", " + invalidReason);
continue;
}
try { try {
if (goblinstoreMgtSqbGoodsService.sqbGoodsEditSpu(currentUid, sqbGoods, localGoodsInfoVo)) { if (goblinstoreMgtSqbGoodsService.sqbGoodsEditSpu(currentUid, sqbGoods, localGoodsInfoVo)) {
...@@ -167,7 +177,7 @@ public class GoblinStoreMgtSqbGoodsController { ...@@ -167,7 +177,7 @@ public class GoblinStoreMgtSqbGoodsController {
storeId, localSpuId, sqbSpuId, e); storeId, localSpuId, sqbSpuId, e);
} }
} }
return ResponseDto.success(buildEditResult(editSuccess, notAdded, sqbNotFound, editFail)); return ResponseDto.success(buildEditResult(editSuccess, notAdded, sqbNotFound, editFail, invalidReasons));
} }
private boolean existsSqbSpu(String mallSn, String sqbSpuId) { private boolean existsSqbSpu(String mallSn, String sqbSpuId) {
...@@ -225,20 +235,62 @@ public class GoblinStoreMgtSqbGoodsController { ...@@ -225,20 +235,62 @@ public class GoblinStoreMgtSqbGoodsController {
return null; return null;
} }
private Map<String, Integer> buildAddResult(int addSuccess, int alreadyExists, int addFail) { private String validateSqbGoodsForSync(GoblinSqbPerfGoodsVo sqbGoods) {
Map<String, Integer> result = new HashMap<>(); if (sqbGoods == null) {
return "收钱吧商品为空";
}
if (StringUtils.isBlank(sqbGoods.getMallSn())) {
return "收钱吧商品校验失败: mallSn为空, spuId=" + StringUtils.defaultString(sqbGoods.getSpuId());
}
if (StringUtils.isBlank(sqbGoods.getSignature())) {
return "收钱吧商品校验失败: signature为空, mallSn=" + sqbGoods.getMallSn() + ", spuId=" + StringUtils.defaultString(sqbGoods.getSpuId());
}
if (StringUtils.isBlank(sqbGoods.getSpuId())) {
return "收钱吧商品校验失败: spuId为空, mallSn=" + sqbGoods.getMallSn();
}
if (StringUtils.isBlank(sqbGoods.getTitle())) {
return "收钱吧商品校验失败: title为空, mallSn=" + sqbGoods.getMallSn() + ", spuId=" + sqbGoods.getSpuId();
}
if (CollectionUtils.isEmpty(sqbGoods.getSkuResults())) {
return "收钱吧商品校验失败: skuResults为空, mallSn=" + sqbGoods.getMallSn() + ", spuId=" + sqbGoods.getSpuId();
}
for (int i = 0; i < sqbGoods.getSkuResults().size(); i++) {
MallProductsQueryData.Sku sku = sqbGoods.getSkuResults().get(i);
if (sku == null) {
return "收钱吧商品校验失败: skuResults[" + i + "]为空, mallSn=" + sqbGoods.getMallSn() + ", spuId=" + sqbGoods.getSpuId();
}
if (StringUtils.isBlank(sku.getSkuId())) {
return "收钱吧商品校验失败: skuId为空, mallSn=" + sqbGoods.getMallSn() + ", spuId=" + sqbGoods.getSpuId() + ", index=" + i;
}
if (StringUtils.isBlank(sku.getSkuName())) {
return "收钱吧商品校验失败: skuName为空, mallSn=" + sqbGoods.getMallSn() + ", spuId=" + sqbGoods.getSpuId() + ", skuId=" + sku.getSkuId();
}
if (sku.getPrice() == null) {
return "收钱吧商品校验失败: price为空, mallSn=" + sqbGoods.getMallSn() + ", spuId=" + sqbGoods.getSpuId() + ", skuId=" + sku.getSkuId();
}
}
return null;
}
private Map<String, Object> buildAddResult(int addSuccess, int alreadyExists, int addFail, List<String> invalidReasons) {
Map<String, Object> result = new HashMap<>();
result.put("addSuccess", addSuccess); result.put("addSuccess", addSuccess);
result.put("alreadyExists", alreadyExists); result.put("alreadyExists", alreadyExists);
result.put("addFail", addFail); result.put("addFail", addFail);
result.put("invalidCount", CollectionUtils.isEmpty(invalidReasons) ? 0 : invalidReasons.size());
result.put("invalidReasons", invalidReasons);
return result; return result;
} }
private Map<String, Integer> buildEditResult(int editSuccess, int notAdded, int sqbNotFound, int editFail) { private Map<String, Object> buildEditResult(int editSuccess, int notAdded, int sqbNotFound, int editFail,
Map<String, Integer> result = new HashMap<>(); List<String> invalidReasons) {
Map<String, Object> result = new HashMap<>();
result.put("editSuccess", editSuccess); result.put("editSuccess", editSuccess);
result.put("notAdded", notAdded); result.put("notAdded", notAdded);
result.put("sqbNotFound", sqbNotFound); result.put("sqbNotFound", sqbNotFound);
result.put("editFail", editFail); result.put("editFail", editFail);
result.put("invalidCount", CollectionUtils.isEmpty(invalidReasons) ? 0 : invalidReasons.size());
result.put("invalidReasons", invalidReasons);
return result; return result;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment