createAppInfoLogic.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package logic
  2. import (
  3. "GtDataStore/app/model"
  4. "GtDataStore/common/crypto/md5"
  5. "context"
  6. "fmt"
  7. "time"
  8. "GtDataStore/app/cmd/organization/internal/svc"
  9. "GtDataStore/app/cmd/organization/pb"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type CreateAppInfoLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewCreateAppInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAppInfoLogic {
  18. return &CreateAppInfoLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. func (l *CreateAppInfoLogic) CreateAppInfo(in *pb.CreateAppInfoReq) (*pb.CreateAppInfoResp, error) {
  25. now := time.Now()
  26. expire := now.Add(time.Duration(in.Expire) * time.Second)
  27. appInfo := &model.DcAppInfo{
  28. AppName: in.AppName,
  29. ProjectIds: in.ProjectIds,
  30. Secret: md5.Md5([]byte(fmt.Sprintf("%s_%d:%d", in.AppName, 0, expire.UnixMilli()))),
  31. Status: 0,
  32. ExpireAt: expire,
  33. MTime: now,
  34. }
  35. r, err := l.svcCtx.AppInfo.Insert(l.ctx, appInfo)
  36. if err != nil {
  37. return nil, err
  38. }
  39. lid, _ := r.LastInsertId()
  40. return &pb.CreateAppInfoResp{AppInfo: &pb.AppInfo{
  41. Id: lid,
  42. AppName: appInfo.AppName,
  43. ProjectIds: appInfo.ProjectIds,
  44. Secret: appInfo.Secret,
  45. Status: appInfo.Status,
  46. ExpireAt: appInfo.ExpireAt.Format("2006-01-02 15:04:05"),
  47. CTime: appInfo.MTime.Format("2006-01-02 15:04:05"),
  48. }}, nil
  49. }