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.
107 lines
2.9 KiB
107 lines
2.9 KiB
package ValidationUtil
|
|
|
|
import (
|
|
"dsDataex/MyModel_del/DataSource/DatasourceService"
|
|
"dsDataex/MyModel_del/JYT2012/Jyt2012DAO"
|
|
"dsDataex/MyModel_del/MetaData/MetadataDAO"
|
|
"dsDataex/MyModel_del/MySwagger"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func ValidESDataContent(datasourceId string, dataContent map[string]interface{}) (bool, string) {
|
|
var fails string
|
|
var query MySwagger.MetadataQuery
|
|
r := true
|
|
|
|
query.Conditions = " AND datasource_id=" + datasourceId
|
|
result, _, _, metadatas, _ := MetadataDAO.GetMetadataResults(query)
|
|
if result == true {
|
|
for _, v := range metadatas {
|
|
for _, vv := range v {
|
|
if _, ok := dataContent[vv.(string)]; ok {
|
|
res, mes, _ := ValidESDataContentItem(v, vv.(string), dataContent[vv.(string)])
|
|
if res == false {
|
|
//fail := make(map[string]interface{})
|
|
//fail[vv.(string)] = mes
|
|
fails += vv.(string) + mes + " "
|
|
|
|
r = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
fails = strings.TrimRight(fails, " ")
|
|
|
|
return r, fails
|
|
}
|
|
|
|
func ValidESDataContentItem(dataContentItem map[string]interface{}, itemName string, itemValue interface{}) (bool, string, error) {
|
|
//var where string
|
|
//where = "datasource_id='" + datasourceId + "' AND item_name='" + itemName + "'"
|
|
//result, _, row, _ := MetadataDAO.GetMetadataRow(where)
|
|
if dataContentItem != nil {
|
|
dicId := dataContentItem["dic_id"]
|
|
itemLength, _ := strconv.Atoi(dataContentItem["item_length"].(string))
|
|
checkName, _ := strconv.Atoi(dataContentItem["check_name"].(string))
|
|
checkDic, _ := strconv.Atoi(dataContentItem["check_dic"].(string))
|
|
checkType, _ := strconv.Atoi(dataContentItem["check_type"].(string))
|
|
checkPattern, _ := strconv.Atoi(dataContentItem["check_pattern"].(string))
|
|
checkExist, _ := strconv.Atoi(dataContentItem["check_exist"].(string))
|
|
|
|
if itemLength > 0 {
|
|
if len(itemValue.(string)) > itemLength {
|
|
return false, "最大长度超出", nil
|
|
} else {
|
|
return true, "ok", nil
|
|
}
|
|
} else if checkName > 0 {
|
|
return true, "ok", nil
|
|
} else if checkDic > 0 {
|
|
if CheckDic(dicId.(string), itemValue) == false {
|
|
return false, "字典检测不通过", nil
|
|
} else {
|
|
return true, "ok", nil
|
|
}
|
|
} else if checkType > 0 {
|
|
return true, "ok", nil
|
|
} else if checkPattern > 0 {
|
|
return true, "ok", nil
|
|
} else if checkExist > 0 {
|
|
if itemValue == nil {
|
|
return false, itemName + "是必填项", nil
|
|
} else {
|
|
return true, "ok", nil
|
|
}
|
|
} else {
|
|
return true, "ok", nil
|
|
}
|
|
} else {
|
|
return false, "", nil
|
|
}
|
|
}
|
|
|
|
func GetDatasourceIdByCode(datasourceCode string) (bool, string) {
|
|
res, _, datasourceId, _ := DatasourceService.GetDatasourceIdByCode(datasourceCode)
|
|
if res == true {
|
|
return res, datasourceId.(string)
|
|
} else {
|
|
return res, ""
|
|
}
|
|
}
|
|
|
|
//func CheckType(esType string, sqlType string) bool {
|
|
//
|
|
//}
|
|
|
|
// 字典校验
|
|
func CheckDic(dicId string, itemValue interface{}) bool {
|
|
total := Jyt2012DAO.GetJyt2012CountByParentIdAndDicValue(dicId, itemValue.(string))
|
|
if total > 0 {
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
}
|