apiPlugin.go 18.0 KB
Newer Older
Y
Your Name 已提交
1
package consolemysql
E
eoLinker API Management 已提交
2 3 4 5 6 7 8

import (
	SQL "database/sql"
	"errors"
	"fmt"
	"strings"

黄孟柱 已提交
9
	log "github.com/eolinker/goku-api-gateway/goku-log"
E
eoLinker API Management 已提交
10

黄孟柱 已提交
11
	database2 "github.com/eolinker/goku-api-gateway/common/database"
E
eoLinker API Management 已提交
12 13 14 15 16 17

	"time"
)

var apiPlugins = []string{"goku-proxy_caching", "goku-circuit_breaker"}

Y
Your Name 已提交
18 19
// AddPluginToAPI 新增插件到接口
func AddPluginToAPI(pluginName, config, strategyID string, apiID, userID int) (bool, interface{}, error) {
E
eoLinker API Management 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
	db := database2.GetConnection()
	// 查询接口是否添加该插件
	sql := "SELECT apiID FROM goku_conn_plugin_api WHERE strategyID = ? AND pluginName = ? AND apiID = ?;"
	var id int
	err := db.QueryRow(sql, strategyID, pluginName, apiID).Scan(&id)
	if err == nil {
		return false, "[ERROR]The api plugin is already exist", errors.New("[ERROR]The api plugin is already exist")
	}
	now := time.Now().Format("2006-01-02 15:04:05")
	Tx, _ := db.Begin()
	result, err := Tx.Exec("INSERT INTO goku_conn_plugin_api (pluginName,pluginConfig,strategyID,apiID,updateTime,createTime,pluginStatus,updaterID) VALUES (?,?,?,?,?,?,?,?);", pluginName, config, strategyID, apiID, now, now, 1, userID)
	if err != nil {
		Tx.Rollback()
		return false, "[ERROR]Fail to insert data", errors.New("[ERROR]Fail to insert data")
	}
	connID, _ := result.LastInsertId()
	sql = "UPDATE goku_gateway_strategy SET updateTime = ? WHERE strategyID = ?;"
	_, err = Tx.Exec(sql, now, strategyID)
	if err != nil {
		Tx.Rollback()
		return false, "[ERROR]Failed to update data!", err
	}
	Tx.Commit()
	return true, int(connID), nil
}

Y
Your Name 已提交
46 47
// EditAPIPluginConfig 修改接口插件配置
func EditAPIPluginConfig(pluginName, config, strategyID string, apiID, userID int) (bool, interface{}, error) {
E
eoLinker API Management 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
	db := database2.GetConnection()
	// 查询接口是否添加该插件
	t := time.Now()
	now := t.Format("2006-01-02 15:04:05")

	sql := "SELECT connID,apiID FROM goku_conn_plugin_api WHERE strategyID = ? AND pluginName = ? AND apiID = ?;"
	var id, aID int
	err := db.QueryRow(sql, strategyID, pluginName, apiID).Scan(&id, &aID)
	if err != nil {
		return false, "[ERROR]The api plugin is not exist", errors.New("[ERROR]The api plugin is not exist")
	}
	updateTag := t.Format("20060102150405")
	Tx, _ := db.Begin()
	_, err = Tx.Exec("UPDATE goku_conn_plugin_api SET updateTag = ?,pluginConfig = ?,updateTime = ?,updaterID = ? WHERE strategyID = ? AND apiID = ? AND pluginName = ?;", updateTag, config, now, userID, strategyID, apiID, pluginName)
	if err != nil {
		Tx.Rollback()
		return false, "[ERROR]Fail to update data", errors.New("[ERROR]Fail to update data")
	}

	sql = "UPDATE goku_gateway_strategy SET updateTime = ? WHERE strategyID = ?;"
	_, err = Tx.Exec(sql, now, strategyID)
	if err != nil {
		Tx.Rollback()
		return false, "[ERROR]Failed to update data!", err
	}
	Tx.Commit()
	return true, id, nil
}

