38 lines
946 B
Go
38 lines
946 B
Go
package audit
|
|
|
|
// 管����作审计公共能力�
|
|
//
|
|
// �责�
|
|
// 1. OperatorFromCtx �HTTP 请求 context ��当�登录�作人(uid �用户�)�
|
|
// �logic 层记录人工�作时�带�
|
|
//
|
|
// �作人缺失兜底:"系统"(自动化触�,�人工�作)�
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
xhttp "bj_power_mes/common/httpx"
|
|
"bj_power_mes/ent"
|
|
"bj_power_mes/ent/user"
|
|
)
|
|
|
|
// OperatorFromCtx 从请�context ���作人用户��
|
|
// æ— ç™»å½•ä¸Šä¸‹æ–‡ï¼ˆè‡ªåŠ¨è§¦å�‘)返回 "系统";查库失败兜åº?"用户#<id>",ä¿�è¯�审计ä¸�丢æ“�作人ã€?
|
|
func OperatorFromCtx(ctx context.Context, entClient *ent.Client) string {
|
|
if entClient == nil {
|
|
return "系统"
|
|
}
|
|
uid := xhttp.GetUidFromCtx(ctx)
|
|
if uid <= 0 {
|
|
return "系统"
|
|
}
|
|
u, err := entClient.User.Query().
|
|
Where(user.IDEQ(int(uid))).
|
|
Only(ctx)
|
|
if err != nil {
|
|
return fmt.Sprintf("用户#%d", uid)
|
|
}
|
|
return u.Username
|
|
}
|