|
@@ -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
|
|
|
+}
|