Y
Your Name 已提交
77 78
//GetAPIPluginList 获取接口插件列表
func GetAPIPluginList(apiID int, strategyID string) (bool, []map[string]interface{}, error) {
E
eoLinker API Management 已提交
79 80 81 82 83 84 85 86 87
	db := database2.GetConnection()
	sql := `SELECT goku_conn_plugin_api.connID,goku_conn_plugin_api.pluginName,IFNULL(goku_conn_plugin_api.createTime,""),IFNULL(goku_conn_plugin_api.updateTime,""),goku_conn_plugin_api.pluginConfig,goku_plugin.pluginPriority, IF(goku_plugin.pluginStatus=0,-1,goku_conn_plugin_api.pluginStatus) as pluginStatus,goku_gateway_api.requestURL FROM goku_conn_plugin_api INNER JOIN goku_plugin ON goku_plugin.pluginName = goku_conn_plugin_api.pluginName INNER goku_gateway_api.apiID = goku_conn_plugin_api.apiID WHERE goku_conn_plugin_api.apiID = ? AND goku_conn_plugin_api.strategyID = ? ORDER BY pluginStatus DESC,goku_conn_plugin_api.updateTime DESC;`
	rows, err := db.Query(sql, apiID, strategyID)
	if err != nil {
		return false, nil, err
	}
	defer rows.Close()
	pluginList := make([]map[string]interface{}, 0)
	//获取记录列
Y
Your Name 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
	for rows.Next() {
		var pluginPriority, pluginStatus, connID int
		var pluginName, pluginConfig, createTime, updateTime, requestURL string
		err = rows.Scan(&connID, &pluginName, &pluginConfig, &createTime, &updateTime, &pluginPriority, &pluginStatus, &requestURL)
		if err != nil {
			info := err.Error()
			log.Info(info)
		}
		pluginInfo := map[string]interface{}{
			"connID":         connID,
			"pluginName":     pluginName,
			"pluginConfig":   pluginConfig,
			"pluginPriority": pluginPriority,
			"pluginStatus":   pluginStatus,
			"createTime":     createTime,
			"updateTime":     updateTime,
			"requestURL":     requestURL,
E
eoLinker API Management 已提交
105
		}
Y
Your Name 已提交
106
		pluginList = append(pluginList, pluginInfo)
E
eoLinker API Management 已提交
107
	}
Y
Your Name 已提交
108
	return true, pluginList, nil
E
eoLinker API Management 已提交
109 110
}

Y
Your Name 已提交
111
// GetPluginIndex 获取插件优先级
E
eoLinker API Management 已提交
112 113 114 115 116 117 118 119 120 121 122
func GetPluginIndex(pluginName string) (bool, int, error) {
	db := database2.GetConnection()
	var pluginPriority int
	sql := "SELECT pluginPriority FROM goku_plugin WHERE pluginName = ?;"
	err := db.QueryRow(sql, pluginName).Scan(pluginPriority)
	if err != nil {
		return false, 0, err
	}
	return true, pluginPriority, nil
}

Y
Your Name 已提交
123 124
// GetAPIPluginConfig 通过APIID获取配置信息
func GetAPIPluginConfig(apiID int, strategyID, pluginName string) (bool, map[string]string, error) {
E
eoLinker API Management 已提交
125 126 127 128 129 130 131 132
	db := database2.GetConnection()
	sql := "SELECT goku_gateway_api.apiName,goku_gateway_api.requestURL,goku_conn_plugin_api.pluginConfig FROM goku_conn_plugin_api INNER JOIN goku_gateway_api ON goku_gateway_api.apiID = goku_conn_plugin_api.apiID WHERE goku_conn_plugin_api.apiID = ? AND goku_conn_plugin_api.strategyID = ? AND goku_conn_plugin_api.pluginName = ?;"
	var p, apiName, requestURL string
	err := db.QueryRow(sql, apiID, strategyID, pluginName).Scan(&apiName, &requestURL, &p)
	if err != nil {
		if err == SQL.ErrNoRows {
			return false, nil, errors.New("[ERROR]Can not find the plugin")
		}
Y
Your Name 已提交
133
		return false, nil, err
E
eoLinker API Management 已提交
134 135

	}
Y
Your Name 已提交
136 137 138 139 140 141
	apiPluginInfo := map[string]string{
		"pluginConfig": p,
		"apiName":      apiName,
		"requestURL":   requestURL,
	}
	return true, apiPluginInfo, nil
E
eoLinker API Management 已提交
142 143
}

Y
Your Name 已提交
144 145
// CheckPluginIsExistInAPI 检查策略组是否绑定插件
func CheckPluginIsExistInAPI(strategyID, pluginName string, apiID int) (bool, error) {
E
eoLinker API Management 已提交
146 147 148 149 150 151 152
	db := database2.GetConnection()
	sql := "SELECT apiID FROM goku_conn_plugin_api WHERE strategyID = ? AND pluginName = ? AND apiID = ?;"
	var id int
	err := db.QueryRow(sql, strategyID, pluginName, apiID).Scan(&id)
	if err != nil {
		return false, err
	}
Y
Your Name 已提交
153
	return true, err
E
eoLinker API Management 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
}

