新火炬后端单体项目初始化代码
zhangherong
13 小时以前 9e97ded95f71e4c736bf11464ea2c25860d2aab8
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package org.jeecg.modules.mes.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
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.MaterialCategoryEnum;
import org.jeecg.modules.lsw.enums.MaterialInboundCategory;
import org.jeecg.modules.lsw.enums.MaterialOutboundCategory;
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.jeecg.modules.mes.entity.MesMaterialLoading;
import org.jeecg.modules.mes.entity.MesMaterialUnloading;
import org.jeecg.modules.mes.mapper.MesMaterialLoadingMapper;
import org.jeecg.modules.mes.service.IMesMaterialLoadingService;
import org.jeecg.modules.mes.service.IMesMaterialUnloadingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
/**
 * @Description: 上料
 * @Author: jeecg-boot
 * @Date: 2025-07-07
 * @Version: V1.0
 */
@Service
public class MesMaterialLoadingServiceImpl extends ServiceImpl<MesMaterialLoadingMapper, MesMaterialLoading> implements IMesMaterialLoadingService {
 
    @Autowired
    private ILineSideWarehouseService lineSideWarehouseService;
    @Autowired
    private ILswMaterialOutboundService lswMaterialOutboundService;
    @Autowired
    private ILswMaterialInventoryService materialInventoryService;
    @Autowired
    private ILswMaterialService materialService;
    @Autowired
    private IMesMaterialUnloadingService mesMaterialUnloadingService;
    @Autowired
    private ILswMaterialInboundService materialInboundService;
 
    @Override
    public List<MesMaterialUnloading> queryUnloadingByLoadingId(String loadingId) {
        return baseMapper.queryUnloadingByLoadingId(loadingId);
    }
 
