gongchunyi
16 小时以前 285fa628a51ccc480ee946d2a1ee5bd13e9ae65a
src/main/java/com/ruoyi/production/service/impl/ProductBomServiceImpl.java
@@ -18,6 +18,8 @@
import com.ruoyi.production.pojo.ProductProcess;
import com.ruoyi.production.pojo.ProductStructure;
import com.ruoyi.production.service.*;
import com.ruoyi.project.system.domain.SysDictData;
import com.ruoyi.project.system.mapper.SysDictDataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -42,7 +44,6 @@
    @Autowired
    private ProductBomMapper productBomMapper;
    @Autowired
    private ProductStructureService productStructureService;
@@ -55,39 +56,31 @@
    @Autowired
    private ProductMaterialSkuService productMaterialSkuService;
    @Autowired
    private SysDictDataMapper sysDictDataMapper;
    @Override
    public IPage<ProductBomDto> listPage(Page page, ProductBomDto productBomDto) {
    public IPage<ProductBomDto> listPage(Page<ProductBom> page, ProductBomDto productBomDto) {
        return productBomMapper.listPage(page, productBomDto);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult add(ProductBom productBom) {
        if (productBom == null || productBom.getDictCode() == null) {
            throw new ServiceException("新增BOM失败,产品类型不能为空");
        }
        SysDictData sysDictData = sysDictDataMapper.selectDictDataById(productBom.getDictCode());
        if (sysDictData == null) {
            throw new ServiceException("新增BOM失败,产品类型不存在");
        }
        boolean save = productBomMapper.insert(productBom) > 0;
        if (save) {
            String no = "BM." + String.format("%05d", productBom.getId());
            productBom.setBomNo(no);
            productBomMapper.updateById(productBom);
            //  查询出产品模型信息
            if (productBom.getProductModelId() == null) {
                throw new ServiceException("请选择产品模型");
            }
            ProductMaterialSku productModel = productMaterialSkuService.getById(productBom.getProductModelId());
            if (productModel == null) {
                throw new ServiceException("选择的产品模型不存在");
            }
            ProductMaterial productMaterial = productMaterialService.getById(productModel.getProductId());
            //  添加初始的产品结构
            ProductStructure productStructure = new ProductStructure();
            productStructure.setProductModelId(productBom.getProductModelId());
            productStructure.setUnit(productMaterial != null ? productMaterial.getUnit() : null);
            productStructure.setUnitQuantity(BigDecimal.valueOf(1));
            productStructure.setBomId(productBom.getId());
            productStructureService.save(productStructure);
            return AjaxResult.success();
        }
@@ -96,7 +89,14 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult uploadBom(MultipartFile file) {
    public AjaxResult uploadBom(MultipartFile file, Long dictCode) {
        if (dictCode == null) {
            return AjaxResult.error("导入失败,产品类型不能为空");
        }
        SysDictData sysDictData = sysDictDataMapper.selectDictDataById(dictCode);
        if (sysDictData == null) {
            return AjaxResult.error("导入失败,产品类型不存在");
        }
        ExcelUtil<BomImportDto> util = new ExcelUtil<>(BomImportDto.class);
        List<BomImportDto> list;
        try {
@@ -105,7 +105,9 @@
            return AjaxResult.error("Excel解析失败");
        }
        if (list == null || list.isEmpty()) return AjaxResult.error("数据为空");
        if (list == null || list.isEmpty()) {
            return AjaxResult.error("数据为空");
        }
        //  处理工序
        list.forEach(dto -> {
@@ -122,7 +124,7 @@
        BomImportDto first = list.get(0);
        ProductMaterialSku rootModel = findModel(first.getParentName(), first.getParentSpec());
        ProductBom bom = new ProductBom();
        bom.setProductModelId(rootModel.getId());
        bom.setDictCode(dictCode);
        bom.setVersion("1.0");
        productBomMapper.insert(bom);
        bom.setBomNo("BM." + String.format("%05d", bom.getId()));
@@ -313,5 +315,3 @@
        return s.replaceAll("[\\u00A0\\u3000]", "").trim();
    }
}