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.
85 lines
1.9 KiB
85 lines
1.9 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 UpdateOrganizationLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 更新机构
|
|
func NewUpdateOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrganizationLogic {
|
|
return &UpdateOrganizationLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *UpdateOrganizationLogic) UpdateOrganization(req *types.UpdateOrgRequest) (resp *types.OrgInfo, err error) {
|
|
org, err := model.OrgFindOne(l.ctx, l.svcCtx.DB, req.Id)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("机构不存在: %v", err)
|
|
}
|
|
|
|
if req.ParentId != nil {
|
|
org.ParentId = *req.ParentId
|
|
}
|
|
if req.Name != "" {
|
|
org.Name = req.Name
|
|
}
|
|
if req.Code != "" {
|
|
org.Code = req.Code
|
|
}
|
|
if req.Leader != "" {
|
|
org.Leader = req.Leader
|
|
}
|
|
if req.Phone != "" {
|
|
org.Phone = req.Phone
|
|
}
|
|
if req.Email != "" {
|
|
org.Email = req.Email
|
|
}
|
|
if req.SortOrder != nil {
|
|
org.SortOrder = *req.SortOrder
|
|
}
|
|
if req.Status != nil {
|
|
org.Status = *req.Status
|
|
}
|
|
|
|
err = model.OrgUpdate(l.ctx, l.svcCtx.DB, org)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("更新机构失败: %v", err)
|
|
}
|
|
|
|
memberCount, _ := model.UserOrgCountByOrgId(l.ctx, l.svcCtx.DB, org.Id)
|
|
|
|
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: memberCount,
|
|
Children: []types.OrgInfo{},
|
|
CreatedAt: org.CreatedAt.Format("2006-01-02 15:04:05"),
|
|
UpdatedAt: org.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
}, nil
|
|
}
|
|
|