package jobs

/*import (
	"encoding/json"
	"gadmin/config"
	"gadmin/internal/gorm/model"
	"gadmin/internal/gorm/query"
	"github.com/sirupsen/logrus"
	model2 "leafstalk/covenant/model"
	"sync"
	"time"
)

type Rank38 struct {
	Min    int64     `json:"rankingUpperLimit"`
	Max    int64     `json:"rankingLowerLimit"`
	Reward [][]int64 `json:"reward"`
}

var (
	Repay38           = new(jRepay38)
	Rank38Json        = `[{"rankingUpperLimit":1,"rankingLowerLimit":1,"reward":[[1017,25],[1014,25],[6011,50],[6013,50],[1001,5000000]]},{"rankingUpperLimit":2,"rankingLowerLimit":2,"reward":[[1017,20],[1014,20],[6011,35],[6013,35],[1001,4500000]]},{"rankingUpperLimit":3,"rankingLowerLimit":3,"reward":[[1017,15],[1014,15],[6011,20],[6013,20],[1001,4000000]]},{"rankingUpperLimit":4,"rankingLowerLimit":6,"reward":[[1017,10],[1014,10],[6011,13],[6013,13],[1001,3500000]]},{"rankingUpperLimit":7,"rankingLowerLimit":10,"reward":[[1017,5],[1014,5],[6011,8],[6013,8],[1001,3000000]]},{"rankingUpperLimit":11,"rankingLowerLimit":50,"reward":[[1017,3],[1014,3],[6011,5],[6013,5],[1001,2500000]]},{"rankingUpperLimit":51,"rankingLowerLimit":200,"reward":[[1017,2],[1014,2],[6011,3],[6013,3],[1001,2000000]]},{"rankingUpperLimit":201,"rankingLowerLimit":500,"reward":[[1017,1],[1014,1],[6011,2],[6013,2],[1001,1500000]]},{"rankingUpperLimit":501,"rankingLowerLimit":1000,"reward":[[1015,5],[1013,5],[6011,1],[6013,1],[1001,1000000]]},{"rankingUpperLimit":1001,"rankingLowerLimit":30000,"reward":[[1015,1],[1012,5],[1001,500000]]}]`
	allPrayRankReward []*Rank38
)

type jRepay38 struct {
	sync.RWMutex
}

func (j *jRepay38) Run() {
	logrus.Info("jRepay38 Run.....")
	j.handle()
}

func (j *jRepay38) ExtractMaterials(lst [][]int64) (dms []*model2.DropMaterial) {
	for _, v := range lst {
		dm := &model2.DropMaterial{
			ID:    v[0],
			Count: int(v[1]),
		}
		dms = append(dms, dm)
	}
	return
}

func (j *jRepay38) FindLady38RankPrize(rank int64) ([]*model2.DropMaterial, []int64) {
	for _, v := range allPrayRankReward {
		if rank >= v.Min && rank <= v.Max {
			ms := j.ExtractMaterials(v.Reward)
			return ms, nil
		}
	}
	return nil, nil
}

func (j *jRepay38) FindLady38RankLevel(playerId int32) int {
	for _, v := range allLevel38 {
		if v.PlayerId == playerId {
			return v.ExtraInfo.Level
		}
	}
	return 0
}

func (j *jRepay38) handle() {
	j.RLock()
	defer j.RUnlock()

	err := json.Unmarshal([]byte(Rank38Json), &allPrayRankReward)
	if err != nil {
		logrus.Panicf("Unmarshal Rank38Json err:%+v", err)
		return
	}

	if err := json.Unmarshal([]byte(Level38Json), &allLevel38); err != nil {
		logrus.Panicf("Unmarshal Level38Json err:%+v", err)
		return
	}

	//logrus.Infof("allLevel38:%+v", allLevel38)

	//return

	var (
		u         = query.Use(config.DB).Lady38rank2
		whitelist = map[int64]struct{}{
			10: {},
			11: {},
			24: {},
			40: {},
		}
	)

	type ExtraData struct {
		Materials []*model2.DropMaterial `json:"materials"`
		Equips    []int64                `json:"equips"`
	}

	lists, err := u.Limit(10000).Find()
	if err != nil {
		logrus.Panicf("jRepay38 Find err:%+v", err)
		return
	}

	for _, item := range lists {
		logrus.Warningf("item:%+v", item)

		// 50名之前，没发的补发，已发的不再发。
		// 51名和之后，不管发没发，都补发。
		if item.Mingci <= 50 {
			_, ok := whitelist[item.Mingci]
			if !ok {
				continue
			}
		}

		if 2514575 == item.ID {
			continue
		}

		ms, es := j.FindLady38RankPrize(item.Mingci)
		if ms != nil || es != nil {

			var l = query.Use(config.GDB1).PlayerLetter
			letter := model.PlayerLetter{
				PlayerID:    int64(item.ID),
				Type:        19, //女神驾到排行
				ExpireTime:  time.Now().Add(time.Hour * 24 * 7),
				CreateTime:  time.Now(),
				DisplayTime: time.Now(),
			}

			var em ExtraData
			em.Materials = append(em.Materials, ms...)
			em.Equips = es
			emb, err := json.Marshal(&em)
			if err != nil {
				logrus.Panicf("Repay38Items Materials marshal error. %v, error: %v", em, err)
			}
			letter.Extra = string(emb)

			//level := j.FindLady38RankLevel(item.ID)
			//if level == 0 {
			//	logrus.Panicf("FindLady38RankLevel = 0 item.ID: %v", item.ID)
			//}

			extra := make(map[string]interface{})
			extra["level"] = item.Score
			extra["rank"] = item.Mingci
			jex, err := json.Marshal(&extra)
			if err != nil {
				logrus.Panicf("Repay38Items LetterExtraRank marshal error. %v, error: %v", extra, err)
			}
			letter.ExtraInfo = string(jex)

			if err = l.Create(&letter); err != nil {
				logrus.Panicf("addLetter Create err :%+v, letter:%+v", err, letter)
				//return err
			}

			//letter := new(model.Letter)
			//letter.PlayerId = item.PlayerID
			//letter.Type = t.MailType
			//letter.Extra.Materials = ms
			//letter.Extra.Equips = es
			//letter.ExpireTime = expTime
			//extra := model.LetterExtraInfo{
			//	Level: item.Level,
			//	Rank:  item.Rank,
			//}
			//jex, err := json.Marshal(&extra)
			//if err != nil {
			//	log.WithField("from", t.Name).Errorf("SendRankPrizeByTimer LetterExtraRank marshal error. %v, error: %v", extra, err)
			//	continue
			//}
			//letter.ExtraInfo = string(jex)
			//letterLst = append(letterLst, letter)
		}
	}

	logrus.Infof("Repay38 ok!!")
}*/
