| | |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.exception.EntityNotFoundException; |
| | |
| | | import com.oying.modules.pc.product.domain.ProductAudit; |
| | | import com.oying.modules.pc.product.domain.ProductImage; |
| | | import com.oying.modules.pc.product.domain.ProductLabel; |
| | | import com.oying.modules.pc.product.domain.dto.ProductAuditData; |
| | | import com.oying.modules.pc.product.domain.dto.ProductImageCreateRequest; |
| | | import com.oying.modules.pc.product.domain.dto.ProductMerchantCreateRequest; |
| | | import com.oying.modules.pc.product.domain.dto.ProductMerchantUpdateRequest; |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(ProductMerchantUpdateRequest request) { |
| | | Product existingProduct = this.findOrThrow(request.getProductId()); |
| | | this.validateApprovedStatus(existingProduct.getStatus()); |
| | | this.validateApprovedStatus(existingProduct.getShelfStatus()); |
| | | this.processImagesUpdate(request); |
| | | this.processLabelsUpdate(request); |
| | | BeanUtils.copyProperties(request, existingProduct); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateImages(ProductMerchantUpdateRequest request) { |
| | | Product existingProduct = this.findOrThrow(request.getProductId()); |
| | | this.validateApprovedStatus(existingProduct.getStatus()); |
| | | this.validateApprovedStatus(existingProduct.getShelfStatus()); |
| | | this.findOrThrow(request.getProductId()); |
| | | this.processImagesUpdate(request); |
| | | } |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateLabels(ProductMerchantUpdateRequest request) { |
| | | Product existingProduct = this.findOrThrow(request.getProductId()); |
| | | this.validateApprovedStatus(existingProduct.getStatus()); |
| | | this.validateApprovedStatus(existingProduct.getShelfStatus()); |
| | | this.findOrThrow(request.getProductId()); |
| | | this.processImagesUpdate(request); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void putOnShelf(Long productId) { |
| | | Product existingProduct = productService.getById(productId); |
| | | if (ProductStatusEnum.AVAILABLE.getValue().equals(existingProduct.getShelfStatus())) { |
| | | throw new BadRequestException("商品已上架"); |
| | | } |
| | | |
| | | if (productAuditService.hasPendingByStoreId(productId)) { |
| | | throw new BadRequestException("已在审核中"); |
| | | } |
| | | |
| | | ProductAudit audit = new ProductAudit(); |
| | | audit.setProductId(productId); |
| | | audit.setType(ProductChangeTypeEnum.PUT_ON_SHELF.name()); |
| | | audit.setStatus(AuditStatusEnum.PENDING.getValue()); |
| | | ProductAuditData auditData = new ProductAuditData(); |
| | | auditData.setOriginalStore(existingProduct); |
| | | audit.setData(JSON.toJSONString(auditData)); |
| | | productAuditService.create(audit); |
| | | LambdaUpdateWrapper<Product> wrapper = new LambdaUpdateWrapper<Product>() |
| | | .eq(Product::getProductId, productId) |
| | |
| | | |
| | | @Override |
| | | public void takeOffShelf(Long productId) { |
| | | Product existingProduct = productService.getById(productId); |
| | | if (ProductStatusEnum.NO_AVAILABLE.getValue().equals(existingProduct.getShelfStatus())) { |
| | | return; |
| | | } |
| | | LambdaUpdateWrapper<Product> wrapper = new LambdaUpdateWrapper<Product>() |
| | | .eq(Product::getProductId, productId) |
| | | .set(Product::getStatus, ProductStatusEnum.NO_AVAILABLE.getValue()); |
| | | .set(Product::getStatus, ProductStatusEnum.NO_AVAILABLE.getValue()) |
| | | .set(Product::getShelfStatus, ProductStatusEnum.NO_AVAILABLE.getValue()); |
| | | productService.update(wrapper); |
| | | } |
| | | |
| | |
| | | |
| | | private void handlePutOnShelfAuditEvent(ProductAudit audit) { |
| | | AuditStatusEnum auditStatus = AuditStatusEnum.get(audit.getStatus()); |
| | | if (AuditStatusEnum.APPROVED.equals(auditStatus)) { |
| | | Product existingProduct = productService.getById(audit.getProductId()); |
| | | if (AuditStatusEnum.APPROVED.equals(auditStatus)) { |
| | | existingProduct.setStatus(ProductStatusEnum.AVAILABLE.getValue()); |
| | | existingProduct.setShelfStatus(ProductStatusEnum.AVAILABLE.getValue()); |
| | | } else { |
| | | existingProduct.setStatus(auditStatus.getValue()); |
| | | productService.updateById(existingProduct); |
| | | } |
| | | productService.updateById(existingProduct); |
| | | } |
| | | |
| | | private void validateApprovedStatus(Integer status) { |