This commit is contained in:
2025-10-27 15:24:08 +08:00
parent 4186cd0caf
commit df4c3dd46f
47 changed files with 1757 additions and 306 deletions

View File

@@ -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 {