liding
2026-03-18 89424c883ac408d9136af3345136f73f38c0124c
src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
@@ -21,6 +21,7 @@
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import lombok.AllArgsConstructor;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@@ -44,16 +45,23 @@
    @Override
    public int addOrEditProductModel(ProductModelDto productModelDto) {
        if (productModelDto.getId() == null) {
            ProductModel productModel = new ProductModel();
            BeanUtils.copyProperties(productModelDto, productModel);
            return productModelMapper.insert(productModel);
        } else {
            return productModelMapper.updateById(productModelDto);
        ProductModel productModel = new ProductModel();
        BeanUtils.copyProperties(productModelDto, productModel);
        try {
            if (productModelDto.getId() == null) {
                int result = productModelMapper.insert(productModel);
                productModelDto.setId(productModel.getId());
                return result;
            } else {
                int result = productModelMapper.updateById(productModel);
                productModelDto.setId(productModel.getId());
                return result;
            }
        } catch (DuplicateKeyException e) {
            // 捕获数据库唯一约束异常
            throw new RuntimeException("该产品已存在相同的规格型号和单位", e);
        }
    }
    @Override
    public int delProductModel(Long[] ids) {