You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.7 KiB
70 lines
1.7 KiB
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package organization
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/youruser/base/internal/svc"
|
|
"github.com/youruser/base/internal/types"
|
|
"github.com/youruser/base/model"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type CreateOrganizationLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 创建机构
|
|
func NewCreateOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrganizationLogic {
|
|
return &CreateOrganizationLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *CreateOrganizationLogic) CreateOrganization(req *types.CreateOrgRequest) (resp *types.OrgInfo, err error) {
|
|
// 检查编码唯一性
|
|
existing, _ := model.OrgFindOneByCode(l.ctx, l.svcCtx.DB, req.Code)
|
|
if existing != nil {
|
|
return nil, fmt.Errorf("机构编码 %s 已存在", req.Code)
|
|
}
|
|
|
|
org := &model.Organization{
|
|
ParentId: req.ParentId,
|
|
Name: req.Name,
|
|
Code: req.Code,
|
|
Leader: req.Leader,
|
|
Phone: req.Phone,
|
|
Email: req.Email,
|
|
SortOrder: req.SortOrder,
|
|
Status: 1,
|
|
}
|
|
|
|
_, err = model.OrgInsert(l.ctx, l.svcCtx.DB, org)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("创建机构失败: %v", err)
|
|
}
|
|
|
|
return &types.OrgInfo{
|
|
Id: org.Id,
|
|
ParentId: org.ParentId,
|
|
Name: org.Name,
|
|
Code: org.Code,
|
|
Leader: org.Leader,
|
|
Phone: org.Phone,
|
|
Email: org.Email,
|
|
SortOrder: org.SortOrder,
|
|
Status: org.Status,
|
|
MemberCount: 0,
|
|
Children: []types.OrgInfo{},
|
|
CreatedAt: org.CreatedAt.Format("2006-01-02 15:04:05"),
|
|
UpdatedAt: org.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
}, nil
|
|
}
|
|
|