From 007b9d9dfb4547cb416a9b9a7e752353c145668c Mon Sep 17 00:00:00 2001 From: wangshuai Date: Thu, 24 Sep 2020 08:20:52 +0800 Subject: [PATCH] 'commit' --- .../Utils/ValidationUtil/ValidationUtil.go | 145 +++++++++++++++++- .../MyModel/JYT2012/Jyt2012DAO/Jyt2012DAO.go | 2 +- 2 files changed, 142 insertions(+), 5 deletions(-) diff --git a/dsDataex/Utils/ValidationUtil/ValidationUtil.go b/dsDataex/Utils/ValidationUtil/ValidationUtil.go index 3497af51..8cdc6dba 100644 --- a/dsDataex/Utils/ValidationUtil/ValidationUtil.go +++ b/dsDataex/Utils/ValidationUtil/ValidationUtil.go @@ -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 diff --git a/dsSupport/MyModel/JYT2012/Jyt2012DAO/Jyt2012DAO.go b/dsSupport/MyModel/JYT2012/Jyt2012DAO/Jyt2012DAO.go index 41472dc0..00b9733e 100644 --- a/dsSupport/MyModel/JYT2012/Jyt2012DAO/Jyt2012DAO.go +++ b/dsSupport/MyModel/JYT2012/Jyt2012DAO/Jyt2012DAO.go @@ -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