package com.weaver.seconddev.chapanda.beisen.esb;

import com.weaver.common.base.entity.result.WeaResult;
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
import com.weaver.seconddev.chapanda.beisen.util.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;

@Service("Esb2BeisenJobRequirementUnRelateAction")
public class Esb2BeisenJobRequirementUnRelateAction implements EsbServerlessRpcRemoteInterface {
    private final static Logger log = LoggerFactory.getLogger(Esb2BeisenJobRequirementUnRelateAction.class);

    @Autowired
    Esb2BeisenUnRelateRequestUtil esb2BeisenUnRelateRequestUtil;

    @Override
    public WeaResult<Map<String, Object>> execute(Map<String, Object> params) {

        String form_data_id = String.valueOf(params.get("form_data_id"));
        String requirementId = String.valueOf(params.get("requirementId"));

        if(StringUtils.isBlank(requirementId)){
            return WeaResult.fail(500,"招聘需求信息获取为空");
        }

        log.error("requirementId:" + requirementId);
        String code = esb2BeisenUnRelateRequestUtil.unRelateJobRequirement(requirementId);
        log.error("code:" + code);
        if(StringUtils.isBlank(code)){
            return WeaResult.fail(500,"取消招聘需求失败");
        }

        if(!"200".equals(code)){
            return WeaResult.fail(500,"取消招聘需求失败");
        }

        Map<String, Object> actionMap = new HashMap<String, Object>();
        actionMap.put("code",200);
        actionMap.put("msg","取消招聘需求成功");
        actionMap.put("datacode",code);
        actionMap.put("form_data_id",form_data_id);

        return WeaResult.success(actionMap);
    }

}
