You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
223 lines
7.0 KiB
223 lines
7.0 KiB
package MetadataService
|
|
|
|
import (
|
|
"dsDataex/GenXorm/models"
|
|
"dsDataex/MyModel/DataSource/DatasourceService"
|
|
"dsDataex/MyModel/JYT2012/Jyt2012Service"
|
|
"dsDataex/MyModel/MetaData/MetadataDAO"
|
|
"dsDataex/MyModel/MySwagger"
|
|
"dsDataex/Utils/CacheUtil"
|
|
"dsDataex/Utils/CommonUtil"
|
|
"dsDataex/Utils/ES7Util"
|
|
"fmt"
|
|
"html"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func GetMetadataResults (swag MySwagger.MetadataSwag) (bool, string, int32, []map[string]interface{}, error) {
|
|
var condition string
|
|
var conditions []string
|
|
var page int
|
|
var query MySwagger.MetadataQuery
|
|
|
|
if swag.DatasourceId != "" {
|
|
conditions = append(conditions, "datasource_id=" + "'" + html.EscapeString(swag.DatasourceId) + "'")
|
|
}
|
|
if swag.ItemName != "" {
|
|
conditions = append(conditions, "item_name=" + "'" + html.EscapeString(swag.ItemName) + "'")
|
|
}
|
|
if swag.DicId != "" {
|
|
conditions = append(conditions, "dic_id=" + "'" + html.EscapeString(swag.DicId) + "'")
|
|
}
|
|
if swag.ItemLength != 0 {
|
|
conditions = append(conditions, "item_length=" + "'" + strconv.Itoa(swag.ItemLength) + "'")
|
|
}
|
|
if swag.ItemPattern != "" {
|
|
conditions = append(conditions, "item_pattern=" + "'" + html.EscapeString(swag.ItemPattern) + "'")
|
|
}
|
|
if swag.ItemInfo != "" {
|
|
conditions = append(conditions, "item_info=" + "'" + html.EscapeString(swag.ItemInfo) + "'")
|
|
}
|
|
if swag.CheckName != 0 {
|
|
conditions = append(conditions, "check_name=" + "'" + strconv.Itoa(swag.CheckName) + "'")
|
|
}
|
|
if swag.CheckDic != 0 {
|
|
conditions = append(conditions, "check_dic=" + "'" + strconv.Itoa(swag.CheckDic) + "'")
|
|
}
|
|
if swag.CheckType != 0 {
|
|
conditions = append(conditions, "check_type=" + "'" + strconv.Itoa(swag.CheckType) + "'")
|
|
}
|
|
if swag.CheckPattern != 0 {
|
|
conditions = append(conditions, "check_pattern=" + "'" + strconv.Itoa(swag.CheckPattern) + "'")
|
|
}
|
|
if swag.CheckExist != 0 {
|
|
conditions = append(conditions, "check_exist=" + "'" + strconv.Itoa(swag.CheckExist) + "'")
|
|
}
|
|
if swag.EnableFlag != 0 {
|
|
conditions = append(conditions, "enable_flag=" + "'" + strconv.Itoa(swag.EnableFlag) + "'")
|
|
}
|
|
if swag.Page != 0 {
|
|
page = swag.Page
|
|
query.Page = (page -1) * 100
|
|
} else {
|
|
query.Page = 0
|
|
}
|
|
|
|
if len(conditions) > 0 {
|
|
condition = " AND " + strings.Join(conditions, " AND ")
|
|
} else {
|
|
condition = ""
|
|
}
|
|
query.Conditions = condition
|
|
|
|
|
|
result, message, count, data, failResult := MetadataDAO.GetMetadataResults(query)
|
|
|
|
return result, message, count, data, failResult
|
|
}
|
|
|
|
|
|
func CreateMetadata (model models.TDataexMetadata) (bool, string, error) {
|
|
if ! DatasourceService.IsDatasourceExistsById(model.DatasourceId) {
|
|
return false, "DatasourceId不存在", nil
|
|
}
|
|
if ! Jyt2012Service.IsJyt2012ExistsById(model.DicId) {
|
|
return false, "DicId不存在", nil
|
|
}
|
|
business := new(models.TDataexMetadata)
|
|
business.Id = CommonUtil.GetUUID()
|
|
business.DatasourceId = html.EscapeString(model.DatasourceId)
|
|
business.ItemName = html.EscapeString(model.ItemName)
|
|
business.DicId = html.EscapeString(model.DicId)
|
|
business.ItemType = model.ItemType
|
|
business.ItemLength = model.ItemLength
|
|
business.ItemPattern = html.EscapeString(model.ItemPattern)
|
|
business.ItemInfo = html.EscapeString(model.ItemInfo)
|
|
business.CheckName = model.CheckName
|
|
business.CheckDic = model.CheckDic
|
|
business.CheckType = model.CheckType
|
|
business.CheckPattern = model.CheckPattern
|
|
business.CheckExist = model.CheckExist
|
|
business.CreateTime = time.Now()
|
|
business.DeleteFlag = -1
|
|
business.EnableFlag = 1
|
|
result, message, error:= MetadataDAO.CreateMetadata(business)
|
|
|
|
return result, message, error
|
|
}
|
|
|
|
func UpdateMetadata (id string, model models.TDataexMetadata) (bool, string, error) {
|
|
if ! DatasourceService.IsDatasourceExistsById(model.DatasourceId) {
|
|
return false, "DatasourceId不存在", nil
|
|
}
|
|
if ! Jyt2012Service.IsJyt2012ExistsById(model.DicId) {
|
|
return false, "DicId不存在", nil
|
|
}
|
|
business := new(models.TDataexMetadata)
|
|
|
|
//清除Redis缓存
|
|
var ids = []string{id}
|
|
var selector = CacheUtil.GetBean("t_dataex_metadata")
|
|
CacheUtil.DeleteCacheByIds(ids, selector)
|
|
|
|
business.ChangeTime = time.Now()
|
|
business.DatasourceId = html.EscapeString(model.DatasourceId)
|
|
business.ItemName = html.EscapeString(model.ItemName)
|
|
business.DicId = html.EscapeString(model.DicId)
|
|
business.ItemType = model.ItemType
|
|
business.ItemLength = model.ItemLength
|
|
business.ItemPattern = html.EscapeString(model.ItemPattern)
|
|
business.ItemInfo = html.EscapeString(model.ItemInfo)
|
|
business.CheckName = model.CheckName
|
|
business.CheckDic = model.CheckDic
|
|
business.CheckType = model.CheckType
|
|
business.CheckPattern = model.CheckPattern
|
|
business.CheckExist = model.CheckExist
|
|
|
|
result, message, error:= MetadataDAO.UpdateMetadata(id, business)
|
|
|
|
return result, message, error
|
|
}
|
|
|
|
func RemoveMetadata (id string) (bool, string, error) {
|
|
business := new(models.TDataexMetadata)
|
|
|
|
//清除Redis缓存
|
|
var ids = []string{id}
|
|
var selector = CacheUtil.GetBean("t_dataex_metadata")
|
|
CacheUtil.DeleteCacheByIds(ids, selector)
|
|
|
|
business.Id = html.EscapeString(id)
|
|
business.ChangeTime = time.Now()
|
|
business.DeleteTime = time.Now()
|
|
business.DeleteFlag = 1
|
|
business.EnableFlag = -1
|
|
|
|
result, message, error:= MetadataDAO.RemoveMetadata(id, business)
|
|
|
|
return result, message, error
|
|
}
|
|
|
|
func CreateMetadataES (indexName string) (bool, string, error) {
|
|
res, _, datasourceId, _ := DatasourceService.GetDatasourceIdByCode(indexName)
|
|
if res == true {
|
|
if MetadataDAO.IsMetadataExistsByDatasourceId(datasourceId.(string)) == true {
|
|
MetadataDAO.DeleteMetadataByDatasourceId(datasourceId.(string))
|
|
}
|
|
fmt.Println("datasourceId: ", datasourceId)
|
|
result := ES7Util.IndexDataContentMapping(indexName)
|
|
var itemType string
|
|
itemType = "string"
|
|
business := []models.TDataexMetadata{}
|
|
for k, v := range result{
|
|
fmt.Println(k, v)
|
|
fmt.Println("v: ", v.(map[string]interface{})["type"])
|
|
if v.(map[string]interface{})["type"] == "float" {
|
|
itemType = "float"
|
|
} else if v.(map[string]interface{})["type"] == "keyword" {
|
|
itemType = "string"
|
|
} else if v.(map[string]interface{})["type"] == "date" {
|
|
itemType = "datetime"
|
|
} else if v.(map[string]interface{})["type"] == "integer" {
|
|
itemType = "integer"
|
|
} else if v.(map[string]interface{})["type"] == "long" {
|
|
itemType = "text"
|
|
} else if v.(map[string]interface{})["type"] == "text" {
|
|
itemType = "text"
|
|
} else if v.(map[string]interface{})["type"] == "boolean" {
|
|
itemType = "boolean"
|
|
} else {
|
|
itemType = "string"
|
|
}
|
|
|
|
b := models.TDataexMetadata{}
|
|
b.Id = CommonUtil.GetUUID()
|
|
b.DatasourceId = html.EscapeString(datasourceId.(string))
|
|
b.ItemName = html.EscapeString(k)
|
|
//b.DicId = html.EscapeString("BA710E2E-895B-4563-9377-0CA5B3DE1CFD")
|
|
b.ItemType = itemType
|
|
b.ItemLength = -1
|
|
b.ItemPattern = html.EscapeString("")
|
|
b.ItemInfo = html.EscapeString("")
|
|
b.CheckName = -1
|
|
b.CheckDic = -1
|
|
b.CheckType = -1
|
|
b.CheckPattern = -1
|
|
b.CheckExist = -1
|
|
b.CreateTime = time.Now()
|
|
b.DeleteFlag = -1
|
|
|
|
business = append(business, b)
|
|
}
|
|
|
|
fmt.Println(business)
|
|
result1, message, error:= MetadataDAO.CreateMetadataBatch(business)
|
|
return result1, message, error
|
|
//return true, "ok", nil
|
|
} else {
|
|
return false, "", nil
|
|
}
|
|
}
|