1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package uniqid
- import (
- "crazy-fox-backend-api/config"
- "crazy-fox-backend-api/model"
- "crazy-fox-backend-api/utils"
- "github.com/google/uuid"
- "github.com/pkg/errors"
- )
- // uniqId=>stageType=>parentIndex=>typeKey=>idx
- var stageIdxMapping = make(map[string]map[string]map[string]map[string]int64)
- // getIdxByStageKey 获取当前层级Index
- func getIdxByStageKey(uniqId, stageType, val string, parentIdx ...int64) int64 {
- parentKey := utils.Ternary(len(parentIdx) == 0, "0", utils.Implode(parentIdx, "_"))
- if _, Ok := stageIdxMapping[uniqId]; !Ok {
- stageIdxMapping[uniqId] = map[string]map[string]map[string]int64{}
- }
- if _, Ok := stageIdxMapping[uniqId][stageType]; !Ok {
- stageIdxMapping[uniqId][stageType] = map[string]map[string]int64{}
- }
- if _, Ok := stageIdxMapping[uniqId][stageType][parentKey]; !Ok {
- stageIdxMapping[uniqId][stageType][parentKey] = map[string]int64{}
- }
- if stageIdxMapping[uniqId][stageType][parentKey][val] == 0 {
- stageIdxMapping[uniqId][stageType][parentKey][val] = int64(len(stageIdxMapping[uniqId][stageType][parentKey])) + 1
- }
- return stageIdxMapping[uniqId][stageType][parentKey][val]
- }
- // GetStageIdx 获取当前层级所有分组的Idx
- func GetStageIdx(uniqId string, stage ...any) []int64 {
- idxArr := make([]int64, 0, len(stage))
- for i := 0; i < len(stage); i++ {
- switch val := stage[i].(type) {
- case model.LvRange:
- key := utils.Implode([]int64{val.LvStart, val.LvEnd}, "_")
- idxArr = append(idxArr, getIdxByStageKey(uniqId, config.ActGroupTypeLv, key, idxArr...))
- case model.SpinsRange:
- key := utils.Implode([]int64{val.SpinsStart, val.SpinsEnd}, "_")
- idxArr = append(idxArr, getIdxByStageKey(uniqId, config.ActGroupTypeSpins, key, idxArr...))
- case model.VipPointRange:
- key := utils.Implode([]int64{val.VipPointStart, val.VipPointEnd}, "_")
- idxArr = append(idxArr, getIdxByStageKey(uniqId, config.ActGroupTypeVipPoint, key, idxArr...))
- case model.LostHourRange:
- key := utils.Implode([]int64{val.LostHourStart, val.LostHourEnd}, "_")
- idxArr = append(idxArr, getIdxByStageKey(uniqId, config.ActGroupTypeLostHour, key, idxArr...))
- case model.SsGroup:
- key := utils.Implode(val.Shushu, "_")
- idxArr = append(idxArr, getIdxByStageKey(uniqId, config.ActGroupTypeShushu, key, idxArr...))
- }
- }
- return idxArr
- }
- // DelMapByUniqId 通过唯一ID删除map元素
- func DelMapByUniqId(uniqId string) {
- delete(stageIdxMapping, uniqId)
- }
- // GetUniqId 获取唯一ID
- func GetUniqId() string {
- unique, err := uuid.NewUUID()
- if err != nil {
- panic(errors.Wrap(err, "获取唯一Id失败"))
- }
- return unique.String()
- }
|