123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- // 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
- }
|