|
|
|
@ -6,13 +6,15 @@ import (
|
|
|
|
|
"dsDataex/MyService/MySwagger"
|
|
|
|
|
"dsDataex/Utils/CommonUtil"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"reflect"
|
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var dics []map[string]interface{}
|
|
|
|
|
const TIME_LAYOUT = "2020/09/14 15:29:10"
|
|
|
|
|
const TIME_LAYOUT = "2020-09-14 15:29:10"
|
|
|
|
|
|
|
|
|
|
type RegexCheck struct {}
|
|
|
|
|
|
|
|
|
@ -39,6 +41,8 @@ func ValidESDataContent(datasourceCode string, datas []MySwagger.Data) (bool, st
|
|
|
|
|
var dicIds []string
|
|
|
|
|
var dicIdsStr string
|
|
|
|
|
|
|
|
|
|
fmt.Println("datas: ", datas)
|
|
|
|
|
|
|
|
|
|
conditions = "datasource_id='" + datasourceCode + "'"
|
|
|
|
|
// 获取该数据源对应的元数据集合
|
|
|
|
|
result, _, _, metadatas, _ := DataexDAO.GetMetadataResults(conditions)
|
|
|
|
@ -65,6 +69,7 @@ func ValidESDataContent(datasourceCode string, datas []MySwagger.Data) (bool, st
|
|
|
|
|
if _, ok := dataContent[v["item_name"].(string)]; ok {
|
|
|
|
|
// 校验数据
|
|
|
|
|
res, mes, _ := ValidESDataContentItem(v, v["item_name"].(string), dataContent[v["item_name"].(string)])
|
|
|
|
|
//fmt.Println(res, mes)
|
|
|
|
|
if res == false {
|
|
|
|
|
failMessages = v["item_name"].(string) + mes + " "
|
|
|
|
|
r = false
|
|
|
|
@ -75,7 +80,7 @@ func ValidESDataContent(datasourceCode string, datas []MySwagger.Data) (bool, st
|
|
|
|
|
fails["fail_id"] = datas[no].DataID
|
|
|
|
|
fails["fail_msg"] = failMessages
|
|
|
|
|
dataContentFailIDs = append(dataContentFailIDs,fails)
|
|
|
|
|
continue
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -115,44 +120,42 @@ func ValidESDataContentItem(dataContentItem map[string]interface{}, itemName str
|
|
|
|
|
checkPattern := dataContentItem["check_pattern"].(int64)
|
|
|
|
|
checkExist := dataContentItem["check_exist"].(int64)
|
|
|
|
|
|
|
|
|
|
fmt.Println("dataContentItem: ", dataContentItem)
|
|
|
|
|
|
|
|
|
|
if itemLength > 0 { // 校验长度
|
|
|
|
|
if CommonUtil.ConvertIntToInt64(len(itemValue.(string))) > itemLength {
|
|
|
|
|
fmt.Println(itemValue.(string) + "最大长度超出")
|
|
|
|
|
return false, "最大长度超出", nil
|
|
|
|
|
} else {
|
|
|
|
|
return true, "ok", nil
|
|
|
|
|
}
|
|
|
|
|
} else if checkName > 0 { // 校验名称
|
|
|
|
|
return true, "ok", nil
|
|
|
|
|
|
|
|
|
|
} else if checkDic > 0 { // 校验字典
|
|
|
|
|
if CheckDic(itemValue, dicId, dics) == false {
|
|
|
|
|
fmt.Println("字典校验不通过")
|
|
|
|
|
return false, "字典校验不通过", nil
|
|
|
|
|
} else {
|
|
|
|
|
return true, "ok", nil
|
|
|
|
|
}
|
|
|
|
|
} else if checkType > 0 { // 校验类型
|
|
|
|
|
if CheckType(itemValue, itemType) == false {
|
|
|
|
|
fmt.Println("类型校验不通过")
|
|
|
|
|
return false, "类型校验不通过", nil
|
|
|
|
|
} else {
|
|
|
|
|
return true, "ok", nil
|
|
|
|
|
}
|
|
|
|
|
} else if checkPattern > 0 { // 校验规则
|
|
|
|
|
if CheckPattern(itemValue, itemPattern) == false {
|
|
|
|
|
fmt.Println("数据项模式校验不通过")
|
|
|
|
|
return false, "数据项模式校验不通过", nil
|
|
|
|
|
} else {
|
|
|
|
|
return true, "ok", nil
|
|
|
|
|
}
|
|
|
|
|
} else if checkExist > 0 { // 校验必填项
|
|
|
|
|
if itemValue == nil {
|
|
|
|
|
fmt.Println("是必填项")
|
|
|
|
|
return false, itemName + "是必填项", nil
|
|
|
|
|
} else {
|
|
|
|
|
return true, "ok", nil
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return true, "ok", nil
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Println("缺少dataContentItem")
|
|
|
|
|
return false, "校验失败, 缺少dataContentItem", nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true, "ok", nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -187,12 +190,17 @@ func CheckDic(itemValue interface{}, dicId string, dics []map[string]interface{}
|
|
|
|
|
*/
|
|
|
|
|
func CheckType(itemValue interface{}, itemType string) bool {
|
|
|
|
|
flag := false
|
|
|
|
|
fmt.Println("itemType: ", itemType)
|
|
|
|
|
if itemType == "string" { // 校验是否是字符串
|
|
|
|
|
_, ok := itemValue.(string)
|
|
|
|
|
if ok {
|
|
|
|
|
flag = true
|
|
|
|
|
}
|
|
|
|
|
tp := reflect.TypeOf(itemValue)
|
|
|
|
|
fmt.Println("tp: ", tp)
|
|
|
|
|
} else if itemType == "float" { // 校验是否是浮点数
|
|
|
|
|
//tp := reflect.TypeOf(itemValue)
|
|
|
|
|
//fmt.Println("tp: ", tp)
|
|
|
|
|
_, ok := itemValue.(float32)
|
|
|
|
|
if ok {
|
|
|
|
|
flag = true
|
|
|
|
@ -201,6 +209,7 @@ func CheckType(itemValue interface{}, itemType string) bool {
|
|
|
|
|
if ok1 {
|
|
|
|
|
flag = true
|
|
|
|
|
}
|
|
|
|
|
//fmt.Println("flag: ", flag)
|
|
|
|
|
} else if itemType == "datetime" { // 校验时间格式是否正确
|
|
|
|
|
_, e := time.Parse(TIME_LAYOUT, itemValue.(string))
|
|
|
|
|
if e == nil {
|
|
|
|
|