新火炬后端单体项目初始化代码
zhangherong
13 小时以前 399e7d565f19f59a8da82277da8f3eab527c2c56
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
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.core.toolkit.Wrappers;
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.LswMaterialInventory;
import org.jeecg.modules.lsw.entity.LswMaterialOutbound;
import org.jeecg.modules.lsw.enums.MaterialCategoryEnum;
import org.jeecg.modules.lsw.enums.MaterialOutboundCategory;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
 
/**
 * @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;
 
    @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;
    }
}