update
This commit is contained in:
@@ -26,14 +26,14 @@ func NewStore(db *repository.Store, log *logger.Logger) system.DepartmentReposit
|
||||
}
|
||||
}
|
||||
|
||||
func (s *store) Initialize(ctx context.Context) error {
|
||||
func (s *store) Initialize(ctx context.Context) (*system.Department, error) {
|
||||
count, err := s.Count(ctx, dto.SearchDto{})
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if count == 0 {
|
||||
obj := system.Department{
|
||||
obj := &system.Department{
|
||||
Name: "公司",
|
||||
ParentID: 0,
|
||||
ParentPath: ",0,",
|
||||
@@ -42,21 +42,33 @@ func (s *store) Initialize(ctx context.Context) error {
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
return s.Create(ctx, &obj)
|
||||
return s.Create(ctx, obj)
|
||||
}
|
||||
return nil
|
||||
return s.Get(ctx, 1)
|
||||
}
|
||||
|
||||
func (s *store) Create(ctx context.Context, obj *system.Department) error {
|
||||
func (s *store) Create(ctx context.Context, obj *system.Department) (*system.Department, error) {
|
||||
//goland:noinspection ALL
|
||||
const q = `
|
||||
INSERT INTO sys_department (
|
||||
name, parent_id, parent_path, status, sort
|
||||
) VALUES (
|
||||
:name, :parent_id, :parent_path, :status, :sort
|
||||
);`
|
||||
) RETURNING *;`
|
||||
|
||||
return sqldb.NamedExecContext(ctx, s.log, s.db.DB(ctx), q, obj)
|
||||
data := map[string]any{
|
||||
"name": obj.Name,
|
||||
"parent_id": obj.ParentID,
|
||||
"parent_path": obj.ParentPath,
|
||||
"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, err
|
||||
}
|
||||
|
||||
func (s *store) Update(ctx context.Context, obj *system.Department) error {
|
||||
|
||||
Reference in New Issue
Block a user