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
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<DsTaskDetail> 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<DsTaskDetail> 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<DsTaskDetail> 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<DsTaskDetail> detailList =  dsTaskDetailService.selectAQCurTaskDetailList(deptId);
 
        List<DsTaskDetailVO> 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<DsTaskDetail> 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<TaskPlace> covertToPlaceType(List<DsTaskDetail> list){
        List<TaskPlace> taskPlaces = new ArrayList<>();
 
        Map<Long, List<DsTaskDetail>> 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<Long, List<DsTaskDetail>> entry : groupedByBerthId.entrySet()) {
            Long berthId = entry.getKey();
            List<DsTaskDetail> 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<TaskPlanStatis> covertToStatis(List<DsTaskDetail> list){
        Map<Long, List<DsTaskDetail>> 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<TaskPlanStatis> result = new ArrayList<>();
        for (Map.Entry<Long, List<DsTaskDetail>> entry : groupedByBerthId.entrySet()) {
            List<DsTaskDetail> 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<TaskPlanStatisTime> covertToStatisTime(List<DsTaskDetail> list){
        Map<Long, List<DsTaskDetailVO>> 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<TaskPlanStatisTime> result = new ArrayList<>();
        for (Map.Entry<Long, List<DsTaskDetailVO>> entry : groupedByBerthId.entrySet()) {
            List<DsTaskDetailVO> 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));
    }
 
}