5 天以前 0d7d874912d0147376826b55667a1deb6547ed91
src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
@@ -17,9 +17,12 @@
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.sales.dto.LossProductModelDto;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.technology.mapper.TechnologyBomMapper;
import com.ruoyi.technology.pojo.TechnologyBom;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -43,6 +46,7 @@
    private final ProductMapper productMapper;
    private final SalesLedgerProductMapper salesLedgerProductMapper;
    private final TechnologyBomMapper technologyBomMapper;
    private ProductModelMapper productModelMapper;
    @Override
@@ -86,6 +90,14 @@
            throw new RuntimeException("已经存在该产品的销售台账和采购台账");
        }
        // 是否存在BOM
        List<TechnologyBom> technologyBoms = technologyBomMapper.selectList(new QueryWrapper<TechnologyBom>()
                .lambda().in(TechnologyBom::getProductModelId, ids));
        if (CollectionUtils.isNotEmpty(technologyBoms)) {
            throw new RuntimeException("已经存在该产品的BOM数据");
        }
        return productModelMapper.deleteBatchIds(Arrays.asList(ids));
    }
@@ -112,14 +124,14 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult importProductModel(MultipartFile file, Integer productId) {
    public R<?> importProductModel(MultipartFile file, Integer productId) {
        if (productId == null) {
            return AjaxResult.error("请先选择产品再导入规格型号");
            return R.fail("请先选择产品再导入规格型号");
        }
        Product product = productMapper.selectById(productId);
        if (product == null) {
            return AjaxResult.error("选择的产品不存在");
            return R.fail("选择的产品不存在");
        }
        try {
@@ -127,7 +139,7 @@
            List<ProductModel> productModelList = productModelExcelUtil.importExcel(file.getInputStream());
            if (CollectionUtils.isEmpty(productModelList)) {
                return AjaxResult.error("导入数据不能为空");
                return R.fail("导入数据不能为空");
            }
            //  获取当前产品下所有的规格型号名
@@ -142,13 +154,13 @@
                int rowNum = i + 2;
                if (StringUtils.isEmpty(item.getProductCode())) {
                    return AjaxResult.error("第 " + rowNum + " 行导入失败: [产品编码] 不能为空");
                    return R.fail("第 " + rowNum + " 行导入失败: [产品编码] 不能为空");
                }
                if (StringUtils.isEmpty(item.getModel())) {
                    return AjaxResult.error("第 " + rowNum + " 行导入失败: [规格型号] 不能为空");
                    return R.fail("第 " + rowNum + " 行导入失败: [规格型号] 不能为空");
                }
                if (StringUtils.isEmpty(item.getUnit())) {
                    return AjaxResult.error("第 " + rowNum + " 行导入失败: [单位] 不能为空");
                    return R.fail("第 " + rowNum + " 行导入失败: [单位] 不能为空");
                }
                //  去重,如果已包含该型号,则跳过
@@ -168,9 +180,9 @@
            }
            if (skipCount == 0) {
                return AjaxResult.success(String.format("成功导入 %d 条数据", waitToSaveList.size()));
                return R.ok(null, String.format("成功导入 %d 条数据", waitToSaveList.size()));
            } else {
                return AjaxResult.success(String.format("成功导入 %d 条,跳过已存在数据 %d 条", waitToSaveList.size(), skipCount));
                return R.ok(null, String.format("成功导入 %d 条,跳过已存在数据 %d 条", waitToSaveList.size(), skipCount));
            }
        } catch (Exception e) {
            log.error("导入产品规格异常", e);