自动化立体仓库 - WMS系统
#
wang..123
2022-02-18 0574251b05ea099b84d7ddd4bdc65a78ff03aea7
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
package com.zy.asrs.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.StockOutParam;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.VersionUtils;
import com.zy.common.model.LocDetlDto;
import com.zy.common.service.CommonService;
import com.zy.ints.entity.WaitMatout;
import com.zy.ints.mapper.WaitMatoutMapper;
import com.zy.ints.service.WaitMatoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
@Service
public class MatOutServiceImpl implements MatOutService {
    // 工作号生成规则默认类型
    private static final int DEFAULT_WORK_NO_TYPE = 0;
    // 库位排号分配默认类别
    private static final int DEFAULT_ROW_NO_TYPE = 1;
 
    @Autowired
    BasDevpService basDevpService;
    @Autowired
    LocDetlService locDetlService;
    @Autowired
    LocMastService locMastService;
    @Autowired
    StaDescService staDescService;
    @Autowired
    private CommonService commonService;
    @Autowired
    private WrkDetlService wrkDetlService;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private WaitMatoutMapper waitMatoutMapper;
    @Autowired
    private WaitMatoutService waitMatoutService;
 
    @Override
    @Transactional
    public void startupMatOut(StockOutParam param, Long userId){
 
        // 目标站点状态检测
        BasDevp staNo = basDevpService.checkSiteStatus(param.getOutSite());
        // 获取库位明细
        List<LocDetlDto> locDetlDtos = new ArrayList<>();
        for (StockOutParam.LocDetl paramLocDetl : param.getLocDetls()) {
            if (!Cools.isEmpty(paramLocDetl.getMatNo())) {
                //查询所有库位状态为F的库位信息
                List<LocDetl> locDetls=locDetlService.getlocDetlList(paramLocDetl.getMatNo());
                if (locDetls.size()==0){
                    throw new CoolException("库位状态出错");
                }
                for (LocDetl locDetl : locDetls) {
                    WaitMatout waitMatout = waitMatoutService.selectOne(new EntityWrapper<WaitMatout>().eq("bill_no", paramLocDetl.getBillNo()).eq("seq_no",paramLocDetl.getSeqNo()));
                    Double outQty = paramLocDetl.getCount() - waitMatout.getOutQty();
                    if(waitMatout.getOutQty() >= waitMatout.getQty()){
                        break;
                    }
                    // 判断入出库类型:101.全板出库 or 103.拣料出库
                    Double sumCount=locDetlService.getLocDetlSumQty(locDetl.getLocNo());
                    int ioType=0;
                    ioType = sumCount-locDetl.getQty()>0 ? 103 : 101;
 
                    Double curOutQty = outQty >= locDetl.getQty() ? locDetl.getQty() : outQty;   //本次出库量
                    stockOut(waitMatout.getBillNo(),waitMatout.getSeqNo(),staNo,new LocDetlDto(locDetl,curOutQty),ioType,userId);
                    waitMatout.setOutQty(waitMatout.getOutQty() + curOutQty);
                    waitMatout.setIoStatus(1);
                    //修改记录
                    Integer update = waitMatoutMapper.update(waitMatout, new EntityWrapper<WaitMatout>().eq("bill_no", paramLocDetl.getBillNo())
                            .eq("seq_no",paramLocDetl.getSeqNo()));
 
//                    if (outQty >= locDetl.getQty()){
//                        //生成文档记录
//                        stockOut(waitMatout.getBillNo(),waitMatout.getSeqNo(),staNo,new LocDetlDto(locDetl,locDetl.getQty()),ioType,userId);
//                        waitMatout.setOutQty(waitMatout.getOutQty() + locDetl.getQty());
//                        waitMatout.setIoStatus(1);
//                        //修改记录
//                        Integer update = waitMatoutMapper.update(waitMatout, new EntityWrapper<WaitMatout>().eq("bill_no", paramLocDetl.getBillNo())
//                                                                .eq("seq_no",paramLocDetl.getSeqNo()));
//                    }else {
//                        //生成文档记录
//                        stockOut(waitMatout.getBillNo(),waitMatout.getSeqNo(),staNo,new LocDetlDto(locDetl,outQty),ioType,userId);
//                        waitMatout.setOutQty(waitMatout.getOutQty() + outQty);
//                        waitMatout.setIoStatus(1);
//                        //修改记录
//                        Integer update = waitMatoutMapper.update(waitMatout, new EntityWrapper<WaitMatout>().eq("bill_no", paramLocDetl.getBillNo())
//                                                                .eq("seq_no",paramLocDetl.getSeqNo()));
//                    }
                }
            }
        }
    }
 
