新火炬后端单体项目初始化代码
zhangherong
2 天以前 91bf52413fded1d71f3c6d0e359d3c5c2bbd8900
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
127
128
129
130
131
132
133
134
135
136
137
138
139
package org.jeecg.modules.lsw.service.impl;
 
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.base.entity.LineSideWarehouse;
import org.jeecg.modules.base.service.ILineSideWarehouseService;
import org.jeecg.modules.lsw.entity.LswMaterial;
import org.jeecg.modules.lsw.entity.LswMaterialInbound;
import org.jeecg.modules.lsw.entity.LswMaterialInventory;
import org.jeecg.modules.lsw.entity.LswMaterialOutbound;
import org.jeecg.modules.lsw.enums.MaterialInboundCategory;
import org.jeecg.modules.lsw.enums.MaterialInventoryCategoryEnum;
import org.jeecg.modules.lsw.enums.MaterialOutboundCategory;
import org.jeecg.modules.lsw.mapper.LswMaterialInboundMapper;
import org.jeecg.modules.lsw.service.ILswMaterialInboundService;
import org.jeecg.modules.lsw.service.ILswMaterialInventoryService;
import org.jeecg.modules.lsw.service.ILswMaterialOutboundService;
import org.jeecg.modules.lsw.service.ILswMaterialService;
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.Date;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @Description: 物料入库单
 * @Author: jeecg-boot
 * @Date: 2025-06-30
 * @Version: V1.0
 */
@Service
public class LswMaterialInboundServiceImpl extends ServiceImpl<LswMaterialInboundMapper, LswMaterialInbound> implements ILswMaterialInboundService {
    @Autowired
    private ILswMaterialInventoryService inventoryService;
    @Autowired
    private ILswMaterialService materialService;
    @Autowired
    private ILineSideWarehouseService lineSideWarehouseService;
    @Autowired
    private ILswMaterialOutboundService materialOutboundService;
 
    @Override
    public IPage<Map<String, Object>> getlswMaterialInboundListData(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("batchNumber") && StringUtils.isNotBlank(parameterMap.get("batchNumber")[0])) {
                paramMap.put("batchNumber", parameterMap.get("batchNumber")[0].trim());
            }
        }
        return super.getBaseMapper().getlswMaterialInboundListData(pageData, paramMap);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean inboundMaterial(LswMaterialInbound materialInbound) {
        if (StringUtils.isBlank(materialInbound.getMaterialNumber())
                || StringUtils.isBlank(materialInbound.getFactoryId())
                || StringUtils.isBlank(materialInbound.getWarehouseId())
                || materialInbound.getQuantity() == null
                || materialInbound.getQuantity().intValue() < 1
                || StringUtils.isBlank(materialInbound.getBatchNumber())
                || StringUtils.isBlank(materialInbound.getOriginalCode())
                || StringUtils.isBlank(materialInbound.getOriginalName())
                || StringUtils.isBlank(materialInbound.getInboundCategory())) {
            throw new JeecgBootException("参数错误!");
        }
        LswMaterial material = materialService.queryByMaterialNumber(materialInbound.getMaterialNumber());
        if (material == null) {
            throw new JeecgBootException("物料编号不存在!");
        }
        LineSideWarehouse warehouse = lineSideWarehouseService.getById(materialInbound.getWarehouseId());
        if (warehouse == null) {
            throw new JeecgBootException("线边库不存在!");
        }
        String heatTreatmentFlag = CommonConstant.STATUS_0;
        if (materialInbound.getInboundCategory().equals(MaterialInboundCategory.HEAT_TREATMENT_INBOUND.name())) {
            heatTreatmentFlag = CommonConstant.STATUS_1;
        }
        //库存类型
        String inventoryCategory = MaterialInventoryCategoryEnum.INBOUND.name();
        if (materialInbound.getInboundCategory().equals(MaterialInboundCategory.MATERIAL_INNER_TRANSFER.name())) {
            inventoryCategory = MaterialInventoryCategoryEnum.TRANSFER.name();
            //查询来源线边库
            LineSideWarehouse lineSideWarehouse = lineSideWarehouseService.queryByWarehouseCode(materialInbound.getOriginalCode());
            if (lineSideWarehouse == null) {
                throw new JeecgBootException("未找到来源线边库!");
            }
            //调拨 出库原始库存
            LswMaterialInventory originalInventory = inventoryService.queryByMaterialNumberAndBatchNumber(materialInbound.getMaterialNumber(), materialInbound.getBatchNumber(), lineSideWarehouse.getId());
            if (originalInventory == null) {
                throw new JeecgBootException("未找到来源线边库库存!");
            }
            if (materialInbound.getQuantity().compareTo(originalInventory.getQuantity()) != 0) {
                throw new JeecgBootException("调拨数量需要等于来源库存数量!");
            }
            //出库信息
            LswMaterialOutbound outbound = new LswMaterialOutbound();
            outbound.setWarehouseId(lineSideWarehouse.getId());
            outbound.setFactoryId(lineSideWarehouse.getFactoryId());
            outbound.setOutboundStaff(materialInbound.getReceiver());
            outbound.setMaterialName(materialInbound.getMaterialName());
            outbound.setMaterialNumber(materialInbound.getMaterialNumber());
            outbound.setQuantity(originalInventory.getQuantity());
            outbound.setBatchNumber(originalInventory.getBatchNumber());
            outbound.setInventoryId(originalInventory.getId());
            outbound.setOutboundCategory(MaterialOutboundCategory.MATERIAL_INNER_TRANSFER.name());
            //调拨出库
            boolean b = materialOutboundService.outboundMaterial(outbound);
            if (!b) {
                throw new JeecgBootException("调拨出库失败!");
            }
        } else if (materialInbound.getInboundCategory().equals(MaterialInboundCategory.PRODUCTION_UNLOADING.name())) {
            inventoryCategory = MaterialInventoryCategoryEnum.UNLOADING.name();
        }
        //保存入库信息
        materialInbound.setDelFlag(CommonConstant.DEL_FLAG_0);
        materialInbound.setReceiveTime(new Date());
        super.save(materialInbound);
        //保存库存信息
        LswMaterialInventory lswMaterialInventory = new LswMaterialInventory(materialInbound, material.getId(), inventoryCategory, heatTreatmentFlag);
        inventoryService.save(lswMaterialInventory);
        return true;
    }
}