jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package com.ld.igds.grain;
 
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 根据电缆起始方位、起始点位、布线方向等进行调转
 *
 * @author: chen
 * @description:
 * @version:
 * @data:2022年08月06日
 */
@Component
public class GrainUtil {
 
    /**
     * 粮情点位验证
     *
     * @param args
     */
    public static void main(String[] args) {
        //层行列:2-3-4
        int cableZ = 2;  //层
        int cableY = 3;  //行
        int cableX = 4;  //列
 
        List<Double> temps = new ArrayList<>();
        for (int i = 1; i < (cableX * cableY * cableZ + 1); i++) {
            temps.add(i + 0.0);
        }
        System.out.println("--默认起始,默认布线--" + temps.toString());
        List<Double> list;
 
        /*==========右边起始,横向布线==========*/
        list = new ArrayList<>();
        for (int x = 1; x <= cableX; x++) {
            for (int y = 1; y <= cableY; y++) {
                for (int z = 1; z <= cableZ; z++) {
                    list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
                }
            }
        }
        System.out.println("--右边起始,横向布线--" + list.toString());
 
        /*==========右上起始,横向布线==========*/
        list = new ArrayList<>();
        for (int x = 1; x <= cableX; x++) {
            for (int y = cableY; y >= 1; y--) {
                for (int z = 1; z <= cableZ; z++) {
                    list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
                }
            }
        }
        System.out.println("--右上起始,横向布线--" + list.toString());
 
        /*==========右上起始,纵向布线==========*/
        list = new ArrayList<>();
        for (int x = 1; x <= cableX; x++) {
            for (int y = cableY; y >= 1; y--) {
                for (int z = 1; z <= cableZ; z++) {
                    list.add(temps.get((x - 1) * cableZ * cableY + (y - 1) * cableZ + z - 1));
                }
            }
        }
        System.out.println("--右上起始,纵向布线--" + list.toString());
 
        /*==========左上起始,横向布线==========*/
        list = new ArrayList<>();
        for (int x = cableX; x >= 1; x--) {
            for (int y = cableY; y >= 1; y--) {
                for (int z = 1; z <= cableZ; z++) {
                    list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
                }
            }
        }
        System.out.println("--左上起始,横向布线--" + list.toString());
 
        /*==========左上起始,纵向布线==========*/
        list = new ArrayList<>();
        for (int i = temps.size() - 1; i >= 0; i--) {
            list.add(temps.get(i));
        }
        System.out.println("--左上起始,纵向布线--" + list.toString());
 
        /*==========左边起始,横向布线=========*/
        list = new ArrayList<>();
        for (int x = cableX; x >= 1; x--) {
            for (int y = 1; y <= cableY; y++) {
                for (int z = 1; z <= cableZ; z++) {
                    list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
                }
            }
        }
        System.out.println("--左边起始,横向布线--" + list.toString());
 
        /*==========左边起始,纵向布线==========*/
        list = new ArrayList<>();
        for (int i = 1; i <= temps.size(); i++) {
            list.add(temps.get((cableX - 1) * cableY * cableZ + ((i - 1) % (cableY * cableZ))));
            if (i % (cableY * cableZ) == 0) {
                cableX = cableX - 1;
            }
        }
        System.out.println("--左边起始,纵向布线--" + list.toString());
 
        /*==========上下翻转==========*/
        list = new ArrayList<>();
        for (int i = 0; i <= temps.size() - cableZ; i += cableZ) {
            for (int j = cableZ - 1; j >= 0; j--) {
                list.add(temps.get(i + j));
            }
        }
        System.out.println("--上下翻转--" + list.toString());
    }
 
    /**
     * 转换粮情,从右边起始,横向布线
     *
     * @param temps
     * @param cable
     * @return
     */
    public List<Double> reversalRight1(List<Double> temps, String cable) {
        String[] attCable = cable.split("-");
        int cableZ = Integer.valueOf(attCable[0]);
        int cableY = Integer.valueOf(attCable[1]);
        int cableX = Integer.valueOf(attCable[2]);
        List<Double> list = new ArrayList<>();
        for (int x = 1; x <= cableX; x++) {
            for (int y = 1; y <= cableY; y++) {
                for (int z = 1; z <= cableZ; z++) {
                    list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
                }
            }
        }
        return list;
    }
 