// GetAPIPluginInStrategyByAPIID 通过接口ID获取策略组中接口插件列表
func GetAPIPluginInStrategyByAPIID(strategyID string, apiID int, keyword string, condition int) (bool, []map[string]interface{}, map[string]interface{}, error) {
	db := database2.GetConnection()
	var (
		apiName       string
		requestURL    string
		targetURL     string
		target        string
		rewriteTarget string
	)
	sql := "SELECT A.apiName,A.requestURL,IFNULL(A.targetURL,''),IFNULL(A.balanceName,''),IFNULL(B.target,'') FROM goku_gateway_api A INNER JOIN goku_conn_strategy_api B ON A.apiID = B.apiID WHERE B.apiID = ? AND B.strategyID = ?;"
	err := db.QueryRow(sql, apiID, strategyID).Scan(&apiName, &requestURL, &targetURL, &target, &rewriteTarget)
	if err != nil {
		return false, nil, nil, err
	}
	apiInfo := map[string]interface{}{
		"apiID":         apiID,
		"apiName":       apiName,
		"requestURL":    requestURL,
		"targetURL":     targetURL,
		"target":        target,
		"rewriteTarget": rewriteTarget,
	}

	rule := make([]string, 0, 3)

	rule = append(rule, fmt.Sprintf("A.strategyID = '%s'", strategyID))
	rule = append(rule, fmt.Sprintf("A.apiID = %d", apiID))
	if keyword != "" {
		searchRule := "(A.pluginName LIKE '%" + keyword + "%' OR C.pluginDesc LIKE '%" + keyword + "%')"
		rule = append(rule, searchRule)
	}
	if condition > 0 {
		rule = append(rule, fmt.Sprintf("IF(C.pluginStatus=0,-1,A.pluginStatus) = %d", condition-1))
	}
	ruleStr := ""
	if len(rule) > 0 {
		ruleStr += "WHERE " + strings.Join(rule, " AND ")
	}
	sql = fmt.Sprintf(`SELECT A.connID,A.pluginName,IFNULL(A.createTime,""),IFNULL(A.updateTime,""),IF(C.pluginStatus=0,-1,A.pluginStatus) as pluginStatus,IFNULL(C.pluginDesc,""),IF(B.remark is null or B.remark = "",B.loginCall,B.remark) AS updaterName FROM goku_conn_plugin_api A LEFT JOIN goku_admin B ON A.updaterID=B.userID INNER JOIN goku_plugin C ON C.pluginName = A.pluginName %s ORDER BY pluginStatus DESC,A.updateTime DESC;`, ruleStr)
	rows, err := db.Query(sql)
	if err != nil {
		panic(err)
		return false, nil, nil, err
	}
	defer rows.Close()
	pluginList := make([]map[string]interface{}, 0)
	//获取记录列
	for rows.Next() {
		var updaterName SQL.NullString
		var pluginStatus, connID int
		var pluginName, pluginDesc, createTime, updateTime string
		err = rows.Scan(&connID, &pluginName, &createTime, &updateTime, &pluginStatus, &pluginDesc, &updaterName)
		if err != nil {
			return false, nil, nil, err
		}

		pluginInfo := map[string]interface{}{
			"connID":       connID,
			"pluginName":   pluginName,
			"pluginStatus": pluginStatus,
			"createTime":   createTime,
			"updateTime":   updateTime,
			"updaterName":  updaterName.String,
			"pluginDesc":   pluginDesc,
		}
		pluginList = append(pluginList, pluginInfo)
	}
	return true, pluginList, apiInfo, nil
}

