Ver Fonte

超级订阅到期提醒

WH01243 há 1 ano atrás
pai
commit
03122c6c2b
5 ficheiros alterados com 386 adições e 0 exclusões
  1. 51 0
      vipTask/config.yaml
  2. 101 0
      vipTask/config/config.go
  3. 208 0
      vipTask/entity/timetask.go
  4. 6 0
      vipTask/logs.yaml
  5. 20 0
      vipTask/main.go

+ 51 - 0
vipTask/config.yaml

@@ -0,0 +1,51 @@
+user:
+  dbName: qfw
+  address: "192.168.3.206:27080"
+  userName: ""
+  passWord: ""
+  size: 5
+initConfig:
+  -
+    startDays: 53
+    endDays: 60
+    cycleDays: 360
+  -
+    startDays: 38
+    endDays: 45
+    cycleDays: 90
+  -
+    startDays: 1
+    endDays: 7
+    cycleDays: 7
+dailyConfig:
+  -
+    startDays: 60
+    endDays: 60
+    cycleDays: 360
+  -
+    startDays: 45
+    endDays: 45
+    cycleDays: 90
+  -
+    startDays: 15
+    endDays: 15
+    cycleDays: 30
+  -
+    startDays: 7
+    endDays: 7
+    cycleDays: 7
+statisticTime: "00:01"
+jianyu:
+  dbName: jianyu
+  address: "192.168.3.217:4000"
+  userName: root
+  passWord: "=PDT49#80Z!RVv52_z"
+  maxOpenConns: 5
+  maxIdleConns: 5
+subjectdb:
+  dbName: jianyu_subjectdb_test
+  address: "192.168.3.149:4000"
+  userName: jianyu
+  passWord: "TopMysql@123"
+  maxOpenConns: 5
+  maxIdleConns: 5

+ 101 - 0
vipTask/config/config.go

