|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+package com.water.dispatch.service;
|
|
|
2
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
3
|
+import com.water.dispatch.entity.*;
|
|
|
4
|
+import com.water.dispatch.mapper.*;
|
|
|
5
|
+import lombok.RequiredArgsConstructor;
|
|
|
6
|
+import org.springframework.stereotype.Service;
|
|
|
7
|
+import java.time.*; import java.util.*;
|
|
|
8
|
+@Service @RequiredArgsConstructor
|
|
|
9
|
+public class DispatchBizService {
|
|
|
10
|
+ private final DutyScheduleMapper dutyMapper;
|
|
|
11
|
+ private final DispatchCommandMapper cmdMapper;
|
|
|
12
|
+ private final WorkOrderMapper woMapper;
|
|
|
13
|
+ private final DutyLogMapper logMapper;
|
|
|
14
|
+ private final DispatchStrategyMapper stratMapper;
|
|
|
15
|
+ private final EmergencyPlanMapper planMapper;
|
|
|
16
|
+
|
|
|
17
|
+ public List<DutySchedule> getTodayDuty() {
|
|
|
18
|
+ return dutyMapper.selectList(new LambdaQueryWrapper<DutySchedule>()
|
|
|
19
|
+ .eq(DutySchedule::getDutyDate, LocalDate.now()));
|
|
|
20
|
+ }
|
|
|
21
|
+ public Map<String,Object> createCommand(Map<String,Object> req) {
|
|
|
22
|
+ DispatchCommand c = new DispatchCommand();
|
|
|
23
|
+ c.setCmdNo("CMD-" + System.currentTimeMillis());
|
|
|
24
|
+ c.setTitle((String)req.get("title")); c.setContent((String)req.get("content"));
|
|
|
25
|
+ c.setType((String)req.getOrDefault("type","常规")); c.setStatus(0);
|
|
|
26
|
+ cmdMapper.insert(c);
|
|
|
27
|
+ return Map.of("id",c.getId(),"cmdNo",c.getCmdNo());
|
|
|
28
|
+ }
|
|
|
29
|
+ public Map<String,Object> issueCommand(String cmdNo) {
|
|
|
30
|
+ DispatchCommand c = cmdMapper.selectOne(new LambdaQueryWrapper<DispatchCommand>()
|
|
|
31
|
+ .eq(DispatchCommand::getCmdNo, cmdNo));
|
|
|
32
|
+ if(c==null) throw new RuntimeException("指令不存在");
|
|
|
33
|
+ c.setStatus(1); c.setIssuedTime(LocalDateTime.now());
|
|
|
34
|
+ cmdMapper.updateById(c);
|
|
|
35
|
+ return Map.of("cmdNo",cmdNo,"status",1);
|
|
|
36
|
+ }
|
|
|
37
|
+ public List<DispatchCommand> listCommands(Integer status) {
|
|
|
38
|
+ return cmdMapper.selectList(new LambdaQueryWrapper<DispatchCommand>()
|
|
|
39
|
+ .eq(status!=null, DispatchCommand::getStatus, status));
|
|
|
40
|
+ }
|
|
|
41
|
+ public Map<String,Object> createWorkOrder(Map<String,Object> req) {
|
|
|
42
|
+ WorkOrder w = new WorkOrder();
|
|
|
43
|
+ w.setOrderNo("WO-" + System.currentTimeMillis());
|
|
|
44
|
+ w.setTitle((String)req.get("title")); w.setDescription((String)req.get("description"));
|
|
|
45
|
+ w.setType((String)req.getOrDefault("type","维修")); w.setStatus(0);
|
|
|
46
|
+ w.setPriority((String)req.getOrDefault("priority","中"));
|
|
|
47
|
+ woMapper.insert(w);
|
|
|
48
|
+ return Map.of("id",w.getId(),"orderNo",w.getOrderNo());
|
|
|
49
|
+ }
|
|
|
50
|
+ public Map<String,Object> updateWorkOrderStatus(Long id, int status) {
|
|
|
51
|
+ WorkOrder w = woMapper.selectById(id);
|
|
|
52
|
+ if(w==null) throw new RuntimeException("工单不存在");
|
|
|
53
|
+ w.setStatus(status);
|
|
|
54
|
+ if(status==2) w.setCompletedAt(LocalDateTime.now());
|
|
|
55
|
+ woMapper.updateById(w);
|
|
|
56
|
+ return Map.of("id",id,"status",status);
|
|
|
57
|
+ }
|
|
|
58
|
+ public void addDutyLog(Long scheduleId, Long userId, String type, String content) {
|
|
|
59
|
+ DutyLog l = new DutyLog();
|
|
|
60
|
+ l.setScheduleId(scheduleId); l.setUserId(userId);
|
|
|
61
|
+ l.setLogType(type); l.setContent(content);
|
|
|
62
|
+ logMapper.insert(l);
|
|
|
63
|
+ }
|
|
|
64
|
+ public List<DutyLog> getDutyLogs(Long scheduleId) {
|
|
|
65
|
+ return logMapper.selectList(new LambdaQueryWrapper<DutyLog>()
|
|
|
66
|
+ .eq(DutyLog::getScheduleId, scheduleId));
|
|
|
67
|
+ }
|
|
|
68
|
+ public List<DispatchStrategy> listStrategies(String type) {
|
|
|
69
|
+ return stratMapper.selectList(new LambdaQueryWrapper<DispatchStrategy>()
|
|
|
70
|
+ .eq(type!=null, DispatchStrategy::getType, type));
|
|
|
71
|
+ }
|
|
|
72
|
+ public List<EmergencyPlan> listPlans(String type) {
|
|
|
73
|
+ return planMapper.selectList(new LambdaQueryWrapper<EmergencyPlan>()
|
|
|
74
|
+ .eq(type!=null, EmergencyPlan::getType, type));
|
|
|
75
|
+ }
|
|
|
76
|
+ public Map<String,Object> simulateEmergency(String type, double lng, double lat) {
|
|
|
77
|
+ return Map.of("type",type,"lng",lng,"lat",lat,
|
|
|
78
|
+ "affectedArea","半径500米","affectedUsers",120,
|
|
|
79
|
+ "estimatedDuration","4小时");
|
|
|
80
|
+ }
|
|
|
81
|
+}
|