移除轮询
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package services
|
||||
|
||||
import "server/models"
|
||||
|
||||
// OperationLogUser 根据操作日志的租户范围解析操作人信息。
|
||||
// tid 为空或为 0 时,日志来自平台管理员;否则来自租户用户。
|
||||
func OperationLogUser(tid *uint64, userID uint64) (account, name string) {
|
||||
if userID == 0 {
|
||||
return "", ""
|
||||
}
|
||||
|
||||
if tid != nil && *tid != 0 {
|
||||
var user models.SystemTenantUser
|
||||
if err := models.Orm.QueryTable(new(models.SystemTenantUser)).
|
||||
Filter("tid", *tid).
|
||||
Filter("uid", userID).
|
||||
One(&user); err == nil {
|
||||
if user.Account != nil {
|
||||
account = *user.Account
|
||||
}
|
||||
if user.Name != nil {
|
||||
name = *user.Name
|
||||
}
|
||||
}
|
||||
return account, name
|
||||
}
|
||||
|
||||
var user models.AdminUser
|
||||
if err := models.Orm.QueryTable(new(models.AdminUser)).
|
||||
Filter("id", userID).
|
||||
One(&user); err == nil {
|
||||
account = user.Account
|
||||
if user.Name != nil {
|
||||
name = *user.Name
|
||||
}
|
||||
}
|
||||
return account, name
|
||||
}
|
||||
@@ -8,34 +8,29 @@ import (
|
||||
"server/models"
|
||||
)
|
||||
|
||||
/* findTenantByLoginName 根据租户简称、短名或编码查找租户。
|
||||
*
|
||||
* 当前表结构中 tenant_name 的业务含义就是“租户简称”,同时兼容
|
||||
* tenant_short_name 和 tenant_code 两个历史/备用登录标识。
|
||||
*/
|
||||
|
||||
func findTenantByLoginName(loginName string) (*models.SystemTenant, error) {
|
||||
loginName = strings.TrimSpace(loginName)
|
||||
if loginName == "" {
|
||||
return nil, orm.ErrNoRows
|
||||
}
|
||||
|
||||
qs := models.Orm.QueryTable(new(models.SystemTenant)).
|
||||
Filter("status", 1).
|
||||
Filter("delete_time__isnull", true)
|
||||
|
||||
// tenant_name 的业务含义是租户简称。使用 TRIM 兼容历史数据中字段值
|
||||
// 前后存在空格的情况;参数通过 SetArgs 绑定,避免 SQL 注入。
|
||||
tenant := &models.SystemTenant{}
|
||||
query := `
|
||||
SELECT id, tenant_code, tenant_name, tenant_short_name,
|
||||
contact_person, contact_phone, contact_email, address,
|
||||
worktime, status, remark, create_time, update_time, delete_time
|
||||
FROM yz_system_tenant
|
||||
WHERE (TRIM(tenant_name) = TRIM(?) OR
|
||||
TRIM(tenant_short_name) = TRIM(?) OR
|
||||
TRIM(tenant_code) = TRIM(?))
|
||||
AND status <> 0
|
||||
ORDER BY id ASC
|
||||
LIMIT 1`
|
||||
err := models.Orm.Raw(query).
|
||||
SetArgs(loginName, loginName, loginName).
|
||||
QueryRow(tenant)
|
||||
err := qs.Filter("tenant_name", loginName).One(tenant)
|
||||
if err == nil {
|
||||
return tenant, nil
|
||||
}
|
||||
|
||||
tenant = &models.SystemTenant{}
|
||||
err = models.Orm.QueryTable(new(models.SystemTenant)).
|
||||
Filter("status", 1).
|
||||
Filter("delete_time__isnull", true).
|
||||
Filter("tenant_code", loginName).
|
||||
One(tenant)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user