自动化立体仓库 - WMS系统
zwl
3 天以前 2acfc2d2a0e956910c51bd996f443b3cb9bd3dc9
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
package com.zy.common.service;
 
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.result.FindLocNoAttributeVo;
import com.zy.common.model.LocTypeDto;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
 
import java.util.List;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
 
class CommonServiceLocTypeStrategyTest {
 
    private final CommonService commonService = new CommonService();
 
    @Test
    void normalizeLocTypeDto_forFullPallet_ignoresLocType2AndLocType3() {
        FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo();
        attributeVo.setMatnr("MAT-001");
        LocTypeDto locTypeDto = new LocTypeDto();
        locTypeDto.setLocType1((short) 1);
        locTypeDto.setLocType2((short) 1);
        locTypeDto.setLocType3((short) 2);
 
        LocTypeDto normalized = ReflectionTestUtils.invokeMethod(
                commonService, "normalizeLocTypeDto", 1, attributeVo, locTypeDto);
 
        assertEquals(Short.valueOf((short) 1), normalized.getLocType1());
        org.junit.jupiter.api.Assertions.assertNull(normalized.getLocType2());
        org.junit.jupiter.api.Assertions.assertNull(normalized.getLocType3());
    }
 
    @Test
    void normalizeLocTypeDto_forEmptyPallet_prefersNarrowAndKeepsHeight() {
        FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo();
        attributeVo.setMatnr("emptyPallet");
        LocTypeDto locTypeDto = new LocTypeDto();
        locTypeDto.setLocType1((short) 1);
        locTypeDto.setLocType3((short) 2);
 
        LocTypeDto normalized = ReflectionTestUtils.invokeMethod(
                commonService, "normalizeLocTypeDto", 10, attributeVo, locTypeDto);
 
        assertEquals(Short.valueOf((short) 1), normalized.getLocType1());
        assertEquals(Short.valueOf((short) 1), normalized.getLocType2());
        assertEquals(Short.valueOf((short) 2), normalized.getLocType3());
    }
 
    @Test
    void buildRetryCompatibleLocTypeDto_forEmptyPallet_onlyRaisesHeightAndKeepsOtherLocTypes() {
        FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo();
        attributeVo.setMatnr("emptyPallet");
        LocTypeDto locTypeDto = new LocTypeDto();
        locTypeDto.setLocType1((short) 1);
        locTypeDto.setLocType2((short) 1);
        locTypeDto.setLocType3((short) 2);
 
        LocTypeDto compatible = ReflectionTestUtils.invokeMethod(
                commonService, "buildRetryCompatibleLocTypeDto", 10, attributeVo, locTypeDto);
 
        assertEquals(Short.valueOf((short) 2), compatible.getLocType1());
        assertEquals(Short.valueOf((short) 1), compatible.getLocType2());
        assertEquals(Short.valueOf((short) 2), compatible.getLocType3());
    }
 
    @Test
    void buildRetryCompatibleLocTypeDto_forFullPallet_onlyRaisesHeight() {
        FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo();
        attributeVo.setMatnr("MAT-001");
        LocTypeDto locTypeDto = new LocTypeDto();
        locTypeDto.setLocType1((short) 1);
        locTypeDto.setLocType2((short) 2);
        locTypeDto.setLocType3((short) 2);
        LocTypeDto normalized = ReflectionTestUtils.invokeMethod(
                commonService, "normalizeLocTypeDto", 1, attributeVo, locTypeDto);
 
        LocTypeDto compatible = ReflectionTestUtils.invokeMethod(
                commonService, "buildRetryCompatibleLocTypeDto", 1, attributeVo, normalized);
 
        assertEquals(Short.valueOf((short) 2), compatible.getLocType1());
        org.junit.jupiter.api.Assertions.assertNull(compatible.getLocType2());
        org.junit.jupiter.api.Assertions.assertNull(compatible.getLocType3());
    }
 
