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.
238 lines
7.4 KiB
238 lines
7.4 KiB
package MetadataService
|
|
|
|
import (
|
|
"dsSupport/MyModel/DataSource/DatasourceDAO"
|
|
"dsSupport/MyModel/JYT2012/Jyt2012DAO"
|
|
"dsSupport/MyModel/MetaData/MetadataDAO"
|
|
"dsSupport/MyModel/MySwagger"
|
|
"dsSupport/Utils/CacheUtil"
|
|
"dsSupport/Utils/CommonUtil"
|
|
"dsSupport/Utils/ES7Util"
|
|
"dsSupport/models"
|
|
"html"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func GetMetadataResults(swag MySwagger.MetadataSwag) (bool, string, int, []map[string]interface{}, error) {
|
|
var condition string
|
|
var conditions []string
|
|
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.DeleteFlag != 0 {
|
|
conditions = append(conditions, "delete_flag="+"'"+strconv.Itoa(swag.DeleteFlag)+"'")
|
|
} else {
|
|
conditions = append(conditions, "delete_flag='-1'")
|
|
}
|
|
if swag.EnableFlag != 0 {
|
|
conditions = append(conditions, "enable_flag="+"'"+strconv.Itoa(swag.EnableFlag)+"'")
|
|
}
|
|
if swag.Page != 0 {
|
|
query.Page = swag.Page
|
|
} else {
|
|
query.Page = 1
|
|
}
|
|
|
|
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 !DatasourceDAO.IsDatasourceExistsByCode(html.EscapeString(model.DatasourceId)) {
|
|
return false, "数据源编码不存在", nil
|
|
}
|
|
if model.DicId != "" && !Jyt2012DAO.IsJyt2012ExistsById(model.DicId) {
|
|
return false, "该字典不存在", 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()
|
|
if model.DeleteFlag == 0 {
|
|
business.DeleteFlag = -1
|
|
} else {
|
|
business.DeleteFlag = model.DeleteFlag
|
|
}
|
|
if model.EnableFlag == 0 {
|
|
business.EnableFlag = 1
|
|
} else {
|
|
business.EnableFlag = model.EnableFlag
|
|
}
|
|
|
|
result, message, error := MetadataDAO.CreateMetadata(business)
|
|
|
|
return result, message, error
|
|
}
|
|
|
|
func UpdateMetadata(id string, model models.TDataexMetadata) (bool, string, error) {
|
|
// 校验数据源编码是否存在
|
|
if !DatasourceDAO.IsDatasourceExistsByCode(html.EscapeString(model.DatasourceId)) {
|
|
return false, "数据源编码不存在", nil
|
|
}
|
|
if model.DicId != "" && !Jyt2012DAO.IsJyt2012ExistsById(model.DicId) {
|
|
return false, "该字典不存在", 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
|
|
if model.DeleteFlag != 0 {
|
|
business.DeleteFlag = model.DeleteFlag
|
|
}
|
|
if model.EnableFlag != 0 {
|
|
business.EnableFlag = model.EnableFlag
|
|
}
|
|
|
|
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, _, _, _ := DatasourceDAO.GetDatasourceIdByCode(indexName)
|
|
if res == true {
|
|
r, _ := ES7Util.IndexExist(indexName)
|
|
if r == true {
|
|
if MetadataDAO.IsMetadataExistsByDatasourceCode(indexName) == true {
|
|
MetadataDAO.DeleteMetadataByDatasourceCode(indexName)
|
|
}
|
|
result := ES7Util.IndexDataContentMapping(indexName)
|
|
var itemType string
|
|
itemType = "string"
|
|
business := []models.TDataexMetadata{}
|
|
for k, v := range result {
|
|
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(indexName)
|
|
b.ItemName = html.EscapeString(k)
|
|
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)
|
|
}
|
|
result1, message, error := MetadataDAO.CreateMetadataBatch(business)
|
|
return result1, message, error
|
|
} else {
|
|
return false, "", nil
|
|
}
|
|
} else {
|
|
return false, "", nil
|
|
}
|
|
}
|