Quellcode durchsuchen

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

yeshijie vor 7 Jahren
Ursprung
Commit
3508d10b7e

+ 9 - 7
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/common/http/HttpClientUtil.java

@ -18,6 +18,7 @@ import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
@ -29,10 +30,11 @@ import java.util.Map;
/**
 * Created by hzp on 2016/8/9.
 */
@Component
public class HttpClientUtil {
    /**************************** 私有方法 *****************************************/
    private static CloseableHttpClient getCloseableHttpClient(SSLConnectionSocketFactory ssl) {
    private CloseableHttpClient getCloseableHttpClient(SSLConnectionSocketFactory ssl) {
        if(ssl == null)
        {
            return HttpClients.createDefault();
@ -45,7 +47,7 @@ public class HttpClientUtil {
        }
    }
    private static void close(CloseableHttpClient httpClient, CloseableHttpResponse response) {
    private void close(CloseableHttpClient httpClient, CloseableHttpResponse response) {
        try {
            if (httpClient != null) {
                httpClient.close();
@ -62,7 +64,7 @@ public class HttpClientUtil {
        }
    }
    private static HttpRequestBase getRequest(String method,String url,Map<String,Object> params,Map<String,Object> header) throws Exception
    private HttpRequestBase getRequest(String method,String url,Map<String,Object> params,Map<String,Object> header) throws Exception
    {
        List<BasicNameValuePair> jsonParams = new ArrayList<>();
        //配置参数
@ -101,7 +103,7 @@ public class HttpClientUtil {
    /**
     * get请求
     */
    public static HttpResponse request(String method,String url,Map<String,Object> params,Map<String,Object> header,SSLConnectionSocketFactory ssl,String user,String password) {
    public HttpResponse request(String method,String url,Map<String,Object> params,Map<String,Object> header,SSLConnectionSocketFactory ssl,String user,String password) {
        HttpResponse re = new HttpResponse();
        CloseableHttpResponse response = null;
        CloseableHttpClient httpclient = getCloseableHttpClient(ssl);
@ -142,7 +144,7 @@ public class HttpClientUtil {
     * @param chatSet 编码格式
     * @return
     */
    public static String get(String url, String chatSet) {
    public String get(String url, String chatSet) {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        try {
            // 创建httpget.
@ -175,7 +177,7 @@ public class HttpClientUtil {
        return null;
    }
    public static String postBody(String url,JSONObject params){
    public String postBody(String url,JSONObject params){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
@ -186,7 +188,7 @@ public class HttpClientUtil {
        return ret;
    }
    public static void putBody(String url,JSONObject params){
    public void putBody(String url,JSONObject params){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");

+ 4 - 2
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/common/http/HttpHelper.java

@ -3,7 +3,7 @@ package com.yihu.hos.device.common.http;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.ssl.SSLContexts;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.net.ssl.SSLContext;
@ -23,6 +23,8 @@ public class HttpHelper {
    private String httpsUser;
    private String httpsUserPassword;
    @Autowired
    private HttpClientUtil HttpClientUtil;
    private SSLConnectionSocketFactory  getDefaultSSL()
    {
@ -148,7 +150,7 @@ public class HttpHelper {
        }
    }
    public static HttpResponse delete(String url,Map<String,Object> params,Map<String,Object> header,SSLConnectionSocketFactory ssl,String user,String password)
    public HttpResponse delete(String url,Map<String,Object> params,Map<String,Object> header,SSLConnectionSocketFactory ssl,String user,String password)
    {
        return HttpClientUtil.request("DELETE",url,params,header,ssl,user,password);

+ 17 - 10
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/common/util/ImUtill.java

@ -2,11 +2,18 @@ package com.yihu.hos.device.common.util;
import com.yihu.hos.device.common.http.HttpClientUtil;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * Created by 卓 on 2017/1/13.
 */
@Component
public class ImUtill {
    @Autowired
    private HttpClientUtil HttpClientUtil;
    /**
     * 发送消息给IM
     *
@ -14,7 +21,7 @@ public class ImUtill {
     * @param contentType 1文字 2图片消息
     * @param content     内容
     */
    public static String sendImMsg(String baseUrl,String from,String fromName, String sessionId, String contentType, String content,String businessType) {
    public String sendImMsg(String baseUrl,String from,String fromName, String sessionId, String contentType, String content,String businessType) {
        String imAddr = baseUrl + "/api/v2/sessions/"+sessionId+"/messages";
        JSONObject params = new JSONObject();
        params.put("sender_id", from);
@ -35,7 +42,7 @@ public class ImUtill {
     * @param contentType 1文字 2图片消息
     * @param content     内容
     */
    public static String sendTopicIM(String baseUrl,String from,String fromName, String topicId, String contentType, String content) {
    public String sendTopicIM(String baseUrl,String from,String fromName, String topicId, String contentType, String content) {
        String url = baseUrl+ ("api/v2/sessions/topic/"+topicId+"/messages");
        JSONObject params = new JSONObject();
        params.put("sender_id", from);
@ -55,7 +62,7 @@ public class ImUtill {
     * @param endUserName 结束人名字
     * @param sessionId 会话ID
     */
    public static JSONObject endTopics(String baseUrl,String sessionId,String endUser, String endUserName,String topicId) {
    public JSONObject endTopics(String baseUrl,String sessionId,String endUser, String endUserName,String topicId) {
        String imAddr = baseUrl + "api/v2/sessions/"+sessionId+"/topics/"+topicId+"/ended";
        JSONObject params = new JSONObject();
        params.put("session_id", sessionId);
@ -78,7 +85,7 @@ public class ImUtill {
     * @param user 结束人名字
     * @param sessionId 会话ID
     */
    public static void updateTopicUser(String baseUrl,String sessionId,String user) {
    public void updateTopicUser(String baseUrl,String sessionId,String user) {
        String imAddr = baseUrl + "api/v2/sessions/"+sessionId+"/participants/"+user;
        JSONObject params = new JSONObject();
        params.put("user", user+":"+0);
@ -92,7 +99,7 @@ public class ImUtill {
     * @param topicName  议题名称
     * @param participants 成员
     */
    public static JSONObject createTopics(String baseUrl,String sessionId, String topicId, String topicName, JSONObject participants, JSONObject messages, String sessionType) {
    public JSONObject createTopics(String baseUrl,String sessionId, String topicId, String topicName, JSONObject participants, JSONObject messages, String sessionType) {
        String imAddr = baseUrl + "api/v2/sessions/"+topicId+"/topics";
        JSONObject params = new JSONObject();
        params.put("topic_id", topicId);
@ -115,7 +122,7 @@ public class ImUtill {
     * 创建会话(system)
     *
     */
    public static JSONObject createSession(String baseUrl,JSONObject participants,String sessionType,String sessionName,String sessionId) {
    public JSONObject createSession(String baseUrl,JSONObject participants,String sessionType,String sessionName,String sessionId) {
        String imAddr = baseUrl + "api/v2/sessions";
        JSONObject params = new JSONObject();
        params.put("participants", participants.toString());
@ -141,7 +148,7 @@ public class ImUtill {
     * @param images
     * @return
     */
    public static JSONObject getCreateTopicMessage(String senderId,String senderName,String title,String description,String images){
    public JSONObject getCreateTopicMessage(String senderId,String senderName,String title,String description,String images){
        JSONObject messages = new JSONObject();
        messages.put("description",description);
        messages.put("title",title);
@ -151,7 +158,7 @@ public class ImUtill {
        return messages;
    }
    public static JSONObject getTopicMessage(String baseUrl,String topicId,String startMsgId,String endMsgId,int page,int pagesize,String uid){
    public JSONObject getTopicMessage(String baseUrl,String topicId,String startMsgId,String endMsgId,int page,int pagesize,String uid){
        String url = baseUrl
                + "api/v2/sessions/topic/"+topicId+"/messages?topic_id="+topicId+"&end="+startMsgId
                +"&start="+(endMsgId==null?"":endMsgId)+"&page="+page+"&pagesize="+pagesize+"&user="+uid;
@ -176,7 +183,7 @@ public class ImUtill {
     * @param sessionId
     * @return
     */
    public static JSONObject deleteMucUser(String baseUrl,String userId,String oldUserId,String sessionId) throws  Exception{
    public JSONObject deleteMucUser(String baseUrl,String userId,String oldUserId,String sessionId) throws  Exception{
        String url = baseUrl
                + "api/v2/sessions/"+sessionId+"/participant/update";
        try{
@ -202,7 +209,7 @@ public class ImUtill {
     * @param topicId
     * @return
     */
    public static JSONObject getTopic(String baseUrl,String topicId) throws  Exception{
    public JSONObject getTopic(String baseUrl,String topicId) throws  Exception{
        String url =baseUrl
                + "api/v2/sessions/topics/"+topicId+"?topic_id="+topicId;
        try{

+ 5 - 2
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/service/DeviceService.java

@ -19,7 +19,6 @@ import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@ -58,6 +57,8 @@ public class DeviceService {
    @Autowired
    private HttpHelper httpHelper;
    @Autowired
    private HttpClientUtil HttpClientUtil;
    @Autowired
    private SystemConfig systemConfig;
    @Autowired
    private JdbcTemplate jdbcTemplate;
@ -65,6 +66,8 @@ public class DeviceService {
    private  PatientBloodSuggerDao patientBloodSuggerDao;
    @Autowired
    private PatientHealthTimeDao patientHealthTimeDao;
    @Autowired
    private PushMsgTask pushMsgTask;
    private ObjectMapper objectMapper = new ObjectMapper();
    private Integer aStart;
@ -775,7 +778,7 @@ public class DeviceService {
        // 批量保存消息
        messageDao.save(messages);
        // 推送消息给医生
        PushMsgTask.getInstance().put(array);
        pushMsgTask.put(array);
    }
    /**

+ 10 - 20
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/task/PushMsgTask.java

@ -1,39 +1,28 @@
package com.yihu.hos.device.task;
import com.yihu.hos.device.common.configuration.SystemConfig;
import com.yihu.hos.device.common.util.ImUtill;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.concurrent.LinkedBlockingQueue;
@Component
public class PushMsgTask {
	public static String url="";
	private static Logger logger = LoggerFactory.getLogger(PushMsgTask.class);
	// 最大容量为50的数组堵塞队列
	private static LinkedBlockingQueue<JSONObject> queue = new LinkedBlockingQueue<JSONObject>();
	private static PushMsgTask instance;
	private static Object lock = new Object();
	@Value("${systemConfig.socket_server}")
	private String socket_server;
	@Autowired
	private SystemConfig systemConfig;
	public static PushMsgTask getInstance() {
		synchronized (lock) {
			if (instance == null) {
				instance = new PushMsgTask();
				instance.run();
			}
		}
		return instance;
	}
	private ImUtill ImUtill;
	/**
	 * 添加一条推送消息
@ -75,6 +64,7 @@ public class PushMsgTask {
		}
	}
	@PostConstruct
	private void run() {
		new Thread(new ConsumerTask()).start();
	}
@ -116,7 +106,7 @@ public class PushMsgTask {
	 * @param msg 消息内容
	 * @param data 消息数据
	 */
	public static boolean pushMessage(String receiver, String msgType, String title, String msg, String data) {
	public boolean pushMessage(String receiver, String msgType, String title, String msg, String data) {
		try {
//			String url = "http://127.0.0.1:3000/api/v1/chats/sm";
//			HttpHelper httpHelper=new HttpHelper();
@ -135,8 +125,8 @@ public class PushMsgTask {
//			} else {
//				throw new Exception("接口调用错误!"+response.getBody());
//			}
			String url = "http://127.0.0.1:3000/";
			String url = socket_server +"/";
			org.json.JSONObject participants = new org.json.JSONObject();
			participants.put("system",0);
			participants.put(receiver,0);

+ 4 - 4
patient-co-service/wlyy_device/src/main/resources/application.yml

@ -52,8 +52,8 @@ spring:
  profiles: test
  datasource:
    url: jdbc:mysql://172.19.103.85:3306/device?useUnicode=true&characterEncoding=utf-8&autoReconnect=true
    username: ssgg
    password: ssgg
    username: linzhou
    password: linzhou
    driverClassName: com.mysql.jdbc.Driver
    maxTotal: 500
    maxIdle: 30
@ -77,7 +77,7 @@ healthStandard:
systemConfig:
  msg_push_server: http://127.0.0.1:3000/system/sendmsg.im
  jw_server: http://172.19.103.88:8011/wlyy_service-1.0-SNAPSHOT
  socket_server: http://192.168.131.102:3008
  socket_server: http://172.19.103.88:3000
---
spring:
  profiles: production
@ -107,5 +107,5 @@ healthStandard:
  ssy_max: 140
systemConfig:
  msg_push_server: http://127.0.0.1:3000/system/sendmsg.im
  jw_server: http://59.61.92.90:8087/wlyy_service
  jw_server: http://59.61.92.90:8072/wlyy_service
  socket_server: http://27.155.101.77:3000