|
|
@@ -494,4 +494,75 @@ public class ButlerService {
|
|
|
summary.put("description", bp != null ? bp.getDescription() : "");
|
|
|
return summary;
|
|
|
}
|
|
|
+
|
|
|
+ // ==================== 管理端分配管理 ====================
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分配关系分页列表
|
|
|
+ */
|
|
|
+ public Result<Map<String, Object>> listAssignments(Integer pageNum, Integer pageSize) {
|
|
|
+ int pn = pageNum == null || pageNum < 1 ? 1 : pageNum;
|
|
|
+ int ps = pageSize == null || pageSize < 1 ? 10 : Math.min(pageSize, 100);
|
|
|
+ Page<ButlerAssignment> page = butlerAssignmentMapper.selectPage(new Page<>(pn, ps),
|
|
|
+ new LambdaQueryWrapper<ButlerAssignment>()
|
|
|
+ .orderByDesc(ButlerAssignment::getAssignedAt));
|
|
|
+
|
|
|
+ List<Map<String, Object>> rows = new java.util.ArrayList<>();
|
|
|
+ for (ButlerAssignment a : page.getRecords()) {
|
|
|
+ Map<String, Object> row = new HashMap<>();
|
|
|
+ row.put("id", a.getId());
|
|
|
+ row.put("familyId", a.getFamilyId());
|
|
|
+ row.put("butlerUserId", a.getButlerUserId());
|
|
|
+ row.put("level", a.getLevel());
|
|
|
+ row.put("assignedAt", a.getAssignedAt());
|
|
|
+ User bu = userMapper.selectById(a.getButlerUserId());
|
|
|
+ row.put("butlerNickname", bu != null ? bu.getNickname() : "");
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("total", page.getTotal());
|
|
|
+ data.put("records", rows);
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 强制解绑(物理删除分配行 + 回退管家计数)
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Result<Void> unassign(Long assignmentId) {
|
|
|
+ ButlerAssignment assignment = butlerAssignmentMapper.selectById(assignmentId);
|
|
|
+ if (assignment == null) {
|
|
|
+ return Result.error("分配记录不存在");
|
|
|
+ }
|
|
|
+ butlerAssignmentMapper.deleteById(assignmentId);
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<ButlerProfile> decr = new LambdaUpdateWrapper<>();
|
|
|
+ decr.eq(ButlerProfile::getUserId, assignment.getButlerUserId())
|
|
|
+ .setSql("member_count = GREATEST(member_count - 1, 0)");
|
|
|
+ butlerProfileMapper.update(null, decr);
|
|
|
+
|
|
|
+ log.info("Admin unassigned assignmentId={}, family={}, butler={}",
|
|
|
+ assignmentId, assignment.getFamilyId(), assignment.getButlerUserId());
|
|
|
+ return Result.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 管家停接/恢复接单开关(不影响存量绑定)
|
|
|
+ */
|
|
|
+ public Result<Void> toggleAccepting(Long butlerUserId, Integer accepting) {
|
|
|
+ if (accepting == null || (accepting != 0 && accepting != 1)) {
|
|
|
+ return Result.error("accepting 取值只能为 0 或 1");
|
|
|
+ }
|
|
|
+ ButlerProfile profile = butlerProfileMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<ButlerProfile>()
|
|
|
+ .eq(ButlerProfile::getUserId, butlerUserId)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (profile == null) {
|
|
|
+ return Result.error("管家不存在");
|
|
|
+ }
|
|
|
+ profile.setAccepting(accepting);
|
|
|
+ profile.setUpdatedAt(new Date());
|
|
|
+ butlerProfileMapper.updateById(profile);
|
|
|
+ return Result.success(null);
|
|
|
+ }
|
|
|
}
|