Просмотр исходного кода

feat: 权益中台增加校验

zhangxinlei1996 2 лет назад
Родитель
Сommit
a0117c47d5
6 измененных файлов с 50 добавлено и 3 удалено
  1. 2 0
      go.mod
  2. 4 0
      go.sum
  3. 7 3
      rpc/etc/powercheck.yaml
  4. 6 0
      rpc/init/init.go
  5. 5 0
      rpc/internal/config/config.go
  6. 26 0
      service/power.go

+ 2 - 0
go.mod

@@ -4,6 +4,7 @@ go 1.19
 
 require (
 	app.yhyue.com/moapp/jybase v0.0.0-20221229065928-e4ba75127ac9
+	bp.jydev.jianyu360.cn/BP/jynsq v0.0.0-20220222052708-ebc43af90698
 	github.com/go-sql-driver/mysql v1.7.0
 	github.com/zeromicro/go-zero v1.4.3
 	google.golang.org/grpc v1.51.0
@@ -44,6 +45,7 @@ require (
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
+	github.com/nsqio/go-nsq v1.1.0 // indirect
 	github.com/openzipkin/zipkin-go v0.4.0 // indirect
 	github.com/pelletier/go-toml/v2 v2.0.6 // indirect
 	github.com/pkg/errors v0.9.1 // indirect

+ 4 - 0
go.sum

@@ -1,6 +1,8 @@
 app.yhyue.com/moapp/esv1 v0.0.0-20220414031211-3da4123e648d/go.mod h1:91/lSD/hS+ckMVP3WdidRzDhC60lLMdyce9QHy0cSMA=
 app.yhyue.com/moapp/jybase v0.0.0-20221229065928-e4ba75127ac9 h1:oEtIsT9iO6EcKzvv0Tbq7CckuGfj9F1lExywviJJUp0=
 app.yhyue.com/moapp/jybase v0.0.0-20221229065928-e4ba75127ac9/go.mod h1:efAeRPDpJ13JuNODuqtfLlKQSQgCbnUcwGPzhFU5krY=
+bp.jydev.jianyu360.cn/BP/jynsq v0.0.0-20220222052708-ebc43af90698 h1:2xGDnrmbGt4VzAmDSsKH+C9Bq40z9eQ4NJfH/779o8g=
+bp.jydev.jianyu360.cn/BP/jynsq v0.0.0-20220222052708-ebc43af90698/go.mod h1:ojo/AUH9Yr1wzarEjOaNMkj1Cet/9r8IgLyba64Z52E=
 cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
 cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
 cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
@@ -720,6 +722,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW
 github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
 github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
+github.com/nsqio/go-nsq v1.1.0 h1:PQg+xxiUjA7V+TLdXw7nVrJ5Jbl3sN86EhGCQj4+FYE=
+github.com/nsqio/go-nsq v1.1.0/go.mod h1:vKq36oyeVXgsS5Q8YEO7WghqidAVXQlcFxzQbQTuDEY=
 github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
 github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
 github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=

+ 7 - 3
rpc/etc/powercheck.yaml

@@ -7,7 +7,7 @@ Etcd:
 Timeout: 10000
 MysqlMain:
   dbName: jianyu
-  address: 192.168.3.11:3366
+  address: 192.168.3.149:3306
   userName: root
   passWord: Topnet123
   maxOpenConns: 5
@@ -25,5 +25,9 @@ Mongo:
     size: 50
     address: 192.168.3.206:27080
 RedisAddrees:
-  - newother=192.168.3.206:1712
-  - other=192.168.3.206:1712
+  - newother=192.168.3.149:1712
+  - other=192.168.3.149:1712
+AlertRemind:
+  addr: 192.168.3.71:4150
+  toppic: jyalert
+  id: power_alert

+ 6 - 0
rpc/init/init.go

@@ -78,4 +78,10 @@ func init() {
 	log.Println("初始化 redis")
 	redis.InitRedisBySize(strings.Join(C.RedisAddrees, ","), 100, 30, 300)
 
+	//
+	if C.AlertRemind.Addr != "" {
+		entity.AlertRemind.Addr = C.AlertRemind.Addr
+		entity.AlertRemind.Toppic = C.AlertRemind.Toppic
+		entity.AlertRemind.Id = C.AlertRemind.Id
+	}
 }

+ 5 - 0
rpc/internal/config/config.go

@@ -13,4 +13,9 @@ type Config struct {
 		Main *entity.MongoStruct
 	}
 	RedisAddrees []string
+	AlertRemind  struct {
+		Addr   string
+		Toppic string
+		Id     string
+	}
 }

+ 26 - 0
service/power.go

@@ -10,6 +10,7 @@ import (
 
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
+	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/redis"
 	"bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/entity"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -49,6 +50,13 @@ var level_map = map[int64]string{
 */
 func (this *PowerService) Power(userid string, baseUserId, accountId, entId, positionType, positionId int64) *entity.Power {
 	logx.Info("-----req------", userid, baseUserId, accountId, entId, positionType, positionId)
+	if positionId == 0 {
+		return &entity.Power{
+			Free: &entity.Free{
+				IsFree: true,
+			},
+		}
+	}
 	ent := &entity.Ent{}
 	entniche := &entity.Entniche{}
 	vip := &entity.Vip{}
@@ -62,6 +70,24 @@ func (this *PowerService) Power(userid string, baseUserId, accountId, entId, pos
 		}
 	}
 	if !cacheBl {
+		if userid == "" && positionId > 0 {
+			logx.Info("检测到异常数据:", userid, baseUserId, accountId, entId, positionType, positionId)
+			if baseUserId <= 0 {
+				//获取mongodb的userid
+				pd := this.Conn.BaseMysql.SelectBySql(`select user_id from base_service.base_position where id =? limit 1`, positionId)
+				if pd != nil && len(*pd) > 0 {
+					baseUserId = common.Int64All((*pd)[0]["user_id"])
+				}
+			}
+			if baseUserId > 0 {
+				ud, ok := this.Conn.MgoJy.FindOneByField("user", map[string]interface{}{"base_user_id": baseUserId}, `{"_id:1"}`)
+				if ud != nil && ok && len(*ud) > 0 {
+					userid = mongodb.BsonIdToSId((*ud)["_id"])
+				}
+			}
+			entity.Alert(fmt.Sprintf("检测到异常数据: userId:%s ,positionId:%v ,positionType:%v", userid, positionType, positionType))
+			logx.Info("检测到异常数据修复后:", userid, baseUserId, accountId, entId, positionType, positionId)
+		}
 		//获取用户本身的注册时间和邮箱、这个与个人、企业无关
 		mgoUserFields := map[string]interface{}{
 			"s_myemail":     1,