crontab.go 2.4 KB
package crontab

import (
	"context"

	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"

	"github.com/beego/beego/v2/task"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/syncdata"
)

type CrontabService struct {
}

func NewCrontabService(options map[string]interface{}) *CrontabService {
	newCrontabService := &CrontabService{}
	return newCrontabService
}

func (crontabService *CrontabService) initTask() {
	//拉取物料数据 每5分执行
	pullMaterialK3cloud := task.NewTask("pullMaterialK3cloud", "0 */5 0 * * *", func(ctx context.Context) error {
		srv := syncdata.PullDataK3CloudService{}
		return srv.PullMaterialNewest()
	})
	task.AddTask("pullMaterialK3cloud", pullMaterialK3cloud)
	//拉取物料分组数据 每5分执行
	pullMaterialGroupK3cloud := task.NewTask("pullMaterialGroupK3cloud", "0 */5 0 * * *", func(ctx context.Context) error {
		srv := syncdata.PullDataK3CloudService{}
		return srv.PullMaterialGroup()
	})
	task.AddTask("pullMaterialGroupK3cloud", pullMaterialGroupK3cloud)
	//拉取订生产订单数据 每5分执行
	PullPrdMoK3cloud := task.NewTask("PullPrdMoK3cloud", "0 */5 0 * * *", func(ctx context.Context) error {
		srv := syncdata.PullDataK3CloudService{}
		return srv.PullPrdMoNewest()
	})
	task.AddTask("PullPrdMoK3cloud", PullPrdMoK3cloud)

	autoApproveAttendanceRecord := task.NewTask("autoApproveAttendanceRecord", "0 */2 * * * *", AutoApproveProductAttendanceRecord)
	task.AddTask("autoApproveAttendanceRecord", autoApproveAttendanceRecord)

	autoApproveRecord := task.NewTask("autoApproveRecord", "0 */2 * * * *", AutoApproveProductRecord)
	task.AddTask("autoApproveRecord", autoApproveRecord)

	autoFlushDeviceDailyRunningRecord := task.NewTask("autoFlushDeviceDailyRunningRecord", "0 */1 * * * *", AutoFlushDeviceDailyRunningRecord)
	task.AddTask("autoFlushDeviceDailyRunningRecord", autoFlushDeviceDailyRunningRecord)

	autoWorkshopPlanCompletionRecord := task.NewTask("autoFlushDeviceDailyRunningRecord", "0 1 1-10/3 * * *", AutoWorkshopPlanCompletionRecord)
	task.AddTask("autoWorkshopPlanCompletionRecord", autoWorkshopPlanCompletionRecord)
}

func (crontabService *CrontabService) StartCrontabTask() {
	crontabService.initTask()
	task.StartTask()
	log.Logger.Info("crontab start!")
}

func (crontabService *CrontabService) StopCrontabTask() {
	task.StopTask()
	log.Logger.Info("crontab stop!")
}