新火炬后端单体项目初始化代码
zhangherong
4 天以前 bfaca7703dea9a0bb2db61184f944534d02fd8b4
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package org.jeecg.modules.lsw.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.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.lsw.entity.LswMaterial;
import org.jeecg.modules.lsw.entity.LswMaterialInventory;
import org.jeecg.modules.lsw.mapper.LswMaterialInventoryMapper;
import org.jeecg.modules.lsw.mapper.LswMaterialMapper;
import org.jeecg.modules.lsw.service.ILswMaterialService;
import org.jeecg.modules.mes.entity.MesProductionOrder;
import org.jeecg.modules.pms.entity.PmsProcessBillMaterials;
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.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Description: 线边库物料信息
 * @Author: jeecg-boot
 * @Date: 2025-06-30
 * @Version: V1.0
 */
@Service
public class LswMaterialServiceImpl extends ServiceImpl<LswMaterialMapper, LswMaterial> implements ILswMaterialService {
 
    @Autowired
    private LswMaterialMapper lswMaterialMapper;
    @Autowired
    private LswMaterialInventoryMapper lswMaterialInventoryMapper;
 
    @Override
    public IPage<Map<String, Object>> getLswMaterialListData(Integer pageNo, Integer pageSize, HttpServletRequest req) {
        IPage<Map> pageData = new Page<Map>(pageNo, pageSize);
        Map<String, String> paramMap = new HashMap<String, String>();
        Map<String, String[]> parameterMap = req.getParameterMap();
        if (null != parameterMap) {
            if (parameterMap.containsKey("materialNumber") && StringUtils.isNotBlank(parameterMap.get("materialNumber")[0])) {
                paramMap.put("materialNumber", parameterMap.get("materialNumber")[0]);
            }
            if (parameterMap.containsKey("materialName") && StringUtils.isNotBlank(parameterMap.get("materialName")[0])) {
                paramMap.put("materialName", parameterMap.get("materialName")[0].trim());
            }
            if (parameterMap.containsKey("materialModel") && StringUtils.isNotBlank(parameterMap.get("materialModel")[0])) {
                paramMap.put("materialModel", parameterMap.get("materialModel")[0].trim());
            }
            if (parameterMap.containsKey("materialCategory") && StringUtils.isNotBlank(parameterMap.get("materialCategory")[0])) {
                paramMap.put("materialCategory", parameterMap.get("materialCategory")[0].trim());
            }
        }
        return super.getBaseMapper().getLswMaterialListData(pageData, paramMap);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean editMaterial(LswMaterial lswMaterial) {
        LswMaterial entity = this.getBaseMapper().selectById(lswMaterial.getId());
        if (entity == null) {
            throw new JeecgBootException("要编辑的数据不存在!");
        }
        entity.setMaterialCategory(lswMaterial.getMaterialCategory());
        this.updateById(entity);
        return true;
    }
 
    @Override
    public LswMaterial queryByMaterialNumber(String materialNumber) {
        LambdaQueryWrapper<LswMaterial> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LswMaterial::getMaterialNumber, materialNumber);
        queryWrapper.eq(LswMaterial::getDelFlag, CommonConstant.DEL_FLAG_0);
        List<LswMaterial> list = this.getBaseMapper().selectList(queryWrapper);
        if (CollectionUtil.isEmpty(list)) {
            return null;
        }
        return list.get(0);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdateMaterial(Map<String, MesProductionOrder> orderMap, List<OrderBomDTO> orderBomDTOList) {
        Map<String, LswMaterial> addMap = new HashMap<>();
        for (Map.Entry<String, MesProductionOrder> entry : orderMap.entrySet()) {
            MesProductionOrder order = entry.getValue();
            LswMaterial material = queryByMaterialNumber(order.getMaterialNumber());
            if (material == null) {
                //新增物料
                material = new LswMaterial();
                material.setMaterialStatus(CommonConstant.STATUS_1);
                material.setMaterialNumber(order.getMaterialNumber());
                material.setMaterialName(order.getMaterialName());
                material.setMaterialUnit(order.getProductionUnit());
                material.setDelFlag(CommonConstant.DEL_FLAG_0);
                addMap.put(material.getMaterialNumber(), material);
            }
        }
        for (OrderBomDTO bomDTO : orderBomDTOList) {
            LswMaterial material = queryByMaterialNumber(bomDTO.getMATNR());
            if (material == null) {
                //新增物料
                material = new LswMaterial();
                material.setMaterialStatus(CommonConstant.STATUS_1);
                material.setMaterialNumber(bomDTO.getMATNR());
                material.setMaterialName(bomDTO.getMAKTX());
                material.setMaterialUnit(bomDTO.getMEINS());
                material.setDelFlag(CommonConstant.DEL_FLAG_0);
                addMap.put(material.getMaterialNumber(), material);
            }
        }
        if (CollectionUtil.isNotEmpty(addMap)) {
            Collection<LswMaterial> addList = addMap.values();
            super.saveBatch(addList);
        }
        return true;
    }
 
}