123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- package services
- import (
- "encoding/json"
- "errors"
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/services/alarm_msg"
- "eta_gn/eta_api/utils"
- "fmt"
- "time"
- )
- // HandleDataCollectCache
- // @Description: 资产收藏处理
- // @author: Roc
- // @datetime 2024-12-27 16:56:36
- func HandleDataCollectCache() {
- var err error
- for {
- utils.Rc.Brpop(utils.CACHE_KEY_DATA_COLLECT_HANDLER, func(b []byte) {
- defer func() {
- if err != nil {
- utils.FileLog.Info("HandleDataCollectCache err:" + err.Error())
- go alarm_msg.SendAlarmMsg("资产收藏处理失败提醒,errMsg:"+err.Error(), 3)
- }
- }()
- record := new(data_manage.DataCollectHandleItem)
- if err = json.Unmarshal(b, &record); err != nil {
- fmt.Println("json unmarshal wrong!")
- return
- }
- dataId := record.DataId
- dataType := record.DataType
- utils.FileLog.Info(fmt.Sprintf("资产收藏处理失败提醒 DealReplaceEdbCache: 旧指标ID:%d,新指标ID:%d", dataId, dataType))
- deleteCache := true
- setNxKey := fmt.Sprintf("EDB_INFO_REPLACE:%d-%d", dataId, dataType)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(setNxKey)
- }
- }()
- if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
- deleteCache = false
- err = fmt.Errorf("资产收藏处理:%d为新指标%d:正在处理中", dataId, dataType)
- return
- }
- switch dataType {
- case 1: // 指标处理
- handleEdbCollectCache(dataId)
- case 2: // 图表处理
- handleChartCollectCache(dataId)
- }
- })
- }
- }
- // handleEdbCollectCache
- // @Description: 指标收藏关系处理
- // @author: Roc
- // @datetime 2024-12-27 17:15:19
- // @param edbInfoId int
- func handleEdbCollectCache(edbInfoId int) {
- var err error
- defer func() {
- if err != nil {
- utils.FileLog.Info("handleEdbCollectCache err:" + err.Error())
- go alarm_msg.SendAlarmMsg("指标收藏处理失败提醒,errMsg:"+err.Error(), 3)
- }
- }()
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- return
- }
- // 公开那就直接返回
- if edbInfo.PublicStatus == utils.DataPublicSuccess {
- return
- }
- edbCollectObj := data_manage.EdbCollect{}
- // 获取所有已经收藏的人
- allCollectUserIdList, err := edbCollectObj.GetEdbAllCollectUserIdList(edbInfoId)
- if err != nil {
- err = errors.New("查找指标的所有收藏人失败,Err:" + err.Error())
- return
- }
- // 没有人收藏,那么就直接返回
- if len(allCollectUserIdList) <= 0 {
- return
- }
- userIdMap := make(map[int]bool)
- for _, v := range allCollectUserIdList {
- userIdMap[v] = true
- }
- // 自己的指标,肯定可以收藏的
- delete(userIdMap, edbInfo.SysUserId)
- // 获取该指标的被分享人
- obj := data_manage.EdbInfoShare{}
- shareUserIdList, err := obj.GetAllUserIdListByEdbInfoId(edbInfoId)
- if err != nil {
- err = errors.New("查找指标的所有收藏人失败,Err:" + err.Error())
- return
- }
- for _, v := range shareUserIdList {
- delete(userIdMap, v)
- }
- // 没有待移除的用户,那么就直接返回
- if len(userIdMap) < 0 {
- return
- }
- // 删除收藏关系
- deleteUserIdList := make([]int, 0)
- for userId, _ := range userIdMap {
- deleteUserIdList = append(deleteUserIdList, userId)
- }
- // 删除收藏关系
- err = edbCollectObj.DeleteByEdbInfoIdAndUserIdList(edbInfoId, deleteUserIdList)
- return
- }
- // handleChartCollectCache
- // @Description: 图表收藏关系处理
- // @author: Roc
- // @datetime 2024-12-27 17:15:19
- // @param chartInfoId int
- func handleChartCollectCache(chartInfoId int) {
- var err error
- defer func() {
- if err != nil {
- utils.FileLog.Info("handleChartCollectCache err:" + err.Error())
- go alarm_msg.SendAlarmMsg("图表收藏处理失败提醒,errMsg:"+err.Error(), 3)
- }
- }()
- chartInfo, err := data_manage.GetChartInfoById(chartInfoId)
- if err != nil {
- return
- }
- // 公开那就直接返回
- if chartInfo.PublicStatus == utils.DataPublicSuccess {
- return
- }
- chartCollectObj := data_manage.ChartCollect{}
- // 获取所有已经收藏的人
- allCollectUserIdList, err := chartCollectObj.GetChartAllCollectUserIdList(chartInfoId)
- if err != nil {
- err = errors.New("查找图表的所有收藏人失败,Err:" + err.Error())
- return
- }
- // 没有人收藏,那么就直接返回
- if len(allCollectUserIdList) <= 0 {
- return
- }
- userIdMap := make(map[int]bool)
- for _, v := range allCollectUserIdList {
- userIdMap[v] = true
- }
- // 自己的图表,肯定可以收藏的
- delete(userIdMap, chartInfo.SysUserId)
- // 获取该图表的被分享人
- obj := data_manage.ChartInfoShare{}
- shareUserIdList, err := obj.GetAllUserIdListByChartInfoId(chartInfoId)
- if err != nil {
- err = errors.New("查找图表的所有收藏人失败,Err:" + err.Error())
- return
- }
- for _, v := range shareUserIdList {
- delete(userIdMap, v)
- }
- // 没有待移除的用户,那么就直接返回
- if len(userIdMap) < 0 {
- return
- }
- // 删除收藏关系
- deleteUserIdList := make([]int, 0)
- for userId, _ := range userIdMap {
- deleteUserIdList = append(deleteUserIdList, userId)
- }
- // 删除收藏关系
- err = chartCollectObj.DeleteByChartInfoIdAndUserIdList(chartInfoId, deleteUserIdList)
- return
- }
|