123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- 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"
- "fmt"
- "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 := GetFutureDateTimeStr(allocation.EndDays)
- startTime := GetFutureDateTimeStr(allocation.StartDays)
- config.JianYu.SelectByBath(1, func(l *[]map[string]interface{}) bool {
- go func(m map[string]interface{}) {
- //logx.Info("企业数据处理", allocation, m)
- //企业开始结束时间查询
- endId := gconv.Int64(m["ent_id"])
- if endId == 86268 {
- logx.Info(1111)
- }
- orderList := config.JianYu.SelectBySql("select start_time,end_time from entniche_wait_empower where ent_id=? ORDER BY end_time desc", endId)
- if (*orderList) == nil || len(*orderList) == 0 {
- return
- }
- endTime := int64(0)
- startTime := int64(0)
- if len(*orderList) == 1 {
- time1, _ := time.Parse("2006-01-02 15:04:05", gconv.String((*orderList)[0]["start_time"]))
- time2, _ := time.Parse("2006-01-02 15:04:05", gconv.String((*orderList)[0]["end_time"]))
- startTime = time1.Unix()
- endTime = time2.Unix()
- } else {
- startTime, endTime = CalculateSuperOrderPeriod(orderList)
- }
- userId := ""
- nickname := ""
- logx.Info("企业数据处理", allocation, m, time.Unix(startTime, 0), time.Unix(endTime, 0))
- if TimeHandle(startTime, endTime, allocation.CycleDays) {
- //周期符合条件
- //查看新增还是修改
- //先查询企业信息
- 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,
- "name": nickname,
- "companyName": company,
- "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,
- })
- }
- }
- }((*l)[0])
- return true
- }, ` select * from ( select ent_id,MAX(end_time) end_time from entniche_wait_empower where product_type="VIP订阅" GROUP BY ent_id ) a where a.end_time<=? and a.end_time>=?`, endTime, startTime)
- fmt.Println(` select * from ( select ent_id,MAX(end_time) end_time from entniche_wait_empower GROUP BY ent_id ) a where a.end_time<=? and a.end_time>=?`, endTime, startTime)
- }
- // 获取几天以后的时间
- 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 GetFutureDateTimeStr(days int64) string {
- // 获取当前时间
- 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.Format("2006-01-02 15:04:05")
- }
- // 时间处理
- func TimeHandle(startTime, endTime, cycleDays int64) bool {
- if endTime-startTime > cycleDays*24*60*60 {
- return true
- }
- return false
- }
- type Order struct {
- StartDate time.Time
- EndDate time.Time
- }
- // 时间对比
- func CalculateSuperOrderPeriod(orders *[]map[string]interface{}) (int64, int64) {
- startDate, _ := time.Parse("2006-01-02 15:04:05", gconv.String((*orders)[0]["start_time"]))
- endDate, _ := time.Parse("2006-01-02 15:04:05", gconv.String((*orders)[0]["end_time"]))
- for i, order := range *orders {
- if i == 0 {
- continue
- }
- time1, _ := time.Parse("2006-01-02 15:04:05", gconv.String(order["start_time"]))
- time2, _ := time.Parse("2006-01-02 15:04:05", gconv.String(order["end_time"]))
- //先查看有没有交集
- if startDate.Unix() <= time2.Unix() || (startDate.Unix() > time2.Unix() && startDate.Unix()-time2.Unix() < 24*60*60) {
- if startDate.Unix() >= time1.Unix() {
- startDate = time1
- }
- } else {
- break
- }
- }
- return startDate.Unix(), endDate.Unix()
- }
|