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 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 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 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 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 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 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(); } }