@@ -0,0 +1,101 @@
+package config
+
+import (
+	. "app.yhyue.com/moapp/jybase/mongodb"
+	"app.yhyue.com/moapp/jybase/mysql"
+	"flag"
+	"github.com/zeromicro/go-zero/core/conf"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+var UserMgo *MongodbSim
+var DbConf *dbConf
+var JianYu *mysql.Mysql
+var Subjectdb *mysql.Mysql
+var logc Logc
+
+type dbConf struct {
+	User          *MgoConf
+	InitConfig    []*ExpireConfig
+	DailyConfig   []*ExpireConfig
+	StatisticTime string
+	JianYu        *MysqlConf
+	Subjectdb     *MysqlConf
+}
+type MysqlConf struct {
+	DbName       string
+	Address      string
+	UserName     string
+	PassWord     string
+	MaxOpenConns int
+	MaxIdleConns int
+}
+type ExpireConfig struct {
+	CycleDays int64
+	EndDays   int64
+	StartDays int64
+}
+type MgoConf struct {
+	Address  string
+	Size     int
+	DbName   string
+	UserName string
+	Password string
+}
+
+// 日志信息
+type Logc struct {
+	Mode     string
+	Path     string
+	Level    []string
+	KeepDays int
+}
+
+var logFile = flag.String("lf", "./logs.yaml", "the config file")
+var configFile = flag.String("rf", "./config.yaml", "the config file")
+
+func init() {
+	//util.ReadConfig(&DbConf)
+	//初始化日志信息
+	//日志初始化
+	conf.MustLoad(*logFile, &logc)
+	conf.MustLoad(*configFile, &DbConf)
+	if len(logc.Level) > 0 {
+		for _, v := range logc.Level {
+			logx.MustSetup(logx.LogConf{
+				Mode:     logc.Mode,
+				Path:     logc.Path,
+				Level:    v,
+				KeepDays: logc.KeepDays,
+			})
+			logx.Info(v, "--日志记录")
+		}
+	}
+	//初始化mongo用户库
+	UserMgo = &MongodbSim{
+		MongodbAddr: DbConf.User.Address,
+		Size:        DbConf.User.Size,
+		DbName:      DbConf.User.DbName,
+		UserName:    DbConf.User.UserName,
+		Password:    DbConf.User.Password,
+	}
+	UserMgo.InitPool()
+	JianYu = &mysql.Mysql{
+		Address:      DbConf.JianYu.Address,
+		UserName:     DbConf.JianYu.UserName,
+		PassWord:     DbConf.JianYu.PassWord,
+		DBName:       DbConf.JianYu.DbName,
+		MaxOpenConns: DbConf.JianYu.MaxOpenConns,
+		MaxIdleConns: DbConf.JianYu.MaxIdleConns,
+	}
+	JianYu.Init()
+	Subjectdb = &mysql.Mysql{
+		Address:      DbConf.Subjectdb.Address,
+		UserName:     DbConf.Subjectdb.UserName,
+		PassWord:     DbConf.Subjectdb.PassWord,
+		DBName:       DbConf.Subjectdb.DbName,
+		MaxOpenConns: DbConf.Subjectdb.MaxOpenConns,
+		MaxIdleConns: DbConf.Subjectdb.MaxIdleConns,
+	}
+	Subjectdb.Init()
+}

+ 208 - 0
vipTask/entity/timetask.go

@@ -0,0 +1,208 @@
+package entity
+
+import (
+	util "app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/date"
+	"app.yhyue.com/moapp/jybase/mongodb"
+	"bp.jydev.jianyu360.cn/BaseService/biService/vipTask/config"
+	"github.com/gogf/gf/v2/util/gconv"
+	"github.com/zeromicro/go-zero/core/logx"
+	"time"
+)
+
+type TimeTask struct {
+}
+
+func (t *TimeTask) Run() {
+	go util.SimpleCrontab(false, config.DbConf.StatisticTime, func() {
+		t.DataHandle(config.DbConf.DailyConfig)
+	})
+}
+func (t *TimeTask) DataHandle(allocation []*config.ExpireConfig) {
+	for _, expireConfig := range allocation {
+		sourceMap := config.Subjectdb.FindOne("clue_info_source", map[string]interface{}{
+			"judge": expireConfig.EndDays,
+		}, "id", "")
+		if sourceMap == nil {
+			logx.Info(expireConfig.EndDays, ":查不到来源")
+			return
+		}
+		sourceId := gconv.Int64((*sourceMap)["id"])
+		//数据查询处理
+		//个人数据处理
+		PersonExpireHandle(expireConfig, sourceId)
+		//企业数据处理
+		EntExpireHandle(expireConfig, sourceId)
+	}
+}
+
+// 分批处理数据
+func PersonExpireHandle(allocation *config.ExpireConfig, sourceId int64) {
+	//按时间查询数据
+	endTime := GetFutureDateTime(allocation.EndDays)
+	startTime := GetFutureDateTime(allocation.StartDays)
+	sess := config.UserMgo.GetMgoConn()
+	defer config.UserMgo.DestoryMongoConn(sess)
+	it := sess.DB("qfw").C("user").Find(map[string]interface{}{
+		"l_vip_endtime": map[string]interface{}{
+			"$gte": startTime,
+			"$lte": endTime,
+		},
+		"i_vip_status": map[string]interface{}{
+			"$gt": 0,
+		},
+	}).Select(map[string]interface{}{
+		"s_phone":         1,
+		"s_m_phone":       1,
+		"_id":             1,
+		"l_vip_endtime":   1,
+		"l_vip_starttime": 1,
+		"s_jyname":        1,
+		"s_nickname":      1,
+		"s_company":       1,
+	}).Iter()
+	for m := make(map[string]interface{}); it.Next(&m); {
+		logx.Info("个人数据处理", allocation, m)
+		userId := mongodb.BsonIdToSId(m["_id"])
+		/*endTime := gconv.Int64(m["l_vip_endtime"])
+		startTime := gconv.Int64(m["l_vip_starttime"])*/
+		company := gconv.String(m["s_company"])
+		phone := gconv.String(m["s_phone"])
+		nickname := gconv.String(m["s_nickname"])
+		if nickname == "" {
+			nickname = gconv.String(m["s_jyname"])
+		}
+		if phone == "" {
+			phone = gconv.String(m["s_m_phone"])
+		}
+		//if TimeHandle(startTime, endTime, allocation.CycleDays) {
+		//周期符合条件
+		//查看新增还是修改
+		if config.Subjectdb.Count("clue_info", map[string]interface{}{
+			"userId": userId,
+		}) > 0 {
+			//修改
+			config.Subjectdb.Update("clue_info", map[string]interface{}{
+				"userId": userId,
+			}, map[string]interface{}{
+				"sourceId":   sourceId,
+				"updatetime": time.Now().Format(date.Date_Full_Layout),
+			})
+		} else {
+			//新增
+			config.Subjectdb.Insert("clue_info", map[string]interface{}{
+				"sourceId":    sourceId,
+				"updatetime":  time.Now().Format(date.Date_Full_Layout),
+				"phone":       phone,
+				"name":        nickname,
+				"companyName": company,
+				"createtime":  time.Now().Format(date.Date_Full_Layout),
+				"userId":      userId,
+			})
+		}
+		//}
+	}
+}
+func EntExpireHandle(allocation *config.ExpireConfig, sourceId int64) {
+	//按时间查询数据
+	endTime := GetFutureDateTime(allocation.EndDays)
+	startTime := GetFutureDateTime(allocation.StartDays)
+	sess := config.UserMgo.GetMgoConn()
+	defer config.UserMgo.DestoryMongoConn(sess)
+	it := *sess.DB("qfw").C("ent_user").Pipe(
+		[]map[string]interface{}{
+			{
+				"$match": map[string]interface{}{
+					"l_vip_endtime": map[string]interface{}{
+						"$gte": startTime,
+						"$lte": endTime,
+					},
+					"i_vip_status": map[string]interface{}{
+						"$gt": 0,
+					},
+				},
+			},
+			{
+				"$group": map[string]interface{}{
+					"_id": "$i_entid",
+				},
+			},
+		},
+	).Iter()
+	for m := make(map[string]interface{}); it.Next(&m); {
+		logx.Info("企业数据处理", allocation, m)
+		userId := ""
+		endTime := gconv.Int64(m["l_vip_endtime"])
+		startTime := gconv.Int64(m["l_vip_starttime"])
+		nickname := ""
+		if TimeHandle(startTime, endTime, allocation.CycleDays) {
+			//周期符合条件
+			//查看新增还是修改
+			//先查询企业信息
+			endId := gconv.Int64(m["_id"])
+			entMap := config.JianYu.FindOne("entniche_info", map[string]interface{}{
+				"id": endId,
+			}, "name,phone", "")
+			if entMap == nil {
+				logx.Info(endId, ":企业查询不到")
+			}
+			company := gconv.String((*entMap)["name"])
+			phone := gconv.String((*entMap)["phone"])
+			//用户信息查询
+			userData, ok := config.UserMgo.Find("user", map[string]interface{}{
+				"i_appid": 2,
+				"$or": []map[string]interface{}{
+					{"s_phone": phone},
+					{"s_m_phone": phone}},
+			}, `{"s_phone":-1}`, `{"_id":1,"s_nickname":1,"s_jyname":1}`, false, -1, -1)
+			if ok && userData != nil && len(*userData) > 0 {
+				nickname = gconv.String((*userData)[0]["s_nickname"])
+				if nickname == "" {
+					nickname = gconv.String((*userData)[0]["s_jyname"])
+				}
+				userId = gconv.String(mongodb.BsonIdToSId((*userData)[0]["_id"]))
+			}
+			if config.Subjectdb.Count("clue_info", map[string]interface{}{
+				"userId": userId,
+			}) > 0 {
+				//修改
+				config.Subjectdb.Update("clue_info", map[string]interface{}{
+					"userId": userId,
+				}, map[string]interface{}{
+					"sourceId":   sourceId,
+					"updatetime": time.Now().Format(date.Date_Full_Layout),
+				})
+			} else {
+				//新增
+				config.Subjectdb.Insert("clue_info", map[string]interface{}{
+					"sourceId":    sourceId,
+					"updatetime":  time.Now().Format(date.Date_Full_Layout),
+					"phone":       phone,
+					"name":        nickname,
+					"companyName": company,
+					"createtime":  time.Now().Format(date.Date_Full_Layout),
+					"userId":      userId,
+				})
+			}
+		}
+	}
+}
+
+// 获取几天以后的时间
+func GetFutureDateTime(days int64) int64 {
+	// 获取当前时间
+	now := time.Now()
+	// 计算未来的时间
+	future := now.AddDate(0, 0, gconv.Int(days))
+	// 设置时间为23点59分59秒
+	future = time.Date(future.Year(), future.Month(), future.Day(), 23, 59, 59, 0, future.Location())
+	return future.Unix()
+}
+
+// 时间处理
+func TimeHandle(startTime, endTime, cycleDays int64) bool {
+	if endTime-startTime > cycleDays*24*60*60 {
+		return true
+	}
+	return false
+}

+ 6 - 0
vipTask/logs.yaml

@@ -0,0 +1,6 @@
+Mode: file
+Path: ./logs
+Level:
+  - info
+  - error
+KeepDays: 10

+ 20 - 0
vipTask/main.go

@@ -0,0 +1,20 @@
+package main
+
+import (
+	"bp.jydev.jianyu360.cn/BaseService/biService/vipTask/config"
+	"bp.jydev.jianyu360.cn/BaseService/biService/vipTask/entity"
+	"flag"
+)
+
+func main() {
+	//初始化配置
+	m := flag.Int("m", 0, " 1-跑配置项数据")
+	//m := flag.Int("m", 1, " 1-跑配置项数据")
+	flag.Parse()
+	if *m == 1 {
+		(&entity.TimeTask{}).DataHandle(config.DbConf.InitConfig)
+	} else {
+		(&entity.TimeTask{}).Run()
+		<-chan bool(nil)
+	}
+}