13693261870
2025-07-02 6708810c4de34dfb9513061432d656f91d56ee3a
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
package com.ruoyi.buss.controller;
 
/**
 * 支队舰船补给计划逻辑Controller
 *
 * @author yl
 * @date 2025-03-20
 */
 
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.buss.domain.DsTaskDetail;
import com.ruoyi.buss.domain.DsTaskList2;
import com.ruoyi.buss.domain.dto.ZdSupplyPlanDTO;
import com.ruoyi.buss.service.IDsTaskDetailService;
import com.ruoyi.buss.service.IDsTaskList2Service;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.service.ISysDictDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
@Tag(name = "支队舰船补给计划")
@Controller
@RequestMapping("/buss/zd/supplyplan")
public class ZdSupplyPlanController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(ZdSupplyPlanController.class);
 
    private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
    private static String OIL_SUPPLY_TYPE = "1";
    private static String MISSILE_SUPPLY_TYPE = "2";
    private static String GOODS_SUPPLY_TYPE = "3";
    private static String WATER_SUPPLY_TYPE = "4";
 
    private static int OIL_UNIT_NUM = 100;  // 单位:100吨
    private static int WATER_UNIT_NUM = 10;  // 单位:10吨
    private static int GOODS_UNIT_NUM = 1;  // 单位:1车
    private static int MISSILE_UNIT_NUM = 4; //单位:4枚
 
    // 如下定义054、056、073舰型不同补给类型单位数量所需时间
    private static int[] OIL_USE_TIME = new int[]{3, 3, 3, 3, 3}; // 100吨油料所需时间
    private static int[] WATER_USE_TIME = new int[]{1, 1, 1, 1, 1};  // 10吨淡水所需时间
    private static int[] GOODS_USE_TIME = new int[]{2, 2, 2, 2, 2};  // 1车物资搬运上舰2小时
    private static int[] MISSILE_USE_TIME = new int[]{4, 4, 4, 4, 4};  // 10吨物资所需时间
 
    // 定义舰型
    private static String[] SHIP_TYPE = new String[]{"052D", "054A", "056A", "071", "072"};
 
    @Autowired
    private IDsTaskList2Service dsTaskListService;
    @Autowired
    private IDsTaskDetailService dsTaskDetailService;
    @Autowired
    private ISysDictDataService sysDictDataService;
 
    @Operation(description = "获取支队舰船补给计划")
    @Log(title = "支队补给计划", businessType = BusinessType.INSERT)
    @PostMapping("/get")
    @ResponseBody
    public AjaxResult getZdSupplyPlan(@RequestBody ZdSupplyPlanDTO zdSupplyPlanDTO) throws IOException, ParseException {
        Long taskId = zdSupplyPlanDTO.getTaskId();
        String t1Time = zdSupplyPlanDTO.getT1Time();
        String usedBerthIds = zdSupplyPlanDTO.getUsedBerthIds();
 
        LoginUser sysUser = getLoginUser();
        Long deptId = sysUser.getDeptId();
 
        JSONArray rootJSONArray = new JSONArray();
        if (usedBerthIds != null && usedBerthIds.length() > 0) {
            String[] berthIdArray = usedBerthIds.split(","); // usedBerthIds为多个泊位ID,以逗号分隔
            for (int i = 0; i < berthIdArray.length; i++) {
                JSONObject rootJSONObj = new JSONObject();
                JSONArray jsonArray = new JSONArray();
                JSONObject sub1JsonObj = new JSONObject();
                List<DsTaskList2> dsTaskLists = dsTaskListService.getDsTaskListForSupplyPlan(deptId, taskId, Long.parseLong(berthIdArray[i]));
 
                // 遍历各泊位的各舰船,计算每艘舰船所需补给时间,生成各舰船的补给计划数据
                if (dsTaskLists.size() > 0) {
                    sub1JsonObj.put("harborName", dsTaskLists.get(0).getHarborName());
                    sub1JsonObj.put("berthName", dsTaskLists.get(0).getBerthName());
                    sub1JsonObj.put("berthId", dsTaskLists.get(0).getBerthId());
                    sub1JsonObj.put("parkingType", dsTaskLists.get(0).getParkingType());
                    // 岸电节点总时长
                    int andianTotalTime = 0;
                    // 淡水补给总时长
                    int waterTotalTime = 0;
                    // 燃料补给总时长
                    int oilTotalTime = 0;
                    // 弹药补给总时长
                    int missileTotalTime = 0;
                    // 物资补给总时长
                    int goodsTotalTime = 0;
 
                    JSONArray subJSONArray = new JSONArray();
                    for (int j = 0; j < dsTaskLists.size(); j++) {
                        DsTaskDetail dsTaskDetail = new DsTaskDetail();
                        JSONObject jsonObj =  new JSONObject();
                        DsTaskList2 tempDsTaskList = dsTaskLists.get(j);
                        String shipType = tempDsTaskList.getShipType(); // 舰型
                        String shipNo = tempDsTaskList.getShipNo(); // 舷号
                        String supplySeq = tempDsTaskList.getSupplySeq(); // 补给序列
 
                        String supplySeqLabel = sysDictDataService.selectDictLabel("dd_rule_supply", supplySeq); // 补给序列标签
                        // 第一缆绳
                        String firstCabelLabel = "T" + (j + 1);
                        // 岸电接电起始时间Label
                        String andianStartTimeLabel = firstCabelLabel + "+1";
 
                        // 淡水补给起始时间Label
                        String waterStartTimeLabel = firstCabelLabel + "+1";
                        // 淡水补给结束时间Label
                        int addWaterTimeNum = calcSupplyTimeBySupplyType(WATER_SUPPLY_TYPE, shipType, tempDsTaskList.getWATER());
                        String waterEndTimeLabel = firstCabelLabel + "+" +(addWaterTimeNum + 1);
                        waterTotalTime += addWaterTimeNum;
 
                        // 燃油补给时间Label
                        String oilStartTimeLabel = "";
                        String oilEndTimeLabel = "";
                        // 弹药补给时间Label
                        String missileStartTimeLabel = "";
                        String missileEndTimeLabel = "";
 
                        // 补给结束测算时间
                        String supplyEndTimeLabel = "";
                        Double oilA = tempDsTaskList.getOilA() == null ? 0 : tempDsTaskList.getOilA();
                        Double oilB = tempDsTaskList.getOilB() == null ? 0 : tempDsTaskList.getOilB();
                        Double oilG = tempDsTaskList.getOilG() == null ? 0 : tempDsTaskList.getOilG();
                        double totalOilNum = oilA + oilB + oilG; // 总加油量
                        int addOilTimeNum = calcSupplyTimeBySupplyType(OIL_SUPPLY_TYPE, shipType, totalOilNum);
                        Long ammoD = tempDsTaskList.getAmmoD() == null ? 0 : tempDsTaskList.getAmmoD();
                        int addMissileTimeNum = calcSupplyTimeBySupplyType(MISSILE_SUPPLY_TYPE, shipType, (double) ammoD);
                        if("1".equals(tempDsTaskList.getSupplySeq())){//同时进行
                            oilStartTimeLabel = firstCabelLabel + "+" + "2";
                            oilEndTimeLabel = firstCabelLabel + "+" + (addOilTimeNum + 2);
                            missileStartTimeLabel = firstCabelLabel + "+" + "2";;
                            missileEndTimeLabel = firstCabelLabel + "+" + (addMissileTimeNum + 2);
                            if(addOilTimeNum > addMissileTimeNum){
                                supplyEndTimeLabel = firstCabelLabel + "+" + (addOilTimeNum + 2 + 1);
                                dsTaskDetail.setETIME(DateUtils.addDays(format.parse(t1Time), addOilTimeNum + 2 + 1));
                            }else{
                                supplyEndTimeLabel = firstCabelLabel + "+" + (addMissileTimeNum + 2 + 1);
                                dsTaskDetail.setETIME(DateUtils.addDays(format.parse(t1Time), addMissileTimeNum + 2 + 1));
                            }
 
                            dsTaskDetail.setOilStime(2);
                            dsTaskDetail.setOilEtime(2 + addOilTimeNum);
                            dsTaskDetail.setAmmoStime(2);
                            dsTaskDetail.setAmmoEtime(2 + addMissileTimeNum);
                        }else if("2".equals(tempDsTaskList.getSupplySeq())){//先油后弹
                            oilStartTimeLabel = firstCabelLabel + "+" + "2";
                            oilEndTimeLabel = firstCabelLabel + "+" + (addOilTimeNum + 2);
                            missileStartTimeLabel = firstCabelLabel + "+" + (addOilTimeNum + 2);
                            missileEndTimeLabel = firstCabelLabel + "+" + (addOilTimeNum + 2 + addMissileTimeNum);
                            supplyEndTimeLabel = firstCabelLabel + "+" + (addOilTimeNum + 2 + addMissileTimeNum + 1);
 
                            dsTaskDetail.setOilStime(2);
                            dsTaskDetail.setOilEtime(2+ addOilTimeNum);
                            dsTaskDetail.setAmmoStime(addOilTimeNum + 2 + 1);
                            dsTaskDetail.setAmmoEtime(addOilTimeNum + 2 + 1 + addMissileTimeNum);
                            dsTaskDetail.setETIME(DateUtils.addDays(format.parse(t1Time), addOilTimeNum + 2 + addMissileTimeNum + 1));
                        }else if("3".equals(tempDsTaskList.getSupplySeq())){//先弹后油
                            missileStartTimeLabel = firstCabelLabel + "+2";
                            missileEndTimeLabel = firstCabelLabel + "+" + (addMissileTimeNum + 2);
                            oilStartTimeLabel = firstCabelLabel + "+" + (addMissileTimeNum + 2);
                            oilEndTimeLabel = firstCabelLabel + "+" + (addMissileTimeNum + 2 + addOilTimeNum);
                            supplyEndTimeLabel = firstCabelLabel + "+" + (addMissileTimeNum + 2 + addOilTimeNum + 1);
 
                            dsTaskDetail.setOilStime(addMissileTimeNum + 2 + 1);
                            dsTaskDetail.setOilEtime(addMissileTimeNum + 2 + 1 + addOilTimeNum);
                            dsTaskDetail.setAmmoStime(2);
                            dsTaskDetail.setAmmoEtime(addMissileTimeNum + 2);
                            dsTaskDetail.setETIME(DateUtils.addDays(format.parse(t1Time), addMissileTimeNum + 2 + addOilTimeNum + 1));
                        }
                        oilTotalTime += addOilTimeNum;
                        missileTotalTime += addMissileTimeNum;
 
                        if(addOilTimeNum >= addMissileTimeNum){
                            andianTotalTime += addOilTimeNum;
                        } else {
                            andianTotalTime += addMissileTimeNum;
                        }
 
                        // 物资补给时间Label
                        String goodsStartTimeLabel = "";
                        String goodsEndTimeLabel = "";
                        Long food = tempDsTaskList.getFOOD() == null? 0 : tempDsTaskList.getFOOD();
                        Long foodW = tempDsTaskList.getFoodW() == null? 0 : tempDsTaskList.getFoodW();
                        Long foodO = tempDsTaskList.getFoodO() == null? 0 : tempDsTaskList.getFoodO();
                        double totalGoodsNum = food + foodW + foodO; // 总加物资量
                        int addGoodTimeNum = calcSupplyTimeBySupplyType(GOODS_SUPPLY_TYPE, shipType, totalGoodsNum);
                        goodsStartTimeLabel = firstCabelLabel + "+2";
                        goodsEndTimeLabel = firstCabelLabel + "+" + (addGoodTimeNum + 2);
                        goodsTotalTime += addGoodTimeNum;
 
                        // 构建每艘舰船构建JSON对象
                        jsonObj.put("id", String.valueOf(j+1));
                        jsonObj.put("shipType", shipType);
                        jsonObj.put("shipNo", shipNo);
                        jsonObj.put("supplySeq", supplySeqLabel);
                        jsonObj.put("sTime", firstCabelLabel);
                        jsonObj.put("electSTime", andianStartTimeLabel);
                        jsonObj.put("waterSTime", waterStartTimeLabel);
                        jsonObj.put("waterETime", waterEndTimeLabel);
                        jsonObj.put("oilSTime", oilStartTimeLabel);
                        jsonObj.put("oilETime", oilEndTimeLabel);
                        jsonObj.put("ammoSTime", missileStartTimeLabel);
                        jsonObj.put("ammoETime", missileEndTimeLabel);
                        jsonObj.put("matSTime", goodsStartTimeLabel);
                        jsonObj.put("matETime", goodsEndTimeLabel);
                        jsonObj.put("supplyETime", supplyEndTimeLabel);
                        jsonObj.put("path", tempDsTaskList.getPath());
                        subJSONArray.add(jsonObj);
                        sub1JsonObj.put("subData", subJSONArray);
 
                        // 更新船舶补给计划数据
                        dsTaskDetail.setTaskId(taskId);
                        dsTaskDetail.setHarborId(tempDsTaskList.getHarborId());
                        dsTaskDetail.setHarborName(tempDsTaskList.getHarborName());
                        dsTaskDetail.setBerthId(Long.parseLong(berthIdArray[i]));
                        dsTaskDetail.setBerthName(tempDsTaskList.getBerthName());
                        dsTaskDetail.setParkingType(tempDsTaskList.getParkingType());
                        dsTaskDetail.setShipNo(tempDsTaskList.getShipNo());
                        dsTaskDetail.setShipType(tempDsTaskList.getShipType());
                        dsTaskDetail.setSTIME(format.parse(t1Time));
                        dsTaskDetail.setElecStime(1);
                        dsTaskDetail.setWaterStime(1);
                        dsTaskDetail.setWaterEtime(addWaterTimeNum);
                        dsTaskDetail.setMatStime(2);
                        dsTaskDetail.setMatEtime(addGoodTimeNum + 2);
                        dsTaskDetail.setOilTime(addOilTimeNum);
                        dsTaskDetail.setAmmoTime(addMissileTimeNum);
                        dsTaskDetail.setMatTime(addGoodTimeNum);
                        dsTaskDetail.setWaterTime(addWaterTimeNum);
                        dsTaskDetail.setT1(format.parse(t1Time));
                        dsTaskDetail.setSupplySeq(tempDsTaskList.getSupplySeq());
                        dsTaskDetail.setCarCount((int) totalGoodsNum);
                        dsTaskDetail.setFood((double) food);
                        dsTaskDetail.setFoodW((double) foodW);
                        dsTaskDetail.setFoodO((double) foodO);
 
                        // 根据taskId和shipNo和shipType判断是否存在船舶补给计划数据
                        DsTaskDetail tempDsTaskDetail = new DsTaskDetail();
                        tempDsTaskDetail.setTaskId(taskId);
                        tempDsTaskDetail.setShipNo(shipNo);
                        tempDsTaskDetail.setShipType(shipType);
                        List<DsTaskDetail> dsTaskDetails = dsTaskDetailService.selectDsTaskDetailList(tempDsTaskDetail);
                        if (dsTaskDetails != null && dsTaskDetails.size() > 0) {
                            dsTaskDetail.setPKID(dsTaskDetails.get(0).getPKID());
                            dsTaskDetailService.updateDsTaskDetail(dsTaskDetail);
                        } else {
                            dsTaskDetailService.insertDsTaskDetail(dsTaskDetail);
                        }
                    }
                    jsonArray.add(sub1JsonObj);
                    rootJSONObj.put("berthDatas", jsonArray);
                    rootJSONObj.put("totalJiedianTime", andianTotalTime);
                    rootJSONObj.put("totalWaterTime", waterTotalTime);
                    rootJSONObj.put("totalOilTime", oilTotalTime);
                    rootJSONObj.put("totalAmmoTime", missileTotalTime);
                    rootJSONObj.put("totalMatTime", goodsTotalTime);
                    rootJSONArray.add(rootJSONObj);
                }
            }
        }
        return AjaxResult.success(rootJSONArray);
    }
 
    @Operation(description = "获取支队时间补给计划")
    @Log(title = "支队支队时间补给计划", businessType = BusinessType.INSERT)
    @PostMapping("/getdate")
    @ResponseBody
    // 不显示T,显示yyyy-MM-dd HH:mm:ss
    public AjaxResult getZdSupplyPlanDate(@RequestBody ZdSupplyPlanDTO zdSupplyPlanDTO) throws IOException, ParseException {
        Long taskId = zdSupplyPlanDTO.getTaskId();
        String t1Time = zdSupplyPlanDTO.getT1Time();
        String usedBerthIds = zdSupplyPlanDTO.getUsedBerthIds();
 
        LoginUser sysUser = getLoginUser();
        Long deptId = sysUser.getDeptId();
 
        JSONArray rootJSONArray = new JSONArray();
        if (usedBerthIds != null && usedBerthIds.length() > 0) {
            String[] berthIdArray = usedBerthIds.split(","); // usedBerthIds为多个泊位ID,以逗号分隔
            for (int i = 0; i < berthIdArray.length; i++) {
                JSONObject rootJSONObj = new JSONObject();
                JSONArray jsonArray = new JSONArray();
                JSONObject sub1JsonObj = new JSONObject();
                List<DsTaskList2> dsTaskLists = dsTaskListService.getDsTaskListForSupplyPlan(deptId, taskId, Long.parseLong(berthIdArray[i]));
 
                // 遍历各泊位的各舰船,计算每艘舰船所需补给时间,生成各舰船的补给计划数据
                if (dsTaskLists.size() > 0) {
                    sub1JsonObj.put("harborName", dsTaskLists.get(0).getHarborName());
                    sub1JsonObj.put("berthName", dsTaskLists.get(0).getBerthName());
                    sub1JsonObj.put("berthId", dsTaskLists.get(0).getBerthId());
                    sub1JsonObj.put("parkingType", dsTaskLists.get(0).getParkingType());
                    // 岸电节点总时长
                    int andianTotalTime = 0;
                    // 淡水补给总时长
                    int waterTotalTime = 0;
                    // 燃料补给总时长
                    int oilTotalTime = 0;
                    // 弹药补给总时长
                    int missileTotalTime = 0;
                    // 物资补给总时长
                    int goodsTotalTime = 0;
 
                    JSONArray subJSONArray = new JSONArray();
                    for (int j = 0; j < dsTaskLists.size(); j++) {
                        DsTaskDetail dsTaskDetail = new DsTaskDetail();
                        JSONObject jsonObj =  new JSONObject();
                        DsTaskList2 tempDsTaskList = dsTaskLists.get(j);
                        String shipType = tempDsTaskList.getShipType(); // 舰型
                        String shipNo = tempDsTaskList.getShipNo(); // 舷号
                        String supplySeq = tempDsTaskList.getSupplySeq(); // 补给序列
 
                        String supplySeqLabel = sysDictDataService.selectDictLabel("dd_rule_supply", supplySeq); // 补给序列标签
                        // 第一缆绳
                        String firstCabelLabel = "T" + (j + 1);
                        String firstCabelLabelDate = format.format(addHoursToDate(t1Time, (j+1)));
 
                        // 岸电接电起始时间Label
                        String andianStartTimeLabel = firstCabelLabel + "+1";
                        String andianStartTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, 1));
 
                        // 淡水补给起始时间Label
                        String waterStartTimeLabel = firstCabelLabel + "+1";
                        String waterStartTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, 1));
 
                        // 淡水补给结束时间Label
                        int addWaterTimeNum = calcSupplyTimeBySupplyType(WATER_SUPPLY_TYPE, shipType, tempDsTaskList.getWATER());
                        String waterEndTimeLabel = firstCabelLabel + "+" +(addWaterTimeNum + 1);
                        String waterEndTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addWaterTimeNum + 1)));
                        waterTotalTime += addWaterTimeNum;
 
                        // 燃油补给时间Label
                        String oilStartTimeLabel = "";
                        String oilStartTimeLabelDate = "";
                        String oilEndTimeLabel = "";
                        String oilEndTimeLabelDate = "";
                        // 弹药补给时间Label
                        String missileStartTimeLabel = "";
                        String missileStartTimeLabelDate = "";
                        String missileEndTimeLabel = "";
                        String missileEndTimeLabelDate = "";
 
                        // 补给结束测算时间
                        String supplyEndTimeLabel = "";
                        String supplyEndTimeLabelDate = "";
                        Double oilA = tempDsTaskList.getOilA() == null ? 0 : tempDsTaskList.getOilA();
                        Double oilB = tempDsTaskList.getOilB() == null ? 0 : tempDsTaskList.getOilB();
                        Double oilG = tempDsTaskList.getOilG() == null ? 0 : tempDsTaskList.getOilG();
                        double totalOilNum = oilA + oilB + oilG; // 总加油量
                        int addOilTimeNum = calcSupplyTimeBySupplyType(OIL_SUPPLY_TYPE, shipType, totalOilNum);
                        Long ammoD = tempDsTaskList.getAmmoD() == null ? 0 : tempDsTaskList.getAmmoD();
                        int addMissileTimeNum = calcSupplyTimeBySupplyType(MISSILE_SUPPLY_TYPE, shipType, (double) ammoD);
                        if("1".equals(tempDsTaskList.getSupplySeq())){//同时进行
                            oilStartTimeLabel = firstCabelLabel + "+" + "2";
                            oilStartTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, 2));
                            oilEndTimeLabel = firstCabelLabel + "+" + (addOilTimeNum + 2);
                            oilEndTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addOilTimeNum + 2)));
                            missileStartTimeLabel = firstCabelLabel + "+" + "2";;
                            missileStartTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, 2));
                            missileEndTimeLabel = firstCabelLabel + "+" + (addMissileTimeNum + 2);
                            missileEndTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addMissileTimeNum + 2)));
                            if(addOilTimeNum > addMissileTimeNum){
                                supplyEndTimeLabel = firstCabelLabel + "+" + (addOilTimeNum + 2 + 1);
                                supplyEndTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addOilTimeNum + 2 + 1)));
                                dsTaskDetail.setETIME(DateUtils.addHours(format.parse(t1Time), addOilTimeNum + 2 + 1));
                            }else{
                                supplyEndTimeLabel = firstCabelLabel + "+" + (addMissileTimeNum + 2 + 1);
                                supplyEndTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addMissileTimeNum + 2 + 1)));
                                dsTaskDetail.setETIME(DateUtils.addHours(format.parse(t1Time), addMissileTimeNum + 2 + 1));
                            }
 
                            dsTaskDetail.setOilStime(2);
                            dsTaskDetail.setOilEtime(2 + addOilTimeNum);
                            dsTaskDetail.setAmmoStime(2);
                            dsTaskDetail.setAmmoEtime(2 + addMissileTimeNum);
                        }else if("2".equals(tempDsTaskList.getSupplySeq())){//先油后弹
                            oilStartTimeLabel = firstCabelLabel + "+" + "2";
                            oilEndTimeLabel = firstCabelLabel + "+" + (addOilTimeNum + 2);
                            missileStartTimeLabel = firstCabelLabel + "+" + (addOilTimeNum + 2);
                            missileEndTimeLabel = firstCabelLabel + "+" + (addOilTimeNum + 2 + addMissileTimeNum);
                            supplyEndTimeLabel = firstCabelLabel + "+" + (addOilTimeNum + 2 + addMissileTimeNum + 1);
                            oilStartTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, 2));
                            oilEndTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addOilTimeNum + 2)));
                            missileStartTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addOilTimeNum + 2)));
                            missileEndTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addOilTimeNum + 2 + addMissileTimeNum)));
                            supplyEndTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addOilTimeNum + 2 + addMissileTimeNum + 1)));
 
                            dsTaskDetail.setOilStime(2);
                            dsTaskDetail.setOilEtime(2+ addOilTimeNum);
                            dsTaskDetail.setAmmoStime(addOilTimeNum + 2 + 1);
                            dsTaskDetail.setAmmoEtime(addOilTimeNum + 2 + 1 + addMissileTimeNum);
                            dsTaskDetail.setETIME(DateUtils.addHours(format.parse(t1Time), addOilTimeNum + 2 + addMissileTimeNum + 1));
                        }else if("3".equals(tempDsTaskList.getSupplySeq())){//先弹后油
                            missileStartTimeLabel = firstCabelLabel + "+2";
                            missileEndTimeLabel = firstCabelLabel + "+" + (addMissileTimeNum + 2);
                            oilStartTimeLabel = firstCabelLabel + "+" + (addMissileTimeNum + 2);
                            oilEndTimeLabel = firstCabelLabel + "+" + (addMissileTimeNum + 2 + addOilTimeNum);
                            supplyEndTimeLabel = firstCabelLabel + "+" + (addMissileTimeNum + 2 + addOilTimeNum + 1);
                            oilStartTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addMissileTimeNum + 2)));
                            oilEndTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addMissileTimeNum + 2 + addOilTimeNum)));
                            missileStartTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, 2));
                            missileEndTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addMissileTimeNum + 2)));
                            supplyEndTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addMissileTimeNum + 2 + addOilTimeNum + 1)));
 
                            dsTaskDetail.setOilStime(addMissileTimeNum + 2 + 1);
                            dsTaskDetail.setOilEtime(addMissileTimeNum + 2 + 1 + addOilTimeNum);
                            dsTaskDetail.setAmmoStime(2);
                            dsTaskDetail.setAmmoEtime(addMissileTimeNum + 2);
                            dsTaskDetail.setETIME(DateUtils.addHours(format.parse(t1Time), addMissileTimeNum + 2 + addOilTimeNum + 1));
                        }
                        oilTotalTime += addOilTimeNum;
                        missileTotalTime += addMissileTimeNum;
 
                        if(addOilTimeNum >= addMissileTimeNum){
                            andianTotalTime += addOilTimeNum;
                        } else {
                            andianTotalTime += addMissileTimeNum;
                        }
 
                        // 物资补给时间Label
                        String goodsStartTimeLabel = "";
                        String goodsStartTimeLabelDate = "";
                        String goodsEndTimeLabel = "";
                        String goodsEndTimeLabelDate = "";
                        Long food = tempDsTaskList.getFOOD() == null? 0 : tempDsTaskList.getFOOD();
                        Long foodW = tempDsTaskList.getFoodW() == null? 0 : tempDsTaskList.getFoodW();
                        Long foodO = tempDsTaskList.getFoodO() == null? 0 : tempDsTaskList.getFoodO();
                        double totalGoodsNum = food + foodW + foodO; // 总加物资量
                        int addGoodTimeNum = calcSupplyTimeBySupplyType(GOODS_SUPPLY_TYPE, shipType, totalGoodsNum);
                        goodsStartTimeLabel = firstCabelLabel + "+2";
                        goodsStartTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, 2));
                        goodsEndTimeLabel = firstCabelLabel + "+" + (addGoodTimeNum + 2);
                        goodsEndTimeLabelDate = format.format(addHoursToDate(firstCabelLabelDate, (addGoodTimeNum + 2)));
                        goodsTotalTime += addGoodTimeNum;
 
                        // 构建每艘舰船构建JSON对象
                        jsonObj.put("id", String.valueOf(j+1));
                        jsonObj.put("shipType", shipType);
                        jsonObj.put("shipNo", shipNo);
                        jsonObj.put("supplySeq", supplySeqLabel);
                        jsonObj.put("sTime", firstCabelLabelDate);
                        jsonObj.put("electSTime", andianStartTimeLabelDate);
                        jsonObj.put("waterSTime", waterStartTimeLabelDate);
                        jsonObj.put("waterETime", waterEndTimeLabelDate);
                        jsonObj.put("oilSTime", oilStartTimeLabelDate);
                        jsonObj.put("oilETime", oilEndTimeLabelDate);
                        jsonObj.put("ammoSTime", missileStartTimeLabelDate);
                        jsonObj.put("ammoETime", missileEndTimeLabelDate);
                        jsonObj.put("matSTime", goodsStartTimeLabelDate);
                        jsonObj.put("matETime", goodsEndTimeLabelDate);
                        jsonObj.put("supplyETime", supplyEndTimeLabelDate);
                        subJSONArray.add(jsonObj);
                        sub1JsonObj.put("subData", subJSONArray);
 
                        // 更新船舶补给计划数据
                        dsTaskDetail.setTaskId(taskId);
                        dsTaskDetail.setHarborId(tempDsTaskList.getHarborId());
                        dsTaskDetail.setHarborName(tempDsTaskList.getHarborName());
                        dsTaskDetail.setBerthId(Long.parseLong(berthIdArray[i]));
                        dsTaskDetail.setBerthName(tempDsTaskList.getBerthName());
                        dsTaskDetail.setParkingType(tempDsTaskList.getParkingType());
                        dsTaskDetail.setShipNo(tempDsTaskList.getShipNo());
                        dsTaskDetail.setShipType(tempDsTaskList.getShipType());
                        dsTaskDetail.setSTIME(format.parse(t1Time));
                        dsTaskDetail.setElecStime(1);
                        dsTaskDetail.setWaterStime(1);
                        dsTaskDetail.setWaterEtime(addWaterTimeNum);
                        dsTaskDetail.setMatStime(2);
                        dsTaskDetail.setMatEtime(addGoodTimeNum + 2);
                        dsTaskDetail.setOilTime(addOilTimeNum);
                        dsTaskDetail.setAmmoTime(addMissileTimeNum);
                        dsTaskDetail.setMatTime(addGoodTimeNum);
                        dsTaskDetail.setWaterTime(addWaterTimeNum);
                        dsTaskDetail.setT1(format.parse(t1Time));
                        dsTaskDetail.setSupplySeq(tempDsTaskList.getSupplySeq());
                        dsTaskDetail.setCarCount((int) totalGoodsNum);
                        dsTaskDetail.setFood((double) food);
                        dsTaskDetail.setFoodW((double) foodW);
                        dsTaskDetail.setFoodO((double) foodO);
 
                        // 根据taskId和shipNo和shipType判断是否存在船舶补给计划数据
                        DsTaskDetail tempDsTaskDetail = new DsTaskDetail();
                        tempDsTaskDetail.setTaskId(taskId);
                        tempDsTaskDetail.setShipNo(shipNo);
                        tempDsTaskDetail.setShipType(shipType);
                        List<DsTaskDetail> dsTaskDetails = dsTaskDetailService.selectDsTaskDetailList(tempDsTaskDetail);
                        if (dsTaskDetails == null && dsTaskDetails.size() > 0) {
                            dsTaskDetail.setPKID(dsTaskDetails.get(0).getPKID());
                            dsTaskDetailService.updateDsTaskDetail(dsTaskDetail);
                        } else {
                            dsTaskDetailService.insertDsTaskDetail(dsTaskDetail);
                        }
                    }
                    jsonArray.add(sub1JsonObj);
                    rootJSONObj.put("berthDatas", jsonArray);
                    rootJSONObj.put("totalJiedianTime", andianTotalTime);
                    rootJSONObj.put("totalWaterTime", waterTotalTime);
                    rootJSONObj.put("totalOilTime", oilTotalTime);
                    rootJSONObj.put("totalAmmoTime", missileTotalTime);
                    rootJSONObj.put("totalMatTime", goodsTotalTime);
                    rootJSONArray.add(rootJSONObj);
                }
            }
        }
        return AjaxResult.success(rootJSONArray);
    }
 
    /**
     * 根据补给需求量,计算各种补剂所需时间。
     * @param supplyType
     * @param shipType
     * @param supplyTotalNum
     * @return 整小时
     */
    private int calcSupplyTimeBySupplyType(String supplyType, String shipType, double supplyTotalNum) {
        if (OIL_SUPPLY_TYPE.equals(supplyType)) {//补给油料
            for (int i = 0; i < SHIP_TYPE.length; i++) {
                if (shipType.equals(SHIP_TYPE[i])) {
                    return (int) Math.ceil(supplyTotalNum / OIL_UNIT_NUM * OIL_USE_TIME[i]);
                }
            }
        } else if (MISSILE_SUPPLY_TYPE.equals(supplyType)) {//补给DY
            for (int i = 0; i < SHIP_TYPE.length; i++) {
                if (shipType.equals(SHIP_TYPE[i])) {
                    return (int) Math.ceil(supplyTotalNum / MISSILE_UNIT_NUM * MISSILE_USE_TIME[i]);
                }
            }
        } else if (GOODS_SUPPLY_TYPE.equals(supplyType)) {//补给物资
            for (int i = 0; i < SHIP_TYPE.length; i++) {
                if (shipType.equals(SHIP_TYPE[i])) {
                    return (int) Math.ceil(supplyTotalNum / GOODS_UNIT_NUM * GOODS_USE_TIME[i]);
                }
            }
        } else if (WATER_SUPPLY_TYPE.equals(supplyType)) {//补给淡水
            for (int i = 0; i < SHIP_TYPE.length; i++) {
                if (shipType.equals(SHIP_TYPE[i])) {
                    return (int) Math.ceil(supplyTotalNum / WATER_UNIT_NUM * WATER_USE_TIME[i]);
                }
            }
        }
        return 0;
    }
 
    @Operation(description = "修改舰船补给顺序")
    @Log(title = "修改舰船补给顺序", businessType = BusinessType.INSERT)
    @PostMapping("/changeSupplySeq")
    @ResponseBody
    public AjaxResult changeSupplySeqById(Long taskId, String shipNo, String supplySeq) throws IOException, ParseException {
        // 更新DsTaskList2中的SupplySeq值
        DsTaskList2 dsTaskList2 = new DsTaskList2();
        dsTaskList2.setTaskId(taskId);
        dsTaskList2.setShipNo(shipNo);
        List<DsTaskList2> dsTaskLists = dsTaskListService.selectDsTaskListList(dsTaskList2);
        int result1 = -1;
        if(dsTaskLists != null && dsTaskLists.size() >0){
            dsTaskList2.setPKID(dsTaskLists.get(0).getPKID());
            dsTaskList2.setSupplySeq(supplySeq);
            result1 = dsTaskListService.updateDsTaskList(dsTaskList2);
            log.debug("更新DsTaskList表中的SupplySeq字段结果 =====: " + result1);
        }
        // 更新DsTaskDetail中的SupplySeq值
        DsTaskDetail dsTaskDetail = new DsTaskDetail();
        dsTaskDetail.setTaskId(taskId);
        dsTaskDetail.setShipNo(shipNo);
        List<DsTaskDetail> dsTaskDetails = dsTaskDetailService.selectDsTaskDetailList(dsTaskDetail);
        int result2 = -1;
        if(dsTaskDetails != null && dsTaskDetails.size() >0){
            dsTaskDetail.setPKID(dsTaskDetails.get(0).getPKID());
            dsTaskDetail.setSupplySeq(supplySeq);
            result2 = dsTaskDetailService.updateDsTaskDetail(dsTaskDetail);
            log.debug("更新DsTaskDetail表中的SupplySeq字段结果 =====: " + result2);
        }
        if (result2 >= 0 && result2 >= 0) {
            return AjaxResult.success("补给顺序修改成功");
        } else {
            return AjaxResult.error(-1, "补给顺序修改失败");
        }
    }
 
    /**
     * 在指定的日期(字符串)上增加指定的小时数。
     * @param dateStr
     * @param hours
     * @return
     * @throws ParseException
     */
    private Date addHoursToDate(String dateStr, int hours) throws ParseException {
        // 将输入的日期字符串解析为 Date 对象
        Date date = format.parse(dateStr);
        // 创建 Calendar 实例并设置日期
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 增加指定的小时数
        calendar.add(Calendar.HOUR_OF_DAY, hours);
        // 获取增加小时数后的 Date 对象
        return calendar.getTime();
    }
}