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

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

收钱 同步参数校验

parent 1ae61d36
......@@ -73,16 +73,19 @@ public class GoblinStoreMgtSqbGoodsController {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
if (CollectionUtils.isEmpty(items)) {
return ResponseDto.success(buildAddResult(0, 0, 0));
return ResponseDto.success(buildAddResult(0, 0, 0, Collections.emptyList()));
}
if (log.isDebugEnabled()) {
log.debug("收钱吧商品管理:批量添加:[items={}]", JsonUtils.toJson(items));
}
int addSuccess = 0, alreadyExists = 0, addFail = 0;
List<String> invalidReasons = new ArrayList<>();
for (GoblinSqbPerfGoodsVo sqbGoods : items) {
if (sqbGoods == null || StringUtils.isBlank(sqbGoods.getSpuId()) || StringUtils.isBlank(sqbGoods.getMallSn())) {
String invalidReason = validateSqbGoodsForSync(sqbGoods);
if (StringUtils.isNotBlank(invalidReason)) {
addFail++;
invalidReasons.add(invalidReason);
continue;
}
if (existsSqbSpu(sqbGoods.getMallSn(), sqbGoods.getSpuId())) {
......@@ -109,7 +112,7 @@ public class GoblinStoreMgtSqbGoodsController {
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)
......@@ -122,10 +125,11 @@ public class GoblinStoreMgtSqbGoodsController {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
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;
List<String> invalidReasons = new ArrayList<>();
for (String localSpuId : localSpuIds) {
if (StringUtils.isBlank(localSpuId)) {
editFail++;
......@@ -154,6 +158,12 @@ public class GoblinStoreMgtSqbGoodsController {
sqbNotFound++;
continue;
}
String invalidReason = validateSqbGoodsForSync(sqbGoods);
if (StringUtils.isNotBlank(invalidReason)) {
editFail++;
invalidReasons.add("localSpuId=" + localSpuId + ", " + invalidReason);
continue;
}
try {
if (goblinstoreMgtSqbGoodsService.sqbGoodsEditSpu(currentUid, sqbGoods, localGoodsInfoVo)) {
......@@ -167,7 +177,7 @@ public class GoblinStoreMgtSqbGoodsController {
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) {
......@@ -225,20 +235,62 @@ public class GoblinStoreMgtSqbGoodsController {
return null;
}
private Map<String, Integer> buildAddResult(int addSuccess, int alreadyExists, int addFail) {
Map<String, Integer> result = new HashMap<>();
private String validateSqbGoodsForSync(GoblinSqbPerfGoodsVo sqbGoods) {
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("alreadyExists", alreadyExists);
result.put("addFail", addFail);
result.put("invalidCount", CollectionUtils.isEmpty(invalidReasons) ? 0 : invalidReasons.size());
result.put("invalidReasons", invalidReasons);
return result;
}
private Map<String, Integer> buildEditResult(int editSuccess, int notAdded, int sqbNotFound, int editFail) {
Map<String, Integer> result = new HashMap<>();
private Map<String, Object> buildEditResult(int editSuccess, int notAdded, int sqbNotFound, int editFail,
List<String> invalidReasons) {
Map<String, Object> result = new HashMap<>();
result.put("editSuccess", editSuccess);
result.put("notAdded", notAdded);
result.put("sqbNotFound", sqbNotFound);
result.put("editFail", editFail);
result.put("invalidCount", CollectionUtils.isEmpty(invalidReasons) ? 0 : invalidReasons.size());
result.put("invalidReasons", invalidReasons);
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