| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- // Code scaffolded by goctl. Safe to edit.
- // goctl 1.10.2
- package application
- import (
- "context"
- "errors"
- "udeServer/internal/apierr"
- "udeServer/internal/log"
- "udeServer/internal/model"
- "udeServer/internal/svc"
- "udeServer/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type UpdateApplicationStatusLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- // 切换应用凭证状态(启用/禁用互换)
- func NewUpdateApplicationStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateApplicationStatusLogic {
- return &UpdateApplicationStatusLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
- func (l *UpdateApplicationStatusLogic) UpdateApplicationStatus(req *types.ApplicationCredentialsUpdateStatusReq) (*types.ApplicationCredentialsUpdateStatusResp, error) {
- if err := checkId(req.Id); err != nil {
- return nil, err
- }
- cred, err := l.svcCtx.ApplicationCredModel.FindOne(l.ctx, req.Id)
- if errors.Is(err, model.ErrNotFound) {
- return nil, apierr.NotFound("application credential", req.Id)
- }
- if err != nil {
- log.RecordError(l.ctx, err)
- return nil, apierr.New(500, "查询应用凭证失败")
- }
- // 启用/禁用互换:1<->2;其他状态视为数据异常
- toggle := map[int64]int64{1: 2, 2: 1}
- newStatus, ok := toggle[cred.Status]
- if !ok {
- return nil, apierr.BadRequest("当前应用状态(status=%d)不支持切换", cred.Status)
- }
- cred.Status = newStatus
- cred.UpdatedBy = operatorName
- if err := l.svcCtx.ApplicationCredModel.Update(l.ctx, cred); err != nil {
- log.RecordError(l.ctx, err)
- return nil, apierr.New(500, "更新应用凭证状态失败")
- }
- return &types.ApplicationCredentialsUpdateStatusResp{Iden: cred.CredIden}, nil
- }
|