package jobs

/*import (
	"context"
	"encoding/json"
	"errors"
	"gadmin/config"
	"gadmin/internal/gorm/model"
	"gadmin/internal/gorm/query"
	"gadmin/package/gmmodule"
	"github.com/sirupsen/logrus"
	"gorm.io/gorm"
	model2 "leafstalk/covenant/model"
)

var StatisticsDPS = new(jStatisticsDPS)

type jStatisticsDPS struct {
}

func (j *jStatisticsDPS) Run() {
	logrus.Info("jStatisticsDPS Run.....")

	gmmodule.LoadBattleAttr("./resource/public/serverjson/equipBattleAttr.json",
		"./resource/public/serverjson/roleBattleAttr.json",
		"./resource/public/serverjson/talent.json",
		"./resource/public/serverjson/exskill.json",
		"./resource/public/serverjson/Skill.json",
	)

	type UserIdResult struct {
		UserId int64
	}

	var result []int64
	var tx *gorm.DB
	tx = config.DB.Model(&model.LoginLog{}). //and user_id = 511349
							Raw("select user_id from login_logs where event_id = 2 and event_at >= 1661616000 group by user_id having sum(1)>=1").
							Scan(&result)
	if tx.Error != nil {
		logrus.Errorf("select login_logs err: %v", tx.Error)
	}

	logrus.Warnf("result:%+v", result)

	type PlayerDps struct {
		Playerid int64
		Battle   *gmmodule.PlayerBattleAttr
		DPS      int64
	}
	var (
		o = query.Use(config.GDB1).PlayerAttr
		m = o.WithContext(context.TODO())
		//allPlayerid = make([]PlayerDps, 0)
		ma = query.Use(config.GDB1).PlayerMaterial
	)

	for _, v := range result {
		mod, err := m.Select(o.Playerid, o.Level).Where(o.Playerid.In(v)).First()

		if errors.Is(err, gorm.ErrRecordNotFound) {
			continue
		}

		if err != nil {
			logrus.Warnf("orderLst Scan err . %v", err)
			return
		}

		if mod.Level >= 12 {
			material, err := ma.Where(ma.Playerid.Eq(mod.Playerid)).First()
			if errors.Is(err, gorm.ErrRecordNotFound) {
				continue
			}

			if err != nil {
				logrus.Warnf("material Scan err . %v", err)
				return
			}

			var (
				equipments = make(map[string]model2.DropEquipment)
				roles      = make([]*model2.DropedRole, 0)
				talents    = make(map[int]int)
				equips     = make([]int64, 0)
				role       int64
				allRoles   = make([]int64, 0)
			)

			err = json.Unmarshal([]byte(material.Equipments), &equipments)
			if err != nil {
				logrus.Warnf("json.Unmarshal Equipments err . %v, material.Equipments:%+v", err, material.Equipments)
				continue
			}
			err = json.Unmarshal([]byte(material.Roles), &roles)
			if err != nil {
				logrus.Warnf("json.Unmarshal Roles err . %v, material.Roles:%+v", err, material.Roles)
				continue
			}
			err = json.Unmarshal([]byte(material.Talents), &talents)
			if err != nil {
				logrus.Warnf("json.Unmarshal Talents err . %v, material.Talents:%+v", err, material.Talents)
				continue
			}

			logrus.Warnf("material:%+v", equipments)

			var isw bool

			//for _, e := range equipments {
			//	if e.Wear {
			//		equips = append(equips, e.EID)
			//
			//		eids := fmt.Sprintf("%v", e.EID)
			//		logrus.Warnf("eids:%v, eids[:1]:%v", eids, eids[:1])
			//		if eids[:1] == "1" {
			//			isw = true
			//		}
			//	}
			//
			//}

			if len(equips) == 0 {
				equips = append(equips, 10001001)
				isw = true
			}

			if !isw {
				equips = append(equips, 10001001)
			}

			for _, r := range roles {
				//if r.Wear {
				//	role = r.ID
				//}
				allRoles = append(allRoles, r.ID)
			}
			logrus.Debugf("Playerid：%v,isw:%v, equips:%#v, role:%#v, talents%#v, allRoles%#v", material.Playerid, isw, equips, role, talents, allRoles)
			battle := gmmodule.CalcBattleAttr(equips, role, talents, allRoles)

			//allPlayerid = append(allPlayerid, PlayerDps{
			//	Playerid: material.Playerid,
			//	Battle:   battle,
			//	DPS:      int64(battle.Atk * 60 / battle.AtkSpeed),
			//})

			var (
				q      = query.Use(config.DB).PlayerDp
				models model.PlayerDp
			)

			if err = q.Where(q.Playerid.Eq(material.Playerid)).Scan(&models); err != nil {
				logrus.Warnf("PlayerDp err . %v", err)
				return
			}

			data := model.PlayerDp{
				Playerid: material.Playerid,
				Dps:      int32(float64(battle.Atk*60) / battle.AtkSpeed),
			}

			if models.ID > 0 {
				if _, err := query.Use(config.DB).PlayerDp.Where(q.Playerid.Eq(material.Playerid)).Updates(&data); err != nil {
					logrus.Warnf("PlayerDp Updates err . %v", err)
					return
				}
			} else {
				err := query.Use(config.DB).PlayerDp.Create(&data)
				if err != nil {
					logrus.Warnf("PlayerDp Create err . %v", err)
					return
				}

			}
		}
	}

	//logrus.Warnf("allPlayerid:%+v", allPlayerid)

}*/
