package weaver.interfaces.htsc.cus;

import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * Author:DTY-PC
 * Date:2020/10/21 18:26
 * Description: 驳回时调用保存行程接口
 * Copyright:上海泛微网络科技股份有限公司
 */
public class SaveTrip4RejectAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = Util.null2String(requestInfo.getRequestid());
        String src = Util.null2String(requestInfo.getRequestManager().getSrc());
        try {
            if("reject".equals(src)){//退回
                HTUtil htUtil = new HTUtil();
                Map<String,Object> para = new HashMap<>();
                para.put("requestid",requestid);
                para.put("status","RETURN");
                String res = htUtil.getSaveTripReqString(para);
                if(!"".equals(res)){
                    if(!"-1".equals(res)){
                        boolean isSucc = htUtil.saveTrip(res);
                        if(!isSucc){
                            requestInfo.getRequestManager().setMessageid("1111111");
                            requestInfo.getRequestManager().setMessagecontent("调用保存行程接口出错，请联系管理员！");
                            writeLog("拼接保存行程接口请求字符串是："+res);
                            return Action.FAILURE_AND_CONTINUE;
                        }
                    }
                }else{
                    requestInfo.getRequestManager().setMessageid("1111111");
                    requestInfo.getRequestManager().setMessagecontent("调用保存行程接口出错，请联系管理员！");
                    writeLog("拼接保存行程接口请求字符串是："+res);
                    return Action.FAILURE_AND_CONTINUE;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid("1111111");
            requestInfo.getRequestManager().setMessagecontent("调用保存行程接口捕获异常，请联系管理员！");
            return Action.FAILURE_AND_CONTINUE;
        }
        return Action.SUCCESS;
    }
}
