master
wangshuai 5 years ago
parent 84f878a5cd
commit 007b9d9dfb

@ -6,10 +6,15 @@ import (
"dsDataex/MyService/MySwagger"
"dsDataex/Utils/CommonUtil"
"encoding/json"
"regexp"
"strings"
"time"
)
var dics []map[string]interface{}
const TIME_LAYOUT = "2020/09/14 15:29:10"
type RegexCheck struct {}
/**
* @title ValidESDataContent
@ -102,6 +107,8 @@ func ValidESDataContentItem(dataContentItem map[string]interface{}, itemName str
if dataContentItem != nil {
dicId := dataContentItem["dic_id"].(string)
itemLength := dataContentItem["item_length"].(int64)
itemType := dataContentItem["item_type"].(string)
itemPattern := dataContentItem["item_pattern"].(string)
checkName := dataContentItem["check_name"].(int64)
checkDic := dataContentItem["check_dic"].(int64)
checkType := dataContentItem["check_type"].(int64)
@ -118,14 +125,22 @@ func ValidESDataContentItem(dataContentItem map[string]interface{}, itemName str
return true, "ok", nil
} else if checkDic > 0 { // 校验字典
if CheckDic(itemValue, dicId, dics) == false {
return false, "字典检测不通过", nil
return false, "字典校验不通过", nil
} else {
return true, "ok", nil
}
} else if checkType > 0 { // 校验类型
return true, "ok", nil
if CheckType(itemValue, itemType) == false {
return false, "类型校验不通过", nil
} else {
return true, "ok", nil
}
} else if checkPattern > 0 { // 校验规则
return true, "ok", nil
if CheckPattern(itemValue, itemPattern) == false {
return false, "数据项模式校验不通过", nil
} else {
return true, "ok", nil
}
} else if checkExist > 0 { // 校验必填项
if itemValue == nil {
return false, itemName + "是必填项", nil
@ -136,7 +151,7 @@ func ValidESDataContentItem(dataContentItem map[string]interface{}, itemName str
return true, "ok", nil
}
} else {
return false, "", nil
return false, "校验失败, 缺少dataContentItem", nil
}
}
@ -161,6 +176,128 @@ func CheckDic(itemValue interface{}, dicId string, dics []map[string]interface{}
return flag
}
/**
* @title CheckType
* @Description
* @Author wangshuai
* @Date 2020-09-23
* @Param itemValue interface{}
* @Param itemType string
* @Return bool
*/
func CheckType(itemValue interface{}, itemType string) bool {
flag := false
if itemType == "string" { // 校验是否是字符串
_, ok := itemValue.(string)
if ok {
flag = true
}
} else if itemType == "float" { // 校验是否是浮点数
_, ok := itemValue.(float32)
if ok {
flag = true
}
_, ok1 := itemValue.(float64)
if ok1 {
flag = true
}
} else if itemType == "datetime" { // 校验时间格式是否正确
_, e := time.Parse(TIME_LAYOUT, itemValue.(string))
if e == nil {
flag = true
}
} else if itemType == "text" { // 校验是否是文本
_, ok := itemValue.(string)
if ok {
flag = true
}
}
return flag
}
/**
* @title CheckPattern
* @Description
* @Author wangshuai
* @Date 2020-09-23
* @Param itemValue interface{}
* @Param itemPattern string
* @Return bool
*/
func CheckPattern(itemValue interface{}, itemPattern string) bool {
flag := false
if itemPattern == "valid_email" {
if ValidEmail(itemValue.(string)) {
flag = true
}
} else if itemPattern == "valid_mobile" {
if ValidMobile(itemValue.(string)) {
flag = true
}
}
return flag
}
/**
* @title ValidTelephone
* @Description 8
* @Author wangshuai
* @Date 2020-09-23
* @Param str ...string
* @Return bool
*/
func ValidTelephone(str ...string) bool {
var b bool
for _, s := range str {
b, _ = regexp.MatchString("^[0-9]{8}$", s)
if false == b {
return b
}
}
return b
}
/**
* @title ValidMobile
* @Description 11
* @Author wangshuai
* @Date 2020-09-23
* @Param str ...string
* @Return bool
*/
func ValidMobile(str ...string) bool {
var b bool
for _, s := range str {
b, _ = regexp.MatchString("^1[0-9]{10}$", s)
if false == b {
return b
}
}
return b
}
/**
* @title ValidEmail
* @Description 30
* @Author wangshuai
* @Date 2020-09-23
* @Param str ...string
* @Return bool
*/
func ValidEmail(str ...string) bool {
var b bool
for _, s := range str {
b, _ = regexp.MatchString("^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$", s)
if false == b {
return b
}
}
return b
}
// 暂时作废 2020-09-16
func ValidESDataContentBak(datasourceCode string, dataContent map[string]interface{}) (bool, string) {
var fails string

@ -13,7 +13,7 @@ import (
var db = DbUtil.Engine
func GetJyt2012Results(query MySwagger.Jyt2012Query) (bool, string, int, []map[string]interface{}, error) {
sql := "SELECT * FROM t_dataex_jyt2012 WHERE 1 = 1" + query.Conditions + " ORDER BY create_time DESC, change_time DESC"
sql := "SELECT * FROM t_dataex_jyt2012 WHERE 1 = 1" + query.Conditions + " ORDER BY create_time ASC, change_time ASC"
//接收传入参数
var limit = 100
var offset = (query.Page - 1) * limit

Loading…
Cancel
Save