自动化立体仓库 - WMS系统
#
lty
2 天以前 078d76d0e964be567927b1765986dffe8f2c170a
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
package com.zy.common.model;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.service.LocDetlService;
import lombok.Data;
 
import java.util.*;
 
/**
 * Created by vincent on 2022/3/28
 */
@Data
public class TaskDto {
 
    private String locNo;
 
    private Integer staNo;
    private List<LocDetlDto> locDetlDtos = new ArrayList<>();
 
    private List<LocDto> locDtos;
 
    {
        locDtos = new ArrayList<>();
    }
 
    public TaskDto(String locNo, Integer staNo) {
        this.locNo = locNo;
        this.staNo = staNo;
    }
 
    public TaskDto(String locNo, Integer staNo, LocDto locDto) {
        this.locNo = locNo;
        this.staNo = staNo;
        this.locDtos.add(locDto);
    }
 
    public TaskDto(String locNo, Integer staNo, List<LocDto> locDtos) {
        this.locNo = locNo;
        this.staNo = staNo;
        this.locDtos = locDtos;
    }
 
    public static boolean has(List<TaskDto> list, TaskDto dto) {
        if (Cools.isEmpty(list)) {
            return false;
        }
        for (TaskDto taskDto : list) {
            if (dto.getLocNo().equals(taskDto.getLocNo()) && taskDto.getStaNo().equals(dto.getStaNo())) {
                return true;
            }
        }
        return false;
    }
 
    public static TaskDto find(List<TaskDto> list, TaskDto dto) {
        if (Cools.isEmpty(list)) {
            return null;
        }
        for (TaskDto taskDto : list) {
            if (dto.getLocNo().equals(taskDto.getLocNo()) && taskDto.getStaNo().equals(dto.getStaNo())) {
                return taskDto;
            }
        }
        return null;
    }
 
//    public boolean isAll(){
//        // 汇总不考虑序列码
//        List<DetlDto> detlDtos = new ArrayList<>();
//        for (LocDto locDto : this.getLocDtos()) {
//            DetlDto dto = new DetlDto(locDto);
//            if (DetlDto.has(detlDtos, dto)) {
//                DetlDto detlDto = DetlDto.find(detlDtos, locDto);
//                assert detlDto != null;
//                detlDto.setAnfme(detlDto.getAnfme() + locDto.getAnfme());
//            } else {
//                detlDtos.add(new DetlDto(locDto));
//            }
//        }
//
//        // 查询当前库位号所有的库存明细
//        LocDetlService locDetlService = SpringUtils.getBean(LocDetlService.class);
//        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", this.locNo));
//        if (locDetls == null || locDetls.isEmpty()){
//            throw new CoolException("检索库存明细失败,库位号=" + this.locNo);
//        }
//        int sameNumber = 0;
//        for (LocDetl locDetl : locDetls) {
//            Iterator<DetlDto> iterator = detlDtos.iterator();
//            while (iterator.hasNext()) {
//                DetlDto dto = iterator.next();
//                if (!dto.getMatnr().equals(locDetl.getMatnr())) {
//                    continue;
//                }
//                if (Cools.isEmpty(dto.getBatch()) && !Cools.isEmpty(locDetl.getBatch())) {
//                    continue;
//                }
//                if (!Cools.isEmpty(dto.getBatch()) && Cools.isEmpty(locDetl.getBatch())) {
//                    continue;
//                }
//                if (!Cools.isEmpty(dto.getBatch()) && !Cools.isEmpty(locDetl.getBatch())) {
//                    if (!dto.getBatch().equals(locDetl.getBatch())) {
//                        continue;
//                    }
//                }
//                if (dto.getAnfme() > locDetl.getAnfme()) {
//                    throw new CoolException("服务器内部错误");
//                }
//                if (dto.getAnfme().equals(locDetl.getAnfme())) {
//                    sameNumber++;
//                    iterator.remove();
//                    break;
//                }
//            }
//        }
//        return sameNumber == locDetls.size();
//    }
public boolean isAll() {
    // 深拷贝,防止原集合被修改
    List<LocDetlDto> locDetlDtosCp = new ArrayList<>(this.locDetlDtos);
 
    // 查询当前库位号所有库存明细
    LocDetlService locDetlService = SpringUtils.getBean(LocDetlService.class);
    List<LocDetl> locDetls = locDetlService.selectList(
            new EntityWrapper<LocDetl>().eq("loc_no", this.locNo)
    );
 
    if (locDetls == null || locDetls.isEmpty()) {
        throw new CoolException("检索库存明细失败,库位号=" + this.locNo);
    }
 
    int sameNumber = 0;
 
    for (LocDetl locDetl : locDetls) {
        boolean matched = false;
 
        System.out.println("当前库存明细: matnr=" + locDetl.getMatnr() + ", batch=" + locDetl.getBatch() + ", anfme=" + locDetl.getAnfme());
 
        Iterator<LocDetlDto> iterator = locDetlDtosCp.iterator();
        while (iterator.hasNext()) {
            LocDetlDto dto = iterator.next();
            String dtoMatnr = dto.getLocDetl().getMatnr();
            String dtoBatch = dto.getLocDetl().getBatch();
            Double dtoCount = dto.getCount();
 
            System.out.println("比较对象: matnr=" + dtoMatnr + ", batch=" + dtoBatch + ", count=" + dtoCount);
 
            if (!dtoMatnr.equals(locDetl.getMatnr())) continue;
            if (!Cools.eq(dtoBatch, locDetl.getBatch())) continue;
 
            if (dtoCount > locDetl.getAnfme()) {
                throw new CoolException("服务器内部错误,数量大于库存");
            }
 
            if (dtoCount.equals(locDetl.getAnfme())) {
                sameNumber++;
                matched = true;
                iterator.remove();
                System.out.println("匹配成功并移除该项,当前 sameNumber = " + sameNumber + ",剩余匹配数: " + locDetlDtosCp.size());
                break;
            }
        }
 
        if (!matched) {
            System.out.println("未匹配成功: matnr=" + locDetl.getMatnr() + ", batch=" + locDetl.getBatch());
        }
    }
 
    return sameNumber == locDetls.size();
}
 
 
}