    @Override
    public IPage<MesMaterialLoading> queryPageList(Page<MesMaterialLoading> page, MesMaterialLoading mesMaterialLoading) {
        QueryWrapper<MesMaterialLoading> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(mesMaterialLoading.getFactoryId())) {
            queryWrapper.eq("mml.factory_id", mesMaterialLoading.getFactoryId());
        }
        if (StringUtils.isNotBlank(mesMaterialLoading.getCategory())) {
            queryWrapper.eq("mml.category", mesMaterialLoading.getCategory());
        }
        if (StringUtils.isNotBlank(mesMaterialLoading.getMaterialNumber())) {
            queryWrapper.like("mml.material_number", mesMaterialLoading.getMaterialNumber());
        }
        if (StringUtils.isNotBlank(mesMaterialLoading.getMaterialName())) {
            queryWrapper.like("mml.material_name", mesMaterialLoading.getMaterialName());
        }
        if (StringUtils.isNotBlank(mesMaterialLoading.getBatchNumber())) {
            queryWrapper.like("mml.batch_number", mesMaterialLoading.getBatchNumber());
        }
        queryWrapper.orderByDesc("mml.create_time");
        return this.baseMapper.queryPageList(page, queryWrapper);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean loading(MesMaterialLoading mesMaterialLoading) {
        if (mesMaterialLoading == null) {
            throw new JeecgBootException("参数错误!");
        }
        if (StringUtils.isBlank(mesMaterialLoading.getFactoryId())
                || StringUtils.isBlank(mesMaterialLoading.getMaterialNumber())
                || mesMaterialLoading.getQuantity() == null
                || mesMaterialLoading.getQuantity().intValue() < 1
                || StringUtils.isBlank(mesMaterialLoading.getBatchNumber())) {
            throw new JeecgBootException("参数错误!");
        }
        LineSideWarehouse warehouse = lineSideWarehouseService.queryByFactoryId(mesMaterialLoading.getFactoryId());
        if (warehouse == null) {
            throw new JeecgBootException("线边库不存在,请检查!");
        }
 
        LswMaterial material = materialService.queryByMaterialNumber(mesMaterialLoading.getMaterialNumber());
        if (material == null) {
            throw new JeecgBootException("物料信息不存在,请检查!");
        }
 
        if (MaterialCategoryEnum.STEEL_BALL.name().equals(material.getMaterialCategory()) && StringUtils.isBlank(mesMaterialLoading.getSteelBallSize())) {
            throw new JeecgBootException("钢球尺寸不能为空,请检查!");
        }
 
        LswMaterialInventory inventory = materialInventoryService.queryByMaterialNumberAndBatchNumber(mesMaterialLoading.getMaterialNumber(), mesMaterialLoading.getBatchNumber(), warehouse.getId());
        if (inventory == null) {
            throw new JeecgBootException("库存不存在,请检查!");
        }
        if (inventory.getQuantity().compareTo(mesMaterialLoading.getQuantity()) != 0) {
            throw new JeecgBootException("上料和库存数量不匹配,请检查!");
        }
 
        //人员信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser == null) {
            throw new JeecgBootException("用户信息获取失败!");
        }
        LswMaterialOutbound outbound = new LswMaterialOutbound();
        outbound.setMaterialNumber(mesMaterialLoading.getMaterialNumber());
        outbound.setMaterialName(mesMaterialLoading.getMaterialName());
        outbound.setQuantity(mesMaterialLoading.getQuantity());
        outbound.setFactoryId(mesMaterialLoading.getFactoryId());
        outbound.setWarehouseId(warehouse.getId());
        outbound.setBatchNumber(mesMaterialLoading.getBatchNumber());
        outbound.setOutboundCategory(MaterialOutboundCategory.MATERIAL_LOADING.name());
        outbound.setInventoryId(inventory.getId());
        outbound.setOutboundStaff(sysUser.getUsername());
        boolean b = lswMaterialOutboundService.outboundMaterial(outbound);
        if (!b) {
            throw new JeecgBootException("库存出库失败!");
        }
        mesMaterialLoading.setWarehouseId(warehouse.getId());
        mesMaterialLoading.setRemainingQuantity(mesMaterialLoading.getQuantity());
        mesMaterialLoading.setDelFlag(CommonConstant.DEL_FLAG_0);
        mesMaterialLoading.setUnloadingFlag(CommonConstant.STATUS_0);
        this.save(mesMaterialLoading);
        return true;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean unloading(MesMaterialLoading mesMaterialLoading) {
        if (mesMaterialLoading == null) {
            throw new JeecgBootException("参数错误!");
        }
        if (StringUtils.isBlank(mesMaterialLoading.getId())
                || mesMaterialLoading.getUnloadingQuantity() == null
                || mesMaterialLoading.getUnloadingQuantity().intValue() < 1) {
            throw new JeecgBootException("参数错误!");
        }
        //查询上料数据
        MesMaterialLoading loading = super.getById(mesMaterialLoading.getId());
        if (loading == null) {
            throw new JeecgBootException("未查询到上料数据!");
        }
        if (loading.getRemainingQuantity().compareTo(mesMaterialLoading.getUnloadingQuantity()) < 0) {
            throw new JeecgBootException("下料数量不能大于当前剩余数量!");
        }
        //线边库信息
        LineSideWarehouse warehouse = lineSideWarehouseService.getById(loading.getWarehouseId());
        if(warehouse == null) {
            throw new JeecgBootException("未查询到线边库!");
        }
        loading.setUnloadingFlag(CommonConstant.STATUS_1);
        loading.setRemainingQuantity(loading.getRemainingQuantity().subtract(mesMaterialLoading.getUnloadingQuantity()));
        super.updateById(loading);
        //保存下料信息
        MesMaterialUnloading unloading = new MesMaterialUnloading();
        unloading.setLoadingId(loading.getId());
        unloading.setMaterialNumber(loading.getMaterialNumber());
        unloading.setMaterialName(loading.getMaterialName());
        unloading.setBatchNumber(loading.getBatchNumber());
        unloading.setQuantity(mesMaterialLoading.getUnloadingQuantity());
        mesMaterialUnloadingService.save(unloading);
        //保存入库信息
        LswMaterialInbound materialInbound = new LswMaterialInbound()
                .setFactoryId(loading.getFactoryId())
                .setWarehouseId(loading.getWarehouseId())
                .setMaterialNumber(loading.getMaterialNumber())
                .setMaterialName(loading.getMaterialName())
                .setBatchNumber(loading.getBatchNumber())
                .setQuantity(unloading.getQuantity())
                .setInboundCategory(MaterialInboundCategory.PRODUCTION_UNLOADING.name())//下料
                .setOriginalCode(warehouse.getWarehouseCode())
                .setOriginalName(warehouse.getWarehouseName());
        materialInboundService.inboundMaterial(materialInbound);
        return true;
    }
}