Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mall-tiny-06 EsProductServiceImpl create方法错误 #127

Open
OrigamiWang opened this issue Sep 1, 2022 · 0 comments
Open

mall-tiny-06 EsProductServiceImpl create方法错误 #127

OrigamiWang opened this issue Sep 1, 2022 · 0 comments

Comments

@OrigamiWang
Copy link

源代码中的create方法,入参为id,根本无法添加新的商品

// 修改后的方法(仅供参考) 
@Override
    public CommonResult<EsProduct> create(EsProduct esProduct) {
        if (esProduct != null) {
            long id = esProduct.getId();
            Iterable<EsProduct> all = productRepository.findAll();
            Iterator<EsProduct> iterator = all.iterator();
            while (iterator.hasNext()) {
                Long id1 = iterator.next().getId();
                if (Objects.equal(id, id1)) {
                    LOGGER.warn("此id: {}已经被创建", id);
                    return CommonResult.failed();
                }
            }
            productRepository.save(esProduct);
            LOGGER.info("创建商品成功,id:{}", id);
            return CommonResult.success(esProduct);
        }
        return CommonResult.failed();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant