2
This commit is contained in:
71
internal/erpserver/model/system/audit_log.go
Normal file
71
internal/erpserver/model/system/audit_log.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
)
|
||||
|
||||
type AuditLogRepository interface {
|
||||
Create(ctx context.Context, obj *AuditLog) error
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*AuditLog, int64, error)
|
||||
}
|
||||
|
||||
type AuditLog struct {
|
||||
ID int64 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Email string `json:"email"`
|
||||
StartAt time.Time `json:"start_at"`
|
||||
EndAt time.Time `json:"end_at"`
|
||||
Duration string `json:"duration"`
|
||||
Url string `json:"url"`
|
||||
Method string `json:"method"`
|
||||
Parameters string `json:"parameters"`
|
||||
RefererUrl string `json:"referer_url"`
|
||||
Os string `json:"os"`
|
||||
Ip string `json:"ip"`
|
||||
Browser string `json:"browser"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
func (AuditLog) TableName() string {
|
||||
return "sys_audit_log"
|
||||
}
|
||||
|
||||
func NewAuditLog(r *http.Request, email, os, browser string, start, end time.Time) *AuditLog {
|
||||
var params string
|
||||
method := r.Method
|
||||
if method == "GET" {
|
||||
params = r.URL.Query().Encode()
|
||||
} else if method == "POST" {
|
||||
contentType := r.Header.Get("Content-Type")
|
||||
if strings.Contains(contentType, "application/json") {
|
||||
body := make([]byte, r.ContentLength)
|
||||
r.Body.Read(body)
|
||||
params = string(body)
|
||||
} else if strings.Contains(contentType, "application/x-www-form-urlencoded") {
|
||||
params = r.Form.Encode()
|
||||
}
|
||||
}
|
||||
|
||||
duration := end.Sub(start)
|
||||
|
||||
return &AuditLog{
|
||||
CreatedAt: time.Now(),
|
||||
Email: email,
|
||||
StartAt: start,
|
||||
EndAt: end,
|
||||
Duration: strconv.FormatInt(duration.Milliseconds(), 10),
|
||||
Url: r.URL.RequestURI(),
|
||||
Method: method,
|
||||
Parameters: params,
|
||||
RefererUrl: r.Header.Get("Referer"),
|
||||
Os: os,
|
||||
Ip: r.RemoteAddr,
|
||||
Browser: browser,
|
||||
}
|
||||
}
|
||||
28
internal/erpserver/model/system/config.go
Normal file
28
internal/erpserver/model/system/config.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
)
|
||||
|
||||
type ConfigRepository interface {
|
||||
Create(ctx context.Context, obj *Config) error
|
||||
Update(ctx context.Context, obj *Config) error
|
||||
Get(ctx context.Context, id int32) (*Config, error)
|
||||
GetByKey(ctx context.Context, key string) (*Config, error)
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*Config, int64, error)
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
ID int32 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
Key string `json:"key" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
Value []byte `json:"value" gorm:"type:bytea;not null;"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
||||
}
|
||||
|
||||
func (Config) TableName() string {
|
||||
return "sys_config"
|
||||
}
|
||||
32
internal/erpserver/model/system/department.go
Normal file
32
internal/erpserver/model/system/department.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
)
|
||||
|
||||
type DepartmentRepository interface {
|
||||
Create(ctx context.Context, obj *Department) error
|
||||
Update(ctx context.Context, obj *Department) error
|
||||
Get(ctx context.Context, id int32) (*Department, error)
|
||||
All(ctx context.Context) ([]*Department, error)
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*Department, int64, error)
|
||||
RebuildParentPath(ctx context.Context) error
|
||||
}
|
||||
|
||||
type Department struct {
|
||||
ID int32 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
Name string `json:"name" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
ParentID int32 `json:"parent_id" gorm:"type:int;not null;"`
|
||||
ParentPath string `json:"parent_path" gorm:"type:varchar(500);not null;"`
|
||||
Status int32 `json:"status" gorm:"type:int;not null;default:0;"`
|
||||
Sort int32 `json:"sort" gorm:"type:int;not null;default:0;"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
||||
}
|
||||
|
||||
func (Department) TableName() string {
|
||||
return "sys_department"
|
||||
}
|
||||
56
internal/erpserver/model/system/login_log.go
Normal file
56
internal/erpserver/model/system/login_log.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
)
|
||||
|
||||
type LoginLogRepository interface {
|
||||
Create(ctx context.Context, obj *LoginLog) error
|
||||
GetLatest(ctx context.Context, email string) (*LoginLog, error)
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*LoginLog, int64, error)
|
||||
Count(ctx context.Context, email string) (int64, error)
|
||||
}
|
||||
|
||||
type LoginLog struct {
|
||||
ID int64 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
Email string `json:"email" gorm:"type:varchar(100);not null;"`
|
||||
IsSuccess bool `json:"is_success" gorm:"type:boolean;not null;"`
|
||||
Message string `json:"message" gorm:"type:varchar(300);not null;"`
|
||||
RefererUrl string `json:"referer_url" gorm:"type:varchar(500);not null;"`
|
||||
Url string `json:"url" gorm:"type:varchar(500);not null;"`
|
||||
Os string `json:"os" gorm:"type:varchar(50);not null;"`
|
||||
Ip string `json:"ip" gorm:"type:varchar(20);not null;"`
|
||||
Browser string `json:"browser" gorm:"type:varchar(100);not null;"`
|
||||
}
|
||||
|
||||
func (LoginLog) TableName() string {
|
||||
return "sys_user_login_log"
|
||||
}
|
||||
|
||||
func NewLoginLog(email, os, ip, browser, url, referer string) *LoginLog {
|
||||
return &LoginLog{
|
||||
CreatedAt: time.Now(),
|
||||
Email: email,
|
||||
IsSuccess: false,
|
||||
RefererUrl: referer,
|
||||
Url: url,
|
||||
Os: os,
|
||||
Ip: ip,
|
||||
Browser: browser,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LoginLog) SetMessage(message string) *LoginLog {
|
||||
l.Message = message
|
||||
return l
|
||||
}
|
||||
|
||||
func (l *LoginLog) SetOk(message string) *LoginLog {
|
||||
l.Message = message
|
||||
l.IsSuccess = true
|
||||
return l
|
||||
}
|
||||
37
internal/erpserver/model/system/menu.go
Normal file
37
internal/erpserver/model/system/menu.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MenuRepository interface {
|
||||
Create(ctx context.Context, obj *Menu) error
|
||||
Update(ctx context.Context, obj *Menu) error
|
||||
Get(ctx context.Context, id int32) (*Menu, error)
|
||||
GetByUrl(ctx context.Context, url string) (*Menu, error)
|
||||
All(ctx context.Context) ([]*Menu, error)
|
||||
RebuildParentPath(ctx context.Context) error
|
||||
}
|
||||
|
||||
type Menu struct {
|
||||
ID int32 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
Name string `json:"name" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
DisplayName string `json:"display_name" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
Url string `json:"url" gorm:"type:varchar(200);not null;"`
|
||||
Type string `json:"type" gorm:"type:varchar(50);not null;"`
|
||||
ParentID int32 `json:"parent_id" gorm:"type:int;not null;"`
|
||||
ParentPath string `json:"parent_path" gorm:"type:varchar(500);not null;"`
|
||||
Avatar string `json:"avatar" gorm:"type:varchar(100);not null;"`
|
||||
Style string `json:"style" gorm:"type:varchar(100);not null;"`
|
||||
Visible bool `json:"visible" gorm:"type:boolean;not null;"`
|
||||
IsList bool `json:"is_list" gorm:"type:boolean;not null;"`
|
||||
Status int32 `json:"status" gorm:"type:int;not null;default:0;"`
|
||||
Sort int32 `json:"sort" gorm:"type:int;not null;default:0;"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
||||
}
|
||||
|
||||
func (Menu) TableName() string {
|
||||
return "sys_menu"
|
||||
}
|
||||
34
internal/erpserver/model/system/role.go
Normal file
34
internal/erpserver/model/system/role.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
)
|
||||
|
||||
type RoleRepository interface {
|
||||
Create(ctx context.Context, obj *Role) error
|
||||
Update(ctx context.Context, obj *Role) error
|
||||
Get(ctx context.Context, id int32) (*Role, error)
|
||||
All(ctx context.Context) ([]*Role, error)
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*Role, int64, error)
|
||||
RebuildParentPath(ctx context.Context) error
|
||||
}
|
||||
|
||||
type Role struct {
|
||||
ID int32 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
Name string `json:"name" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
DisplayName string `json:"display_name" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
ParentID int32 `json:"parent_id" gorm:"type:int;not null;"`
|
||||
ParentPath string `json:"parent_path" gorm:"type:varchar(500);not null;"`
|
||||
Vip bool `json:"-" gorm:"type:boolean;not null;"`
|
||||
Status int32 `json:"status" gorm:"type:int;not null;default:0;"`
|
||||
Sort int32 `json:"sort" gorm:"type:int;not null;default:0;"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
||||
}
|
||||
|
||||
func (Role) TableName() string {
|
||||
return "sys_role"
|
||||
}
|
||||
18
internal/erpserver/model/system/role_menu.go
Normal file
18
internal/erpserver/model/system/role_menu.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package system
|
||||
|
||||
import "context"
|
||||
|
||||
type RoleMenuRepository interface {
|
||||
Create(ctx context.Context, obj []*RoleMenu) error
|
||||
DeleteByRoleID(ctx context.Context, roleID int32) error
|
||||
ListByRoleID(ctx context.Context, roleID int32) ([]*RoleMenu, error)
|
||||
}
|
||||
|
||||
type RoleMenu struct {
|
||||
RoleID int32 `json:"role_id" gorm:"primaryKey;autoIncrement:false;type:int;not null;"`
|
||||
MenuID int32 `json:"menu_id" gorm:"primaryKey;autoIncrement:false;type:int;not null;"`
|
||||
}
|
||||
|
||||
func (RoleMenu) TableName() string {
|
||||
return "sys_role_menu"
|
||||
}
|
||||
@@ -1,38 +1,41 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type UserRepository interface {
|
||||
Create(ctx context.Context, obj *User) error
|
||||
Update(ctx context.Context, obj *User) error
|
||||
Get(ctx context.Context, id int32) (*User, error)
|
||||
GetByEmail(ctx context.Context, email string) (*User, error)
|
||||
All(ctx context.Context) ([]*User, error)
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*User, int64, error)
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int32 `json:"id" gorm:"primaryKey"`
|
||||
Uuid uuid.UUID `json:"uuid"`
|
||||
// 邮箱地址
|
||||
Email string `json:"email"`
|
||||
// 用户名称
|
||||
Username string `json:"username"`
|
||||
// 加密密码
|
||||
HashedPassword []byte `json:"hashed_password"`
|
||||
// 密码盐值
|
||||
Salt string `json:"salt"`
|
||||
// 头像
|
||||
Avatar string `json:"avatar"`
|
||||
// 性别
|
||||
Gender int32 `json:"gender"`
|
||||
// 部门
|
||||
DepartmentID int32 `json:"department_id"`
|
||||
// 角色
|
||||
RoleID int32 `json:"role_id"`
|
||||
// 状态
|
||||
Status int32 `json:"status"`
|
||||
// 密码修改时间
|
||||
ChangePasswordAt time.Time `json:"change_password_at"`
|
||||
// 创建时间
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
// 更新时间
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID int32 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
Uuid uuid.UUID `json:"uuid" gorm:"type:uuid;not null;uniqueIndex"`
|
||||
Email string `json:"email" gorm:"type:varchar(100);not null;uniqueIndex"`
|
||||
Username string `json:"username" gorm:"type:varchar(100);not null;uniqueIndex"`
|
||||
HashedPassword []byte `json:"-" gorm:"type:bytea;not null;"`
|
||||
Salt string `json:"-" gorm:"type:varchar(20);not null;"`
|
||||
Avatar string `json:"avatar" gorm:"type:varchar(200);not null;"`
|
||||
Gender int32 `json:"gender" gorm:"type:int;not null;default:0;"`
|
||||
DepartmentID int32 `json:"department_id" gorm:"type:int;not null;default:0;"`
|
||||
RoleID int32 `json:"role_id" gorm:"type:int;not null;default:0;"`
|
||||
Status int32 `json:"status" gorm:"type:int;not null;default:0;"`
|
||||
ChangePasswordAt time.Time `json:"-" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
||||
|
||||
Role *Role `json:"role" gorm:"ForeignKey:RoleID"`
|
||||
Department *Department `json:"department" gorm:"ForeignKey:DepartmentID"`
|
||||
}
|
||||
|
||||
func (User) TableName() string {
|
||||
|
||||
Reference in New Issue
Block a user