|
|
@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -21,15 +22,14 @@ public class DeviceMaintenanceController {
|
|
|
@Resource
|
|
|
private DeviceMaintenanceReminderMapper mapper;
|
|
|
|
|
|
- /**
|
|
|
- * 查询当前用户/家庭的待办提醒:仅 pending 且今天已进入窗口(含逾期)。
|
|
|
- * 测试直接传 userId/familyId/today;生产入口由重载方法从请求上下文取。
|
|
|
- */
|
|
|
+ /** 查询当前用户/家庭的待办提醒:仅 pending 且今天已进入窗口(含逾期)。 */
|
|
|
public Result<?> list(Long userId, Long familyId, LocalDate today) {
|
|
|
+ // 双 null 不加 where 会泄露全表 → 直接返回空(与 K8RecommendationService.activeReminders 对齐)
|
|
|
+ if (userId == null && familyId == null) return Result.success(Collections.emptyList());
|
|
|
LambdaQueryWrapper<DeviceMaintenanceReminder> qw = new LambdaQueryWrapper<>();
|
|
|
qw.eq(DeviceMaintenanceReminder::getStatus, "pending");
|
|
|
if (familyId != null) qw.eq(DeviceMaintenanceReminder::getFamilyId, familyId);
|
|
|
- else if (userId != null) qw.eq(DeviceMaintenanceReminder::getBuyerId, userId);
|
|
|
+ else qw.eq(DeviceMaintenanceReminder::getBuyerId, userId);
|
|
|
List<DeviceMaintenanceReminder> all = mapper.selectList(qw);
|
|
|
LocalDate now = today != null ? today : LocalDate.now();
|
|
|
List<DeviceMaintenanceReminder> result = all.stream()
|
|
|
@@ -39,15 +39,39 @@ public class DeviceMaintenanceController {
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
|
- /** HTTP 入口:从请求上下文取 familyId/userId,今天取系统日期。 */
|
|
|
@PostMapping("/list")
|
|
|
- public Result<?> listHttp(@RequestAttribute(value = "familyId", required = false) Long familyId,
|
|
|
- @RequestAttribute(value = "userId", required = false) Long userId) {
|
|
|
+ public Result<?> listHttp(@RequestAttribute(value = "userId", required = false) Long userId,
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId) {
|
|
|
return list(userId, familyId, LocalDate.now());
|
|
|
}
|
|
|
|
|
|
- /** 更新提醒状态为 done/dismissed。 */
|
|
|
+ /** 后端管理员全量查询(需 admin 角色)。 */
|
|
|
+ public Result<?> adminList(String role) {
|
|
|
+ if (!"admin".equals(role)) return Result.error(403, "无权限");
|
|
|
+ return Result.success(mapper.selectList(null));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/admin/list")
|
|
|
+ public Result<?> adminListHttp(@RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ return adminList(role);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 更新提醒状态:校验归属 + status 白名单。 */
|
|
|
+ public Result<?> updateStatus(Long id, String status, Long userId, Long familyId) {
|
|
|
+ if (!"done".equals(status) && !"dismissed".equals(status)) return Result.error("status 非法");
|
|
|
+ DeviceMaintenanceReminder r = mapper.selectById(id);
|
|
|
+ if (r == null) return Result.error("提醒不存在");
|
|
|
+ boolean owner = (familyId != null && familyId.equals(r.getFamilyId()))
|
|
|
+ || (userId != null && userId.equals(r.getBuyerId()));
|
|
|
+ if (!owner) return Result.error(403, "无权操作他人提醒");
|
|
|
+ r.setStatus(status);
|
|
|
+ mapper.updateById(r);
|
|
|
+ return Result.success(r);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 测试/内部用的无归属校验重载(单测直构兼容),生产 HTTP 入口走带归属校验版本。 */
|
|
|
public Result<?> updateStatus(Long id, String status) {
|
|
|
+ if (!"done".equals(status) && !"dismissed".equals(status)) return Result.error("status 非法");
|
|
|
DeviceMaintenanceReminder r = mapper.selectById(id);
|
|
|
if (r == null) return Result.error("提醒不存在");
|
|
|
r.setStatus(status);
|
|
|
@@ -56,14 +80,10 @@ public class DeviceMaintenanceController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("/{id}/status")
|
|
|
- public Result<?> updateStatusHttp(@PathVariable Long id, @RequestBody java.util.Map<String, Object> body) {
|
|
|
+ public Result<?> updateStatusHttp(@PathVariable Long id, @RequestBody java.util.Map<String, Object> body,
|
|
|
+ @RequestAttribute(value = "userId", required = false) Long userId,
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId) {
|
|
|
Object s = body.get("status");
|
|
|
- return updateStatus(id, s == null ? "done" : String.valueOf(s));
|
|
|
- }
|
|
|
-
|
|
|
- /** 后台全量查询(分页沿用现有约定,此处返回全量 pending+已完成)。 */
|
|
|
- @PostMapping("/admin/list")
|
|
|
- public Result<?> adminList() {
|
|
|
- return Result.success(mapper.selectList(null));
|
|
|
+ return updateStatus(id, s == null ? "done" : String.valueOf(s), userId, familyId);
|
|
|
}
|
|
|
}
|