fix(platform): complete picker parity and message detail
Some checks failed
ci / build-test-parity (push) Has been cancelled
Some checks failed
ci / build-test-parity (push) Has been cancelled
This commit is contained in:
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
@@ -47,6 +48,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
* <ul>
|
||||
* <li>{@code GET /api/notice} — 当前用户消息分页列表,支持 unreadOnly 过滤</li>
|
||||
* <li>{@code GET /api/notice/unread-count} — 轻量未读数计数(顶栏轮询用)</li>
|
||||
* <li>{@code GET /api/notice/{id}/detail} — 已发送/可访问消息详情</li>
|
||||
* <li>{@code POST /api/notice/received/{id}/open} — 收到消息打开详情并置已读</li>
|
||||
* <li>{@code POST /api/notice/{id}/read} — 单条置已读</li>
|
||||
* <li>{@code POST /api/notice/read-all} — 当前用户全部已读</li>
|
||||
* </ul>
|
||||
@@ -119,6 +122,80 @@ public class NoticeController {
|
||||
return okList(items, total);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 消息详情
|
||||
|
||||
/**
|
||||
* 按 sys_message_id 加载消息详情。
|
||||
*
|
||||
* <p>用于「已发送消息」查看按钮,也允许当前用户作为收件人查看同一消息。访问守卫:
|
||||
* 当前用户是 createby,或当前用户在 sys_messageuser 中存在未删除收件记录。
|
||||
*/
|
||||
@Operation(summary = "消息详情(按 sys_message_id,只读)",
|
||||
description = "当前用户必须是发送人或收件人;返回 title/content/sender/receivers/document 等详情字段")
|
||||
@GetMapping("/api/notice/{id}/detail")
|
||||
public Map<String, Object> detail(
|
||||
@Parameter(description = "sys_message_id(36位)") @PathVariable String id) {
|
||||
|
||||
String userId = requireCurrentUserId();
|
||||
String sql = messageDetailSelect()
|
||||
+ " WHERE m.sys_message_id = CAST(? AS character(36))"
|
||||
+ " AND m.isdel = 0"
|
||||
+ " AND (m.createby = CAST(? AS character(36))"
|
||||
+ " OR EXISTS (SELECT 1 FROM eip3.sys_messageuser mu"
|
||||
+ " WHERE mu.sys_message_id = m.sys_message_id"
|
||||
+ " AND mu.sys_user_id = CAST(? AS character(36))"
|
||||
+ " AND mu.isdel = 0))";
|
||||
try {
|
||||
Map<String, Object> row = jdbcTemplate.queryForMap(sql, id.trim(), userId, userId);
|
||||
return okDetail(row, false, false);
|
||||
} catch (EmptyResultDataAccessException ex) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "消息不存在或无权查看");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 sys_messageuser_id 打开收到消息详情,并将当前用户这条接收记录置为已读。
|
||||
*
|
||||
* <p>复刻老 {@code MessageReceiveView.detail()}:先按收到消息主键加载
|
||||
* {@code SYS_MESSAGEUSER},再取 {@code SYS_MESSAGE_ID} 加载 {@code SYS_MESSAGE},未读时更新
|
||||
* {@code ISREAD=true}。这里用一个 POST 完成,避免 GET initApi 承担写副作用。
|
||||
*/
|
||||
@Operation(summary = "打开收到消息详情并置已读",
|
||||
description = "按 sys_messageuser_id + 当前用户校验;未读时 UPDATE sys_messageuser.isread=1")
|
||||
@PostMapping("/api/notice/received/{id}/open")
|
||||
public Map<String, Object> openReceived(
|
||||
@Parameter(description = "sys_messageuser_id(36位)") @PathVariable String id) {
|
||||
|
||||
String userId = requireCurrentUserId();
|
||||
String sql = "SELECT TRIM(mu.sys_messageuser_id) AS receive_id,"
|
||||
+ " mu.isread AS receive_isread,"
|
||||
+ " " + messageDetailColumns()
|
||||
+ " FROM eip3.sys_messageuser mu"
|
||||
+ " JOIN eip3.sys_message m ON m.sys_message_id = mu.sys_message_id"
|
||||
+ " LEFT JOIN view_sys_user u ON u.view_sys_user_id = m.createby"
|
||||
+ " WHERE mu.sys_messageuser_id = CAST(? AS character(36))"
|
||||
+ " AND mu.sys_user_id = CAST(? AS character(36))"
|
||||
+ " AND mu.isdel = 0"
|
||||
+ " AND m.isdel = 0";
|
||||
try {
|
||||
Map<String, Object> row = jdbcTemplate.queryForMap(sql, id.trim(), userId);
|
||||
boolean wasRead = isTruthy(row.get("receive_isread"));
|
||||
boolean changed = false;
|
||||
if (!wasRead) {
|
||||
int affected = jdbcTemplate.update(
|
||||
"UPDATE eip3.sys_messageuser SET isread = 1"
|
||||
+ " WHERE sys_messageuser_id = CAST(? AS character(36))"
|
||||
+ " AND sys_user_id = CAST(? AS character(36))"
|
||||
+ " AND isdel = 0",
|
||||
id.trim(), userId);
|
||||
changed = affected > 0;
|
||||
}
|
||||
return okDetail(row, true, changed);
|
||||
} catch (EmptyResultDataAccessException ex) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "消息不存在或无权查看");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 未读数计数
|
||||
|
||||
/**
|
||||
@@ -239,4 +316,71 @@ public class NoticeController {
|
||||
resp.put("data", data);
|
||||
return resp;
|
||||
}
|
||||
|
||||
private Map<String, Object> okDetail(Map<String, Object> row, boolean received, boolean readChanged) {
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("id", string(row.get("id")));
|
||||
data.put("receiveId", string(row.get("receive_id")));
|
||||
data.put("title", row.get("title"));
|
||||
data.put("content", row.get("content"));
|
||||
data.put("type", row.get("type"));
|
||||
data.put("createTime", row.get("createtime"));
|
||||
data.put("senderId", string(row.get("sender_id")));
|
||||
data.put("sender", fallback(row.get("sender"), row.get("sender_id")));
|
||||
data.put("receivers", row.get("receivers"));
|
||||
data.put("receiverIds", row.get("receiver_ids"));
|
||||
data.put("document", row.get("document"));
|
||||
data.put("params", row.get("params"));
|
||||
data.put("received", received);
|
||||
data.put("readChanged", readChanged);
|
||||
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "");
|
||||
resp.put("data", data);
|
||||
return resp;
|
||||
}
|
||||
|
||||
private static String messageDetailSelect() {
|
||||
return "SELECT " + messageDetailColumns()
|
||||
+ " FROM eip3.sys_message m"
|
||||
+ " LEFT JOIN view_sys_user u ON u.view_sys_user_id = m.createby";
|
||||
}
|
||||
|
||||
private static String messageDetailColumns() {
|
||||
return "TRIM(m.sys_message_id) AS id,"
|
||||
+ " m.title,"
|
||||
+ " m.content,"
|
||||
+ " m.type,"
|
||||
+ " m.createtime,"
|
||||
+ " TRIM(m.createby) AS sender_id,"
|
||||
+ " COALESCE(NULLIF(TRIM(u.displayname), ''), TRIM(m.createby)) AS sender,"
|
||||
+ " m.tousersname AS receivers,"
|
||||
+ " m.tousers AS receiver_ids,"
|
||||
+ " m.document AS document,"
|
||||
+ " m.params AS params";
|
||||
}
|
||||
|
||||
private static String string(Object value) {
|
||||
return value == null ? "" : String.valueOf(value).trim();
|
||||
}
|
||||
|
||||
private static String fallback(Object value, Object fallback) {
|
||||
String s = string(value);
|
||||
return s.isEmpty() ? string(fallback) : s;
|
||||
}
|
||||
|
||||
private static boolean isTruthy(Object value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
if (value instanceof Boolean b) {
|
||||
return b;
|
||||
}
|
||||
if (value instanceof Number n) {
|
||||
return n.intValue() != 0;
|
||||
}
|
||||
String s = String.valueOf(value).trim();
|
||||
return "1".equals(s) || "true".equalsIgnoreCase(s) || "yes".equalsIgnoreCase(s);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user