Y
Your Name 已提交
227 228
// GetAllAPIPluginInStrategy 获取策略组中所有接口插件列表
func GetAllAPIPluginInStrategy(strategyID string) (bool, []map[string]interface{}, error) {
E
eoLinker API Management 已提交
229 230 231 232 233 234 235 236 237
	db := database2.GetConnection()
	sql := `SELECT goku_conn_plugin_api.connID,goku_conn_plugin_api.apiID,goku_gateway_api.apiName,goku_gateway_api.requestURL,goku_conn_plugin_api.pluginName,IFNULL(goku_conn_plugin_api.createTime,""),IFNULL(goku_conn_plugin_api.updateTime,""),IF(goku_plugin.pluginStatus=0,-1,goku_conn_plugin_api.pluginStatus) as pluginStatus,IFNULL(goku_plugin.pluginDesc,"") FROM goku_conn_plugin_api INNER JOIN goku_gateway_api ON goku_gateway_api.apiID = goku_conn_plugin_api.apiID INNER JOIN goku_plugin ON goku_plugin.pluginName = goku_conn_plugin_api.pluginName WHERE goku_conn_plugin_api.strategyID = ? ORDER BY pluginStatus DESC,goku_conn_plugin_api.updateTime DESC;`
	rows, err := db.Query(sql, strategyID)
	if err != nil {
		return false, make([]map[string]interface{}, 0), err
	}
	defer rows.Close()
	pluginList := make([]map[string]interface{}, 0)
	//获取记录列
Y
Your Name 已提交
238 239 240 241 242 243
	for rows.Next() {
		var pluginStatus, apiID, connID int
		var apiName, pluginName, pluginDesc, createTime, updateTime, requestURL string
		err = rows.Scan(&connID, &apiID, &apiName, &requestURL, &pluginName, &createTime, &updateTime, &pluginStatus, &pluginDesc)
		if err != nil {
			return false, make([]map[string]interface{}, 0), err
E
eoLinker API Management 已提交
244
		}
Y
Your Name 已提交
245 246 247 248 249 250 251 252 253 254 255 256
		pluginInfo := map[string]interface{}{
			"connID":       connID,
			"apiID":        apiID,
			"apiName":      apiName,
			"pluginName":   pluginName,
			"pluginStatus": pluginStatus,
			"createTime":   createTime,
			"updateTime":   updateTime,
			"requestURL":   requestURL,
			"pluginDesc":   pluginDesc,
		}
		pluginList = append(pluginList, pluginInfo)
E
eoLinker API Management 已提交
257
	}
Y
Your Name 已提交
258
	return true, pluginList, nil
E
eoLinker API Management 已提交
259 260
}

Y
Your Name 已提交
261 262
// BatchEditAPIPluginStatus 批量修改策略组插件状态
func BatchEditAPIPluginStatus(connIDList, strategyID string, pluginStatus, userID int) (bool, string, error) {
E
eoLinker API Management 已提交
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
	db := database2.GetConnection()
	t := time.Now()
	now := t.Format("2006-01-02 15:04:05")
	updateTag := t.Format("20060102150405")
	Tx, _ := db.Begin()
	sql := "UPDATE goku_conn_plugin_api SET updateTag = ?,pluginStatus = ?,updateTime = ?,updaterID = ? WHERE connID IN (" + connIDList + ");"
	_, err := Tx.Exec(sql, updateTag, pluginStatus, now, userID)
	if err != nil {
		Tx.Rollback()
		return false, "[ERROR]Fail to excute SQL statement!", err
	}

	// 根据connID获取apiID
	sql = "SELECT apiID FROM goku_conn_plugin_api WHERE connID IN (" + connIDList + ");"
	rows, err := db.Query(sql)
	if err != nil {
		Tx.Rollback()
		return false, "[ERROR]Illegal SQL Statement!", err
	}
	defer rows.Close()
	//获取记录列
Y
Your Name 已提交
284 285 286
	for rows.Next() {
		var apiID int
		err = rows.Scan(&apiID)
E
eoLinker API Management 已提交
287 288
		if err != nil {
			Tx.Rollback()
Y
Your Name 已提交
289
			return false, "[ERROR]Fail to get data!", err
E
eoLinker API Management 已提交
290 291
		}
	}
Y
Your Name 已提交
292 293 294 295 296 297 298
	sql = "UPDATE goku_gateway_strategy SET updateTime = ? WHERE strategyID = ?;"
	_, err = Tx.Exec(sql, now, strategyID)
	if err != nil {
		Tx.Rollback()
		return false, "[ERROR]Fail to update data!", err
	}
	Tx.Commit()
E
eoLinker API Management 已提交
299 300 301
	return true, "", nil
}

