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.busiz.req.DeviceReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.common.code.MessageTypeEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

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> deviceReqApiReq = new ApiThirdPartyReq<>();
        deviceReqApiReq.setCode(YesNoEnum.YES.getValue());
        deviceReqApiReq.setType(MessageTypeEnum.TRANSACTION.getValue());
        deviceReqApiReq.setData(content);
        String resp = null;
        try {
            Map<String, String> header = new HashMap<>();
            header.put(HEADER_CONTENT_TYPE, "application/json");
            resp = HttpUtil.doPost(sendUrl, header, JSON.toJSONString(deviceReqApiReq));
        } catch (Exception e) {
            log.error("异常:", e);
        }
    }
}