    /**
     * 转换粮情,从右上起始,横向布线
     *
     * @param temps
     * @param cable
     * @return
     */
    public List<Double> reversalRightUp1(List<Double> temps, String cable) {
        String[] attCable = cable.split("-");
        int cableZ = Integer.valueOf(attCable[0]);
        int cableY = Integer.valueOf(attCable[1]);
        int cableX = Integer.valueOf(attCable[2]);
        List<Double> list = new ArrayList<>();
        for (int x = 1; x <= cableX; x++) {
            for (int y = cableY; y >= 1; y--) {
                for (int z = 1; z <= cableZ; z++) {
                    list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
                }
            }
        }
        return list;
    }
 
    /**
     * 转换粮情,从右上起始,纵向布线
     *
     * @param temps
     * @param cable
     * @return
     */
    public List<Double> reversalRightUp2(List<Double> temps, String cable) {
        String[] attCable = cable.split("-");
        int cableZ = Integer.valueOf(attCable[0]);
        int cableY = Integer.valueOf(attCable[1]);
        int cableX = Integer.valueOf(attCable[2]);
        List<Double> list = new ArrayList<>();
        for (int x = 1; x <= cableX; x++) {
            for (int y = cableY; y >= 1; y--) {
                for (int z = 1; z <= cableZ; z++) {
                    list.add(temps.get((x - 1) * cableZ * cableY + (y - 1) * cableZ + z - 1));
                }
            }
        }
        return list;
    }
 
    /**
     * 转换粮情,从左边起始,横向布线
     *
     * @param temps
     * @param cable
     * @return
     */
    public List<Double> reversalLeft1(List<Double> temps, String cable) {
        String[] attCable = cable.split("-");
        int cableZ = Integer.valueOf(attCable[0]);
        int cableY = Integer.valueOf(attCable[1]);
        int cableX = Integer.valueOf(attCable[2]);
        List<Double> list = new ArrayList<>();
        for (int x = cableX; x >= 1; x--) {
            for (int y = 1; y <= cableY; y++) {
                for (int z = 1; z <= cableZ; z++) {
                    list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
                }
            }
        }
        return list;
    }
 
    /**
     * 转换粮情,从左边起始,纵向布线
     *
     * @param temps
     * @param cable
     * @return
     */
    public List<Double> reversalLeft2(List<Double> temps, String cable) {
        String[] attCable = cable.split("-");
        int cableZ = Integer.valueOf(attCable[0]);
        int cableY = Integer.valueOf(attCable[1]);
        int cableX = Integer.valueOf(attCable[2]);
        List<Double> list = new ArrayList<>();
        for (int i = 1; i <= temps.size(); i++) {
            list.add(temps.get((cableX - 1) * cableY * cableZ + ((i - 1) % (cableY * cableZ))));
            if (i % (cableY * cableZ) == 0) {
                cableX = cableX - 1;
            }
        }
        return list;
    }
 
    /**
     * 转换粮情,从左上起始,横向布线
     *
     * @param temps
     * @param cable
     * @return
     */
    public List<Double> reversalLeftUp1(List<Double> temps, String cable) {
        String[] attCable = cable.split("-");
        int cableZ = Integer.valueOf(attCable[0]);
        int cableY = Integer.valueOf(attCable[1]);
        int cableX = Integer.valueOf(attCable[2]);
        List<Double> list = new ArrayList<>();
        for (int x = cableX; x >= 1; x--) {
            for (int y = cableY; y >= 1; y--) {
                for (int z = 1; z <= cableZ; z++) {
                    list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
                }
            }
        }
        return list;
    }
 
    /**
     * 转换粮情,从左上起始,纵向布线
     *
     * @param temps
     * @param cable
     * @return
     */
    public List<Double> reversalLeftUp2(List<Double> temps, String cable) {
        String[] attCable = cable.split("-");
        int cableZ = Integer.valueOf(attCable[0]);
        int cableY = Integer.valueOf(attCable[1]);
        int cableX = Integer.valueOf(attCable[2]);
        List<Double> list = new ArrayList<>();
        for (int i = temps.size() - 1; i >= 0; i--) {
            list.add(temps.get(i));
        }
        return list;
    }
 
    /**
     * 电缆从下面开始时,将粮情电缆上下翻转
     *
     * @param temps 粮情数据
     * @param cable 层行列配置,如:4-7-11
     * @return
     */
    public List<Double> reversalUpAndDown(List<Double> temps, String cable) {
 
        List<Double> list = new ArrayList<>();
        String[] attCable = cable.split("-");
        int cableZ = Integer.valueOf(attCable[0]); //层
 
        for (int i = 0; i <= temps.size() - cableZ; i += cableZ) {
            for (int j = cableZ - 1; j >= 0; j--) {
                list.add(temps.get(i + j));
            }
        }
        return list;
    }
 
}