新火炬后端单体项目初始化代码
zhangherong
2 天以前 a5aa9503efd20103df066219c512b47b7f65e363
src/main/java/org/jeecg/modules/pms/service/impl/PmsProcessBillMaterialsServiceImpl.java
@@ -1,26 +1,37 @@
package org.jeecg.modules.pms.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.jeecg.modules.mes.entity.MesProductionOrder;
import org.jeecg.modules.pms.entity.PmsProcessBillMaterials;
import org.jeecg.modules.pms.mapper.PmsProcessBillMaterialsMapper;
import org.jeecg.modules.pms.service.IPmsProcessBillMaterialsDetailService;
import org.jeecg.modules.pms.service.IPmsProcessBillMaterialsService;
import org.jeecg.modules.sap.dto.OrderBomDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * @Description: 订单BOM
 * @Author: jeecg-boot
 * @Date:   2025-07-01
 * @Date: 2025-07-01
 * @Version: V1.0
 */
@Service
public class PmsProcessBillMaterialsServiceImpl extends ServiceImpl<PmsProcessBillMaterialsMapper, PmsProcessBillMaterials> implements IPmsProcessBillMaterialsService {
    @Autowired
    private IPmsProcessBillMaterialsDetailService processBillMaterialsDetailService;
    @Override
    public IPage<Map<String, Object>> getpmsProcessBillMaterialsListData(Integer pageNo, Integer pageSize, HttpServletRequest req) {
@@ -40,4 +51,50 @@
        }
        return super.getBaseMapper().getpmsProcessBillMaterialsListData(pageData, paramMap);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdateOrderBom(Map<String, MesProductionOrder> orderMap, List<OrderBomDTO> orderBomDTOList) {
        for (Map.Entry<String, MesProductionOrder> entry :  orderMap.entrySet()) {
            MesProductionOrder order = entry.getValue();
            PmsProcessBillMaterials materials = getByOrderId(order.getId());
            if(materials != null) {
                //更新物料数据
                materials.setOrderId(order.getId());
                materials.setMaterialNumber(order.getMaterialNumber());
                materials.setMaterialName(order.getMaterialName());
                materials.setProductionUnit(order.getProductionUnit());
                materials.setProductionQuantity(order.getOrderQuantity());
                this.getBaseMapper().updateById(materials);
                //更新物料明细数据
                processBillMaterialsDetailService.removeByMaterialsId(materials.getId());
                //过滤出此订单的物料信息
                List<OrderBomDTO> collect = orderBomDTOList.stream().filter(orderBomDTO -> entry.getKey().equals(orderBomDTO.getAUFNR())).collect(Collectors.toList());
                processBillMaterialsDetailService.saveBatchDetail(materials.getId(), collect);
            }else {
                materials = new PmsProcessBillMaterials();
                materials.setOrderId(order.getId());
                materials.setMaterialNumber(order.getMaterialNumber());
                materials.setMaterialName(order.getMaterialName());
                materials.setProductionUnit(order.getProductionUnit());
                materials.setProductionQuantity(order.getOrderQuantity());
                this.getBaseMapper().insert(materials);
                //过滤出此订单的物料信息
                List<OrderBomDTO> collect = orderBomDTOList.stream().filter(orderBomDTO -> entry.getKey().equals(orderBomDTO.getAUFNR())).collect(Collectors.toList());
                processBillMaterialsDetailService.saveBatchDetail(materials.getId(), collect);
            }
        }
        return true;
    }
    @Override
    public PmsProcessBillMaterials getByOrderId(String orderId) {
        LambdaQueryWrapper<PmsProcessBillMaterials> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsProcessBillMaterials::getOrderId, orderId);
        List<PmsProcessBillMaterials> list = super.list(queryWrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            return list.get(0);
        }
        return null;
    }
}