xin
2025-10-17 ab0637e981ab4c85120ccde35ee24ec4abbe3e24
oying-system/src/main/java/com/oying/modules/pc/product/service/impl/ProductServiceImpl.java
@@ -1,8 +1,10 @@
package com.oying.modules.pc.product.service.impl;
import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oying.exception.EntityNotFoundException;
import com.oying.modules.pc.product.domain.Product;
import com.oying.modules.pc.product.domain.dto.ProductQueryCriteria;
import com.oying.modules.pc.product.mapper.ProductMapper;
@@ -10,17 +12,13 @@
import com.oying.utils.FileUtil;
import com.oying.utils.PageResult;
import com.oying.utils.PageUtil;
import com.oying.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 * @author lzp
@@ -44,9 +42,17 @@
    }
    @Override
    public Product getProduct(Long productId) {
        Product existingProduct = getById(productId);
        if (ObjUtil.isEmpty(existingProduct)) {
            throw new EntityNotFoundException(Product.class, "id", Optional.ofNullable(productId).map(Object::toString).orElse("null"));
        }
        return existingProduct;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(Product resources) {
        resources.setCreateBy(SecurityUtils.getCurrentUserId());
        productMapper.insert(resources);
    }
@@ -55,8 +61,19 @@
    public void update(Product resources) {
        Product product = getById(resources.getProductId());
        product.copy(resources);
        product.setUpdateBy(SecurityUtils.getCurrentUserId());
        productMapper.updateById(product);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(Product resources, boolean isDirectUpdate) {
        if (isDirectUpdate) {
            productMapper.updateById(resources);
        } else {
            Product product = getById(resources.getProductId());
            product.copy(resources);
            productMapper.updateById(product);
        }
    }
    @Override
@@ -81,9 +98,9 @@
            map.put("商品名称", product.getName());
            map.put("商品标题", product.getTitle());
            map.put("分类ID", product.getCategoryId());
            map.put("状态:1000-草稿 1001上架 1002下架", product.getStatus());
            map.put("主图片", product.getMainImage());
            map.put("详情图片", product.getDetailImage());
            map.put("状态", product.getStatus());
            map.put("主图片", product.getMainImageId());
            map.put("主图地址", product.getMainImageUrl());
            map.put("商品描述", product.getDescription());
            map.put("销售价格", product.getPrice());
            map.put("库存数量", product.getStockQuantity());