|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+package com.water.mobile.service;
|
|
|
2
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
3
|
+import com.water.mobile.entity.*;
|
|
|
4
|
+import com.water.mobile.mapper.*;
|
|
|
5
|
+import lombok.RequiredArgsConstructor;
|
|
|
6
|
+import org.springframework.stereotype.Service;
|
|
|
7
|
+import java.util.*;
|
|
|
8
|
+@Service @RequiredArgsConstructor
|
|
|
9
|
+public class MobileApiService {
|
|
|
10
|
+ private final MobileUserMapper userMapper;
|
|
|
11
|
+ private final PushNotificationMapper pushMapper;
|
|
|
12
|
+ private final AppVersionMapper verMapper;
|
|
|
13
|
+
|
|
|
14
|
+ public Map<String,Object> login(String username, String password, String appModule) {
|
|
|
15
|
+ MobileUser u = userMapper.selectOne(new LambdaQueryWrapper<MobileUser>()
|
|
|
16
|
+ .eq(MobileUser::getUsername, username)
|
|
|
17
|
+ .eq(MobileUser::getAppModule, appModule));
|
|
|
18
|
+ if (u == null || !u.getPassword().equals(password)) throw new RuntimeException("登录失败");
|
|
|
19
|
+ return Map.of("userId", u.getId(), "realName", u.getRealName(),
|
|
|
20
|
+ "appModule", u.getAppModule(), "token", "mock-token-" + u.getId());
|
|
|
21
|
+ }
|
|
|
22
|
+ // 供水API聚合
|
|
|
23
|
+ public Map<String,Object> getWaterOverview() {
|
|
|
24
|
+ return Map.of("todaySupply", 12500.0, "yesterdaySupply", 11800.0,
|
|
|
25
|
+ "waterQuality", "合格", "alertCount", 3, "deviceOnlineRate", 0.95);
|
|
|
26
|
+ }
|
|
|
27
|
+ // 巡检API聚合
|
|
|
28
|
+ public List<Map<String,Object>> getPatrolTasks(Long userId) {
|
|
|
29
|
+ return List.of(
|
|
|
30
|
+ Map.of("id", 1L, "taskName", "主管网巡检A线", "status", "待执行", "deadline", "今日18:00"),
|
|
|
31
|
+ Map.of("id", 2L, "taskName", "消防栓检查-区域B", "status", "进行中", "deadline", "今日17:00")
|
|
|
32
|
+ );
|
|
|
33
|
+ }
|
|
|
34
|
+ // 收费API聚合
|
|
|
35
|
+ public Map<String,Object> getBillingSummary(Long userId) {
|
|
|
36
|
+ return Map.of("unpaidCount", 2, "totalAmount", 156.80,
|
|
|
37
|
+ "recentBills", List.of(
|
|
|
38
|
+ Map.of("period", "2025-01", "amount", 78.40, "status", "未缴费"),
|
|
|
39
|
+ Map.of("period", "2024-12", "amount", 82.50, "status", "已缴费")
|
|
|
40
|
+ ));
|
|
|
41
|
+ }
|
|
|
42
|
+ // 消息通知
|
|
|
43
|
+ public List<PushNotification> getNotifications(Long userId, Boolean unreadOnly) {
|
|
|
44
|
+ LambdaQueryWrapper<PushNotification> w = new LambdaQueryWrapper<PushNotification>()
|
|
|
45
|
+ .eq(PushNotification::getUserId, userId);
|
|
|
46
|
+ if (Boolean.TRUE.equals(unreadOnly)) w.eq(PushNotification::getIsRead, 0);
|
|
|
47
|
+ return pushMapper.selectList(w.orderByDesc(PushNotification::getCreatedTime));
|
|
|
48
|
+ }
|
|
|
49
|
+ public void markRead(Long notificationId) {
|
|
|
50
|
+ PushNotification n = pushMapper.selectById(notificationId);
|
|
|
51
|
+ if (n != null) { n.setIsRead(1); pushMapper.updateById(n); }
|
|
|
52
|
+ }
|
|
|
53
|
+ public Long sendNotification(Long userId, String title, String content, String type, String appModule) {
|
|
|
54
|
+ PushNotification n = new PushNotification();
|
|
|
55
|
+ n.setUserId(userId); n.setTitle(title); n.setContent(content);
|
|
|
56
|
+ n.setType(type); n.setAppModule(appModule); n.setIsRead(0);
|
|
|
57
|
+ pushMapper.insert(n);
|
|
|
58
|
+ return n.getId();
|
|
|
59
|
+ }
|
|
|
60
|
+ // 版本检查
|
|
|
61
|
+ public Map<String,Object> checkUpdate(String appModule, String currentVersion) {
|
|
|
62
|
+ AppVersion v = verMapper.selectOne(new LambdaQueryWrapper<AppVersion>()
|
|
|
63
|
+ .eq(AppVersion::getAppModule, appModule)
|
|
|
64
|
+ .eq(AppVersion::getStatus, 1)
|
|
|
65
|
+ .orderByDesc(AppVersion::getCreatedTime).last("LIMIT 1"));
|
|
|
66
|
+ if (v == null || v.getVersionNo().equals(currentVersion))
|
|
|
67
|
+ return Map.of("hasUpdate", false);
|
|
|
68
|
+ return Map.of("hasUpdate", true, "versionNo", v.getVersionNo(),
|
|
|
69
|
+ "downloadUrl", v.getDownloadUrl(), "changelog", v.getChangelog(),
|
|
|
70
|
+ "forceUpdate", v.getForceUpdate() == 1);
|
|
|
71
|
+ }
|
|
|
72
|
+}
|