|
@ -88,7 +88,7 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
|
|
|
|
|
|
public String createSurvey(String doctor, JSONObject jsonStr, String accessToken) throws Exception {
|
|
|
System.out.println("=============>"+jsonStr);
|
|
|
System.out.println("=============>" + jsonStr);
|
|
|
// 问卷信息
|
|
|
String surveyCode = getCode();
|
|
|
String surveyName = jsonStr.getString("surveyName");
|
|
@ -275,8 +275,20 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
// 发送居民模板 send=1发送
|
|
|
// ====================================================
|
|
|
if ("1".equals(send)) {
|
|
|
SendMessage sendMessage = new SendMessage(surveyCode, codes, accessToken);
|
|
|
new Thread(sendMessage).start();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
|
|
|
JSONObject json = new JSONObject(str);
|
|
|
|
|
|
codes.stream().forEach(c -> {
|
|
|
Patient p = patientDao.findByCode(c);
|
|
|
String name = p.getName();
|
|
|
String openId = p.getOpenid();
|
|
|
json.put("keyword2", sdf.format(new Date()));
|
|
|
json.put("toUser", c);
|
|
|
json.put("survey_id",surveyCode );
|
|
|
json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
|
|
|
PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
|
|
|
});
|
|
|
}
|
|
|
// =====================================================
|
|
|
// 获取标签数组
|
|
@ -302,6 +314,12 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
int isRequired = Integer.parseInt(tempQestion.get("isRequired").toString());
|
|
|
int sort = Integer.parseInt(tempQestion.get("sort").toString());
|
|
|
int del = 1;
|
|
|
String qstNextQuestion = null;
|
|
|
if (!StringUtils.isEmpty(tempQestion.get("nextQuestion").toString())) {
|
|
|
// optionNextQuestion = tempOption.get("nextQuestion").toString();
|
|
|
qstNextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode, tempQestion.get("nextQuestion"));
|
|
|
qstNextQuestion = (qstNextQuestion == null ? "0" : qstNextQuestion);
|
|
|
}
|
|
|
switch (type) {
|
|
|
case 0:
|
|
|
// 单选
|
|
@ -314,12 +332,15 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
surveyQuestionnaire.setIsRequired(isRequired);
|
|
|
surveyQuestionnaire.setDel(del);
|
|
|
surveyQuestionnaire.setSort(sort);
|
|
|
surveyQuestionnaire.setCreateTime(new Date());
|
|
|
surveyQuestionnaire.setUpdateTime(new Date());
|
|
|
// 单选没有最大最小选项数及题目逻辑跳转
|
|
|
surveyQuestionnaire.setMinNum(null);
|
|
|
surveyQuestionnaire.setMaxNum(null);
|
|
|
surveyQuestionnaire.setQuestionCodeNext(null);
|
|
|
surveyQuestionnaire.setQuestionCodeNext(qstNextQuestion);
|
|
|
|
|
|
surveyQuestionnaireDao.save(surveyQuestionnaire);
|
|
|
System.out.println("=====================================");
|
|
|
// =======================选项保存=========================
|
|
|
// 选择题
|
|
|
JSONArray options = new JSONArray(tempQestion.get("options").toString());
|
|
@ -333,11 +354,14 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
int optionDel = 1;
|
|
|
String optionNextQuestion = null;
|
|
|
if (!StringUtils.isEmpty(tempOption.get("nextQuestion").toString())) {
|
|
|
optionNextQuestion = tempOption.get("nextQuestion").toString();
|
|
|
// optionNextQuestion = tempOption.get("nextQuestion").toString();
|
|
|
optionNextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode, tempOption.get("nextQuestion"));
|
|
|
optionNextQuestion = (optionNextQuestion == null ? "0" : optionNextQuestion);
|
|
|
}
|
|
|
// 自主创建,插入表
|
|
|
SurveyQuestionnaireOptions surveyQuestionnaireOptions = new SurveyQuestionnaireOptions();
|
|
|
surveyQuestionnaireOptions.setCode(optionCode);
|
|
|
SurveyQuestionnaireOptions surveyQuestionnaireOptions = new SurveyQuestionnaireOptions(optionCode, haveComment, questionnaireCode, optionComment,
|
|
|
surveyCode, optionNextQuestion, required, optionSort, optionDel);
|
|
|
/* surveyQuestionnaireOptions.setCode(optionCode);
|
|
|
surveyQuestionnaireOptions.setHaveComment(haveComment);
|
|
|
surveyQuestionnaireOptions.setQuestionnaireCode(questionnaireCode);
|
|
|
surveyQuestionnaireOptions.setContent(optionComment);
|
|
@ -345,8 +369,7 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
surveyQuestionnaireOptions.setQuestionCodeNext(optionNextQuestion);
|
|
|
surveyQuestionnaireOptions.setIsRequired(required);
|
|
|
surveyQuestionnaireOptions.setSort(optionSort);
|
|
|
surveyQuestionnaireOptions.setDel(optionDel);
|
|
|
|
|
|
surveyQuestionnaireOptions.setDel(optionDel);*/
|
|
|
surveyQuestionnaireOptionsDao.save(surveyQuestionnaireOptions);
|
|
|
|
|
|
// 单选题保存到统计表
|
|
@ -378,8 +401,10 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
surveyQuestionnaire1.setMinNum(minOptions);
|
|
|
surveyQuestionnaire1.setMaxNum(maxOptions);
|
|
|
surveyQuestionnaire1.setSort(sort);
|
|
|
surveyQuestionnaire1.setQuestionCodeNext(null);
|
|
|
surveyQuestionnaire1.setQuestionCodeNext(qstNextQuestion);
|
|
|
surveyQuestionnaire1.setDel(del);
|
|
|
surveyQuestionnaire1.setCreateTime(new Date());
|
|
|
surveyQuestionnaire1.setUpdateTime(new Date());
|
|
|
|
|
|
surveyQuestionnaireDao.save(surveyQuestionnaire1);
|
|
|
|
|
@ -396,7 +421,8 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
int optionDel = 1;
|
|
|
String optionNextQuestion = null;
|
|
|
if (!StringUtils.isEmpty(tempOption.get("nextQuestion").toString())) {
|
|
|
optionNextQuestion = tempOption.get("nextQuestion").toString();
|
|
|
// optionNextQuestion = tempOption.get("nextQuestion").toString();
|
|
|
optionNextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode, tempOption.get("nextQuestion"));
|
|
|
}
|
|
|
|
|
|
// 自主创建,插入表
|
|
@ -424,10 +450,12 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
break;
|
|
|
case 2:
|
|
|
// 问答特有属性
|
|
|
String nextQuestion = null;
|
|
|
if (tempQestion.has("nextQuestion")) {
|
|
|
/*String nextQuestion = null;
|
|
|
if (StringUtils.isEmpty(tempQestion.get("nextQuestion").toString())) {
|
|
|
nextQuestion = tempQestion.get("nextQuestion").toString();
|
|
|
}
|
|
|
}else {
|
|
|
nextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode,tempQestion.get("nextQuestion"));
|
|
|
}*/
|
|
|
SurveyQuestionnaire surveyQuestionnaire2 = new SurveyQuestionnaire();
|
|
|
surveyQuestionnaire2.setCode(questionnaireCode);
|
|
|
surveyQuestionnaire2.setTitle(title);
|
|
@ -439,8 +467,10 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
surveyQuestionnaire2.setMinNum(null);
|
|
|
surveyQuestionnaire2.setMaxNum(null);
|
|
|
surveyQuestionnaire2.setSort(sort);
|
|
|
surveyQuestionnaire2.setQuestionCodeNext(nextQuestion);
|
|
|
surveyQuestionnaire2.setQuestionCodeNext(qstNextQuestion);
|
|
|
surveyQuestionnaire2.setDel(del);
|
|
|
surveyQuestionnaire2.setUpdateTime(new Date());
|
|
|
surveyQuestionnaire2.setCreateTime(new Date());
|
|
|
|
|
|
surveyQuestionnaireDao.save(surveyQuestionnaire2);
|
|
|
|
|
@ -462,6 +492,8 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
survey.setTemplateCode(templateCode);
|
|
|
survey.setStatus(status);
|
|
|
survey.setAmount(amount);
|
|
|
survey.setCreateTime(new Date());
|
|
|
survey.setUpdateTime(new Date());
|
|
|
surveyDao.save(survey);
|
|
|
return surveyCode;
|
|
|
}
|
|
@ -620,6 +652,14 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
int isRequired = questionnair.getIsRequired();
|
|
|
int sort = questionnair.getSort();
|
|
|
int type = questionnair.getQuestionType();
|
|
|
if (questionnair.getMaxNum() != null) {
|
|
|
int maxNum = questionnair.getMaxNum();
|
|
|
question.put("maxNum", maxNum);
|
|
|
}
|
|
|
if (questionnair.getMinNum() != null) {
|
|
|
int minNum = questionnair.getMinNum();
|
|
|
question.put("minNum", minNum);
|
|
|
}
|
|
|
if (questionnair.getQuestionComment() != null) {
|
|
|
String comment = questionnair.getQuestionComment();
|
|
|
question.put("comment", comment);
|
|
@ -627,7 +667,7 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
if (questionnair.getQuestionCodeNext() != null) {
|
|
|
String next = questionnair.getQuestionCodeNext();
|
|
|
SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
|
|
|
question.put("nextQuestion", sq.getSort());
|
|
|
question.put("nextQuestion", sq == null ? 0 : sq.getSort());
|
|
|
}
|
|
|
|
|
|
// List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findById(qstcode);
|
|
@ -642,9 +682,11 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
if (option.getQuestionCodeNext() != null) {
|
|
|
String next = option.getQuestionCodeNext();
|
|
|
SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
|
|
|
System.out.println("=============qstcode============== " + qstcode);
|
|
|
System.out.println("=============optCode============== " + option.getCode());
|
|
|
System.out.println("=============sq============== " + sq);
|
|
|
System.out.println("=============next============== " + next);
|
|
|
opt.put("nextQuestion", sq.getSort());
|
|
|
opt.put("nextQuestion", sq == null ? 0 : sq.getSort());
|
|
|
}
|
|
|
opt.put("content", conetent);
|
|
|
opt.put("sort", st);
|
|
@ -1137,7 +1179,6 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
questions.add(question);
|
|
|
}
|
|
|
|
|
@ -1148,11 +1189,11 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
jsonObject.put("comment", tempComment);
|
|
|
jsonObject.put("label", labels);
|
|
|
jsonObject.put("questions", questions);
|
|
|
|
|
|
System.out.println("==========jsonObject============" + jsonObject);
|
|
|
return jsonObject;
|
|
|
}
|
|
|
|
|
|
public int savaSurveyAsTemplate(String code) throws Exception {
|
|
|
public int savaSurveyAsTemplate(String code, String modifyTitle) throws Exception {
|
|
|
Survey survey = surveyDao.findById(code);
|
|
|
String tempCode = getCode();
|
|
|
String title = survey.getTitle();
|
|
@ -1161,10 +1202,20 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
Date createTime = survey.getCreateTime();
|
|
|
Date updateTime = survey.getUpdateTime();
|
|
|
// 查询问卷标题重复情况
|
|
|
int number = surveyTemplatesDao.distinctByTitle(title);
|
|
|
if (number!=0){
|
|
|
int likeNum = surveyTemplatesDao.distinctLikeTitle(title+"%");
|
|
|
return likeNum;
|
|
|
int number = 0;
|
|
|
if (StringUtils.isEmpty(modifyTitle)) {
|
|
|
number = surveyTemplatesDao.distinctByTitle(title);
|
|
|
} else {
|
|
|
number = surveyTemplatesDao.distinctByTitle(modifyTitle);
|
|
|
title = modifyTitle;
|
|
|
}
|
|
|
if (number != 0 && StringUtils.isEmpty(modifyTitle)) {
|
|
|
int likeNum = surveyTemplatesDao.distinctLikeTitle(title + "%");
|
|
|
return likeNum;
|
|
|
}
|
|
|
if (number != 0 && !StringUtils.isEmpty(modifyTitle)) {
|
|
|
int likeNum = surveyTemplatesDao.distinctLikeTitle(modifyTitle + "%");
|
|
|
return likeNum;
|
|
|
}
|
|
|
SurveyTemplates surveyTemplates = new SurveyTemplates(tempCode, title, templateComment, creater, 1, createTime, updateTime);
|
|
|
// 保存模板信息
|
|
@ -1208,15 +1259,25 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
public int modifyTemplate(String code, String templateCode) throws Exception {
|
|
|
public int modifyTemplate(String code, String templateCode, String modifyTitle) throws Exception {
|
|
|
Survey survey = surveyDao.findById(code);
|
|
|
String title = survey.getTitle();
|
|
|
String templateComment = survey.getSurveyComment();
|
|
|
// 查询问卷标题重复情况
|
|
|
int number = surveyTemplatesDao.distinctByTitle(title);
|
|
|
if (number!=0){
|
|
|
int likeNum = surveyTemplatesDao.distinctLikeTitle(title+"%");
|
|
|
return likeNum;
|
|
|
int number = 0;
|
|
|
if (StringUtils.isEmpty(modifyTitle)) {
|
|
|
number = surveyTemplatesDao.distinctByTitle(title);
|
|
|
} else {
|
|
|
number = surveyTemplatesDao.distinctByTitle(modifyTitle);
|
|
|
title = modifyTitle;
|
|
|
}
|
|
|
if (number != 0 && StringUtils.isEmpty(modifyTitle)) {
|
|
|
int likeNum = surveyTemplatesDao.distinctLikeTitle(title + "%");
|
|
|
return likeNum;
|
|
|
}
|
|
|
if (number != 0 && !StringUtils.isEmpty(modifyTitle)) {
|
|
|
int likeNum = surveyTemplatesDao.distinctLikeTitle(modifyTitle + "%");
|
|
|
return likeNum;
|
|
|
}
|
|
|
// SurveyTemplates surveyTemplates = new SurveyTemplates(templateCode, title, templateComment, creater, 1, creater, updateTime);
|
|
|
// 更改模板信息
|
|
@ -1381,10 +1442,10 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
case "0":
|
|
|
break disea;
|
|
|
case "1":
|
|
|
dis += " s.label_name LIKE '%糖尿病%' ";
|
|
|
dis += " s.label_name LIKE '%高血压%' ";
|
|
|
break;
|
|
|
case "2":
|
|
|
dis += " s.label_name LIKE '%高血压%' ";
|
|
|
dis += " s.label_name LIKE '%糖尿病%' ";
|
|
|
break;
|
|
|
}
|
|
|
dis += " OR ";
|
|
@ -1456,46 +1517,11 @@ public class ManagerQuestionnaireService extends BaseService {
|
|
|
str += "AND " + diseas;
|
|
|
}*/
|
|
|
// Map<String, Object> patients = jdbcTemplate.queryForMap(str);
|
|
|
System.out.println("=====query sql =======>>>>" + str);
|
|
|
List<String> patients = jdbcTemplate.queryForList(str, String.class);
|
|
|
return patients;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 线程发送模板消息
|
|
|
*/
|
|
|
class SendMessage implements Runnable {
|
|
|
private String code;
|
|
|
private List<String> codes;
|
|
|
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
private String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
|
|
|
private String accessToken;
|
|
|
|
|
|
private JSONObject json = new JSONObject(str);
|
|
|
|
|
|
public SendMessage(String code, List<String> codes, String accessToken) {
|
|
|
this.code = code;
|
|
|
this.codes = codes;
|
|
|
this.accessToken = accessToken;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
synchronized (this) {
|
|
|
json.put("survey_id", code);
|
|
|
for (String cod : codes) {
|
|
|
Patient p = patientDao.findByCode(cod);
|
|
|
String name = p.getName();
|
|
|
String openId = p.getOpenid();
|
|
|
/*String name = "吴俊杰";
|
|
|
String openId = "o7NFZw1QM4YR1O19mLjwfX1Hh11A";
|
|
|
cod = "jojojojpkpokpko";*/
|
|
|
json.put("keyword2", sdf.format(new Date()));
|
|
|
json.put("toUser", cod);
|
|
|
json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
|
|
|
PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|