|
@ -25,11 +25,13 @@ import org.springframework.jms.core.JmsTemplate;
|
|
|
import org.springframework.jms.core.MessageCreator;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import javax.jms.JMSException;
|
|
|
import javax.jms.Message;
|
|
|
import javax.jms.Session;
|
|
|
import javax.jms.TextMessage;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
|
|
|
/**
|
|
|
* Created by Trick on 2017/11/14.
|
|
@ -52,7 +54,8 @@ public class DoctorJMJkEduArticleController extends BaseController {
|
|
|
private String articleBaseUrl;
|
|
|
@Autowired
|
|
|
DoctorAdminTeamDao teamDao;
|
|
|
|
|
|
// 最大容量为50的数组堵塞队列
|
|
|
private static LinkedBlockingQueue<JSONObject> queue = new LinkedBlockingQueue<>();
|
|
|
|
|
|
/**
|
|
|
* 发送到redis
|
|
@ -153,10 +156,20 @@ public class DoctorJMJkEduArticleController extends BaseController {
|
|
|
// patientSet.add("915cc456-5b1d-11e6-8344-fa163e8aee56");
|
|
|
List<HealthEduArticleES> healthEduArticleESList = jmJkEduArticleService.savePCPushArticle(patientSet, getUID(), 2,"", 0L, articleId,leaveWords,currentRoleCode,currentRoleLevel);
|
|
|
//推送微信模板消息和发送im消息
|
|
|
new Thread(() -> {
|
|
|
//发送任务到redis
|
|
|
sender(healthEduArticleESList);
|
|
|
}).start();
|
|
|
// new Thread(() -> {
|
|
|
// //发送任务到redis
|
|
|
// sender(healthEduArticleESList);
|
|
|
// }).start();
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("patientSet",patientSet);
|
|
|
json.put("sendType",2);
|
|
|
json.put("teamCode",0L);
|
|
|
json.put("articleId",articleId);
|
|
|
json.put("leaveWords",leaveWords);
|
|
|
json.put("currentUserRole",currentRoleCode);
|
|
|
json.put("currentUserRoleLevel",currentRoleLevel);
|
|
|
json.put("sendCode",getUID());
|
|
|
queue.put(json);
|
|
|
return new BaseResultModel();
|
|
|
}catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@ -362,43 +375,82 @@ public class DoctorJMJkEduArticleController extends BaseController {
|
|
|
// //发送任务到redis
|
|
|
// sender(healthEduArticleESList);
|
|
|
// }).start();
|
|
|
new Thread(new HealthEduArticleESTask(patientSet,sendType,teamCode,articleId,leaveWords,currentUserRole,currentUserRoleLevel,getUID())).start();
|
|
|
// new Thread(new HealthEduArticleESTask(patientSet,sendType,teamCode,articleId,leaveWords,currentUserRole,currentUserRoleLevel,getUID())).start();
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("patientSet",patientSet);
|
|
|
json.put("sendType",sendType);
|
|
|
json.put("teamCode",teamCode);
|
|
|
json.put("articleId",articleId);
|
|
|
json.put("leaveWords",leaveWords);
|
|
|
json.put("currentUserRole",currentUserRole);
|
|
|
json.put("currentUserRoleLevel",currentUserRoleLevel);
|
|
|
json.put("sendCode",getUID());
|
|
|
queue.put(json);
|
|
|
return new BaseResultModel();
|
|
|
} catch (Exception e) {
|
|
|
error(e);
|
|
|
return new BaseResultModel(BaseResultModel.statusEm.opera_error.getCode(), BaseResultModel.statusEm.opera_error.getMessage() + ":" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
@PostConstruct
|
|
|
private void run() {
|
|
|
new Thread(new HealthEduArticleESTask()).start();
|
|
|
}
|
|
|
// 消费者
|
|
|
class HealthEduArticleESTask implements Runnable {
|
|
|
Set<String> patientSet;
|
|
|
String sendType;
|
|
|
Long teamCode;
|
|
|
String articleId;
|
|
|
String leaveWords;
|
|
|
String currentUserRole;
|
|
|
String currentUserRoleLevel;
|
|
|
String sendCode;
|
|
|
public HealthEduArticleESTask(Set<String> patientSet,String sendType,Long teamCode,String articleId,String leaveWords,String currentUserRole,String currentUserRoleLevel,String sendCode) {
|
|
|
this.patientSet=patientSet;
|
|
|
this.sendType=sendType;
|
|
|
this.teamCode=teamCode;
|
|
|
this.articleId=articleId;
|
|
|
this.leaveWords=leaveWords;
|
|
|
this.currentUserRole=currentUserRole;
|
|
|
this.currentUserRoleLevel=currentUserRoleLevel;
|
|
|
this.sendCode=sendCode;
|
|
|
}
|
|
|
@Override
|
|
|
public void run() {
|
|
|
try{
|
|
|
List<HealthEduArticleES> healthEduArticleESList = jmJkEduArticleService.savePCPushArticle(patientSet, sendCode, Integer.parseInt(sendType),"", teamCode, articleId,leaveWords,currentUserRole,currentUserRoleLevel);
|
|
|
//发送任务到redis
|
|
|
while (true) {
|
|
|
try {
|
|
|
// 如果queue为空,则当前线程会堵塞,直到有新数据加入
|
|
|
JSONObject json = queue.take();
|
|
|
Set<String> patientSet = (Set<String>)json.get("patientSet");
|
|
|
String sendCode = json.get("patientSet")+"";
|
|
|
String sendType = json.get("sendType")+"";
|
|
|
Long teamCode = Long.valueOf(json.get("teamCode")+"");
|
|
|
String articleId = json.get("articleId")+"";
|
|
|
String leaveWords = json.get("leaveWords")+"";
|
|
|
String currentUserRole = json.get("currentUserRole")+"";
|
|
|
String currentUserRoleLevel = json.get("currentUserRoleLevel")+"";
|
|
|
List<HealthEduArticleES> healthEduArticleESList = jmJkEduArticleService.savePCPushArticle(patientSet, sendCode, Integer.parseInt(sendType),"", teamCode, articleId,leaveWords,currentUserRole,currentUserRoleLevel);
|
|
|
//发送任务到redis
|
|
|
sender(healthEduArticleESList);
|
|
|
}catch (Exception e){
|
|
|
error(e);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// class HealthEduArticleESTask implements Runnable {
|
|
|
// Set<String> patientSet;
|
|
|
// String sendType;
|
|
|
// Long teamCode;
|
|
|
// String articleId;
|
|
|
// String leaveWords;
|
|
|
// String currentUserRole;
|
|
|
// String currentUserRoleLevel;
|
|
|
// String sendCode;
|
|
|
// public HealthEduArticleESTask(Set<String> patientSet,String sendType,Long teamCode,String articleId,String leaveWords,String currentUserRole,String currentUserRoleLevel,String sendCode) {
|
|
|
// this.patientSet=patientSet;
|
|
|
// this.sendType=sendType;
|
|
|
// this.teamCode=teamCode;
|
|
|
// this.articleId=articleId;
|
|
|
// this.leaveWords=leaveWords;
|
|
|
// this.currentUserRole=currentUserRole;
|
|
|
// this.currentUserRoleLevel=currentUserRoleLevel;
|
|
|
// this.sendCode=sendCode;
|
|
|
// }
|
|
|
// @Override
|
|
|
// public void run() {
|
|
|
// try{
|
|
|
// List<HealthEduArticleES> healthEduArticleESList = jmJkEduArticleService.savePCPushArticle(patientSet, sendCode, Integer.parseInt(sendType),"", teamCode, articleId,leaveWords,currentUserRole,currentUserRoleLevel);
|
|
|
// //发送任务到redis
|
|
|
// sender(healthEduArticleESList);
|
|
|
// }catch (Exception e){
|
|
|
// error(e);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "doctorSendArticleToSingle", method = RequestMethod.POST)
|