修改userid
build / build-push (push) Successful in 1m27s

This commit is contained in:
wanghu
2026-09-20 10:56:41 +08:00
parent 6433ccea2d
commit 743f7fec43
3 changed files with 42 additions and 37 deletions
@@ -1,8 +1,7 @@
package com.yunhai.dormnotice.common.listener; package com.yunhai.dormnotice.common.listener;
import com.yunhai.dormnotice.entity.BaseEntity; import com.yunhai.dormnotice.entity.BaseEntity;
import com.yunhai.platform.auth.LoginUser; import com.yunhai.dormnotice.utils.UserContext;
import com.yunhai.platform.auth.UserContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.persistence.PrePersist; import javax.persistence.PrePersist;
@@ -10,9 +9,10 @@ import javax.persistence.PreUpdate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
/** /**
* JPA 审计监听器:在实体持久化/更新前自动填充创建人/更新人(平台当前登录人)与时间戳。 * JPA 审计监听器:实体持久化/更新前自动填充创建人/更新人与时间戳。
* 对应 {@link BaseEntity} 的 createBy / updateBy / createTime / updateTime 字段。 * <p>决策 D4:{@code create_by / update_by} 存**当前登录用户 ID**(数字 id),不再存登录账号。
* 当前登录人取自基础平台 {@link UserContextHolder}。 * id 取自 {@link UserContext#getUserId()}(由 ControllerUserContextAspect 在请求线程填充);
* 无登录上下文(启动种子/系统任务)时为 null,保持原值。</p>
*/ */
@Component @Component
public class NoticeAuditListener { public class NoticeAuditListener {
@@ -22,26 +22,26 @@ public class NoticeAuditListener {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
entity.setCreateTime(now); entity.setCreateTime(now);
entity.setUpdateTime(now); entity.setUpdateTime(now);
String account = currentAccount(); Integer uid = currentUserId();
if (account != null) { if (uid != null) {
if (entity.getCreateBy() == null) { if (entity.getCreateBy() == null) {
entity.setCreateBy(account); entity.setCreateBy(uid);
} }
entity.setUpdateBy(account); entity.setUpdateBy(uid);
} }
} }
@PreUpdate @PreUpdate
public void preUpdate(BaseEntity entity) { public void preUpdate(BaseEntity entity) {
entity.setUpdateTime(LocalDateTime.now()); entity.setUpdateTime(LocalDateTime.now());
String account = currentAccount(); Integer uid = currentUserId();
if (account != null) { if (uid != null) {
entity.setUpdateBy(account); entity.setUpdateBy(uid);
} }
} }
private String currentAccount() { /** 当前登录用户 ID(数字);无上下文返回 null。 */
LoginUser user = UserContextHolder.get(); private Integer currentUserId() {
return user == null ? null : user.getLoginName(); return UserContext.getUserId();
} }
} }
@@ -42,6 +42,7 @@ public class ReadBackfillRunner implements ApplicationRunner {
if (!enabled) { if (!enabled) {
return; return;
} }
try {
List<Receipt> acted = receiptRepository.findByStatusIn(java.util.Arrays.asList("confirmed", "filled")); List<Receipt> acted = receiptRepository.findByStatusIn(java.util.Arrays.asList("confirmed", "filled"));
int added = 0; int added = 0;
for (Receipt r : acted) { for (Receipt r : acted) {
@@ -63,5 +64,9 @@ public class ReadBackfillRunner implements ApplicationRunner {
if (added > 0) { if (added > 0) {
log.info("[ReadBackfill] 依据已确认/已填报回执回填阅读记录 {} 条", added); log.info("[ReadBackfill] 依据已确认/已填报回执回填阅读记录 {} 条", added);
} }
} catch (Exception e) {
// 回填失败不得阻断启动(如列类型未迁移等)
log.warn("[ReadBackfill] 阅读记录回填跳过:{}", e.getMessage());
}
} }
} }
@@ -24,10 +24,10 @@ public abstract class BaseEntity implements Serializable {
private Integer id; private Integer id;
/** /**
* 创建人登录账号 * 创建人用户ID(数字;决策 D4,不存登录账号)
*/ */
@Column(name = "create_by", updatable = false) @Column(name = "create_by", updatable = false)
private String createBy; private Integer createBy;
/** /**
* 创建时间 * 创建时间
@@ -36,10 +36,10 @@ public abstract class BaseEntity implements Serializable {
private LocalDateTime createTime; private LocalDateTime createTime;
/** /**
* 更新人登录账号 * 更新人用户ID(数字;决策 D4,不存登录账号)
*/ */
@Column(name = "update_by") @Column(name = "update_by")
private String updateBy; private Integer updateBy;
/** /**
* 更新时间 * 更新时间