package services

import (
	"fmt"
	"hongze/hz_crm_api/models/eta_business"
	"hongze/hz_crm_api/utils"
)

func Task() {
	fmt.Println("task start")

	go AutoInsertLogToDB()

	go AutoInsertAdminOperateRecordToDB()

	//go FixEtaBusinessCodeEncrypt()

	fmt.Println("task end")
}

// FixEtaBusinessCodeEncrypt 修复商家编码
func FixEtaBusinessCodeEncrypt() {
	ob := new(eta_business.EtaBusiness)
	list, e := ob.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
	if e != nil {
		fmt.Println(e.Error())
		return
	}

	for _, v := range list {
		v.CodeEncrypt = utils.MD5(fmt.Sprintf("%s%s", v.BusinessCode, utils.BusinessCodeSalt))
		if e = v.Update([]string{"CodeEncrypt"}); e != nil {
			fmt.Println(e.Error())
			return
		}
	}
}
