package services

import (
	"fmt"
	"github.com/astaxie/beego/toolbox"
)

func Task() {
	fmt.Println("task start")
	//发送邮件
	sendEmail := toolbox.NewTask("sendEmail", "0 0 12 * * 0 ", SendEmail)
	toolbox.AddTask("sendEmail", sendEmail)

	//潜在客户
	freeViewerDetail := toolbox.NewTask("freeViewerDetail", "0 0 9 * * 1 ", FreeViewerDetail)
	toolbox.AddTask("freeViewerDetail", freeViewerDetail)

	oneMinute := toolbox.NewTask("oneMinute", "0 */1 7-23 * * * ", OneMinute)
	toolbox.AddTask("oneMinute", oneMinute)

	//隆众指标获取
	getLzProductList := toolbox.NewTask("getLzProductList", "0 0 11-19/1 * * * ", GetLzProductList)
	toolbox.AddTask("getLzProductList", getLzProductList)
	//隆众指标数据获取
	getLzProductDetail := toolbox.NewTask("getLzProductDetail", "0 5 11-19/1 * * * ", GetLzProductDetail)
	toolbox.AddTask("getLzProductDetail", getLzProductDetail)

	//隆众价格指标获取
	getLzProductPriceProduct := toolbox.NewTask("getLzProductPriceProduct", "0 5 11-19/1 * * * ", GetLzProductPriceProduct)
	toolbox.AddTask("getLzProductPriceProduct", getLzProductPriceProduct)
	//隆众价格指标数据获取
	getLzProductPriceData := toolbox.NewTask("getLzProductPriceData", "0 10 11-19/1 * * * ", GetLzProductPriceData)
	toolbox.AddTask("getLzProductPriceData", getLzProductPriceData)

	//正式->试用
	companyTryOut := toolbox.NewTask("companyTryOut", "0 5 0 * * *", CompanyTryOut)
	toolbox.AddTask("companyTryOut", companyTryOut)

	//试用->冻结
	companyFreeze := toolbox.NewTask("companyFreeze", "0 10 0 * * *", CompanyFreeze)
	toolbox.AddTask("companyFreeze", companyFreeze)

	//冻结->流失
	companyLoss := toolbox.NewTask("companyLoss", "0 20 0 * * *", CompanyLoss)
	toolbox.AddTask("companyLoss", companyLoss)

	companyReportPermissionClose := toolbox.NewTask("companyReportPermissionClose", "0 30 0 * * *", CompanyReportPermissionClose)
	toolbox.AddTask("用户产品权限试用-->关闭", companyReportPermissionClose)


	//到期提醒
	companyRemind := toolbox.NewTask("companyRemind", "0 30 08 * * *", CompanyRemind)
	toolbox.AddTask("companyRemind", companyRemind)

	//删除日志记录
	//deleteReportSaveLog := toolbox.NewTask("deleteReportSaveLog", "0 30 08 * * *", DeleteReportSaveLog)
	//toolbox.AddTask("deleteReportSaveLog", deleteReportSaveLog)

	toolbox.StartTask()
	//GetHistoryLzProductDetail()
	//GetLzPrice()
	//GetLzProductDetail()
	//LzExportExcel()
	//GetLzProductList()GetLzProductDetail
	fmt.Println("task end")
}

func TaskTest(){
	fmt.Println("The task is start")
	//companyReportPermissionClose := toolbox.NewTask("companyTryOut", "0 5 0 * * *", CompanyReportPermissionClose)
	companyReportPermissionClose := toolbox.NewTask("companyReportPermissionClose", "0/30 * * * * *", CompanyReportPermissionClose)
	toolbox.AddTask("用户产品权限试用-->关闭", companyReportPermissionClose)
	toolbox.StartTask()
	fmt.Println("The task is end")
}

func Task123() {
	fmt.Println("start")
	FreeViewerDetail()
	fmt.Println("end")
	return
}

func SendEmail() (err error) {
	//报告历史访问次数
	go ReportViewTimes()
	//报告访问详情
	go ReportViewDetail()
	//用户权限统计
	go HongzeUsers()
	return
}

func OneMinute() (err error) {
	//日度
	//FrequencyByDay()
	//周度
	FrequencyByWeek()
	//月度
	FrequencyByMonth()
	return
}