| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package dept
- import (
- "context"
- "time"
- "perms-system-server/internal/consts"
- authHelper "perms-system-server/internal/logic/auth"
- "perms-system-server/internal/response"
- "perms-system-server/internal/svc"
- "perms-system-server/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type UpdateDeptLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewUpdateDeptLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateDeptLogic {
- return &UpdateDeptLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
- func (l *UpdateDeptLogic) UpdateDept(req *types.UpdateDeptReq) error {
- if err := authHelper.RequireSuperAdmin(l.ctx); err != nil {
- return err
- }
- dept, err := l.svcCtx.SysDeptModel.FindOne(l.ctx, req.Id)
- if err != nil {
- return response.ErrNotFound("部门不存在")
- }
- dept.Name = req.Name
- dept.Sort = req.Sort
- dept.Remark = req.Remark
- if req.DeptType == consts.DeptTypeNormal || req.DeptType == consts.DeptTypeDev {
- dept.DeptType = req.DeptType
- }
- if req.Status == consts.StatusEnabled || req.Status == consts.StatusDisabled {
- dept.Status = req.Status
- }
- dept.UpdateTime = time.Now().Unix()
- if err := l.svcCtx.SysDeptModel.Update(l.ctx, dept); err != nil {
- return err
- }
- userIds, _ := l.svcCtx.SysUserModel.FindIdsByDeptId(l.ctx, req.Id)
- for _, uid := range userIds {
- l.svcCtx.UserDetailsLoader.Clean(l.ctx, uid)
- }
- return nil
- }
|