/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.zzsmart.qomo.kn.cost.manage.plugin.materialcost;

import com.zzsmart.qomo.kn.cost.manage.plugin.StandardCostService;
import com.zzsmart.qomo.plugin.task.api.*;
import com.zzsmart.qomo.plugin.task.api.parameters.AbstractParameters;

/**
 * 物料成本计算任务
 */
public class MaterialCostTask extends AbstractTask {
    /**
     * taskExecutionContext
     */
    private TaskExecutionContext taskExecutionContext;

    /**
     * sql parameters
     */
    private MaterialCostParameters emptyParameters;


    /**
     * Abstract Yarn Task
     *
     * @param taskRequest taskRequest
     */
    public MaterialCostTask(TaskExecutionContext taskRequest) {
        super(taskRequest);
        this.taskExecutionContext = taskRequest;
        this.emptyParameters = new MaterialCostParameters();
    }

    @Override
    public AbstractParameters getParameters() {
        return emptyParameters;
    }

    @Override
    public void handle(TaskCallBack taskCallBack) throws TaskException {
        log.info("Full EmptyTask parameters: {}", taskExecutionContext);
        try {
            StandardCostService.materialCostTask(taskExecutionContext);
        } catch (Exception e) {
            //运行失败退出
            setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE);
        }
        //运行成功退出
        setExitStatusCode(TaskConstants.EXIT_CODE_SUCCESS);
    }

    @Override
    public void cancel() throws TaskException {

    }
}
