package com.bohuikeji.delivery.backstage.task;

import com.bohuikeji.delivery.backstage.util.capacity.JdUtils;
import com.bohuikeji.frame.module.admin.task.Task;
import com.bohuikeji.frame.module.admin.utils.TaskUtils;
import java.util.HashMap;

/**
 * 京东取消订单任务队列
 * 说明：由于京东取消订单是异步状态，需要多次调用
 * @author Admin
 */
public class JdCancelOrderTask implements Task {
    @Override
    public long delayTime() {
        //首次30秒
        return 1000 * 30;
    }

    @Override
    public void runTask(HashMap<String, Object> params) {
        String deliveryId=String.valueOf(params.get("deliveryId"));
        if (!JdUtils.cancelOrder(deliveryId, (String) params.get("reason"),(String) params.get("operator"))){
            int times=Integer.parseInt(String.valueOf(params.get("times")));
            if (times>=0&&times<10){
                TaskUtils.add(this,delayTime()*times)
                        .addParam(params)
                        .addParam("times",times+1);
            }
        }
    }
}