    @Test
    void wcsFullPalletPayload_whenLowLocExhausted_shouldRetryHighLocWithoutLocType2OrLocType3() {
        FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo();
        attributeVo.setMatnr("MAT-80000001");
        LocTypeDto requestLocType = new LocTypeDto();
        requestLocType.setLocType1((short) 1);
        requestLocType.setLocType2((short) 2);
        requestLocType.setLocType3((short) 2);
        LocTypeDto normalized = ReflectionTestUtils.invokeMethod(
                commonService, "normalizeLocTypeDto", 1, attributeVo, requestLocType);
 
        LocTypeDto compatible = ReflectionTestUtils.invokeMethod(
                commonService, "buildRetryCompatibleLocTypeDto", 1, attributeVo, normalized);
 
        assertEquals(Short.valueOf((short) 2), compatible.getLocType1());
        org.junit.jupiter.api.Assertions.assertNull(compatible.getLocType2());
        org.junit.jupiter.api.Assertions.assertNull(compatible.getLocType3());
    }
 
    @Test
    void matchesLocType_forFullPallet_rejectsNarrowLocType2() {
        FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo();
        attributeVo.setMatnr("MAT-001");
        LocTypeDto requestLocType = new LocTypeDto();
        requestLocType.setLocType1((short) 1);
        LocTypeDto normalized = ReflectionTestUtils.invokeMethod(
                commonService, "normalizeLocTypeDto", 1, attributeVo, requestLocType);
        LocMast narrowLoc = new LocMast();
        narrowLoc.setLocType1((short) 1);
        narrowLoc.setLocType2((short) 1);
 
        Boolean matched = ReflectionTestUtils.invokeMethod(
                commonService, "matchesLocType", narrowLoc, normalized);
 
        assertFalse(Boolean.TRUE.equals(matched));
    }
 
    @Test
    void matchesLocType_forFullPallet_acceptsNonNarrowLocType2() {
        FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo();
        attributeVo.setMatnr("MAT-001");
        LocTypeDto requestLocType = new LocTypeDto();
        requestLocType.setLocType1((short) 1);
        LocTypeDto normalized = ReflectionTestUtils.invokeMethod(
                commonService, "normalizeLocTypeDto", 1, attributeVo, requestLocType);
        LocMast wideLoc = new LocMast();
        wideLoc.setLocType1((short) 1);
        wideLoc.setLocType2((short) 2);
 
        Boolean matched = ReflectionTestUtils.invokeMethod(
                commonService, "matchesLocType", wideLoc, normalized);
 
        assertTrue(Boolean.TRUE.equals(matched));
    }
 
    @Test
    @SuppressWarnings("unchecked")
    void buildEmptyPalletSearchLocTypes_forLowLoc_returnsConfiguredFallbackOrder() {
        LocTypeDto locTypeDto = new LocTypeDto();
        locTypeDto.setLocType1((short) 1);
        locTypeDto.setLocType2((short) 1);
        locTypeDto.setLocType3((short) 2);
 
        List<LocTypeDto> stages = ReflectionTestUtils.invokeMethod(
                commonService, "buildEmptyPalletSearchLocTypes", locTypeDto);
 
        assertEquals(4, stages.size());
        assertEquals(Short.valueOf((short) 1), stages.get(0).getLocType1());
        assertEquals(Short.valueOf((short) 1), stages.get(0).getLocType2());
        assertEquals(Short.valueOf((short) 1), stages.get(1).getLocType1());
        org.junit.jupiter.api.Assertions.assertNull(stages.get(1).getLocType2());
        assertEquals(Short.valueOf((short) 2), stages.get(2).getLocType1());
        assertEquals(Short.valueOf((short) 1), stages.get(2).getLocType2());
        assertEquals(Short.valueOf((short) 2), stages.get(3).getLocType1());
        org.junit.jupiter.api.Assertions.assertNull(stages.get(3).getLocType2());
        assertEquals(Short.valueOf((short) 2), stages.get(3).getLocType3());
    }
}