crontab.go 3.2 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("定时刷新设备每日运行记录", "0 */1 * * * *", AutoFlushDeviceDailyRunningRecord)
	task.AddTask("autoFlushDeviceDailyRunningRecord", autoFlushDeviceDailyRunningRecord)

	autoFlushDeviceDailyRunningRecordOEE := task.NewTask("定时刷新设备每日运行记录-OEE", "0 */10 * * * *", AutoFlushDeviceDailyRunningRecordOEE)
	task.AddTask("autoFlushDeviceDailyRunningRecordOEE", autoFlushDeviceDailyRunningRecordOEE)

	autoWorkshopPlanCompletionRecord := task.NewTask("定时刷新昨日车间计划完成纪录", "0 5 1-17/1 * * *", AutoWorkshopPlanCompletionRecord)
	task.AddTask("autoWorkshopPlanCompletionRecord", autoWorkshopPlanCompletionRecord)

	autoTodayWorkshopPlanCompletionRecord := task.NewTask("定时刷新当天车间计划完成纪录", "0 0 1-23/1 * * *", AutoTodayWorkshopPlanCompletionRecord) // 1:00, 4:00, 每三个小时运行一次
	task.AddTask("autoTodayWorkshopPlanCompletionRecord", autoTodayWorkshopPlanCompletionRecord)

	syncProduct := task.NewTask("定时同步产品信息", "0 0 * * * *", SyncProduct)
	task.AddTask("syncProduct", syncProduct)

	syncProductPlan := task.NewTask("定时同步车间计划", "0 5 * * * *", SyncProductPlan)
	task.AddTask("SyncProductPlan", syncProductPlan)
}

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

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