package com.mortals.xhx.common.utils;

import com.alibaba.fastjson.JSON;
import com.mortals.framework.util.HttpUtil;
import com.mortals.xhx.busiz.req.ApiThirdPartyReq;
import com.mortals.xhx.common.code.MessageTypeEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

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

import static com.mortals.framework.util.HttpUtil.HEADER_CONTENT_TYPE;

/**
 * 发送任务
 *
 * @author: zxfei
 * @date: 2022/4/28 10:56
 * @description:
 **/
@Slf4j
@AllArgsConstructor
public class SendTask implements Runnable {
    private String sendUrl;
    private String content;

    @Override
    public void run() {
        ApiThirdPartyReq<String> apiThirdReqApiReq = new ApiThirdPartyReq<>();
        apiThirdReqApiReq.setCode(YesNoEnum.YES.getValue());
        apiThirdReqApiReq.setType(MessageTypeEnum.TRANSACTION.getValue());
        apiThirdReqApiReq.setData(content);
        String resp = null;
        try {
            Map<String, String> header = new HashMap<>();
            header.put(HEADER_CONTENT_TYPE, "application/json");
            String reqStr = JSON.toJSONString(apiThirdReqApiReq);
            log.info("sendUrl:{} \n sendMessageReq:{}",sendUrl, reqStr);
            resp = HttpUtil.doPost(sendUrl, header, reqStr);
            log.debug("sendMessageResp:{}", resp);
        } catch (Exception e) {
            log.error("异常:", e);
        }
    }
}
