update
This commit is contained in:
@@ -32,7 +32,8 @@ func (s *store) Initialize(ctx context.Context) (*system.Role, error) {
|
||||
return nil, err
|
||||
}
|
||||
if count == 0 {
|
||||
obj := system.Role{
|
||||
var err error
|
||||
obj := &system.Role{
|
||||
Name: "Company",
|
||||
DisplayName: "公司",
|
||||
Vip: false,
|
||||
@@ -42,11 +43,12 @@ func (s *store) Initialize(ctx context.Context) (*system.Role, error) {
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
if err := s.Create(ctx, &obj); err != nil {
|
||||
obj, err = s.Create(ctx, obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
obj1 := system.Role{
|
||||
obj1 := &system.Role{
|
||||
Name: "SuperAdmin",
|
||||
DisplayName: "超级管理员",
|
||||
Vip: true,
|
||||
@@ -56,26 +58,42 @@ func (s *store) Initialize(ctx context.Context) (*system.Role, error) {
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
if err := s.Create(ctx, &obj1); err != nil {
|
||||
obj1, err = s.Create(ctx, obj1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &obj1, nil
|
||||
return obj1, nil
|
||||
}
|
||||
|
||||
return s.GetByVip(ctx, true)
|
||||
|
||||
}
|
||||
|
||||
func (s *store) Create(ctx context.Context, obj *system.Role) error {
|
||||
func (s *store) Create(ctx context.Context, obj *system.Role) (*system.Role, error) {
|
||||
//goland:noinspection ALL
|
||||
const q = `
|
||||
INSERT INTO sys_role (
|
||||
name, display_name, parent_id, parent_path, vip, status, sort
|
||||
) VALUES (
|
||||
:name, :display_name, :parent_id, :parent_path, :vip, :status, :sort
|
||||
)`
|
||||
) RETURNING *`
|
||||
|
||||
return sqldb.NamedExecContext(ctx, s.log, s.db.DB(ctx), q, obj)
|
||||
data := map[string]any{
|
||||
"name": obj.Name,
|
||||
"display_name": obj.DisplayName,
|
||||
"parent_id": obj.ParentID,
|
||||
"parent_path": obj.ParentPath,
|
||||
"vip": obj.Vip,
|
||||
"status": obj.Status,
|
||||
"sort": obj.Sort,
|
||||
}
|
||||
|
||||
err := sqldb.NamedQueryStruct(ctx, s.log, s.db.DB(ctx), q, data, &obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
func (s *store) Update(ctx context.Context, obj *system.Role) error {
|
||||
|
||||
Reference in New Issue
Block a user