|
|
package ProtoDao
|
|
|
|
|
|
import (
|
|
|
"dsAutoCode/Utils/DbUtil"
|
|
|
"fmt"
|
|
|
)
|
|
|
|
|
|
var db = DbUtil.Engine
|
|
|
|
|
|
//根据接口ID获取结构体ID
|
|
|
func GetStructIdByInterfaceId(interfaceId string) (string, string) {
|
|
|
sql := "select struct_id,file_id from t_proto_interface where interface_id=?"
|
|
|
list, _ := db.SQL(sql, interfaceId).Query().List()
|
|
|
if len(list) > 0 {
|
|
|
structId := list[0]["struct_id"].(string)
|
|
|
fileId := list[0]["file_id"].(string)
|
|
|
return structId, fileId
|
|
|
} else {
|
|
|
return "", ""
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//根据名称获取web接口的相关信息
|
|
|
func GetControllerInfoByName(controllerName string) (string, string, string) {
|
|
|
sql := "select controller_id,http_type,description from t_swagger_controller where controller_name=?"
|
|
|
list, _ := db.SQL(sql, controllerName).Query().List()
|
|
|
if len(list) > 0 {
|
|
|
HttpType := list[0]["http_type"].(string)
|
|
|
controllerId := list[0]["controller_id"].(string)
|
|
|
description := list[0]["description"].(string)
|
|
|
return HttpType, controllerId, description
|
|
|
} else {
|
|
|
return "暂无", "暂无", "暂无描述"
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//根据ID获取结构体信息
|
|
|
func GetStructParameterInfoById(structId string) []map[string]interface{} {
|
|
|
sql := "select struct_parameter_name,struct_parameter_type from t_proto_struct_parameter where struct_id=?"
|
|
|
list, _ := db.SQL(sql, structId).Query().List()
|
|
|
return list
|
|
|
}
|
|
|
|
|
|
//获取指定Controller的信息
|
|
|
func GetControllerInfoById(controllerId string) []map[string]interface{} {
|
|
|
sql := `select controller_parameter_id,controller_id,controller_parameter_name,is_required,controller_parameter_type,controller_parameter_get_type,controller_parameter_description from t_swagger_controller_parameter where controller_id=?`
|
|
|
list, _ := db.SQL(sql, controllerId).Query().List()
|
|
|
return list
|
|
|
}
|
|
|
|
|
|
//根据人员ID获取人员信息
|
|
|
func GetPersonInfoById(personId string) map[string]interface{} {
|
|
|
sql := "select * from t_base_person where person_id=?"
|
|
|
list, _ := db.SQL(sql, personId).Query().List()
|
|
|
|
|
|
if len(list) > 0 {
|
|
|
return list[0]
|
|
|
} else {
|
|
|
return nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//根据接口ID获取对应的真实表名称
|
|
|
func GetTrueTableNameFromInterfaceId(interfaceId string) string {
|
|
|
sql := "select file_name from t_proto_files where file_id=(select file_id from t_proto_interface where interface_id=?)"
|
|
|
list, _ := db.SQL(sql, interfaceId).Query().List()
|
|
|
|
|
|
if len(list) > 0 {
|
|
|
return list[0]["file_name"].(string)
|
|
|
} else {
|
|
|
return ""
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//根据文件ID获取ModelArg的结构体ID
|
|
|
func GetStructIdByFileId(fileId string) (bool, string, string) {
|
|
|
sql := "select struct_id from t_proto_struct where file_id=? and struct_name='ModelArg'"
|
|
|
list, _ := db.SQL(sql, fileId).Query().List()
|
|
|
if len(list) > 0 {
|
|
|
return true, "获取成功", list[0]["struct_id"].(string)
|
|
|
} else {
|
|
|
return false, "没有找到此接口对应的ModelArg结构体!", ""
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:根据struct_id获取struct信息
|
|
|
作者:黄海
|
|
|
时间:2020-05-14
|
|
|
*/
|
|
|
func GetStructInfoById(structId string) (bool, string, map[string]interface{}) {
|
|
|
sql := "select * from t_proto_struct where struct_id=?"
|
|
|
list, _ := db.SQL(sql, structId).Query().List()
|
|
|
if len(list) > 0 {
|
|
|
return true, "获取成功", list[0]
|
|
|
} else {
|
|
|
return false, "没有找到此接口对应的结构体!", nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:获取开发者名单
|
|
|
作者:黄海
|
|
|
时间:2020-04-23
|
|
|
*/
|
|
|
func ListPerson() []map[string]interface{} {
|
|
|
var db = DbUtil.Engine
|
|
|
sql := "select * from t_base_person"
|
|
|
list, _ := db.SQL(sql).Query().List()
|
|
|
return list
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功用:绑定接口下拉框
|
|
|
作者:黄海
|
|
|
时间:2020-04-23
|
|
|
*/
|
|
|
func BindInterfaceList() []map[string]interface{} {
|
|
|
sql := "select interface_id,interface_name from t_proto_interface"
|
|
|
var db = DbUtil.Engine
|
|
|
list, _ := db.SQL(sql).Query().List()
|
|
|
return list
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:列举出proto的文件有哪些
|
|
|
作者:黄海
|
|
|
时间:2020-04-22
|
|
|
*/
|
|
|
func ListProto(interfaceId string, page int, limit int) ([]map[string]interface{}, int64) {
|
|
|
var db = DbUtil.Engine
|
|
|
//这里写的很不优雅,还有注入式攻击的问题,但考虑是自己使用的工具,就不再强调了~
|
|
|
var condition = " 1=1 and t1.interface_id=" + interfaceId
|
|
|
if len(interfaceId) == 1 {
|
|
|
condition = " 1=1 "
|
|
|
}
|
|
|
|
|
|
sql := `select t1.file_id,t2.file_name,t1.interface_id,t1.struct_id,t3.struct_name,tsc.controller_id
|
|
|
,(select count(1) from t_swagger_controller as tsc where t1.interface_name=tsc.interface_name) as count
|
|
|
,t1.interface_name,tsc.controller_name from t_proto_interface as t1
|
|
|
left join t_swagger_controller as tsc on tsc.interface_name=t1.interface_name inner join t_proto_files as t2 on t1.file_id=t2.file_id inner join t_proto_struct as t3 on t1.struct_id=t3.struct_id
|
|
|
where ` + condition + ` order by t1.file_id,tsc.interface_name, t1.interface_id`
|
|
|
//个数
|
|
|
sqlCount := "select count(1) as c from (" + sql + ") as t1"
|
|
|
list, _ := db.SQL(sqlCount).Query().List()
|
|
|
count := list[0]["c"].(int64)
|
|
|
//返回数据
|
|
|
limitStr := " limit ?,?"
|
|
|
sql += limitStr
|
|
|
list, _ = db.SQL(sql, (page-1)*limit, limit).Query().List()
|
|
|
return list, count
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
功能:获取指定参数结构体下的参数属性
|
|
|
作者:黄海
|
|
|
时间:2020-04-22
|
|
|
*/
|
|
|
func GetParameterStructInfo(structId string) []map[string]interface{} {
|
|
|
sql := `select struct_parameter_id,struct_parameter_name,struct_parameter_type,struct_id,is_repeate from t_proto_struct_parameter where struct_id=?`
|
|
|
var db = DbUtil.Engine
|
|
|
list, err := db.SQL(sql, structId).Query().List()
|
|
|
if err != nil {
|
|
|
fmt.Println(err.Error())
|
|
|
}
|
|
|
return list
|
|
|
}
|