package task

import (
	omModel "LAPP_LF_MOM_BACKEND/models/om"
	services "LAPP_LF_MOM_BACKEND/services/om"
)

var parseOrderFromFileStatus int
var parseOrderFromDBStatus int
var createParseTaskFrmDBByDayStatus int
var createParseTaskFrmDBByTimeStatus int

/******************************************************************************
*
* @Struct Name              : ParseWorkOrderFromFile
*-----------------------------------------------------------------------------
*
* @Description              : 启动定时任务
*
* @Author                   : zhangxin
*
* @Date                     : 2021-05-12
*
******************************************************************************/
func ParseWorkOrderFromFile() {
	if parseOrderFromFileStatus == 0 {
		parseOrderFromFileStatus = 1
		defer func() {
			parseOrderFromFileStatus = 0
		}()
	} else {
		return
	}
	plantNr := 100
	omService := services.NewParseMesWorkOrderService()
	omService.OMParseDemandFromFile(plantNr)
}

/******************************************************************************
*
* @Struct Name              : ParseWorkOrderFromDB
*-----------------------------------------------------------------------------
*
* @Description              : 启动定时任务
*
* @Author                   : zhangxin
*
* @Date                     : 2021-05-12
*
******************************************************************************/
func ParseWorkOrderFromDB()  {
	if parseOrderFromFileStatus == 1 {
		return
	}
	if parseOrderFromDBStatus == 0 {
		parseOrderFromDBStatus = 1
		defer func() {
			parseOrderFromDBStatus = 0
		}()
	} else {
		return
	}
	plantNr := 100
	omService := services.NewParseMesWorkOrderService()
	omService.OMParseDemandFromDB(plantNr)
}

/******************************************************************************
*
* @Struct Name              : CreateParseFromDBByDayTask
*-----------------------------------------------------------------------------
*
* @Description              : 启动定时任务
*
* @Author                   : zhangxin
*
* @Date                     : 2021-05-12
*
******************************************************************************/
func CreateParseFromDBByDayTask()  {
	if createParseTaskFrmDBByDayStatus == 0 {
		createParseTaskFrmDBByDayStatus = 1
		defer func() {
			createParseTaskFrmDBByDayStatus = 0
		}()
	} else {
		return
	}
	plantNr := 100
	omService := services.NewDemandHeadFromDBService()
	omService.CreateParseTask(plantNr, omModel.ParseTaskTypeByDay)
}

/******************************************************************************
*
* @Struct Name              : CreateParseFromDBByTimeTask
*-----------------------------------------------------------------------------
*
* @Description              : 启动定时任务
*
* @Author                   : zhangxin
*
* @Date                     : 2021-05-12
*
******************************************************************************/
func CreateParseFromDBByTimeTask()  {
	if createParseTaskFrmDBByTimeStatus == 0 {
		createParseTaskFrmDBByTimeStatus = 1
		defer func() {
			createParseTaskFrmDBByTimeStatus = 0
		}()
	} else {
		return
	}
	plantNr := 100
	omService := services.NewDemandHeadFromDBService()
	omService.CreateParseTask(plantNr, omModel.ParseTaskTypeByTime)
}