From 2ce86f04d79b361d951e0be912e6437164154d49 Mon Sep 17 00:00:00 2001 From: herenshan112 Date: Wed, 13 Dec 2023 10:45:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E9=94=AE=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/version1/customerform/form.go | 6 +- api/version1/customerform/formTable.go | 2 + api/version1/publicapi/api.go | 453 ++++++++++++++++++ api/version1/publicapi/type.go | 31 ++ .../taskplatform/taskmanagement/appform.go | 17 +- apirouter/apishiyan/maptostruct.go | 1 + apirouter/v1/public/router.go | 3 + config/configNosql/redis.go | 58 ++- initialization/nosql/redis.go | 2 + initialization/route/initRoute.go | 7 +- middleware/grocerystore/redis.go | 2 +- overall/appConfig.go | 14 +- overall/publicmethod/technique.go | 41 ++ 13 files changed, 607 insertions(+), 30 deletions(-) diff --git a/api/version1/customerform/form.go b/api/version1/customerform/form.go index 02b26bf..db6d894 100644 --- a/api/version1/customerform/form.go +++ b/api/version1/customerform/form.go @@ -7,6 +7,7 @@ import ( "appPlatform/overall/publicmethod" "encoding/json" "fmt" + "reflect" "strconv" "strings" "time" @@ -525,6 +526,7 @@ func (c *CustomerFormMaster) DisassembleForm() (relevance string, err error) { sunFormNameAry := publicmethod.MapOut[string]() sunForm := publicmethod.MapOut[string]() for _, v := range c.List { + fmt.Printf("类只能怪--->%v\n", v.Type) switch v.Type { // case "title": // fmt.Printf("type:%v <===========>label:%v <===========> Name:%v <===========> ModelValue:%v\n", v.Type, v.Control, v.Name, v.Control.ModelValue) @@ -574,7 +576,7 @@ func (c *CustomerFormMaster) DisassembleForm() (relevance string, err error) { case "rate", "inputNumber", "slider", "switch": // sqlStr = fmt.Sprintf("%v %v COMMENT '%v'", sqlStr, ControlJudge(lv.Type, lv.Control), lv.Item.Label) masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v COMMENT '%v'", c.Form.Name, v.Name, ControlJudge(v.Type, v.Control), v.Item.Label)) - case "tinymce": + case "tinymce", "signaturemap": // sqlStr = fmt.Sprintf("%v longtext COMMENT '%v'", sqlStr, lv.Item.Label) masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` longtext COMMENT '%v'", c.Form.Name, v.Name, v.Item.Label)) default: @@ -625,7 +627,7 @@ func (c *CustomerFormMaster) DisassembleForm() (relevance string, err error) { # */ func CreateFormFiled(formName, formNotes string, isMasters bool, sqlList interface{}) { - // fmt.Printf("函数类型----%v---%T\n", reflect.TypeOf(sqlList), sqlList) + fmt.Printf("函数类型----%v---%T\n", reflect.TypeOf(sqlList), sqlList) if sql, isOk := sqlList.([]string); isOk { for k, v := range sql { diff --git a/api/version1/customerform/formTable.go b/api/version1/customerform/formTable.go index 814834c..aec6f62 100644 --- a/api/version1/customerform/formTable.go +++ b/api/version1/customerform/formTable.go @@ -149,6 +149,8 @@ func AnalysisFormUnitClass(subUnit MasterStruct) (fieldCont AnalysisFormSubUnitC case "textarea", "tinymce": //多行文本,富文本 fieldCont.FieldType = "mediumtext" + case "signaturemap": + fieldCont.FieldType = "longtext" case "radio": //单选框组 if subUnit.Config.TransformData == "number" || subUnit.Config.TransformData == "" { var fieldVal string diff --git a/api/version1/publicapi/api.go b/api/version1/publicapi/api.go index d674cf6..af4d262 100644 --- a/api/version1/publicapi/api.go +++ b/api/version1/publicapi/api.go @@ -2,6 +2,7 @@ package publicapi import ( "appPlatform/middleware/grocerystore" + "appPlatform/models/modelshr" "appPlatform/overall" "appPlatform/overall/publicmethod" "fmt" @@ -11,6 +12,7 @@ import ( "unicode" "github.com/gin-gonic/gin" + "github.com/mitchellh/mapstructure" "github.com/mozillazg/go-pinyin" ) @@ -254,3 +256,454 @@ func (a *ApiMethod) CreateOneClickLogin(c *gin.Context) { publicmethod.Result(0, urlStr, c) } + +/* +* +@ 作者: 秦东 +@ 时间: 2023-12-05 15:34:23 +@ 功能: 获取带规则编号 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) GainNumber(c *gin.Context) { + var requestData GainRulsNumner + c.ShouldBindJSON(&requestData) + uuid := strconv.FormatInt(publicmethod.GetUUid(1), 10) + // fmt.Printf("uuidAry---->%v\n", uuid) + if requestData.Automatic { + uuid = requestData.GainUniqueNumber(uuid) + } + + publicmethod.Result(0, uuid, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-12-06 10:39:13 +@ 功能: 获取唯一编号 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (g *GainRulsNumner) GainUniqueNumber(uuid string) string { + var uuidAry []string + if len(g.CustomRules) > 0 { + for _, v := range g.CustomRules { + switch v.Types { + case "text": + uuidAry = append(uuidAry, v.Rule) + case "randomnumber": + maxNum, maxerr := strconv.Atoi(v.Rule) + // fmt.Printf("maxNum---->%v---->%v\n", maxNum, maxerr) + if maxerr != nil { + randNum := publicmethod.GetRandNumber(6) + uuidAry = append(uuidAry, strconv.FormatInt(randNum, 10)) + } else { + randNum := publicmethod.GetRandNumber(maxNum) + uuidAry = append(uuidAry, strconv.FormatInt(randNum, 10)) + } + case "time": + uuidAry = append(uuidAry, JudgeYearType(v.Rule)) + case "serialnumber": + redisClient := grocerystore.RunRedis(overall.CONSTANT_Cluster) + if g.TableKey == "" { + redisKey := fmt.Sprintf("GetEncoding:AppPlatform:Key_Currency_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias) + numAry, numErr := redisClient.Lrange(redisKey, 0, -1) + if numErr != nil { + redisClient.Rpush(redisKey, v.Rule) + uuidAry = append(uuidAry, v.Rule) + } else { + if len(numAry) < 1 { + redisClient.Rpush(redisKey, v.Rule) + uuidAry = append(uuidAry, v.Rule) + } else { + var numFlow JudgeInStringAry + numFlow.Str = v.Rule + numFlow.StrAry = numAry + jieguo := numFlow.GainNotInStr() + redisClient.Rpush(redisKey, jieguo) + uuidAry = append(uuidAry, jieguo) + } + } + + } else { + redisKey := fmt.Sprintf("GetEncoding:AppPlatform:Key_Currency_%v_%v", g.TableKey, overall.CONSTANT_CONFIG.RedisPrefixStr.Alias) + numAry, _ := redisClient.Lrange(redisKey, 0, -1) + var count int64 + err := overall.CONSTANT_DB_CustomerForm.Table(g.TableKey).Count(&count).Error + if err != nil { + var numFlow JudgeInStringAry + numFlow.Str = v.Rule + numFlow.StrAry = numAry + jieguo := numFlow.GainNotInStr() + redisClient.Rpush(redisKey, jieguo) + uuidAry = append(uuidAry, jieguo) + } else { + count = count + 1 + var numFlow JudgeInStringAry + numFlow.Str = strconv.FormatInt(count, 10) + numFlow.StrAry = numAry + jieguo := numFlow.GainNotInStr() + redisClient.Rpush(redisKey, jieguo) + uuidAry = append(uuidAry, jieguo) + } + } + default: + } + } + // fmt.Printf("uuidAry-->%v\n", uuidAry) + if len(uuidAry) > 0 { + uuid = strings.Join(uuidAry, "-") + redisClient := grocerystore.RunRedis(overall.CONSTANT_Cluster) + redisKey := fmt.Sprintf("GetEncoding:AppPlatform:NumKey_Currency_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias) + if g.TableKey != "" { + redisKey = fmt.Sprintf("GetEncoding:AppPlatform:NumKey_Currency_%v_%v", g.TableKey, overall.CONSTANT_CONFIG.RedisPrefixStr.Alias) + } + numAry, _ := redisClient.Lrange(redisKey, 0, -1) + if len(numAry) > 0 { + if !publicmethod.IsInTrue[string](uuid, numAry) { + redisClient.Rpush(redisKey, uuid) + return uuid + } + } else { + redisClient.Rpush(redisKey, uuid) + return uuid + } + } + g.GainUniqueNumber(uuid) + } + return uuid +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-12-06 10:28:01 +@ 功能: 获取一个不存在的字符串 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (j *JudgeInStringAry) GainNotInStr() string { + zhi, _ := strconv.ParseInt(j.Str, 10, 64) + if !publicmethod.IsInTrue[string](j.Str, j.StrAry) { + return j.Str + } + zhi++ + j.Str = strconv.FormatInt(zhi, 10) + return j.GainNotInStr() +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-12-05 16:27:20 +@ 功能: 判定随机字符串年格式 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func JudgeYearType(yearClass string) (timeStr string) { + yearClassBig := strings.ToUpper(yearClass) + curraytime := time.Now().Unix() + switch yearClassBig { + case "YYYYMMDD": + timeStr = publicmethod.UnixTimeToDay(curraytime, 20) + case "YYYYMMD": + timeStr = publicmethod.UnixTimeToDay(curraytime, 28) + case "YYYYMD": + timeStr = publicmethod.UnixTimeToDay(curraytime, 29) + case "YYMD": + timeStr = publicmethod.UnixTimeToDay(curraytime, 30) + case "YYYYMM": + timeStr = publicmethod.UnixTimeToDay(curraytime, 21) + case "YYYYM": + timeStr = publicmethod.UnixTimeToDay(curraytime, 31) + case "YYYY": + timeStr = publicmethod.UnixTimeToDay(curraytime, 16) + case "YY": + timeStr = publicmethod.UnixTimeToDay(curraytime, 32) + case "YMD": + timeStr = publicmethod.UnixTimeToDay(curraytime, 33) + case "YM": + timeStr = publicmethod.UnixTimeToDay(curraytime, 34) + case "Y": + timeStr = publicmethod.UnixTimeToDay(curraytime, 16) + case "MMDD": + timeStr = publicmethod.UnixTimeToDay(curraytime, 35) + case "MMD": + timeStr = publicmethod.UnixTimeToDay(curraytime, 36) + case "MD": + timeStr = publicmethod.UnixTimeToDay(curraytime, 37) + case "M": + timeStr = publicmethod.UnixTimeToDay(curraytime, 38) + case "MM": + timeStr = publicmethod.UnixTimeToDay(curraytime, 17) + case "DD": + timeStr = publicmethod.UnixTimeToDay(curraytime, 18) + case "D": + timeStr = publicmethod.UnixTimeToDay(curraytime, 39) + default: + timeStr = publicmethod.UnixTimeToDay(curraytime, 20) + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-12-13 07:57:27 +@ 功能: 一键登录授权 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) ObtainToken(c *gin.Context) { + ContentType := c.Request.Header.Get("Content-Type") + Origin := c.Request.Header.Get("Origin") + userAgent := c.Request.Header.Get("User-Agent") + var requestData gainAuthorize + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.UserNumber == "" || requestData.Password == "" { + publicmethod.Result(101, err, c) + return + } + + if ContentType == "" || userAgent == "" || Origin == "" { + publicmethod.Result(100, err, c) + return + } + var pwdMd5Cont publicmethod.Md5Encryption + pwdMd5Cont.Md5EncryptionInit(requestData.Password) + pwdStr := pwdMd5Cont.Md5EncryptionAlgorithm() + //验证账号 + var empCont modelshr.EmpowerUser + err = empCont.GetCont(map[string]interface{}{"userkey": requestData.UserNumber, "password": pwdStr}, "verification_code") + if err != nil { + publicmethod.Result(2000, err, c) + return + } + //获取雪花随机数 + uuid := publicmethod.GetUUid(6) + uuidStr := strconv.FormatInt(uuid, 10) + var uuidMd5 publicmethod.Md5Encryption + uuidMd5.Md5EncryptionInit(uuidStr) + if empCont.VerificationCode != "" { + uuidMd5.AppKey = empCont.VerificationCode + } + uuidMd5Str := uuidMd5.Md5EncryptionAlgorithm() + //头文件加密 + //Content-Type + var ContentTypeMd5 publicmethod.Md5Encryption + ContentTypeMd5.Md5EncryptionInit(ContentType) + if empCont.VerificationCode != "" { + ContentTypeMd5.AppKey = empCont.VerificationCode + } + ContentTypeMd5Str := ContentTypeMd5.Md5EncryptionAlgorithm() + //Origin + var OriginMd5 publicmethod.Md5Encryption + OriginMd5.Md5EncryptionInit(Origin) + if empCont.VerificationCode != "" { + OriginMd5.AppKey = empCont.VerificationCode + } + OriginMd5Str := OriginMd5.Md5EncryptionAlgorithm() + //User-Agent + var userAgentMd5 publicmethod.Md5Encryption + userAgentMd5.Md5EncryptionInit(userAgent) + if empCont.VerificationCode != "" { + userAgentMd5.AppKey = empCont.VerificationCode + } + userAgentMd5Str := userAgentMd5.Md5EncryptionAlgorithm() + + tokenRedisKey := fmt.Sprintf("%v-%v-%v-%v-%v-%v", ContentTypeMd5Str, OriginMd5Str, userAgentMd5Str, uuidMd5Str, requestData.UserNumber, pwdStr) + + var tokenMd5 publicmethod.Md5Encryption + tokenMd5.Md5EncryptionInit(tokenRedisKey) + if empCont.VerificationCode != "" { + tokenMd5.AppKey = empCont.VerificationCode + } + tokenMd5Str := tokenMd5.Md5EncryptionAlgorithm() + + //redis键 + redisKey := fmt.Sprintf("Authentication:PasswordFreeLogin:key_%v", tokenMd5Str) + //哈希值 + redisCont := publicmethod.MapOut[string]() + redisCont["number"] = uuidStr + redisCont["userkey"] = requestData.UserNumber + redisCont["password"] = pwdStr + //将信息写入哈希 + redisClient := grocerystore.RunRedis(overall.CONSTANT_Cluster) + redisClient.SetRedisTime(10800) + isTrue := redisClient.HashMsetAdd(redisKey, redisCont) + if !isTrue { + publicmethod.Result(1, overall.CONSTANT_Cluster, c, "授权失败!") + return + } + //输出内容 + sendCont := publicmethod.MapOut[string]() + sendCont["number"] = uuidStr + sendCont["token"] = tokenMd5Str + sendCont["isTrue"] = isTrue + publicmethod.Result(0, sendCont, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-12-13 09:00:45 +@ 功能: 验证一键登录者身份 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) VerifyIdentity(c *gin.Context) { + contentType := c.Request.Header.Get("Content-Type") + origin := c.Request.Header.Get("Origin") + userAgent := c.Request.Header.Get("User-Agent") + token := c.Query("token") + number := c.Query("number") + timeStr := c.Query("time") + if contentType == "" || userAgent == "" || origin == "" || token == "" || number == "" || timeStr == "" { + publicmethod.Result(100, contentType, c) + return + } + // currTime := time.Now().Unix() + // queryTimeInt, _ := strconv.ParseInt(timeStr, 10, 64) + // if (currTime - queryTimeInt) > 30 { + // publicmethod.Result(1, timeStr, c, "授权超时") + // return + // } + //redis键 + redisKey := fmt.Sprintf("Authentication:PasswordFreeLogin:key_%v", token) + redisClient := grocerystore.RunRedis(overall.CONSTANT_Cluster) + tokenInfo, isTrue := redisClient.HashGetAll(redisKey) + if isTrue != true { + publicmethod.Result(1, redisKey, c, "token错误") + return + } + var validator ValidatorType + err := mapstructure.Decode(tokenInfo, &validator) + if err != nil { + publicmethod.Result(1, err, c, "对不起!身份验证失败!") + return + } + //验证账号 + var empCont modelshr.EmpowerUser + err = empCont.GetCont(map[string]interface{}{"userkey": validator.UserKey, "password": validator.PassWord}, "verification_code") + if err != nil { + publicmethod.Result(1, err, c, "对不起!身份验证失败!") + return + } + //头文件加密 + //Content-Type + var contentTypeMd5 publicmethod.Md5Encryption + contentTypeMd5.Md5EncryptionInit(contentType) + if empCont.VerificationCode != "" { + contentTypeMd5.AppKey = empCont.VerificationCode + } + contentTypeMd5Str := contentTypeMd5.Md5EncryptionAlgorithm() + //Origin + var originMd5 publicmethod.Md5Encryption + originMd5.Md5EncryptionInit(origin) + if empCont.VerificationCode != "" { + originMd5.AppKey = empCont.VerificationCode + } + originMd5Str := originMd5.Md5EncryptionAlgorithm() + //User-Agent + var userAgentMd5 publicmethod.Md5Encryption + userAgentMd5.Md5EncryptionInit(userAgent) + if empCont.VerificationCode != "" { + userAgentMd5.AppKey = empCont.VerificationCode + } + userAgentMd5Str := userAgentMd5.Md5EncryptionAlgorithm() + + var uuidMd5 publicmethod.Md5Encryption + uuidMd5.Md5EncryptionInit(validator.Number) + if empCont.VerificationCode != "" { + uuidMd5.AppKey = empCont.VerificationCode + } + uuidMd5Str := uuidMd5.Md5EncryptionAlgorithm() + + tokenRedisKey := fmt.Sprintf("%v-%v-%v-%v-%v-%v", contentTypeMd5Str, originMd5Str, userAgentMd5Str, uuidMd5Str, validator.UserKey, validator.PassWord) + var tokenMd5 publicmethod.Md5Encryption + tokenMd5.Md5EncryptionInit(tokenRedisKey) + if empCont.VerificationCode != "" { + tokenMd5.AppKey = empCont.VerificationCode + } + tokenMd5Str := tokenMd5.Md5EncryptionAlgorithm() + //系统验证系数 + systemKey := fmt.Sprintf("%v-%v", tokenMd5Str, uuidMd5Str) + var systemKeyMd5 publicmethod.Md5Encryption + systemKeyMd5.Md5EncryptionInit(systemKey) + if empCont.VerificationCode != "" { + systemKeyMd5.AppKey = empCont.VerificationCode + } + systemKeyMd5Str := systemKeyMd5.Md5EncryptionAlgorithm() + //接收系数 + receiveKey := fmt.Sprintf("%v-%v", token, number) + var receiveKeyMd5 publicmethod.Md5Encryption + receiveKeyMd5.Md5EncryptionInit(receiveKey) + if empCont.VerificationCode != "" { + receiveKeyMd5.AppKey = empCont.VerificationCode + } + receiveKeyMd5Str := receiveKeyMd5.Md5EncryptionAlgorithm() + if systemKeyMd5Str != receiveKeyMd5Str { + publicmethod.Result(1, err, c, "对不起!身份验证失败!") + return + } + publicmethod.Result(0, err, c) +} diff --git a/api/version1/publicapi/type.go b/api/version1/publicapi/type.go index 4bf016d..6a92c96 100644 --- a/api/version1/publicapi/type.go +++ b/api/version1/publicapi/type.go @@ -32,3 +32,34 @@ type HanziToPinyin struct { type SendUrl struct { UrlStr string `json:"url"` } + +// 生成编号 +type GainRulsNumner struct { + TableKey string `json:"table"` //表单识别符 + Automatic bool `json:"automatic"` //true 自动,false:手动 + CustomRules []CustomRulesInfo `json:"customRules"` //规则 +} + +// 生成编号规则 +type CustomRulesInfo struct { + Types string `json:"type"` //类型 + Rule string `json:"rule"` //值 +} + +type JudgeInStringAry struct { + Str string + StrAry []string +} + +// 授权 +type gainAuthorize struct { + UserNumber string `json:"username"` + Password string `json:"password"` +} + +// 验证器结构 +type ValidatorType struct { + Number string `json:"number"` //随机数 + UserKey string `json:"userkey"` //用户名 + PassWord string `json:"password"` //密码 +} diff --git a/api/version1/taskplatform/taskmanagement/appform.go b/api/version1/taskplatform/taskmanagement/appform.go index cd46685..f30e2ca 100644 --- a/api/version1/taskplatform/taskmanagement/appform.go +++ b/api/version1/taskplatform/taskmanagement/appform.go @@ -1150,16 +1150,19 @@ func (a *ApiMethod) NewCustomerFormEditData(c *gin.Context) { return } - if _, ok := mapData["formKey"]; !ok { - publicmethod.Result(1, err, c, "非法表单!不能提交数据!") - return - } - if _, ok := mapData["formId"]; !ok { + if _, ok := mapData["flowKey"]; !ok { publicmethod.Result(1, err, c, "非法表单!不能提交数据!") return } + // if _, ok := mapData["formId"]; !ok { + // publicmethod.Result(1, err, c, "非法表单!2不能提交数据!") + // return + // } + var runFlowCont modelAppPlatform.Task + runFlowCont.GetCont(map[string]interface{}{"`masters_key`": mapData["flowKey"]}) + var formCont modelAppPlatform.CustomerFormView //获取指定版本的表单 - err = formCont.GetCont(map[string]interface{}{"`id`": mapData["formId"]}) + err = formCont.GetCont(map[string]interface{}{"`id`": runFlowCont.VersionId}) if err != nil { publicmethod.Result(107, err, c) return @@ -1202,7 +1205,7 @@ func (a *ApiMethod) NewCustomerFormEditData(c *gin.Context) { for _, v := range formUnitCont.MasterInfo { masterUnitList[v.Name] = v } - uuid, _ := strconv.ParseInt(mapData["formKey"].(string), 10, 64) + uuid, _ := strconv.ParseInt(mapData["flowKey"].(string), 10, 64) masrWriteMap := MakeFormMapData(uuid, userCont.Key, cureeTime, masterField, masterUnitList, 2) //判断是否 diff --git a/apirouter/apishiyan/maptostruct.go b/apirouter/apishiyan/maptostruct.go index 72cef24..dfb7997 100644 --- a/apirouter/apishiyan/maptostruct.go +++ b/apirouter/apishiyan/maptostruct.go @@ -35,6 +35,7 @@ func (a *ApiRouter) RouterGroup(router *gin.RouterGroup) { apiRouter.POST("genJuIdNumber", methodBinding.GenJuIdNumber) //根据身份证号获取生日和年龄 apiRouter.POST("createFlowChart", methodBinding.CreateFlowChart) //实验流程图生成 + } } func (a *ApiRouter) RouterGroupVerify(router *gin.RouterGroup) { diff --git a/apirouter/v1/public/router.go b/apirouter/v1/public/router.go index 12701c9..f0eef8b 100644 --- a/apirouter/v1/public/router.go +++ b/apirouter/v1/public/router.go @@ -20,5 +20,8 @@ func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { apiRouter.POST("chinese_to_pinyin", methodBinding.ChineseToPinyin) //中文转拼音 apiRouter.POST("create_one_click_login", methodBinding.CreateOneClickLogin) //生成一键登录地址 + apiRouter.POST("gainNumber", methodBinding.GainNumber) //获取带规则编号 + apiRouter.POST("obtainToken", methodBinding.ObtainToken) //一键登录授权 + apiRouter.GET("verifyIdentity", methodBinding.VerifyIdentity) //验证身份登录 } } diff --git a/config/configNosql/redis.go b/config/configNosql/redis.go index b93ab50..a2da20f 100644 --- a/config/configNosql/redis.go +++ b/config/configNosql/redis.go @@ -8,19 +8,21 @@ import ( ) type RedisSetUp struct { - MasterRedis RedisConfitSetUp `mapstructure:"master" json:"master" yaml:"master"` //主数据库 - MasterRedis1 RedisConfitSetUp `mapstructure:"master1" json:"master1" yaml:"master1"` //主数据库 - MasterRedis2 RedisConfitSetUp `mapstructure:"master2" json:"master1" yaml:"master2"` //主数据库 - MasterRedis3 RedisConfitSetUp `mapstructure:"master3" json:"master1" yaml:"master3"` //主数据库 - MasterRedis4 RedisConfitSetUp `mapstructure:"master4" json:"master1" yaml:"master4"` //主数据库 - MasterRedis5 RedisConfitSetUp `mapstructure:"master5" json:"master1" yaml:"master5"` //主数据库 + MasterRedis RedisConfitSetUp `mapstructure:"master" json:"master" yaml:"master"` //主数据库 + MasterRedis1 RedisConfitSetUp `mapstructure:"master1" json:"master1" yaml:"master1"` //主数据库 + MasterRedis2 RedisConfitSetUp `mapstructure:"master2" json:"master2" yaml:"master2"` //主数据库 + MasterRedis3 RedisConfitSetUp `mapstructure:"master3" json:"master3" yaml:"master3"` //主数据库 + MasterRedis4 RedisConfitSetUp `mapstructure:"master4" json:"master4" yaml:"master4"` //主数据库 + MasterRedis5 RedisConfitSetUp `mapstructure:"master5" json:"master5" yaml:"master5"` //主数据库 + RedisCluster RedisConfitSetUp `mapstructure:"redisCluster" json:"redisCluster" yaml:"redisCluster"` //内网集群 } type RedisConfitSetUp struct { - UrlPath string `mapstructure:"url_path" json:"url_path" yaml:"url_path"` // 服务器地址 - Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口 - Name int `mapstructure:"name" json:"name" yaml:"name"` // 数据库名称 - PassWord string `mapstructure:"password" json:"password" yaml:"password"` // 密码 + UrlPath string `mapstructure:"url_path" json:"url_path" yaml:"url_path"` // 服务器地址 + Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口 + Name int `mapstructure:"name" json:"name" yaml:"name"` // 数据库名称 + PassWord string `mapstructure:"password" json:"password" yaml:"password"` // 密码 + UrlPathList []string `mapstructure:"url_path_list" json:"url_path_list"` } func (r *RedisConfitSetUp) OpenRedis() *redis.Client { @@ -35,7 +37,41 @@ func (r *RedisConfitSetUp) OpenRedis() *redis.Client { if err != nil { fmt.Printf("%v Redis链接失败!原因:%v\n", r.Name, err) } else { - fmt.Printf("%v Redis链接成功!=====>%v\n", r.Name, pingLink) + fmt.Printf("%v Redis链接成功!==%v===>%v\n", r.Name, r.UrlPath, pingLink) + } + return redisClient +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-12-13 10:12:38 +@ 功能: 链接redis集群 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (r *RedisConfitSetUp) OpenRedisColony() *redis.ClusterClient { + fmt.Printf("开启%v Redis库 %v\n", r.UrlPathList, r.Name) + redisClient := redis.NewClusterClient(&redis.ClusterOptions{ + Addrs: []string{"172.20.5.34:6379", "172.20.5.30:6379", "172.20.5.31:6379"}, + Password: r.PassWord, + RouteRandomly: true, + // DB: r.Name, + }) + pingLink, err := redisClient.Ping(context.Background()).Result() + if err != nil { + fmt.Printf("%v Redis链接失败!原因:%v\n", r.Name, err) + } else { + fmt.Printf("%v Redis链接成功!==%v===>%v\n", r.Name, r.UrlPath, pingLink) } return redisClient } diff --git a/initialization/nosql/redis.go b/initialization/nosql/redis.go index be52125..f972fb2 100644 --- a/initialization/nosql/redis.go +++ b/initialization/nosql/redis.go @@ -16,4 +16,6 @@ func LoadRedis() { overall.CONSTANT_REDIS3 = redisConfig.MasterRedis3.OpenRedis() overall.CONSTANT_REDIS4 = redisConfig.MasterRedis4.OpenRedis() overall.CONSTANT_REDIS5 = redisConfig.MasterRedis5.OpenRedis() + overall.CONSTANT_Cluster = redisConfig.RedisCluster.OpenRedis() + overall.CONSTANT_ClusterClient = redisConfig.RedisCluster.OpenRedisColony() } diff --git a/initialization/route/initRoute.go b/initialization/route/initRoute.go index bf2183f..3a23580 100644 --- a/initialization/route/initRoute.go +++ b/initialization/route/initRoute.go @@ -38,6 +38,9 @@ func InitialRouter() *gin.Engine { { signCodeApi.RouterGroup(appLoadRouterGroup) } + //公共函数 + publicRouterApi := apirouter.RouterGroupEntry.PublicRouters + publicRouterApi.RouterGroupPc(appLoadRouterGroup) } //验证身份接口 鉴权Url(主要应用端使用) @@ -61,9 +64,7 @@ func InitialRouter() *gin.Engine { //权限矩阵 matrixRouterApi := apirouter.RouterGroupEntry.MatrixApiRouter matrixRouterApi.RouterGroupPc(VerifyIdentity) - //公共函数 - publicRouterApi := apirouter.RouterGroupEntry.PublicRouters - publicRouterApi.RouterGroupPc(VerifyIdentity) + //自定义表单 customerFormRouterApi := apirouter.RouterGroupEntry.CustomerFormRouter customerFormRouterApi.RouterGroupPc(VerifyIdentity) diff --git a/middleware/grocerystore/redis.go b/middleware/grocerystore/redis.go index e382da5..3f32e95 100644 --- a/middleware/grocerystore/redis.go +++ b/middleware/grocerystore/redis.go @@ -109,7 +109,7 @@ func (r *RedisStoreType) HashSet(hashName, hashKey, hashVal string) bool { func (r *RedisStoreType) HashMsetAdd(hashName string, hashVal map[string]interface{}) bool { // rdb := RedisInit() err := r.RedisDb.HMSet(r.Context, r.PreKey+hashName, hashVal).Err() - // fmt.Printf("错误sss=========》%v=====2====》%v\n", err, hashVal) + fmt.Printf("错误sss=========》%v=====2====》%v\n", err, hashVal) // err := rdb.HMSet(ctx, "userfg", hashVal).Err() if err != nil { return false diff --git a/overall/appConfig.go b/overall/appConfig.go index c9338e1..c4afcd6 100644 --- a/overall/appConfig.go +++ b/overall/appConfig.go @@ -49,10 +49,12 @@ var ( CONSTANT_DB_Server *gorm.DB //线上数据库 CONSTANT_DB_Tidb *gorm.DB //私有云数据库 //Redis - CONSTANT_REDIS0 *redis.Client - CONSTANT_REDIS1 *redis.Client - CONSTANT_REDIS2 *redis.Client - CONSTANT_REDIS3 *redis.Client - CONSTANT_REDIS4 *redis.Client - CONSTANT_REDIS5 *redis.Client + CONSTANT_REDIS0 *redis.Client + CONSTANT_REDIS1 *redis.Client + CONSTANT_REDIS2 *redis.Client + CONSTANT_REDIS3 *redis.Client + CONSTANT_REDIS4 *redis.Client + CONSTANT_REDIS5 *redis.Client + CONSTANT_Cluster *redis.Client + CONSTANT_ClusterClient *redis.ClusterClient ) diff --git a/overall/publicmethod/technique.go b/overall/publicmethod/technique.go index a08a809..07b7bb5 100644 --- a/overall/publicmethod/technique.go +++ b/overall/publicmethod/technique.go @@ -77,6 +77,23 @@ func GetUUid(workId int64) (uuId int64) { return } +// 获取随机数 +func GetRandNumber(max int) (num int64) { + maxVal := int64(math.Pow10(max)) - 1 + minVal := int64(math.Pow10(max - 1)) + + // fmt.Printf("max:%v\nmaxVal:%v\nminVal:%v\n", max, maxVal, minVal) + if maxVal < 1 { + maxVal = 9 + } + if minVal < 1 { + minVal = 1 + } + result, _ := rand.Int(rand.Reader, big.NewInt(int64(maxVal))) + num = result.Int64() + int64(minVal) + return +} + // 初始化map(泛型) func MapOut[T GenericityVariable]() (data map[T]interface{}) { data = make(map[T]interface{}) //必可不少,分配内存 @@ -175,6 +192,30 @@ func UnixTimeToDay(timeStamp int64, timeType int) (dateStr string) { timeTemplate = "01.02" case 27: timeTemplate = "2006.01.02 15:04:05" + case 28: + timeTemplate = "2006012" + case 29: + timeTemplate = "200612" + case 30: + timeTemplate = "0612" + case 31: + timeTemplate = "20061" + case 32: + timeTemplate = "06" + case 33: + timeTemplate = "0612" + case 34: + timeTemplate = "061" + case 35: + timeTemplate = "0102" + case 36: + timeTemplate = "012" + case 37: + timeTemplate = "12" + case 38: + timeTemplate = "1" + case 39: + timeTemplate = "2" default: timeTemplate = "2006-01-02 15:04:05" //常规类型 }