1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package logic
- import (
- "GtDataStore/app/model"
- "GtDataStore/common/crypto/md5"
- "context"
- "fmt"
- "time"
- "GtDataStore/app/cmd/organization/internal/svc"
- "GtDataStore/app/cmd/organization/pb"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type CreateAppInfoLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewCreateAppInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAppInfoLogic {
- return &CreateAppInfoLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- func (l *CreateAppInfoLogic) CreateAppInfo(in *pb.CreateAppInfoReq) (*pb.CreateAppInfoResp, error) {
- now := time.Now()
- expire := now.Add(time.Duration(in.Expire) * time.Second)
- appInfo := &model.DcAppInfo{
- AppName: in.AppName,
- ProjectIds: in.ProjectIds,
- Secret: md5.Md5([]byte(fmt.Sprintf("%s_%d:%d", in.AppName, 0, expire.UnixMilli()))),
- Status: 0,
- ExpireAt: expire,
- MTime: now,
- }
- r, err := l.svcCtx.AppInfo.Insert(l.ctx, appInfo)
- if err != nil {
- return nil, err
- }
- lid, _ := r.LastInsertId()
- return &pb.CreateAppInfoResp{AppInfo: &pb.AppInfo{
- Id: lid,
- AppName: appInfo.AppName,
- ProjectIds: appInfo.ProjectIds,
- Secret: appInfo.Secret,
- Status: appInfo.Status,
- ExpireAt: appInfo.ExpireAt.Format("2006-01-02 15:04:05"),
- CTime: appInfo.MTime.Format("2006-01-02 15:04:05"),
- }}, nil
- }
|