package org.well.well.core.util;

import org.well.well.util.Configure;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by phantomli on 2016/2/17.
 */
public class ThreadUtil {
    public static void excuteMsg(Long id, String msg,String wellCode) throws UnsupportedEncodingException {
        ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
        final Long jobId = id;
        final String wellcode = wellCode;
        final String alarmMsg = URLEncoder.encode(msg, "UTF-8");
        cachedThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    String retMsg = HttpClientUtils.post(Configure.getProperty("sendURL", "") + "?id=" + jobId
                            + "&msg="+alarmMsg  + "&wellCode="+wellcode, "");
                    Thread.sleep(500);
                    System.out.println("--------工单和告警推送至web后台成功 " + retMsg + ",工单id：" + jobId);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("--------工单和告警推送至web后台失败，工单id：" + jobId);
                }
            }
        });
    }
}