Y
Your Name 已提交
302 303
// BatchDeleteAPIPlugin 批量删除策略组插件
func BatchDeleteAPIPlugin(connIDList, strategyID string) (bool, string, error) {
E
eoLinker API Management 已提交
304 305 306 307 308 309 310 311 312 313 314 315 316
	db := database2.GetConnection()
	now := time.Now().Format("2006-01-02 15:04:05")
	Tx, _ := db.Begin()
	apiIDList := make([]int, 0)
	// 根据connID获取apiID
	sql := "SELECT apiID FROM goku_conn_plugin_api WHERE connID IN (" + connIDList + ");"
	rows, err := Tx.Query(sql)
	if err != nil {
		Tx.Rollback()
		return false, "[ERROR]Illegal SQL Statement!", err
	}
	defer rows.Close()
	//获取记录列
Y
Your Name 已提交
317 318 319 320 321 322
	for rows.Next() {
		var apiID int
		err = rows.Scan(&apiID)
		if err != nil {
			Tx.Rollback()
			return false, "[ERROR]Fail to get data!", err
E
eoLinker API Management 已提交
323
		}
Y
Your Name 已提交
324
		apiIDList = append(apiIDList, apiID)
E
eoLinker API Management 已提交
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
	}
	sql = "DELETE FROM goku_conn_plugin_api WHERE connID IN (" + connIDList + ");"
	_, err = Tx.Exec(sql)
	if err != nil {
		Tx.Rollback()
		return false, "[ERROR]Fail to excute SQL statement!", err
	}

	sql = "UPDATE goku_gateway_strategy SET updateTime = ? WHERE strategyID = ?;"
	_, err = Tx.Exec(sql, now, strategyID)
	if err != nil {
		Tx.Rollback()
		return false, "[ERROR]Fail to update data!", err
	}
	Tx.Commit()
	return true, "", nil
}

Y
Your Name 已提交
343 344
// GetAPIPluginName 通过connID获取插件名称
func GetAPIPluginName(connID int) (bool, string, error) {
E
eoLinker API Management 已提交
345 346 347 348 349 350 351 352 353 354
	db := database2.GetConnection()
	var pluginName string
	sql := "SELECT pluginName FROM goku_conn_plugin_api WHERE connID = ?"
	err := db.QueryRow(sql, connID).Scan(&pluginName)
	if err != nil {
		return false, "[ERROR]The plugin is not existing!", err
	}
	return true, "", nil
}

Y
Your Name 已提交
355 356
// CheckAPIPluginIsExistByConnIDList 通过connIDList判断插件是否存在
func CheckAPIPluginIsExistByConnIDList(connIDList, pluginName string) (bool, []int, error) {
E
eoLinker API Management 已提交
357 358 359 360 361 362 363 364
	db := database2.GetConnection()
	sql := "SELECT apiID FROM goku_conn_plugin_api WHERE connID IN (" + connIDList + ") AND pluginName = ?;"
	rows, err := db.Query(sql, pluginName)
	if err != nil {
		return false, make([]int, 0), err
	}
	defer rows.Close()
	apiIDList := make([]int, 0)
Y
Your Name 已提交
365 366 367 368 369 370

	for rows.Next() {
		var apiID int
		err = rows.Scan(&apiID)
		if err != nil {
			return false, make([]int, 0), err
E
eoLinker API Management 已提交
371
		}
Y
Your Name 已提交
372
		apiIDList = append(apiIDList, apiID)
E
eoLinker API Management 已提交
373 374 375 376
	}
	return true, apiIDList, nil
}