    @Override
    @Transactional
    public void stockOut(String billNo, Integer seqNo, BasDevp staNo, LocDetlDto locDetlDtos, Integer ioType, Long userId) {
        // 生成工作档
            LocDetl locDetl=locDetlDtos.getLocDetl();
            // 获取库位
            LocMast locMast = locMastService.selectById(locDetl.getLocNo());
            // 获取路径
            Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                    .eq("type_no", ioType)
                    .eq("stn_no", staNo.getDevNo())
                    .eq("crn_no", locMast.getCrnNo());
            StaDesc staDesc = staDescService.selectOne(wrapper);
            if (Cools.isEmpty(staDesc)) {
                throw new CoolException("出库路径不存在");
            }
            int rok;
            if(ioType==103){
                rok=2;
            }else{
                rok=1;
            }
            // 生成工作号
            int workNo = commonService.getWorkNo(rok);
            // 生成工作档
            WrkMast wrkMast = new WrkMast();
            wrkMast.setWrkNo(workNo);
            wrkMast.setIoTime(new Date());
            wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
            wrkMast.setIoType(ioType); // 入出库状态
            wrkMast.setIoPri(13D); // 优先级:13
            wrkMast.setCrnNo(locMast.getCrnNo());
            wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站
            wrkMast.setStaNo(staDesc.getStnNo()); // 目标站
            wrkMast.setSourceLocNo(locDetl.getLocNo()); // 源库位
            wrkMast.setFullPlt("Y"); // 满板:Y
            wrkMast.setPicking("N"); // 拣料
            wrkMast.setExitMk("N"); // 退出
            wrkMast.setEmptyMk("N"); // 空板
            wrkMast.setLinkMis("N");
            wrkMast.setAppeUser(userId); // 操作人员数据
            wrkMast.setAppeTime(new Date());
            wrkMast.setModiUser(userId);
            wrkMast.setModiTime(new Date());
            if (!wrkMastService.insert(wrkMast)) {
                throw new CoolException("保存工作档失败,出库库位号:"+locDetl.getLocNo());
            }
                // 出库时,数量为0的直接忽略
                if (locDetlDtos.getCount()==null || locDetlDtos.getCount() <= 0.0D) {return;}
                WrkDetl wrkDetl = new WrkDetl();
                wrkDetl.setWrkNo(workNo);
                wrkDetl.setIoTime(new Date());
                wrkDetl.setQty(locDetlDtos.getCount()); // 数量
                VersionUtils.setWrkDetl(wrkDetl, locDetlDtos.getLocDetl()); // 版本控制
                wrkDetl.setAppeTime(new Date());
                wrkDetl.setAppeUser(userId);
                wrkDetl.setModiTime(new Date());
                wrkDetl.setBillNo(billNo);
                wrkDetl.setSeqNo(seqNo);
                wrkDetl.setModiUser(userId);
                if (!wrkDetlService.insert(wrkDetl)) {
                    throw new CoolException("保存工作档明细失败");
                }
 
            // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
            locMast = locMastService.selectById(locDetl.getLocNo());
            if (locMast.getLocSts().equals("F")) {
                locMast.setLocSts(ioType==101?"R":"P");
                locMast.setModiUser(userId);
                locMast.setModiTime(new Date());
                if (!locMastService.updateById(locMast)) {
                    throw new CoolException("预约库位状态失败,库位号:"+locDetl.getLocNo());
                }
            } else {
                throw new CoolException(locDetl.getLocNo() + "库位不是在库状态");
            }
        }
}