Browse Source

更改Redis插件版本,由v8切换到v9

li_v1
超级管理员 2 years ago
parent
commit
95d68a08f6
  1. 27
      api/version1/datamanagement/redisController/redis.go
  2. 7
      api/version1/datamanagement/redisController/runredis.go
  3. 454
      api/version1/publicapi/api.go
  4. 24
      api/version1/publicapi/type.go
  5. 1
      apirouter/v1/public/router.go
  6. 1
      config/configDatabase/database.go
  7. 10
      config/configNosql/redis.go
  8. 28
      config/configNosql/redisv9.go
  9. 74
      go.mod
  10. 1197
      go.sum
  11. 1
      initialization/databaseinit/mysql.go
  12. 1
      initialization/initviper/init_viper.go
  13. 5
      initialization/route/initRoute.go
  14. 15
      middleware/grocerystore/redis.go
  15. 414
      middleware/grocerystore/redisclan.go
  16. 3
      overall/appConfig.go
  17. 1
      overall/appConfigRedis.go
  18. 5
      overall/database.go

27
api/version1/datamanagement/redisController/redis.go

@ -5,10 +5,9 @@ import (
"context"
"fmt"
"sort"
"strconv"
"github.com/gin-gonic/gin"
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
)
/*
@ -74,12 +73,13 @@ func (a *ApiMethod) TestRedisLink(c *gin.Context) {
sendInfo.DbNumber = 16
if len(redisCont) == 2 {
for k, v := range redisCont {
if k == 1 {
if val, isOk := v.(string); isOk {
sendInfo.DbNumber, _ = strconv.Atoi(val)
}
fmt.Printf("%v: %v\n", k, v)
// if k == 1 {
// if val, isOk := v.(string); isOk {
// sendInfo.DbNumber, _ = strconv.Atoi(val)
// }
}
// }
}
}
}
@ -126,12 +126,13 @@ func GainRedisDbNumber(redisDb *redis.Client) (dbNumber int) {
dbNumber = 16
if len(redisCont) == 2 {
for k, v := range redisCont {
if k == 1 {
if val, isOk := v.(string); isOk {
dbNumber, _ = strconv.Atoi(val)
}
fmt.Printf("%v: %v\n", k, v)
// if k == 1 {
// if val, isOk := v.(string); isOk {
// dbNumber, _ = strconv.Atoi(val)
// }
}
// }
}
}
}
@ -188,7 +189,7 @@ func (c *CountRedisKeyNumber) TallyRedisKeys(ip, pwd string, port, dbId int) {
@ 返回值
#
#156 6201 6190
@ 方法原型

7
api/version1/datamanagement/redisController/runredis.go

@ -6,7 +6,7 @@ import (
"fmt"
"time"
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
)
type RedisStoreType struct {
@ -40,7 +40,8 @@ func (r *RedisStoreType) SetRedisTimes(timeDate time.Duration) {
}
// 获取数据库配置
func (r *RedisStoreType) ConfigGet(key string) ([]interface{}, error) {
// func (r *RedisStoreType) ConfigGet(key string) (interface{}, error) {
func (r *RedisStoreType) ConfigGet(key string) (map[string]string, error) {
err := r.RedisDb.ConfigGet(r.Context, key)
return err.Val(), err.Err()
}
@ -605,7 +606,7 @@ func (r *RedisStoreType) Zrange(key string, start, stop int64) ([]string, error)
func (r *RedisStoreType) Zadd(key string, val []string) (msg []string) {
if len(val) > 0 {
for _, v := range val {
redisClient := r.RedisDb.ZAdd(r.Context, key, &redis.Z{1, v})
redisClient := r.RedisDb.ZAdd(r.Context, key, redis.Z{1, v})
if redisClient.Err() == nil {
msg = append(msg, fmt.Sprintf("有序集合%v添加%v成功", key, v))
} else {

454
api/version1/publicapi/api.go

@ -3,9 +3,12 @@ package publicapi
import (
"appPlatform/middleware/grocerystore"
"appPlatform/models/modelshr"
"appPlatform/models/modelsschool"
"appPlatform/overall"
"appPlatform/overall/publicmethod"
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"
"time"
@ -515,10 +518,10 @@ func (a *ApiMethod) ObtainToken(c *gin.Context) {
return
}
if ContentType == "" || userAgent == "" || Origin == "" {
publicmethod.Result(100, err, c)
return
}
// if ContentType == "" || userAgent == "" || Origin == "" {
// publicmethod.Result(100, err, c)
// return
// }
var pwdMd5Cont publicmethod.Md5Encryption
pwdMd5Cont.Md5EncryptionInit(requestData.Password)
pwdStr := pwdMd5Cont.Md5EncryptionAlgorithm()
@ -529,6 +532,10 @@ func (a *ApiMethod) ObtainToken(c *gin.Context) {
publicmethod.Result(2000, err, c)
return
}
ContentType = requestData.UserNumber
Origin = pwdStr
userAgent = empCont.VerificationCode
//获取雪花随机数
uuid := publicmethod.GetUUid(6)
uuidStr := strconv.FormatInt(uuid, 10)
@ -578,9 +585,9 @@ func (a *ApiMethod) ObtainToken(c *gin.Context) {
redisCont["userkey"] = requestData.UserNumber
redisCont["password"] = pwdStr
//将信息写入哈希
redisClient := grocerystore.RunRedis(overall.CONSTANT_Cluster)
redisClient := grocerystore.RunRedisClan(overall.CONSTANT_ClusterClient)
redisClient.SetRedisTime(10800)
isTrue := redisClient.HashMsetAdd(redisKey, redisCont)
isTrue := redisClient.HashMsetAddClan(redisKey, redisCont)
if !isTrue {
publicmethod.Result(1, overall.CONSTANT_Cluster, c, "授权失败!")
return
@ -590,6 +597,8 @@ func (a *ApiMethod) ObtainToken(c *gin.Context) {
sendCont["number"] = uuidStr
sendCont["token"] = tokenMd5Str
sendCont["isTrue"] = isTrue
sendCont["tokenRedisKey"] = tokenRedisKey
fmt.Printf("contentType:%v\n", ContentType)
publicmethod.Result(0, sendCont, c)
}
@ -611,14 +620,16 @@ func (a *ApiMethod) ObtainToken(c *gin.Context) {
#
*/
func (a *ApiMethod) VerifyIdentity(c *gin.Context) {
contentType := c.Request.Header.Get("Content-Type")
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")
codeStr := c.Query("code")
timeStr := c.Query("time")
if contentType == "" || userAgent == "" || origin == "" || token == "" || number == "" || timeStr == "" {
publicmethod.Result(100, contentType, c)
openId := c.Query("openid")
if token == "" || number == "" || timeStr == "" || codeStr == "" {
publicmethod.Result(100, ContentType, c)
return
}
// currTime := time.Now().Unix()
@ -629,8 +640,8 @@ func (a *ApiMethod) VerifyIdentity(c *gin.Context) {
// }
//redis键
redisKey := fmt.Sprintf("Authentication:PasswordFreeLogin:key_%v", token)
redisClient := grocerystore.RunRedis(overall.CONSTANT_Cluster)
tokenInfo, isTrue := redisClient.HashGetAll(redisKey)
redisClient := grocerystore.RunRedisClan(overall.CONSTANT_ClusterClient)
tokenInfo, isTrue := redisClient.HashGetAllClan(redisKey)
if isTrue != true {
publicmethod.Result(1, redisKey, c, "token错误")
return
@ -648,14 +659,19 @@ func (a *ApiMethod) VerifyIdentity(c *gin.Context) {
publicmethod.Result(1, err, c, "对不起!身份验证失败!")
return
}
ContentType = validator.UserKey
origin = validator.PassWord
userAgent = empCont.VerificationCode
//头文件加密
//Content-Type
var contentTypeMd5 publicmethod.Md5Encryption
contentTypeMd5.Md5EncryptionInit(contentType)
contentTypeMd5.Md5EncryptionInit(ContentType)
if empCont.VerificationCode != "" {
contentTypeMd5.AppKey = empCont.VerificationCode
}
contentTypeMd5Str := contentTypeMd5.Md5EncryptionAlgorithm()
fmt.Printf("contentType:%v\n", ContentType)
//Origin
var originMd5 publicmethod.Md5Encryption
originMd5.Md5EncryptionInit(origin)
@ -701,9 +717,419 @@ func (a *ApiMethod) VerifyIdentity(c *gin.Context) {
receiveKeyMd5.AppKey = empCont.VerificationCode
}
receiveKeyMd5Str := receiveKeyMd5.Md5EncryptionAlgorithm()
sendData := publicmethod.MapOut[string]()
sendData["systemKeyMd5Str"] = systemKeyMd5Str
sendData["receiveKeyMd5Str"] = receiveKeyMd5Str
sendData["uuidMd5Str"] = uuidMd5Str
sendData["number"] = number
sendData["tokenMd5Str"] = tokenMd5Str
sendData["token"] = token
sendData["tokenRedisKey"] = tokenRedisKey
if systemKeyMd5Str != receiveKeyMd5Str {
publicmethod.Result(1, err, c, "对不起!身份验证失败!")
publicmethod.Result(1, sendData, c, "对不起!身份验证失败!")
return
}
var userCont modelshr.ManCont
err = overall.CONSTANT_DB_HR.Where("`number` = ? AND `emp_type` BETWEEN ? AND ?", codeStr, 1, 10).Find(&userCont).Error
if err != nil {
publicmethod.Result(1, sendData, c, "此账号禁止访问!")
return
}
var md5JiaMi publicmethod.Md5Encryption
md5JiaMi.Md5EncryptionInit(userAgent)
md5Token := md5JiaMi.Md5EncryptionAlgorithm()
var md5JiaMiNumber publicmethod.Md5Encryption
md5JiaMiNumber.Md5EncryptionInit(userCont.Number)
userKeyCode := md5JiaMiNumber.Md5EncryptionAlgorithm()
sha1Str := userKeyCode + userCont.Number + userCont.Password + md5Token
sha1Token := publicmethod.Sha1Encryption(sha1Str)
//返回值
saveData := publicmethod.MapOut[string]()
saveData["key"] = userKeyCode
saveData["token"] = sha1Token
saveData["userinfo"] = userCont
menuoper, jurisdiction := getRoleSeat(userCont.Role)
writeRedisData := map[string]interface{}{
"userkey": userKeyCode,
"key": userCont.Key,
"usernumber": userCont.Number,
"userpwd": userCont.Password,
"usertoken": sha1Token,
"jurisdiction": jurisdiction,
"menuOper": menuoper,
"wand": 118,
}
//API Token数据
redisFileKey := fmt.Sprintf("ScanCode:Authentication:LoginApi_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userKeyCode)
redisClients := grocerystore.RunRedis(overall.CONSTANT_REDIS5)
redisClients.SetRedisTime(10800)
redisClients.HashMsetAdd(redisFileKey, writeRedisData)
_, companyId, _, sunDepartId, _ := publicmethod.GetOrgStructurees(userCont.AdminOrg)
var sunmaindeparment int64
if companyId != sunDepartId {
sunmaindeparment = sunDepartId
}
//缓存写入个人信息
redisMyContKey := fmt.Sprintf("ScanCode:Authentication:UserCont_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userCont.Number)
myCont := publicmethod.MapOut[string]()
myCont["id"] = userCont.Id
myCont["number"] = userCont.Number //员工工号
myCont["name"] = userCont.Name //姓名
myCont["icon"] = userCont.Icon //头像
myCont["hireclass"] = userCont.HireClass //雇佣类型(1:雇佣入职;2:再入职;)
myCont["emptype"] = userCont.EmpType //用工关系(1:临时工 , 2:编外人员 ;3:实习&实习生;4:试用员工;5:待分配;6:待岗;7:临时调入;8:正式员工;9:长期病假;10:停薪留职;11:退休;12:辞职;13:辞退;14:离职)
myCont["company"] = userCont.Company //入职公司
// myCont["maindeparment"] = userCont.MainDeparment //主部门
// myCont["sunmaindeparment"] = userCont.SunMainDeparment //二级主部门
myCont["maindeparment"] = companyId //主部门
myCont["sunmaindeparment"] = sunmaindeparment //二级主部门
myCont["deparment"] = userCont.Deparment //部门
myCont["adminorg"] = userCont.AdminOrg //所属行政组织
myCont["teamid"] = userCont.TeamId //班组
myCont["position"] = userCont.Position //职位
myCont["jobclass"] = userCont.JobClass //职务分类
myCont["jobid"] = userCont.JobId //职务
myCont["jobleve"] = userCont.JobLeve //职务等级
myCont["wechat"] = userCont.Wechat //微信UserId
myCont["workwechat"] = userCont.WorkWechat //企业微信UserId
myCont["state"] = userCont.State //状态(1:启用;2:禁用;3:删除)
myCont["key"] = userCont.Key //key
myCont["isadmin"] = userCont.IsAdmin //是否为管理员(1:不是;2:分公司;3:集团管理员;4:超级管
myCont["password"] = userCont.Password //密码
myCont["role"] = userCont.Role //角色
myCont["idcardno"] = userCont.Idcardno //身份证号
myCont["passportno"] = userCont.Passportno //护照号码
myCont["globalroaming"] = userCont.Globalroaming //国际区号
myCont["mobilephone"] = userCont.Mobilephone //手机号码
myCont["email"] = userCont.Email //电子邮件
myCont["gender"] = userCont.Gender //性别(1:男性;2:女性;3:中性)
myCont["birthday"] = userCont.Birthday //birthday
myCont["myfolk"] = userCont.Myfolk //民族
myCont["nativeplace"] = userCont.Nativeplace //籍贯
myCont["idcardstartdate"] = userCont.Idcardstartdate //身份证有效期开始
myCont["idcardenddate"] = userCont.Idcardenddate //身份证有效期结束
myCont["idcardaddress"] = userCont.Idcardaddress //身份证地址
myCont["idcardIssued"] = userCont.IdcardIssued //身份证签发机关
myCont["health"] = userCont.Health //健康状况(1:良好;2:一般;3:较弱,4:有生理缺陷;5:残废)
myCont["maritalstatus"] = userCont.Maritalstatus //婚姻状况(1:未婚;2:已婚;3:丧偶;4:离异)
myCont["internaltelephone"] = userCont.Internaltelephone //内线电话
myCont["currentresidence"] = userCont.Currentresidence //现居住地址
myCont["constellationing"] = userCont.Constellation //星座(1:白羊座;2:金牛座;3:双子座;4:巨蟹座;5:狮子座;6:处女座;7:天枰座;8:天蝎座;9:射手座;10:摩羯座;11:水瓶座;12:双鱼座)
myCont["isdoubleworker"] = userCont.Isdoubleworker //是否双职工(1:是;2:否)
myCont["isveterans"] = userCont.Isveterans //是否为退役军人(1:是;2:否)
myCont["veteransnumber"] = userCont.Veteransnumber //退役证编号
myCont["jobstartdate"] = userCont.Jobstartdate //参加工作日期
myCont["entrydate"] = userCont.Entrydate //入职日期
myCont["probationperiod"] = userCont.Probationperiod //试用期
myCont["planformaldate"] = userCont.Planformaldate //预计转正日期
myCont["political_outlook"] = userCont.PoliticalOutlook //政治面貌(1:群众;2:无党派;3:台盟会员;4:九三社员;5:致公党员;6:农工党员;7:民进会员;8:民建会员;9:民盟盟员;10:民革会员,11:共青团员;12:预备党员;13:中共党员)
var companyCont modelshr.AdministrativeOrganization
companyCont.GetCont(map[string]interface{}{"`id`": userCont.Company}, "`name`")
myCont["companyname"] = companyCont.Name
var departmentCont modelshr.AdministrativeOrganization
departmentCont.GetCont(map[string]interface{}{"`id`": userCont.MainDeparment}, "`name`")
myCont["maindeparmentname"] = departmentCont.Name
var postInfo modelshr.Position
postInfo.GetCont(map[string]interface{}{"`id`": userCont.Position}, "`name`")
myCont["positionname"] = postInfo.Name
redisClients.HashMsetAdd(redisMyContKey, myCont)
redisClient.HashMsetAddClan(redisMyContKey, myCont)
saveData["usercont"] = myCont
if openId != "" {
var userInfo modelshr.PersonArchives
userInfo.EiteCont(map[string]interface{}{"id": userCont.Id}, map[string]interface{}{"work_wechat": openId})
}
var sendKpiCont WriteIderCont
sendKpiCont.Openid = openId
sendKpiCont.Key = userKeyCode
sendKpiCont.Token = sha1Token
sendKpiCont.UserInfo.Key = strconv.FormatInt(userCont.Key, 10)
sendKpiCont.UserInfo.Number = userCont.Number
sendKpiCont.UserInfo.Password = userCont.Password
sendDate, _ := json.Marshal(sendKpiCont)
publicmethod.CurlPostJosn("http://120.224.6.6:39168/shiyan/write_token", sendDate)
c.Redirect(http.StatusMovedPermanently, "/")
publicmethod.Result(0, saveData, c)
}
// 获取权限点位
func getRoleSeat(roleId string) (menuStr, buttonStr string) {
var roleInfo modelsschool.SystemRole
err := roleInfo.GetCont(map[string]interface{}{"r_id": roleId}, "r_menu_oper", "r_jurisdiction")
if err != nil {
return
}
menuStr = roleInfo.MenuOper
buttonStr = roleInfo.Jurisdiction
return
}
/*
*
@ 作者: 秦东
@ 时间: 2023-12-13 16:09:59
@ 功能: 验证无感登录
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) SilentLogin(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 SilentLoginInfo
err := c.ShouldBindJSON(&requestData)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if requestData.Token == "" || requestData.Number == "" || requestData.Time == "" || requestData.Code == "" {
publicmethod.Result(10001, ContentType, c, "token错误")
return
}
// currTime := time.Now().Unix()
// queryTimeInt, _ := strconv.ParseInt(requestData.Time, 10, 64)
// if (currTime-queryTimeInt) > 30 || (currTime-queryTimeInt) < 0 {
// publicmethod.Result(1, currTime-queryTimeInt, c, "授权超时")
// return
// }
//redis键
redisKey := fmt.Sprintf("Authentication:PasswordFreeLogin:key_%v", requestData.Token)
redisClient := grocerystore.RunRedisClan(overall.CONSTANT_ClusterClient)
tokenInfo, isTrue := redisClient.HashGetAllClan(redisKey)
if isTrue != true {
publicmethod.Result(10001, redisKey, c, "token错误")
return
}
var validator ValidatorType
err = mapstructure.Decode(tokenInfo, &validator)
if err != nil {
publicmethod.Result(10001, 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(10001, err, c, "对不起!身份验证失败!")
return
}
ContentType = validator.UserKey
origin = validator.PassWord
userAgent = empCont.VerificationCode
//头文件加密
//Content-Type
var contentTypeMd5 publicmethod.Md5Encryption
contentTypeMd5.Md5EncryptionInit(ContentType)
if empCont.VerificationCode != "" {
contentTypeMd5.AppKey = empCont.VerificationCode
}
contentTypeMd5Str := contentTypeMd5.Md5EncryptionAlgorithm()
fmt.Printf("contentType:%v\n", ContentType)
//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", requestData.Token, requestData.Number)
var receiveKeyMd5 publicmethod.Md5Encryption
receiveKeyMd5.Md5EncryptionInit(receiveKey)
if empCont.VerificationCode != "" {
receiveKeyMd5.AppKey = empCont.VerificationCode
}
receiveKeyMd5Str := receiveKeyMd5.Md5EncryptionAlgorithm()
sendData := publicmethod.MapOut[string]()
sendData["systemKeyMd5Str"] = systemKeyMd5Str
sendData["receiveKeyMd5Str"] = receiveKeyMd5Str
sendData["uuidMd5Str"] = uuidMd5Str
sendData["number"] = requestData.Number
sendData["tokenMd5Str"] = tokenMd5Str
sendData["token"] = requestData.Token
sendData["tokenRedisKey"] = tokenRedisKey
if systemKeyMd5Str != receiveKeyMd5Str {
publicmethod.Result(10001, sendData, c, "对不起!身份验证失败!")
return
}
publicmethod.Result(0, err, c)
var userCont modelshr.ManCont
err = overall.CONSTANT_DB_HR.Where("`number` = ? AND `emp_type` BETWEEN ? AND ?", requestData.Code, 1, 10).Find(&userCont).Error
if err != nil {
publicmethod.Result(10001, sendData, c, "此账号禁止访问!")
return
}
var md5JiaMi publicmethod.Md5Encryption
md5JiaMi.Md5EncryptionInit(userAgent)
md5Token := md5JiaMi.Md5EncryptionAlgorithm()
var md5JiaMiNumber publicmethod.Md5Encryption
md5JiaMiNumber.Md5EncryptionInit(userCont.Number)
userKeyCode := md5JiaMiNumber.Md5EncryptionAlgorithm()
sha1Str := userKeyCode + userCont.Number + userCont.Password + md5Token
sha1Token := publicmethod.Sha1Encryption(sha1Str)
//返回值
saveData := publicmethod.MapOut[string]()
saveData["key"] = userKeyCode
saveData["token"] = sha1Token
saveData["userinfo"] = userCont
menuoper, jurisdiction := getRoleSeat(userCont.Role)
writeRedisData := map[string]interface{}{
"userkey": userKeyCode,
"key": userCont.Key,
"usernumber": userCont.Number,
"userpwd": userCont.Password,
"usertoken": sha1Token,
"jurisdiction": jurisdiction,
"menuOper": menuoper,
"wand": 118,
}
//API Token数据
redisFileKey := fmt.Sprintf("ScanCode:Authentication:LoginApi_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userKeyCode)
redisClients := grocerystore.RunRedis(overall.CONSTANT_REDIS5)
redisClients.SetRedisTime(10800)
redisClients.HashMsetAdd(redisFileKey, writeRedisData)
_, companyId, _, sunDepartId, _ := publicmethod.GetOrgStructurees(userCont.AdminOrg)
var sunmaindeparment int64
if companyId != sunDepartId {
sunmaindeparment = sunDepartId
}
//缓存写入个人信息
redisMyContKey := fmt.Sprintf("ScanCode:Authentication:UserCont_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userCont.Number)
myCont := publicmethod.MapOut[string]()
myCont["id"] = userCont.Id
myCont["number"] = userCont.Number //员工工号
myCont["name"] = userCont.Name //姓名
myCont["icon"] = userCont.Icon //头像
myCont["hireclass"] = userCont.HireClass //雇佣类型(1:雇佣入职;2:再入职;)
myCont["emptype"] = userCont.EmpType //用工关系(1:临时工 , 2:编外人员 ;3:实习&实习生;4:试用员工;5:待分配;6:待岗;7:临时调入;8:正式员工;9:长期病假;10:停薪留职;11:退休;12:辞职;13:辞退;14:离职)
myCont["company"] = userCont.Company //入职公司
// myCont["maindeparment"] = userCont.MainDeparment //主部门
// myCont["sunmaindeparment"] = userCont.SunMainDeparment //二级主部门
myCont["maindeparment"] = companyId //主部门
myCont["sunmaindeparment"] = sunmaindeparment //二级主部门
myCont["deparment"] = userCont.Deparment //部门
myCont["adminorg"] = userCont.AdminOrg //所属行政组织
myCont["teamid"] = userCont.TeamId //班组
myCont["position"] = userCont.Position //职位
myCont["jobclass"] = userCont.JobClass //职务分类
myCont["jobid"] = userCont.JobId //职务
myCont["jobleve"] = userCont.JobLeve //职务等级
myCont["wechat"] = userCont.Wechat //微信UserId
myCont["workwechat"] = userCont.WorkWechat //企业微信UserId
myCont["state"] = userCont.State //状态(1:启用;2:禁用;3:删除)
myCont["key"] = userCont.Key //key
myCont["isadmin"] = userCont.IsAdmin //是否为管理员(1:不是;2:分公司;3:集团管理员;4:超级管
myCont["password"] = userCont.Password //密码
myCont["role"] = userCont.Role //角色
myCont["idcardno"] = userCont.Idcardno //身份证号
myCont["passportno"] = userCont.Passportno //护照号码
myCont["globalroaming"] = userCont.Globalroaming //国际区号
myCont["mobilephone"] = userCont.Mobilephone //手机号码
myCont["email"] = userCont.Email //电子邮件
myCont["gender"] = userCont.Gender //性别(1:男性;2:女性;3:中性)
myCont["birthday"] = userCont.Birthday //birthday
myCont["myfolk"] = userCont.Myfolk //民族
myCont["nativeplace"] = userCont.Nativeplace //籍贯
myCont["idcardstartdate"] = userCont.Idcardstartdate //身份证有效期开始
myCont["idcardenddate"] = userCont.Idcardenddate //身份证有效期结束
myCont["idcardaddress"] = userCont.Idcardaddress //身份证地址
myCont["idcardIssued"] = userCont.IdcardIssued //身份证签发机关
myCont["health"] = userCont.Health //健康状况(1:良好;2:一般;3:较弱,4:有生理缺陷;5:残废)
myCont["maritalstatus"] = userCont.Maritalstatus //婚姻状况(1:未婚;2:已婚;3:丧偶;4:离异)
myCont["internaltelephone"] = userCont.Internaltelephone //内线电话
myCont["currentresidence"] = userCont.Currentresidence //现居住地址
myCont["constellationing"] = userCont.Constellation //星座(1:白羊座;2:金牛座;3:双子座;4:巨蟹座;5:狮子座;6:处女座;7:天枰座;8:天蝎座;9:射手座;10:摩羯座;11:水瓶座;12:双鱼座)
myCont["isdoubleworker"] = userCont.Isdoubleworker //是否双职工(1:是;2:否)
myCont["isveterans"] = userCont.Isveterans //是否为退役军人(1:是;2:否)
myCont["veteransnumber"] = userCont.Veteransnumber //退役证编号
myCont["jobstartdate"] = userCont.Jobstartdate //参加工作日期
myCont["entrydate"] = userCont.Entrydate //入职日期
myCont["probationperiod"] = userCont.Probationperiod //试用期
myCont["planformaldate"] = userCont.Planformaldate //预计转正日期
myCont["political_outlook"] = userCont.PoliticalOutlook //政治面貌(1:群众;2:无党派;3:台盟会员;4:九三社员;5:致公党员;6:农工党员;7:民进会员;8:民建会员;9:民盟盟员;10:民革会员,11:共青团员;12:预备党员;13:中共党员)
var companyCont modelshr.AdministrativeOrganization
companyCont.GetCont(map[string]interface{}{"`id`": userCont.Company}, "`name`")
myCont["companyname"] = companyCont.Name
var departmentCont modelshr.AdministrativeOrganization
departmentCont.GetCont(map[string]interface{}{"`id`": userCont.MainDeparment}, "`name`")
myCont["maindeparmentname"] = departmentCont.Name
var postInfo modelshr.Position
postInfo.GetCont(map[string]interface{}{"`id`": userCont.Position}, "`name`")
myCont["positionname"] = postInfo.Name
redisClients.HashMsetAdd(redisMyContKey, myCont)
redisClient.HashMsetAddClan(redisMyContKey, myCont)
saveData["usercont"] = myCont
if requestData.Openid != "" {
var userInfo modelshr.PersonArchives
userInfo.EiteCont(map[string]interface{}{"id": userCont.Id}, map[string]interface{}{"work_wechat": requestData.Openid})
}
var sendKpiCont WriteIderCont
sendKpiCont.Openid = requestData.Openid
sendKpiCont.Key = userKeyCode
sendKpiCont.Token = sha1Token
sendKpiCont.UserInfo.Key = strconv.FormatInt(userCont.Key, 10)
sendKpiCont.UserInfo.Number = userCont.Number
sendKpiCont.UserInfo.Password = userCont.Password
sendDate, _ := json.Marshal(sendKpiCont)
publicmethod.CurlPostJosn("http://120.224.6.6:39168/shiyan/write_token", sendDate)
publicmethod.Result(0, saveData, c)
}

24
api/version1/publicapi/type.go

@ -63,3 +63,27 @@ type ValidatorType struct {
UserKey string `json:"userkey"` //用户名
PassWord string `json:"password"` //密码
}
// 写入身份认证
type WriteIderCont struct {
Openid string `json:"openid"`
Key string `json:"key"`
Token string `json:"token"`
UserInfo UserInfoCont `json:"userinfo"`
}
// 人员信息
type UserInfoCont struct {
Number string `json:"number"`
Password string `json:"password"`
Key string `json:"key"`
}
// 无感登录数据
type SilentLoginInfo struct {
Token string `json:"token"`
Number string `json:"number"`
Code string `json:"code"`
Time string `json:"time"`
Openid string `json:"openid"`
}

1
apirouter/v1/public/router.go

@ -23,5 +23,6 @@ func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) {
apiRouter.POST("gainNumber", methodBinding.GainNumber) //获取带规则编号
apiRouter.POST("obtainToken", methodBinding.ObtainToken) //一键登录授权
apiRouter.GET("verifyIdentity", methodBinding.VerifyIdentity) //验证身份登录
apiRouter.POST("silentLogin", methodBinding.SilentLogin) //验证无感登录
}
}

1
config/configDatabase/database.go

@ -54,6 +54,7 @@ func (m *MasterMysqlSetUp) SqlDsn() (dsnStr string) {
if m.ParseTime {
dsnStr = fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=%v&parseTime=%v&loc=%v", m.UserName, m.PassWord, m.UrlPath, m.Port, m.Name, m.Charset, m.ParseTime, m.Loc)
}
// fmt.Printf("dsnStr:%v\n", dsnStr)
return
}

10
config/configNosql/redis.go

@ -4,7 +4,7 @@ import (
"context"
"fmt"
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
)
type RedisSetUp struct {
@ -60,18 +60,18 @@ func (r *RedisConfitSetUp) OpenRedis() *redis.Client {
#
*/
func (r *RedisConfitSetUp) OpenRedisColony() *redis.ClusterClient {
fmt.Printf("开启%v Redis库 %v\n", r.UrlPathList, r.Name)
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"},
Addrs: r.UrlPathList,
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)
fmt.Printf("%v Redis集群链接失败!原因:%v\n", r.Name, err)
} else {
fmt.Printf("%v Redis链接成功!==%v===>%v\n", r.Name, r.UrlPath, pingLink)
fmt.Printf("%v Redis集群链接成功!==%v===>%v\n", r.Name, r.UrlPath, pingLink)
}
return redisClient
}

28
config/configNosql/redisv9.go

@ -0,0 +1,28 @@
package confignosql
import "fmt"
type RedisSetUpV9 struct {
RedisClusterV9 RedisConfitSetUp `mapstructure:"redisCluster" json:"redisCluster" yaml:"redisCluster"` //内网集群
}
/*
*
@ 作者: 秦东
@ 时间: 2023-12-13 11:14:06
@ 功能: 开启v9集群
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (r *RedisConfitSetUp) OpenRedisClan() {
fmt.Printf("开启%v Redis库 %v\n", r.UrlPathList, r.Name)
}

74
go.mod

@ -1,55 +1,57 @@
module appPlatform
go 1.18
go 1.19
require (
github.com/flipped-aurora/gin-vue-admin/server v0.0.0-20220724010254-afab1fdbce13
github.com/fsnotify/fsnotify v1.5.4
github.com/gin-gonic/gin v1.8.1
github.com/go-redis/redis/v8 v8.11.5
github.com/flipped-aurora/gin-vue-admin/server v0.0.0-20231212025023-e0a8e9370425
github.com/fsnotify/fsnotify v1.7.0
github.com/gin-gonic/gin v1.9.1
github.com/mitchellh/mapstructure v1.5.0
github.com/mojocn/base64Captcha v1.3.5
github.com/mozillazg/go-pinyin v0.19.0
github.com/spf13/viper v1.12.0
gorm.io/driver/mysql v1.3.5
gorm.io/gorm v1.23.8
github.com/mozillazg/go-pinyin v0.20.0
github.com/redis/go-redis/v9 v9.3.0
github.com/robfig/cron/v3 v3.0.1
github.com/spf13/viper v1.16.0
gorm.io/driver/mysql v1.5.2
gorm.io/gorm v1.25.5
)
require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

1197
go.sum

File diff suppressed because it is too large

1
initialization/databaseinit/mysql.go

@ -8,6 +8,7 @@ import (
func LoadDatabase() {
sqlConfig := overall.CONSTANT_MYSQL
// fmt.Printf("%v:sqlConfig!\n", sqlConfig)
initviper.RunViper(&sqlConfig, overall.ConfigDatabaseConstant)
//开启主数据库
overall.CONSTANT_DB_Master = sqlConfig.MasterMysql.OpenSql()

1
initialization/initviper/init_viper.go

@ -10,6 +10,7 @@ import (
// 使用viper 处理包解决配置读取问题
func RunViper(configInfo interface{}, path ...string) *viper.Viper {
// fmt.Printf("你正在使用系统默认值。11111配置路径为:%v\n", path)
var config string
if len(path) == 0 {
config = overall.ConfigFilePathConstant

5
initialization/route/initRoute.go

@ -3,15 +3,14 @@ package route
import (
"appPlatform/apirouter"
"appPlatform/identification/interceptor"
"io/ioutil"
"github.com/gin-gonic/gin"
)
// 初始化主路由
func InitialRouter() *gin.Engine {
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = ioutil.Discard
// gin.SetMode(gin.ReleaseMode)
// gin.DefaultWriter = ioutil.Discard
var router = gin.Default()
//app默认相应

15
middleware/grocerystore/redis.go

@ -6,15 +6,16 @@ import (
"fmt"
"time"
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
)
// redis 基础设定
type RedisStoreType struct {
Expiration time.Duration
PreKey string
Context context.Context
RedisDb *redis.Client
Expiration time.Duration
PreKey string
Context context.Context
RedisDb *redis.Client
RedisDbClan *redis.ClusterClient
}
// 启动redis
@ -162,9 +163,9 @@ func (r *RedisStoreType) HashMsetAddAry(hashName string, hashVal []map[string]in
*/
func (r *RedisStoreType) HashGetAll(hashName string) (map[string]string, bool) {
// rdb := RedisInit()
// fmt.Printf("strKEy:===>%v\n", r.PreKey+hashName)
fmt.Printf("strKEy:===>%v\n", r.PreKey+hashName)
val, err := r.RedisDb.HGetAll(r.Context, r.PreKey+hashName).Result()
// fmt.Printf("strKEy:==1=>%v==1=>%v\n", val, err)
fmt.Printf("strKEy:==1=>%v==1=>%v\n", val, err)
if err != nil {
return val, false
}

414
middleware/grocerystore/redisclan.go

@ -0,0 +1,414 @@
package grocerystore
import (
"appPlatform/overall"
"context"
"fmt"
"time"
"github.com/redis/go-redis/v9"
)
/*
*
@ 作者: 秦东
@ 时间: 2023-12-13 13:23:48
@ 功能: Redis集群操作
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func RunRedisClan(redisClient *redis.ClusterClient) *RedisStoreType {
var redisStoreType RedisStoreType
redisStoreType.Expiration = time.Second * 300
redisStoreType.PreKey = fmt.Sprintf("%v:", overall.CONSTANT_CONFIG.RedisPrefixStr.PreFix)
redisStoreType.Context = context.Background()
redisStoreType.RedisDbClan = redisClient
return &redisStoreType
}
// 设置字符串
func (r *RedisStoreType) SetClan(key string, value string) bool {
err := r.RedisDbClan.Set(r.Context, r.PreKey+key, value, r.Expiration).Err()
if err != nil {
return false
}
return true
}
// 获取字符串
func (r *RedisStoreType) GetClan(key string) (bool, string) {
err := r.RedisDbClan.Get(r.Context, r.PreKey+key)
if err.Err() != nil {
return false, ""
}
return true, err.Val()
}
// 删除键
func (r *RedisStoreType) DelKeyClan(key string) bool {
err := r.RedisDbClan.Del(r.Context, r.PreKey+key).Err()
if err != nil {
return false
}
return true
}
//哈希操作
/*
获取单个哈希键值
@hashName 集合名称
@hashKey 哈希键
callback
errs 状态
hashVal 获得值
*/
func (r *RedisStoreType) HashGetClan(hashName, hashKey string) (errs bool, hashVal string) {
err := r.RedisDbClan.HGet(r.Context, r.PreKey+hashName, hashKey)
if err.Err() != nil {
return false, ""
}
return true, err.Val()
}
/*
为哈希表中的字段赋值 单一设置
@hashName 集合名称
@hashKey 哈希键
@hashVal 要添加的值
*/
func (r *RedisStoreType) HashSetClan(hashName, hashKey, hashVal string) bool {
err := r.RedisDbClan.HSet(r.Context, r.PreKey+hashName, hashKey, hashVal).Err()
if err != nil {
return false
}
if r.Expiration == 0 {
r.RedisDbClan.Persist(r.Context, r.PreKey+hashName)
} else {
r.RedisDbClan.PExpire(r.Context, r.PreKey+hashName, r.Expiration)
}
// global.GVA_REDIS.PExpire(r.Context, r.PreKey+hashName, r.Expiration)
return true
}
/*
同时将多个 field-value (字段-)对设置到哈希表中
@hashName 集合名称
@hashVal 要添加的键与值
*/
func (r *RedisStoreType) HashMsetAddClan(hashName string, hashVal map[string]interface{}) bool {
// rdb := RedisInit()
err := r.RedisDbClan.HMSet(r.Context, r.PreKey+hashName, hashVal).Err()
fmt.Printf("错误sss=========》%v=====2====》%v\n", err, hashVal)
// err := rdb.HMSet(ctx, "userfg", hashVal).Err()
if err != nil {
return false
}
if r.Expiration == 0 {
r.RedisDbClan.Persist(r.Context, r.PreKey+hashName)
} else {
r.RedisDbClan.PExpire(r.Context, r.PreKey+hashName, r.Expiration)
}
return true
}
func (r *RedisStoreType) HashMsetAddinterfaceClan(hashName string, hashVal interface{}) bool {
// rdb := RedisInit()
err := r.RedisDbClan.HMSet(r.Context, r.PreKey+hashName, hashVal).Err()
// fmt.Printf("错误sss=========》%v=====2====》%v\n", err, hashVal)
// err := rdb.HMSet(ctx, "userfg", hashVal).Err()
if err != nil {
return false
}
if r.Expiration == 0 {
r.RedisDbClan.Persist(r.Context, r.PreKey+hashName)
} else {
r.RedisDbClan.PExpire(r.Context, r.PreKey+hashName, r.Expiration)
}
return true
}
func (r *RedisStoreType) HashMsetAddAryClan(hashName string, hashVal []map[string]interface{}) bool {
// rdb := RedisInit()
err := r.RedisDbClan.HMSet(r.Context, r.PreKey+hashName, hashVal).Err()
// err := rdb.HMSet(ctx, "userfg", hashVal).Err()
if err != nil {
return false
}
if r.Expiration == 0 {
r.RedisDbClan.Persist(r.Context, r.PreKey+hashName)
} else {
r.RedisDbClan.PExpire(r.Context, r.PreKey+hashName, r.Expiration)
}
// global.GVA_REDIS.PExpire(r.Context, r.PreKey+hashName, r.Expiration)
// fmt.Printf("错误sss=========》%v\n", hashVal)
return true
}
/*
返回哈希表中所有的字段和值
@hashName 集合名称
@hashKey 哈希键
*/
func (r *RedisStoreType) HashGetAllClan(hashName string) (map[string]string, bool) {
// rdb := RedisInit()
fmt.Printf("strKEy:===>%v\n", r.PreKey+hashName)
val, err := r.RedisDbClan.HGetAll(r.Context, r.PreKey+hashName).Result()
fmt.Printf("strKEy:==1=>%v==1=>%v\n", val, err)
if err != nil {
return val, false
}
if len(val) == 0 {
return val, false
}
return val, true
}
//Redis 列表(List)
/*
*
Linsert 命令用于在列表的元素前或者后插入元素当指定元素不存在于列表中时不执行任何操作
当列表不存在时被视为空列表不执行任何操作
如果 key 不是列表类型返回一个错误
@key 列表
@op 插入状态 (1:在pivot之后2在pivot之前)
@pivot 定位值
@value 要插入值
*/
func (r *RedisStoreType) LinsertClan(key string, op int, pivot, value interface{}) (int64, bool) {
BeforeOrAfter := "BEFORE"
if op != 1 {
BeforeOrAfter = "AFTER"
}
linsert, linsertErr := r.RedisDbClan.LInsert(r.Context, key, BeforeOrAfter, pivot, value).Result()
if linsertErr != nil {
return 0, false
}
return linsert, true
}
/*
*
Lindex 命令用于通过索引获取列表中的元素你也可以使用负数下标 -1 表示列表的最后一个元素 -2 表示列表的倒数第二个元素以此类推
@key 列表
@index 索引
*/
func (r *RedisStoreType) LindexClan(key string, index int64) (val string, err error) {
val, err = r.RedisDbClan.LIndex(r.Context, key, index).Result()
return
}
/*
*
Llen 命令用于返回列表的长度 如果列表 key 不存在 key 被解释为一个空列表返回 0 如果 key 不是列表类型返回一个错误
@key 列表
*/
func (r *RedisStoreType) LlenClan(key string) (val int64, err error) {
val, err = r.RedisDbClan.LLen(r.Context, key).Result()
return
}
/*
*
Lpop 命令用于移除并返回列表的第一个元素
@key 列表
*/
func (r *RedisStoreType) LpopClan(key string) (val string, err error) {
val, err = r.RedisDbClan.LPop(r.Context, key).Result()
return
}
/*
*
Lpush 命令将一个或多个值插入到列表头部 如果 key 不存在一个空列表会被创建并执行 LPUSH 操作 key 存在但不是列表类型时返回一个错误
@key 列表
@value 要插入的字符串
*/
func (r *RedisStoreType) LpushClan(key string, value ...interface{}) (val int64, err error) {
val, err = r.RedisDbClan.LPush(r.Context, key, value).Result()
return
}
/*
*
Lpushx 将一个值插入到已存在的列表头部列表不存在时操作无效
@key 列表
@value 要插入的字符串
*/
func (r *RedisStoreType) LpushxClan(key, value string) (val int64, err error) {
val, err = r.RedisDbClan.LPushX(r.Context, key, value).Result()
return
}
/*
*
Lrange 返回列表中指定区间内的元素区间以偏移量 START END 指定 其中 0 表示列表的第一个元素 1 表示列表的第二个元素以此类推 你也可以使用负数下标 -1 表示列表的最后一个元素 -2 表示列表的倒数第二个元素以此类推
@key 列表
@start 起始值
@stop 结束值
*/
func (r *RedisStoreType) LrangeClan(key string, start, stop int64) (val []string, err error) {
val, err = r.RedisDbClan.LRange(r.Context, key, start, stop).Result()
return
}
/*
*
Lrem 根据参数 COUNT 的值移除列表中与参数 VALUE 相等的元素
COUNT 的值可以是以下几种
count > 0 : 从表头开始向表尾搜索移除与 VALUE 相等的元素数量为 COUNT
count < 0 : 从表尾开始向表头搜索移除与 VALUE 相等的元素数量为 COUNT 的绝对值
count = 0 : 移除表中所有与 VALUE 相等的值
@start = COUNT
@key 列表
*/
func (r *RedisStoreType) LremClan(key string, start int64, value ...interface{}) (val int64, err error) {
val, err = r.RedisDbClan.LRem(r.Context, key, start, value).Result()
return
}
/*
*
Redis Lset 通过索引来设置元素的值
当索引参数超出范围或对一个空列表进行 LSET 返回一个错误
@key 列表
@indexes 索引值
*/
func (r *RedisStoreType) LsetClan(key string, indexes int64, value ...interface{}) (val string, err error) {
val, err = r.RedisDbClan.LSet(r.Context, key, indexes, value).Result()
return
}
/*
*
Ltrim 对一个列表进行修剪(trim)就是说让列表只保留指定区间内的元素不在指定区间之内的元素都将被删除
下标 0 表示列表的第一个元素 1 表示列表的第二个元素以此类推 你也可以使用负数下标 -1 表示列表的最后一个元素 -2 表示列表的倒数第二个元素以此类推
@key 列表
@start 起始值
@stop 结束值
*/
func (r *RedisStoreType) LtrimClan(key string, start, stop int64) (val string, err error) {
val, err = r.RedisDbClan.LTrim(r.Context, key, start, stop).Result()
return
}
/*
*
Rpop 命令用于移除列表的最后一个元素返回值为移除的元素
@key 列表
*/
func (r *RedisStoreType) RpopClan(key string) (val string, err error) {
val, err = r.RedisDbClan.RPop(r.Context, key).Result()
return
}
/*
*
Rpoplpush 命令用于移除列表的最后一个元素并将该元素添加到另一个列表并返回
@sourceKey 源列表
@newKey 目标列表
*/
func (r *RedisStoreType) RpoplpushClan(sourceKey, newKey string) (val string, err error) {
val, err = r.RedisDbClan.RPopLPush(r.Context, sourceKey, newKey).Result()
return
}
/*
*
Rpush 命令用于将一个或多个值插入到列表的尾部(最右边)
如果列表不存在一个空列表会被创建并执行 RPUSH 操作 当列表存在但不是列表类型时返回一个错误
@key 列表
@value 要插入的字符串
*/
func (r *RedisStoreType) RpushClan(key string, value ...interface{}) (val int64, err error) {
val, err = r.RedisDbClan.RPush(r.Context, key, value).Result()
return
}
/*
*
Rpushx 命令用于将一个值插入到已存在的列表尾部(最右边)如果列表不存在操作无效
@key 列表
@value 要插入的字符串
*/
func (r *RedisStoreType) RpushxClan(key string, value ...interface{}) (val int64, err error) {
val, err = r.RedisDbClan.RPushX(r.Context, key, value).Result()
return
}
/*
*
Blpop 命令移出并获取列表的第一个元素 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
@key 列表
*/
func (r *RedisStoreType) BlpopClan(key string) (val []string, err error) {
val, err = r.RedisDbClan.BLPop(r.Context, r.Expiration, key).Result()
return
}
/*
*
Brpop 命令移出并获取列表的最后一个元素 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
@key 列表
*/
func (r *RedisStoreType) BrpopClan(key string) (val []string, err error) {
val, err = r.RedisDbClan.BRPop(r.Context, r.Expiration, key).Result()
return
}
/*
*
Brpoplpush 命令从列表中取出最后一个元素并插入到另外一个列表的头部 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
@source 源列表
@destination 目标列表
*/
func (r *RedisStoreType) BrpoplpushClan(source, destination string) (val string, err error) {
val, err = r.RedisDbClan.BRPopLPush(r.Context, source, destination, r.Expiration).Result()
return
}
/*
Redis 键Clan(key)
Redis 键命令用于管理 redis 的键
*/
/*
Redis SCAN 命令
Redis Scan 命令用于迭代数据库中的数据库键
SCAN 命令是一个基于游标的迭代器每次被调用之后 都会向用户返回一个新的游标 用户在下次迭代时需要使用这个新游标作为 SCAN 命令的游标参数 以此来延续之前的迭代过程
SCAN 返回一个包含两个元素的数组 第一个元素是用于进行下一次迭代的新游标 而第二个元素则是一个数组 这个数组中包含了所有被迭代的元素如果新游标返回 0 表示迭代已结束
相关命令
SSCAN 命令用于迭代集合键中的元素
HSCAN 命令用于迭代哈希键中的键值对
ZSCAN 命令用于迭代有序集合中的元素包括元素成员和元素分值
*/
func (r *RedisStoreType) ScanClan(cursor uint64, match string, count int64) (keys []string, cursores uint64, err error) {
keys, cursores, err = r.RedisDbClan.Scan(r.Context, cursor, match, count).Result()
return
}
/*
*Keys 命令用于查找所有符合给定模式 pattern key
*/
func (r *RedisStoreType) KeysClan(key string) (val []string, err error) {
val, err = r.RedisDbClan.Keys(r.Context, key).Result()
return
}

3
overall/appConfig.go

@ -3,7 +3,8 @@ package overall
import (
"appPlatform/config/configApp"
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
)

1
overall/appConfigRedis.go

@ -0,0 +1 @@
package overall

5
overall/database.go

@ -6,6 +6,7 @@ import (
)
var (
CONSTANT_MYSQL configDatabase.MysqlSetUp
CONSTANT_Redis confignosql.RedisSetUp
CONSTANT_MYSQL configDatabase.MysqlSetUp
CONSTANT_Redis confignosql.RedisSetUp
CONSTANT_RedisCluster confignosql.RedisSetUpV9
)

Loading…
Cancel
Save