Y
Your Name 已提交
377 378
// GetAPIPluginListWithNotAssignAPIList 获取没有绑定嵌套插件列表
func GetAPIPluginListWithNotAssignAPIList(strategyID string) (bool, []map[string]interface{}, error) {
E
eoLinker API Management 已提交
379 380 381 382 383 384 385 386 387
	db := database2.GetConnection()
	sql := "SELECT pluginID,pluginDesc,pluginName FROM goku_plugin WHERE pluginType = 2 AND pluginStatus = 1;"
	rows, err := db.Query(sql)
	if err != nil {
		return false, make([]map[string]interface{}, 0), err
	}
	defer rows.Close()
	pluginList := make([]map[string]interface{}, 0)
	//获取记录列
Y
Your Name 已提交
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
	sql = "SELECT goku_gateway_api.apiID,goku_gateway_api.apiName,goku_gateway_api.requestURL FROM goku_gateway_api INNER JOIN goku_conn_strategy_api ON goku_gateway_api.apiID = goku_conn_strategy_api.apiID WHERE goku_conn_strategy_api.strategyID = ? AND goku_gateway_api.apiID NOT IN (SELECT goku_conn_plugin_api.apiID FROM goku_conn_plugin_api WHERE goku_conn_plugin_api.strategyID = ? AND goku_conn_plugin_api.pluginName = ?);"
	for rows.Next() {
		var pluginID int
		var pluginName, chineseName string
		err = rows.Scan(&pluginID, &chineseName, &pluginName)
		if err != nil {
			info := err.Error()
			log.Info(info)
			return false, make([]map[string]interface{}, 0), err
		}
		r, err := db.Query(sql, strategyID, strategyID, pluginName)
		if err != nil {
			return false, make([]map[string]interface{}, 0), err
		}
		defer r.Close()
		apiList := make([]map[string]interface{}, 0)
		for r.Next() {
			var (
				apiID      int
				apiName    string
				requestURL string
			)
			err = r.Scan(&apiID, &apiName, &requestURL)
E
eoLinker API Management 已提交
411 412 413
			if err != nil {
				return false, make([]map[string]interface{}, 0), err
			}
Y
Your Name 已提交
414 415 416 417 418
			apiList = append(apiList, map[string]interface{}{
				"apiID":      apiID,
				"apiName":    apiName,
				"requestURL": requestURL,
			})
E
eoLinker API Management 已提交
419 420

		}
Y
Your Name 已提交
421 422 423 424 425 426 427
		pluginInfo := map[string]interface{}{
			"chineseName": chineseName,
			"pluginName":  pluginName,
			"pluginID":    pluginID,
			"apiList":     apiList,
		}
		pluginList = append(pluginList, pluginInfo)
E
eoLinker API Management 已提交
428
	}
Y
Your Name 已提交
429
	return true, pluginList, nil
E
eoLinker API Management 已提交
430 431
}

Y
Your Name 已提交
432 433
//BatchUpdateAPIPluginUpdateTag 批量更新插件更新标识
func BatchUpdateAPIPluginUpdateTag(strategyIDList string) error {
E
eoLinker API Management 已提交
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
	db := database2.GetConnection()
	code := make([]string, 0, len(apiPlugins))
	strategyIDs := strings.Split(strategyIDList, ",")
	strategyCode := make([]string, 0, len(strategyIDs))
	updateTag := time.Now().Format("20060102150405")
	s := make([]interface{}, 0, len(strategyPlugins)+1+len(strategyIDs))
	s = append(s, updateTag)
	for i := 0; i < len(strategyIDs); i++ {
		strategyCode = append(strategyCode, "?")
		s = append(s, strategyIDs[i])
	}
	for i := 0; i < len(apiPlugins); i++ {
		code = append(code, "?")
		s = append(s, apiPlugins[i])
	}

	sql := "UPDATE goku_conn_plugin_api SET updateTag = ? WHERE strategyID IN (" + strings.Join(strategyCode, ",") + ") AND pluginName IN (" + strings.Join(code, ",") + ");"
	_, err := db.Exec(sql, s...)
	if err != nil {
		return err
	}
	return nil
}

Y
Your Name 已提交
458 459
//UpdateAPITagByPluginName 通过插件名称更新接口插件标识
func UpdateAPITagByPluginName(strategyID string, apiIDList string, pluginList string) error {
E
eoLinker API Management 已提交
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
	db := database2.GetConnection()
	plugins := strings.Split(pluginList, ",")
	code := make([]string, 0, len(plugins))
	updateTag := time.Now().Format("20060102150405")
	s := make([]interface{}, 0, len(plugins)+2)
	s = append(s, updateTag, strategyID)
	for i := 0; i < len(plugins); i++ {
		code = append(code, "?")
		s = append(s, plugins[i])
	}

	sql := "UPDATE goku_conn_plugin_api SET updateTag = ? WHERE strategyID = ? AND apiID IN (" + apiIDList + ") AND pluginName IN (" + strings.Join(code, ",") + ");"
	_, err := db.Exec(sql, s...)
	if err != nil {
		return err
	}
	return nil
}

Y
Your Name 已提交
479 480
//UpdateAllAPIPluginUpdateTag 更新所有接口插件更新标识
func UpdateAllAPIPluginUpdateTag() error {
E
eoLinker API Management 已提交
481 482
	db := database2.GetConnection()
	updateTag := time.Now().Format("20060102150405")
Y
Your Name 已提交
483
	// s := make([]interface{}
E
eoLinker API Management 已提交
484 485 486 487 488 489 490
	sql := "UPDATE goku_conn_plugin_api SET updateTag = ?;"
	_, err := db.Exec(sql, updateTag)
	if err != nil {
		return err
	}
	return nil
}