瀏覽代碼

Merge branch 'dev' of chenweida/patient-co-management into dev

chenweida 8 年之前
父節點
當前提交
3c4416563d

+ 2 - 2
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/message/NoticeJob.java

@ -27,8 +27,8 @@ import java.util.Map;
 * Created by Administrator on 2016/11/7.
 */
@Component
@Scope("prototype")
//@Component
//@Scope("prototype")
public class NoticeJob implements Job {
    public static String jobKey = "Notice_JOB";
    public static String jobCron = "0 0 9,15,20 * * ?"; //每天9点,15点,20 点执行一次

+ 8 - 58
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/task/PushMsgTask.java

@ -1,6 +1,6 @@
package com.yihu.wlyy.statistics.task;
import com.yihu.wlyy.statistics.util.http.HttpResponse;
import com.yihu.wlyy.statistics.util.HttpClientUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.http.NameValuePair;
@ -94,12 +94,13 @@ public class PushMsgTask {
				while (true) {
					// 如果queue为空,则当前线程会堵塞,直到有新数据加入
					JSONObject json = queue.take();
					System.out.println("发送前:"+json);
					// 推送平台消息
					String receiver = json.has("receiver") ? json.getString("receiver") : "";
					String type = json.has("type") ? json.getString("type") : "";
					String title = json.has("title") ? json.getString("title") : "";
					String msg = json.has("msg") ? json.getString("msg") : "";
					String data = json.has("data") ? json.getString("data") : "";
					String receiver = json.containsKey("receiver") ? json.getString("receiver") : "";
					String type = json.containsKey("type") ? json.getString("type") : "";
					String title = json.containsKey("title") ? json.getString("title") : "";
					String msg = json.containsKey("msg") ? json.getString("msg") : "";
					String data = json.containsKey("data") ? json.getString("data") : "";
					boolean res = pushMessage(receiver, type, title, msg, data);
					if (res) {
						logger.info("消息推送成功!");
@ -130,62 +131,11 @@ public class PushMsgTask {
			params.add(new BasicNameValuePair("contentType", msgType));
			params.add(new BasicNameValuePair("title", title));
			params.add(new BasicNameValuePair("summary", data));
			HttpResponse response = post(url, params);
			if (response != null && response.getStatusCode() == 200) {
				JSONObject json = JSONObject.fromObject(response.getBody());
				if (!"200".equals(json.optString("status"))) {
					throw new Exception(json.optString("msg"));
				}
			} else {
				throw new Exception("接口调用错误!"+response.getBody());
			}
			String response = HttpClientUtil.post(url, params, "UTF-8");
			return true;
		} catch (Exception e) {
			logger.error("push message error:", e);
		}
		return false;
	}
	private static HttpResponse post(String url, List<NameValuePair> params) {
		HttpResponse re = new HttpResponse();
		CloseableHttpResponse response = null;
		CloseableHttpClient httpclient =  HttpClients.createDefault();
		//设置请求信息
		try {
			RequestConfig requestConfig = RequestConfig.custom().
					setAuthenticationEnabled(true).build();
			HttpPost request = new HttpPost(url );
			request.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));
			request.setConfig(requestConfig);
			response = httpclient.execute(request);
			re.setStatusCode(response.getStatusLine().getStatusCode());
			re.setBody(EntityUtils.toString(response.getEntity(), "UTF-8"));
		} catch (Exception e) {
			re.setStatusCode(201);
			re.setBody(e.getMessage());
		} finally {
			close(httpclient, response);
		}
		return re;
	}
	private static void close(CloseableHttpClient httpClient, CloseableHttpResponse response) {
		try {
			if (httpClient != null) {
				httpClient.close();
			}
		} catch (Exception e) {
			System.out.print("关闭httpClient失败");
		}
		try {
			if (response != null) {
				response.close();
			}
		} catch (Exception e) {
			System.out.print("关闭response失败");
		}
	}
}

+ 102 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/util/HttpClientUtil.java

@ -0,0 +1,102 @@
package com.yihu.wlyy.statistics.util;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
public class HttpClientUtil {
	/**
	 * 发送post请求
	 * @param url 请求地址
	 * @param params 请求参数
	 * @param chatSet 编码格式
	 * @return
	 */
	public static String post(String url, List<NameValuePair> params, String chatSet) {
		// 创建默认的httpClient实例.
		CloseableHttpClient httpclient = HttpClients.createDefault();
		// 创建httppost
		HttpPost httppost = new HttpPost(url);
		UrlEncodedFormEntity uefEntity;
		try {
			uefEntity = new UrlEncodedFormEntity(params, chatSet);
			httppost.setEntity(uefEntity);
			CloseableHttpResponse response = httpclient.execute(httppost);
			try {
				HttpEntity entity = response.getEntity();
				if (entity != null) {
					return EntityUtils.toString(entity, chatSet);
				}
			} finally {
				response.close();
			}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			// 关闭连接,释放资源
			try {
				httpclient.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
	/**
	 * 发送get请求
	 * @param url 请求地址
	 * @param chatSet 编码格式
	 * @return
	 */
	public static String get(String url, String chatSet) {
		CloseableHttpClient httpclient = HttpClients.createDefault();
		try {
			// 创建httpget.
			HttpGet httpget = new HttpGet(url);
			// 执行get请求.
			CloseableHttpResponse response = httpclient.execute(httpget);
			try {
				// 获取响应实体
				HttpEntity entity = response.getEntity();
				if (entity != null) {
					return EntityUtils.toString(entity, chatSet);
				}
			} finally {
				response.close();
			}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			// 关闭连接,释放资源
			try {
				httpclient.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
}

+ 0 - 36
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/util/http/HttpResponse.java

@ -1,36 +0,0 @@
package com.yihu.wlyy.statistics.util.http;
/**
 * add by hzp at 2016-8-9
 */
public class HttpResponse {
    public HttpResponse()
    {
    }
    public HttpResponse(int statusCode, String body) {
        this.statusCode = statusCode;
        this.body = body;
    }
    private int statusCode;
    private String body;
    public int getStatusCode() {
        return statusCode;
    }
    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }
    public String getBody() {
        return body;
    }
    public void setBody(String body) {
        this.body = body;
    }
}

+ 1 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/discussion/DoctorDiscussionGroupController.java

@ -661,6 +661,7 @@ public class DoctorDiscussionGroupController extends BaseController {
            WlyyTalkGroup wlyyTalkGroup= talkGroupService.findTalkGroup(groupCode);
            json.put("groupCreator", wlyyTalkGroup.getCreator());
            json.put("groupCreatorName", wlyyTalkGroup.getCreatorName());
            json.put("groupType", wlyyTalkGroup.getType());
            return write(200, "查询成功", "data", json);
        } catch (Exception e) {
            return error(-1, "查询失败");