新火炬后端单体项目初始化代码
zhangherong
2 天以前 eeebc22772cbf7dc03ed4bc6f734e6de9f5c3e75
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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.conditions.query.QueryWrapper;
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.lang3.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 java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * @Description: 订单BOM
 * @Author: jeecg-boot
 * @Date: 2025-07-01
 * @Version: V1.0
 */
@Service
public class PmsProcessBillMaterialsServiceImpl extends ServiceImpl<PmsProcessBillMaterialsMapper, PmsProcessBillMaterials> implements IPmsProcessBillMaterialsService {
    @Autowired
    private IPmsProcessBillMaterialsDetailService processBillMaterialsDetailService;
 
    @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;
    }
 
    @Override
    public IPage<PmsProcessBillMaterials> queryPageList(Page<PmsProcessBillMaterials> page, PmsProcessBillMaterials query) {
        QueryWrapper<PmsProcessBillMaterials> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("pbm.create_time");
        if (query != null) {
            //物料编码 模糊查询
            if (StringUtils.isNotBlank(query.getMaterialNumber())) {
                queryWrapper.like("pbm.material_number", query.getMaterialNumber());
            }
            //物料名称 模糊查询
            if (StringUtils.isNotBlank(query.getMaterialName())) {
                queryWrapper.like("pbm.material_name", query.getMaterialName());
            }
            //订单号 模糊查询
            if (StringUtils.isNotBlank(query.getOrderCode())) {
                queryWrapper.like("po.order_code", query.getOrderCode());
            }
        }
        return this.getBaseMapper().queryPageList(page, queryWrapper);
    }
}