1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package provider
- import (
- "context"
- "gd_management/apis"
- "gd_management/errors"
- "gd_management/impl/pubsub"
- "gd_management/rpc_apis"
- "gd_management/rpc_apis/gd_access_log"
- "time"
- "gd_management/common.in/storage"
- "github.com/astaxie/beego/orm"
- )
- func ManagementUpdateProviderPlatform(ctx context.Context, req *apis.ManagementUpdateProviderPlatformReq, reply *apis.ManagementUpdateProviderPlatformReply) error {
- task := func(o orm.Ormer) error {
- nameChanged := false
- if req.ProviderId == 0 {
- return errors.ArgsError
- }
- var providerPlatform apis.ProviderPlatform
- err := o.QueryTable("t_gd_provider").Filter("id", req.ProviderId).One(&providerPlatform)
- if err != nil {
- if err == orm.ErrNoRows {
- return errors.ProviderNotExist
- }
- return errors.DataBaseError
- }
- var timeLayout = "2006-01-02 15:04:05"
- timeNow := time.Now().Format(timeLayout)
- if req.PlatformName != "" {
- if providerPlatform.PlatformName != req.PlatformName {
- nameChanged = true
- }
- providerPlatform.PlatformName = req.PlatformName
- }
- if req.PlatformCode != "" {
- providerPlatform.PlatformCode = req.PlatformCode
- }
- if req.Contact != "" {
- providerPlatform.Contact = req.Contact
- }
- if req.Email != "" {
- providerPlatform.Email = req.Email
- }
- providerPlatform.UpdateTime = timeNow
- _, err = o.Update(&providerPlatform)
- if err != nil {
- return errors.DataBaseError
- }
- if nameChanged {
- if err := pubsub.PublishNameNotify("", 0, req.ProviderId); err != nil {
- return err
- }
- if err := pubsub.PublishProviderExportInfoNotify(); err != nil {
- return err
- }
- dreq := gd_access_log.LogUpdateApiNameReq{
- Type: 3,
- Name: req.PlatformName,
- Id: providerPlatform.Id,
- }
- go func() error {
- _, err := rpc_apis.AccessLog.LogUpdateApiName(context.Background(), &dreq)
- return err
- }()
- }
- return nil
- }
- tasks := []storage.DbaTasker{}
- tasks = append(tasks, storage.GenerateDbaTask(task))
- storage.ExecTrans(tasks...)
- return nil
- }
|