package com.ruoyi.buss.controller; import com.ruoyi.buss.domain.DsTaskDetail; import com.ruoyi.buss.domain.DsTaskList2; import com.ruoyi.buss.domain.vo.*; import com.ruoyi.buss.service.IDsTaskDetailService; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.StringUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.text.DecimalFormat; import java.util.*; @Tag(name = "岸情任务接口") @RestController @RequestMapping("/buss/task/aq") public class DMTaskAQController extends BaseController { private Double OIL_PLACE_PER = 0.3; private Double MAT_PLACE_PER = 0.2; private Double AMMO_PLACE_PER = 0.5; private Double TOTAL_PLACE_PER = 1.5; DecimalFormat decimalFormat = new DecimalFormat("#.##"); @Autowired private IDsTaskDetailService dsTaskDetailService; @Operation(summary = "获取岸情当前任务列表") @GetMapping("/plan/list/statis") @ResponseBody public AjaxResult listPlan(@Parameter(name = "deptId", description = "部门编码") Long deptId) { if(null == deptId)deptId = getDeptId(); // 状态为2 并且 List detailList = dsTaskDetailService.selectAQCurTaskDetailList(deptId); if(null != detailList){ return success(covertToStatis(detailList)); } return error("获取任务列表失败,请重试"); } @Operation(summary = "获取岸情当前任务列表TIME") @GetMapping("/plan/list/statis/time") @ResponseBody public AjaxResult listPlanTime(@Parameter(name = "deptId", description = "部门编码") Long deptId) { if(null == deptId)deptId = getDeptId(); // 状态为2 并且 List detailList = dsTaskDetailService.selectAQCurTaskDetailList(deptId); if(null != detailList){ return success(covertToStatisTime(detailList)); } return error("获取任务列表失败,请重试"); } @Operation(summary = "所有任务列表") @GetMapping("/plan/list") @ResponseBody public AjaxResult list(@Parameter(name = "deptId", description = "部门编码") Long deptId) { if(null == deptId)deptId = getDeptId(); // 状态为2 并且 List detailList = dsTaskDetailService.selectAQCurTaskDetailList(deptId); if(null != detailList){ return success(detailList); } return error("获取任务列表失败,请重试"); } @Operation(summary = "所有任务列表TIME") @GetMapping("/plan/list/time") @ResponseBody public AjaxResult listTime(@Parameter(name = "deptId", description = "部门编码") Long deptId) { if(null == deptId)deptId = getDeptId(); // 状态为2 并且 List detailList = dsTaskDetailService.selectAQCurTaskDetailList(deptId); List result = new ArrayList<>(); for(DsTaskDetail detail : detailList){ result.add(new DsTaskDetailVO(detail)); } if(null != result){ return success(result); } return error("获取任务列表失败,请重试"); } @Operation(summary = "获取场地统筹") @GetMapping("/place/list") @ResponseBody public AjaxResult getPlanList(@Parameter(name = "deptId", description = "部门编码") Long deptId) { if(null == deptId)deptId = getDeptId(); // 状态为2 并且 List detailList = dsTaskDetailService.selectAQCurTaskDetailList(deptId); if(null != detailList){ return success(covertToPlaceType(detailList)); } return error("获取任务列表失败,请重试"); } @Operation(summary = "修改场地作业小组") @PostMapping("/plan/edit/{id}") @ResponseBody public AjaxResult editPla(@Parameter(name = "id", required = true, description = "任务ID") @PathVariable("id") Long id, @Parameter(name = "workGrpId", required = true, description = "工作小组ID") Long workGrpId, @Parameter(name = "type", description = "工作小组类型,默认为1水电,2为物资") String type) { DsTaskDetail detail = dsTaskDetailService.selectDsTaskDetailByPKID(id); if(null != detail){ if(StringUtils.isNotBlank(type) && type.equals("2")){ detail.setWorkMatGrpId(workGrpId); } else{ detail.setWorkGrpId(workGrpId); } int flag = dsTaskDetailService.updateDsTaskDetail(detail); if(flag == 1){ return success("更新作业小组成功"); } return error("更新作业小组失败"); } return error("获取任务信息失败,请检查任务ID"); } @Operation(summary = "修改计划") @PostMapping("/plan/update") @ResponseBody public AjaxResult editPlanDetail(@RequestBody DsTaskDetail detail) { if(null != detail){ Long pkid = detail.getPKID(); if(null == pkid){ return error("对象ID不能为空"); } DsTaskDetail newDetail = dsTaskDetailService.selectDsTaskDetailByPKID(pkid); if(null == newDetail){ return error("未获取到对应的计划信息"); } if(null != detail.getMatStime())newDetail.setMatStime(detail.getMatStime()); if(null != detail.getMatEtime())newDetail.setMatEtime(detail.getMatEtime()); if(null != detail.getWaterStime())newDetail.setWaterStime(detail.getWaterStime()); if(null != detail.getWaterEtime())newDetail.setWaterEtime(detail.getWaterEtime()); if(null != detail.getOilStime())newDetail.setOilStime(detail.getOilStime()); if(null != detail.getOilEtime())newDetail.setOilEtime(detail.getOilEtime()); if(null != detail.getAmmoStime())newDetail.setAmmoStime(detail.getAmmoStime()); if(null != detail.getAmmoEtime())newDetail.setAmmoEtime(detail.getAmmoEtime()); if(null != detail.getWorkGrpId())newDetail.setWorkGrpId(detail.getWorkGrpId()); if(null != detail.getWorkMatGrpId())newDetail.setWorkMatGrpId(detail.getWorkMatGrpId()); int flag = dsTaskDetailService.updateDsTaskDetail(newDetail); if(flag == 1){ return success("更新计划任务成功"); } return error("更新计划任务失败"); } return error("获取任务信息失败,请检查任务ID"); } private List covertToPlaceType(List list){ List taskPlaces = new ArrayList<>(); Map> groupedByBerthId = new HashMap<>(); for (DsTaskDetail task : list) { Long berthId = task.getBerthId(); if (!groupedByBerthId.containsKey(berthId)) { groupedByBerthId.put(berthId, new ArrayList<>()); } groupedByBerthId.get(berthId).add(task); } for (Map.Entry> entry : groupedByBerthId.entrySet()) { Long berthId = entry.getKey(); List tasks = entry.getValue(); String berthName = tasks.get(0).getBerthName(); TaskPlace waterSupply = new TaskPlace(berthId, berthName, "水电补给"); TaskPlace oilSupply = new TaskPlace(berthId, berthName, "油料补给"); TaskPlace ammoSupply = new TaskPlace(berthId, berthName, "弹药补给"); TaskPlace materialSupply = new TaskPlace(berthId, berthName, "物资补给"); TaskPlace totalSupply = new TaskPlace(berthId, berthName, "合计占用"); // 分别计算不同种类的占用到不同时间字段,例如t1 代表时间1的占用,一直到t24 代表第24小时的占用情况, // waterSupply 使用 waterSTime 与 waterETime 字段, oilSupply使用 oilSTime 与oilETime 字段 // ammoSupply 使用 ammoSTime 与 ammoETime 字段, materialSupply 使用 matStime 与 matETime 字段 // 在当前dstaskdetail对象中,例如查看水电补给,需要查看 waterStime 字段代表开始时间,watereTime代表结束时间 // totalSupply 字段代表合计占用 需要把前面四种类型补给合并起来。 for (int i = 1; i <= 24; i++) { String timeSlot = "t" + i; int oilCount = 0; int ammoCount = 0; int matCount = 0; for (DsTaskDetail task : tasks) { if (task.getOilStime() != null && task.getOilStime() <= i && task.getOilEtime() >= i) { oilCount++; } else if (task.getAmmoStime() != null && task.getAmmoStime() <= i && task.getAmmoEtime() >= i) { ammoCount++; } else if (task.getMatStime() != null && task.getMatStime() <= i && task.getMatEtime() >= i) { matCount++; } } waterSupply.setTimeSlot(timeSlot, 0.0); oilSupply.setTimeSlot(timeSlot, Double.valueOf(decimalFormat.format(oilCount * OIL_PLACE_PER))); ammoSupply.setTimeSlot(timeSlot, Double.valueOf(decimalFormat.format(ammoCount * AMMO_PLACE_PER))); materialSupply.setTimeSlot(timeSlot, Double.valueOf(decimalFormat.format(matCount * MAT_PLACE_PER))); totalSupply.setTimeSlot(timeSlot, Double.valueOf(decimalFormat.format(oilCount * OIL_PLACE_PER + ammoCount * AMMO_PLACE_PER + matCount * MAT_PLACE_PER))); } taskPlaces.add(waterSupply); taskPlaces.add(oilSupply); taskPlaces.add(ammoSupply); taskPlaces.add(materialSupply); taskPlaces.add(totalSupply); } return taskPlaces; } private List covertToStatis(List list){ Map> groupedByBerthId = new HashMap<>(); for (DsTaskDetail task : list) { Long berthId = task.getBerthId(); if (!groupedByBerthId.containsKey(berthId)) { groupedByBerthId.put(berthId, new ArrayList<>()); } groupedByBerthId.get(berthId).add(task); } List result = new ArrayList<>(); for (Map.Entry> entry : groupedByBerthId.entrySet()) { List tasks = entry.getValue(); TaskPlanStatis statis = new TaskPlanStatis(); statis.setBerthName(tasks.get(0).getBerthName()); statis.setHarborName(tasks.get(0).getHarborName()); statis.setBerthStrategy(tasks.get(0).getParkingType()); statis.setShipInfo(tasks); result.add(statis); } return result; } private List covertToStatisTime(List list){ Map> groupedByBerthId = new HashMap<>(); for (DsTaskDetail task : list) { Long berthId = task.getBerthId(); if (!groupedByBerthId.containsKey(berthId)) { groupedByBerthId.put(berthId, new ArrayList<>()); } DsTaskDetailVO taskDetailVO = new DsTaskDetailVO(task); groupedByBerthId.get(berthId).add(taskDetailVO); } List result = new ArrayList<>(); for (Map.Entry> entry : groupedByBerthId.entrySet()) { List tasks = entry.getValue(); TaskPlanStatisTime statis = new TaskPlanStatisTime(); statis.setBerthName(tasks.get(0).getBerthName()); statis.setHarborName(tasks.get(0).getHarborName()); statis.setBerthStrategy(tasks.get(0).getParkingType()); statis.setShipInfo(tasks); result.add(statis); } return result; } public static void main(String[] args) { double value = 1.23456789 * 2.34567890; DecimalFormat df = new DecimalFormat("#.##"); // 设置格式为保留10位小数 String formattedValue = df.format(value); System.out.println(value); System.out.println(Double.valueOf(formattedValue)); } }