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.
200 lines
5.9 KiB
200 lines
5.9 KiB
package ValidationUtil
|
|
|
|
import (
|
|
"dsDataex/MyService/DataEX"
|
|
"dsDataex/MyService/DataEX/DataexDAO"
|
|
"dsDataex/MyService/MySwagger"
|
|
"dsDataex/Utils/CommonUtil"
|
|
"encoding/json"
|
|
"strings"
|
|
)
|
|
|
|
var dics []map[string]interface{}
|
|
|
|
/**
|
|
* @title ValidESDataContent
|
|
* @Description 校验ESDataContent
|
|
* @Author wangshuai
|
|
* @Date 2020-09-16
|
|
* @Param datasourceCode string 数据源CODE
|
|
* @Param datas []MySwagger.Data Data
|
|
* @Return bool 校验是否完全通过
|
|
* @Return string 提示信息
|
|
* @Return []MySwagger.Data 校验通过数据集合
|
|
* @Return []string 校验失败ID集合
|
|
*/
|
|
func ValidESDataContent(datasourceCode string, datas []MySwagger.Data) (bool, string, []MySwagger.Data, []map[string]string) {
|
|
var dataContent map[string]interface{}
|
|
var failMessages string
|
|
var dataContentFailIDs []map[string]string
|
|
var successDatas []MySwagger.Data
|
|
var conditions string
|
|
var esData DataEX.ESData
|
|
var r bool
|
|
var dicIds []string
|
|
var dicIdsStr string
|
|
|
|
conditions = "datasource_id='" + datasourceCode + "'"
|
|
// 获取该数据源对应的元数据集合
|
|
result, _, _, metadatas, _ := DataexDAO.GetMetadataResults(conditions)
|
|
if result == true {
|
|
for _, vv := range metadatas {
|
|
// 从元数据集合获取该数据源对应的含有字典ID的字典ID集合
|
|
if vv["dic_id"].(string) != "" {
|
|
dicIds = append(dicIds, "'" + vv["dic_id"].(string) + "'")
|
|
}
|
|
}
|
|
// 字典ID集合字符串
|
|
dicIdsStr = strings.Join(dicIds, ", ")
|
|
// 获取含有
|
|
_, _, _, dics, _ = DataexDAO.GetJyt2012ResultsByParentIds(dicIdsStr)
|
|
for no := 0; no < len(datas) && no < 1000; no++ {
|
|
r = true
|
|
var jsonData map[string]interface{}
|
|
json.Unmarshal([]byte(datas[no].Data), &jsonData)
|
|
|
|
esData.DataContent = jsonData
|
|
dataContent = esData.DataContent
|
|
for _, v := range metadatas {
|
|
// 判断集合中是否含有该项数据
|
|
if _, ok := dataContent[v["item_name"].(string)]; ok {
|
|
// 校验数据
|
|
res, mes, _ := ValidESDataContentItem(v, v["item_name"].(string), dataContent[v["item_name"].(string)])
|
|
if res == false {
|
|
failMessages = v["item_name"].(string) + mes + " "
|
|
r = false
|
|
// 将校验失败的ID集合写入到failIDs
|
|
//failIDs = append(failIDs, datas[no].DataID)
|
|
// 将校验失败的ID和提示信息写入到fails集合
|
|
fails := make(map[string]string)
|
|
fails["fail_id"] = datas[no].DataID
|
|
fails["fail_msg"] = failMessages
|
|
dataContentFailIDs = append(dataContentFailIDs,fails)
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
if r == true {
|
|
// 将校验通过的数据集合写入到successDatas
|
|
successDatas = append(successDatas, datas[no])
|
|
}
|
|
}
|
|
}
|
|
// 首尾去空格
|
|
//fails = strings.TrimRight(fails, " ")
|
|
|
|
return r, failMessages, successDatas, dataContentFailIDs
|
|
}
|
|
|
|
/**
|
|
* @title ValidESDataContentItem
|
|
* @Description 校验ESDataContent每项元数据
|
|
* @Author wangshuai
|
|
* @Date 2020-09-16
|
|
* @Param dataContentItem map[string]interface{} 数据源CODE
|
|
* @Param itemName string 校验项名称
|
|
* @Param itemValue interface{} 校验项值
|
|
* @Return bool 校验是否通过
|
|
* @Return string 校验提示信息
|
|
* @Return error 错误信息
|
|
*/
|
|
func ValidESDataContentItem(dataContentItem map[string]interface{}, itemName string, itemValue interface{}) (bool, string, error) {
|
|
if dataContentItem != nil {
|
|
dicId := dataContentItem["dic_id"].(string)
|
|
itemLength := dataContentItem["item_length"].(int64)
|
|
checkName := dataContentItem["check_name"].(int64)
|
|
checkDic := dataContentItem["check_dic"].(int64)
|
|
checkType := dataContentItem["check_type"].(int64)
|
|
checkPattern := dataContentItem["check_pattern"].(int64)
|
|
checkExist := dataContentItem["check_exist"].(int64)
|
|
|
|
if itemLength > 0 { // 校验长度
|
|
if CommonUtil.ConvertIntToInt64(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(itemValue, dicId, dics) == 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
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @title CheckDic
|
|
* @Description 字典校验
|
|
* @Author wangshuai
|
|
* @Date 2020-09-16
|
|
* @Param itemValue interface{} 字典项值
|
|
* @Param dicId string 字典ID
|
|
* @Param dics []map[string]interface{} 字典项值
|
|
* @Return bool 校验是否通过
|
|
*/
|
|
func CheckDic(itemValue interface{}, dicId string, dics []map[string]interface{}) bool {
|
|
flag := false
|
|
for _, v := range dics {
|
|
if v["dic_value"] == itemValue && v["parent_id"] == dicId {
|
|
flag = true
|
|
}
|
|
}
|
|
|
|
return flag
|
|
}
|
|
|
|
// 暂时作废 2020-09-16
|
|
func ValidESDataContentBak(datasourceCode string, dataContent map[string]interface{}) (bool, string) {
|
|
var fails string
|
|
var conditions string
|
|
r := true
|
|
|
|
conditions = " AND datasource_id=" + datasourceCode
|
|
result, _, _, metadatas, _ := DataexDAO.GetMetadataResults(conditions)
|
|
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 {
|
|
fails += vv.(string) + mes + " "
|
|
|
|
r = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
fails = strings.TrimRight(fails, " ")
|
|
|
|
return r, fails
|
|
}
|
|
|
|
// 暂时作废 2020-09-18
|
|
func CheckDicBak(dicId string, itemValue interface{}) bool {
|
|
total := DataexDAO.GetJyt2012CountByParentIdAndDicValue(dicId, itemValue.(string))
|
|
if total > 0 {
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
}
|