// Copyright 2019 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. package access_log import ( "context" "gd_access_log/apis" "gd_access_log/common.in/storage" "gd_access_log/errors" "fmt" "github.com/astaxie/beego/orm" ) func updateApiName(req *apis.LogUpdateApiNameReq, reply *apis.LogUpdateApiNameReply) error { task := func(o orm.Ormer) error { _, err := o.Raw("update t_gd_access_log_day set api_name=? where api_id=?", req.Name, req.Id).Exec() if err != nil { return errors.DataBaseError } _, err = o.Raw("update t_gd_thirdpart_log_day set api_name=? where api_id=?", req.Name, req.Id).Exec() if err != nil { return errors.DataBaseError } for i := 1; i <= 12; i++ { sql := fmt.Sprintf("update t_gd_access_log_month%d set api_name=? where api_id=?", i) if _, err := o.Raw(sql, req.Name, req.Id).Exec(); err != nil { return errors.DataBaseError } } return nil } tasks := []storage.DbaTasker{} tasks = append(tasks, storage.GenerateDbaTask(task)) storage.ExecTrans(tasks...) return nil } func updateProviderApiName(req *apis.LogUpdateApiNameReq, reply *apis.LogUpdateApiNameReply) error { task := func(o orm.Ormer) error { _, err := o.Raw("update t_gd_thirdpart_log_day set provider_api_name=? where provider_api_id=?", req.Name, req.Id).Exec() if err != nil { return errors.DataBaseError } for i := 1; i <= 12; i++ { sql := fmt.Sprintf("update t_gd_thirdpart_log_month%d set provider_api_name=? where provider_api_id=?", i) if _, err := o.Raw(sql, req.Name, req.Id).Exec(); err != nil { return errors.DataBaseError } } return nil } tasks := []storage.DbaTasker{} tasks = append(tasks, storage.GenerateDbaTask(task)) storage.ExecTrans(tasks...) return nil } func updateMerchantName(req *apis.LogUpdateApiNameReq, reply *apis.LogUpdateApiNameReply) error { task := func(o orm.Ormer) error { _, err := o.Raw("update t_gd_access_log_day set merchant_name=? where merchant_id=?", req.Name, req.Id).Exec() if err != nil { return errors.DataBaseError } _, err = o.Raw("update t_gd_thirdpart_log_day set merchant_name=? where merchant_id=?", req.Name, req.Id).Exec() if err != nil { return errors.DataBaseError } for i := 1; i <= 12; i++ { sql := fmt.Sprintf("update t_gd_access_log_month%d set merchant_name=? where merchant_id=?", i) if _, err := o.Raw(sql, req.Name, req.Id).Exec(); err != nil { return errors.DataBaseError } } return nil } tasks := []storage.DbaTasker{} tasks = append(tasks, storage.GenerateDbaTask(task)) storage.ExecTrans(tasks...) return nil } func updateProviderName(req *apis.LogUpdateApiNameReq, reply *apis.LogUpdateApiNameReply) error { task := func(o orm.Ormer) error { _, err := o.Raw("update t_gd_thirdpart_access_log set provider_name=? where provider_id=?", req.Name, req.Id).Exec() if err != nil { return errors.DataBaseError } _, err = o.Raw("update t_gd_thirdpart_access_log_history set provider_name=? where provider_id=?", req.Name, req.Id).Exec() if err != nil { return errors.DataBaseError } _, err = o.Raw("update t_gd_thirdpart_log_day set provider_name=? where provider_id=?", req.Name, req.Id).Exec() if err != nil { return errors.DataBaseError } for i := 1; i <= 12; i++ { sql := fmt.Sprintf("update t_gd_thirdpart_log_month%d set provider_name=? where provider_id=?", i) if _, err := o.Raw(sql, req.Name, req.Id).Exec(); err != nil { return errors.DataBaseError } } return nil } tasks := []storage.DbaTasker{} tasks = append(tasks, storage.GenerateDbaTask(task)) storage.ExecTrans(tasks...) return nil } func LogUpdateApiName(ctx context.Context, req *apis.LogUpdateApiNameReq, reply *apis.LogUpdateApiNameReply) (err error) { if req.Name == "" || req.Id == 0 { return errors.ArgsError } switch req.Type { case 0: return updateApiName(req, reply) case 1: return updateProviderApiName(req, reply) case 2: return updateMerchantName(req, reply) case 3: return updateProviderName(req, reply) } return nil }