// Copyright 2019 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. package data_api import ( "context" "gd_management/apis" "gd_management/errors" "encoding/json" "time" "gd_management/common.in/storage" "github.com/astaxie/beego/orm" ) // DataApiModifyBaseApi 修改数据api下的基础api func DataApiModifyBaseApi(ctx context.Context, req *apis.ManagementDataApiModifyBaseApiReq, reply *apis.ManagementDataApiModifyBaseApiReply) error { // 参数检查 if req.DataApiBaseApiId == 0 { return errors.ArgsError } task := func(o orm.Ormer) error { var dataApiBaseApi apis.ManagementDataApiBaseApi // 获取老数据 err := o.QueryTable("t_gd_child_data_api").Filter("id", req.DataApiBaseApiId).One(&dataApiBaseApi) if err != nil { if err != orm.ErrNoRows { return errors.DataBaseError } else { return errors.DataApiBaseApiNotExist } } if req.SaleName != "" { dataApiBaseApi.SaleName = req.SaleName } if req.CountCode != "" { dataApiBaseApi.CountCode = req.CountCode } if req.CountType != dataApiBaseApi.CountType { dataApiBaseApi.CountType = req.CountType } if req.ForceUpdate != dataApiBaseApi.ForceUpdate { dataApiBaseApi.ForceUpdate = req.ForceUpdate } if req.IsCrypto != dataApiBaseApi.IsCrypto { dataApiBaseApi.IsCrypto = req.IsCrypto } if req.ReuseTime != dataApiBaseApi.ReuseTime { dataApiBaseApi.ReuseTime = req.ReuseTime } if len(req.RequestParam) != 0 { requestParam, err := json.Marshal(req.RequestParam) if err != nil { return err } dataApiBaseApi.RequestParam = string(requestParam) } if len(req.ResponseParam) != 0 { responseParam, err := json.Marshal(req.ResponseParam) if err != nil { return err } dataApiBaseApi.ResponseParam = string(responseParam) } if len(req.Filters) != 0 { filter, err := json.Marshal(req.Filters) if err != nil { return err } dataApiBaseApi.Filter = string(filter) } else { dataApiBaseApi.Filter = "" } var timeLayout = "2006-01-02 15:04:05" timeNow := time.Now().Format(timeLayout) dataApiBaseApi.UpdateTime = timeNow _, err = o.Update(&dataApiBaseApi) if err != nil { return errors.DataBaseError } for _, group := range req.ProviderGroupList { for _, provider := range group.ProviderApiList { _, err := o.Raw("update t_gd_data_api_provider_api_relation set enable = ? where child_data_api_id=? and group_no=? and provider_api_id=?", provider.Enable, req.DataApiBaseApiId, group.GroupNo, provider.ProviderApiId).Exec() if err != nil { return errors.DataBaseError } } } return nil } tasks := []storage.DbaTasker{} tasks = append(tasks, storage.GenerateDbaTask(task)) storage.ExecTrans(tasks...) return nil }