|
@ -4,15 +4,22 @@ import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.entity.doctor.survey.*;
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.entity.patient.SignFamily;
|
|
|
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
|
|
|
import com.yihu.wlyy.repository.dict.SystemDictDao;
|
|
|
import com.yihu.wlyy.repository.doctor.*;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.repository.patient.SignFamilyDao;
|
|
|
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.service.survey.ManagerQuestionnaireService;
|
|
|
import com.yihu.wlyy.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.util.IdCardUtil;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@ -22,6 +29,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@ -56,6 +64,40 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
private SignFamilyDao signFamilyDao;
|
|
|
@Autowired
|
|
|
private ManagerQuestionnaireService managerQuestionnaireService;
|
|
|
@Autowired
|
|
|
private SurveyDao surveyDao;
|
|
|
@Autowired
|
|
|
private SurveyQuestionsDao surveyQuestionsDao;
|
|
|
@Autowired
|
|
|
private SurveyLabelInfoDao surveyLabelInfoDao;
|
|
|
@Autowired
|
|
|
private SurveyQuestionsOptionsDao surveyQuestionsOptionsDao;
|
|
|
@Autowired
|
|
|
private SurveyUserDao surveyUserDao;
|
|
|
@Autowired
|
|
|
private SurveyFilterDao surveyFilterDao;
|
|
|
@Autowired
|
|
|
private SurveyQuestionnaireOptionsDao surveyQuestionnaireOptionsDao;
|
|
|
@Autowired
|
|
|
private SurveyQuestionnaireDao surveyQuestionnaireDao;
|
|
|
@Autowired
|
|
|
private SurveyTemplateOptionsDao surveyTemplateOptionsDao;
|
|
|
@Autowired
|
|
|
private SurveyAnswersDao surveyAnswersDao;
|
|
|
@Autowired
|
|
|
private SystemDictDao systemDictDao;
|
|
|
@Autowired
|
|
|
private SurveyDimensionDao surveyDimensionDao;
|
|
|
@Autowired
|
|
|
private SurveyDimensionDetailDao surveyDimensionDetailDao;
|
|
|
@Autowired
|
|
|
private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
|
|
|
@Autowired
|
|
|
WeiXinOpenIdUtils weiXinOpenIdUtils;
|
|
|
@Autowired
|
|
|
private PushMsgTask pushMsgTask;
|
|
|
@Autowired
|
|
|
private WechatTemplateConfigDao templateConfigDao;
|
|
|
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
@ -360,7 +402,7 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
|
|
|
public List<Map<String,Object>> getResultByTemplateCode(int pageNo,int pageSize,String templateCode,String patientCode){
|
|
|
int start = (pageNo-1)*pageSize;
|
|
|
String sql ="SELECT st.*,ssr.code screenCode,ssr.screen_result,ssr.screen_result_score,ssr.czrq as screenCzrq,ssr.is_again FROM wlyy_survey_templates st LEFT JOIN wlyy_survey_screen_result ssr ON st.code = ssr.template_code WHERE st.`code`='"+templateCode+"' AND ssr.patient_code='"+patientCode+"' limit ?,?";
|
|
|
String sql ="SELECT st.*,ssr.code screenCode,ssr.screen_result,ssr.screen_result_score,ssr.czrq as screenCzrq,ssr.is_again FROM wlyy_survey_templates st LEFT JOIN wlyy_survey_screen_result ssr ON st.code = ssr.template_code WHERE st.`code`='"+templateCode+"' AND ssr.patient_code='"+patientCode+"' order by ssr.czrq limit ?,?";
|
|
|
return jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
|
|
|
}
|
|
|
|
|
@ -505,4 +547,470 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
List<String> patients = jdbcTemplate.queryForList(sql, String.class);
|
|
|
return patients;
|
|
|
}
|
|
|
|
|
|
|
|
|
public String createSurvey(String doctor, JSONObject jsonStr, String accessToken) throws Exception {
|
|
|
// 问卷信息
|
|
|
String surveyCode = getCode();
|
|
|
String surveyName = jsonStr.getString("surveyName");
|
|
|
String surveyComment = jsonStr.getString("comment");
|
|
|
String templateCode = null;
|
|
|
String send = jsonStr.get("send").toString();
|
|
|
String templateLabel = jsonStr.getString("label");
|
|
|
int status = 1;
|
|
|
// 自主创建
|
|
|
int useType = 1;
|
|
|
if (!StringUtils.isEmpty(jsonStr.getString("templateCode"))) {
|
|
|
// 模板创建
|
|
|
useType = 0;
|
|
|
templateCode = jsonStr.getString("templateCode");
|
|
|
}
|
|
|
// 获取调查对象
|
|
|
JSONObject surveyTarget = jsonStr.getJSONObject("surveyTarget");
|
|
|
// 0不限 1男 2女
|
|
|
// int sex = Integer.parseInt(surveyTarget.get("sex").toString());
|
|
|
JSONArray sex = surveyTarget.getJSONArray("sex");
|
|
|
JSONArray disease = surveyTarget.getJSONArray("disease");
|
|
|
JSONArray service = surveyTarget.getJSONArray("service");
|
|
|
JSONArray healthCondition = surveyTarget.getJSONArray("healthCondition");
|
|
|
|
|
|
int sexList = 0;
|
|
|
for (Object se : sex) {
|
|
|
JSONObject sexJson = new JSONObject(se.toString());
|
|
|
int label = sexJson.getInt("label");
|
|
|
sexList = label;
|
|
|
if (label != 0) {
|
|
|
String dimensionCode = surveyDimensionDao.findByName("性别");
|
|
|
String dimensionDetailCode = getCode();
|
|
|
// SurveyDimensionDetail surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, sex == 1 ? "男" : "女", sex, "性别", 1, surveyCode);
|
|
|
// modify by wjj 2017.7.24 居民标签更改
|
|
|
SurveyDimensionDetail surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, sexJson.getString("labelName"), label, "性别", 1, surveyCode);
|
|
|
surveyDimensionDetailDao.save(surveyDimensionDetail);
|
|
|
// 保存到筛选表
|
|
|
SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
|
|
|
surveyFilterDao.save(surveyFilter);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List servList = new ArrayList();
|
|
|
for (Object serv : service) {
|
|
|
JSONObject servJson = new JSONObject(serv.toString());
|
|
|
int label = servJson.getInt("label");
|
|
|
servList.add(label);
|
|
|
if (label == 0) {
|
|
|
break;
|
|
|
} else {
|
|
|
// ===================================
|
|
|
String dimensionCode = surveyDimensionDao.findByName("服务类型");
|
|
|
String dimensionDetailCode = getCode();
|
|
|
SurveyDimensionDetail surveyDimensionDetail = null;
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, servJson.getString("labelName"), label, "服务类型", 3, surveyCode);
|
|
|
/* switch (Integer.parseInt(serv.toString())) {
|
|
|
// 1.普通人群 2.慢病人群 3.65岁以上人群
|
|
|
case 1:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "普通人群", 1, "服务类型", 3, surveyCode);
|
|
|
break;
|
|
|
case 2:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "慢病人群", 2, "服务类型", 3, surveyCode);
|
|
|
break;
|
|
|
case 3:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "65岁以上人群", 3, "服务类型", 3, surveyCode);
|
|
|
break;
|
|
|
}
|
|
|
*/
|
|
|
surveyDimensionDetailDao.save(surveyDimensionDetail);
|
|
|
|
|
|
SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
|
|
|
surveyFilterDao.save(surveyFilter);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List healthList = new ArrayList();
|
|
|
for (Object health : healthCondition) {
|
|
|
JSONObject healthJson = new JSONObject(health.toString());
|
|
|
int label = healthJson.getInt("label");
|
|
|
healthList.add(label);
|
|
|
if (label == 0) {
|
|
|
break;
|
|
|
} else {
|
|
|
String dimensionCode = surveyDimensionDao.findByName("健康状况");
|
|
|
String dimensionDetailCode = getCode();
|
|
|
String surveyFilterCode = getCode();
|
|
|
SurveyDimensionDetail surveyDimensionDetail = null;
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, healthJson.getString("labelName"), label, "健康状况", 4, surveyCode);
|
|
|
|
|
|
/*switch (Integer.parseInt(health.toString())) {
|
|
|
// 1.健康人群 2.患病人群 3.高危人群 4.恢复期人群
|
|
|
case 1:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "健康人群", 1, "健康状况", 4, surveyCode);
|
|
|
break;
|
|
|
case 2:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "患病人群", 2, "健康状况", 4, surveyCode);
|
|
|
break;
|
|
|
case 3:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "高危人群", 3, "健康状况", 4, surveyCode);
|
|
|
break;
|
|
|
case 4:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "恢复期人群", 4, "健康状况", 4, surveyCode);
|
|
|
break;
|
|
|
}*/
|
|
|
surveyDimensionDetailDao.save(surveyDimensionDetail);
|
|
|
|
|
|
SurveyFilter surveyFilter = new SurveyFilter(surveyFilterCode, surveyCode, dimensionDetailCode);
|
|
|
surveyFilterDao.save(surveyFilter);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List diseaList = new ArrayList();
|
|
|
for (Object disea : disease) {
|
|
|
JSONObject diseaJson = new JSONObject(disea.toString());
|
|
|
int label = diseaJson.getInt("label");
|
|
|
diseaList.add(label);
|
|
|
if (label == 0) {
|
|
|
// dise += ",";
|
|
|
break;
|
|
|
} else {
|
|
|
String dimensionCode = surveyDimensionDao.findByName("疾病类型");
|
|
|
String dimensionDetailCode = getCode();
|
|
|
SurveyDimensionDetail surveyDimensionDetail = null;
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, diseaJson.getString("labelName"), label, "疾病类型", 2, surveyCode);
|
|
|
|
|
|
/*switch (Integer.parseInt(disea.toString())) {
|
|
|
// 1.高血压 2糖尿病 3.高血压+糖尿病
|
|
|
case 1:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "高血压", 1, "疾病类型", 2, surveyCode);
|
|
|
break;
|
|
|
case 2:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "糖尿病", 2, "疾病类型", 2, surveyCode);
|
|
|
break;
|
|
|
}*/
|
|
|
surveyDimensionDetailDao.save(surveyDimensionDetail);
|
|
|
|
|
|
SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
|
|
|
surveyFilterDao.save(surveyFilter);
|
|
|
}
|
|
|
}
|
|
|
// List<String> codes = getCount(surveyTarget.toString());
|
|
|
JSONObject countJson = new JSONObject();
|
|
|
countJson.put("sex", sexList);
|
|
|
countJson.put("disease", diseaList);
|
|
|
countJson.put("healthCondition", healthList);
|
|
|
countJson.put("service", servList);
|
|
|
List<String> codes = getCountByDoctor(countJson.toString(),doctor);
|
|
|
int amount = codes.size();
|
|
|
for (String code : codes) {
|
|
|
// String code = patient.get("patient").toString();
|
|
|
SurveyUser user = new SurveyUser(surveyCode, code, 0, 1, new Date(), new Date());
|
|
|
surveyUserDao.save(user);
|
|
|
}
|
|
|
// 发送居民模板 send=1发送
|
|
|
if ("1".equals(send)) {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
// String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
|
|
|
// JSONObject json = new JSONObject(str);
|
|
|
JSONObject json = new JSONObject();
|
|
|
/* for (String code : codes) {
|
|
|
// codes.stream().forEach(c -> {
|
|
|
// Patient p = patientDao.findByCode(c);
|
|
|
Patient p = patientDao.findByCode(code);
|
|
|
String name = p.getName();
|
|
|
String openId = p.getOpenid();
|
|
|
json.put("keyword2", sdf.format(new Date()));
|
|
|
// json.put("toUser", c);
|
|
|
json.put("toUser", code);
|
|
|
json.put("survey_id", surveyCode);
|
|
|
json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
|
|
|
logger.error("patient =======>" + code);
|
|
|
logger.error("name =======>" + name);
|
|
|
logger.error("openId =======>" + openId);
|
|
|
|
|
|
//判断是否有openId,有发送没有则查找家人发送
|
|
|
if (StringUtils.isNotBlank(p.getOpenid())) {
|
|
|
// 添加到发送队列
|
|
|
logger.error("json =======>" + json);
|
|
|
PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
|
|
|
} else {
|
|
|
JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
|
|
|
Patient member = (Patient) j.get("member");
|
|
|
if (StringUtils.isNotBlank(member.getOpenid())) {
|
|
|
String first = (String) json.get("first");
|
|
|
json.remove("first");
|
|
|
try {
|
|
|
json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) + first);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
logger.error("没有opIn json =======>" + json);
|
|
|
PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
|
|
|
}
|
|
|
}
|
|
|
// });
|
|
|
}*/
|
|
|
WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","scwj");
|
|
|
String remark = templateConfig.getRemark();
|
|
|
String keyword1 = templateConfig.getKeyword1();
|
|
|
String wxTemplateCode = templateCode;
|
|
|
new Thread() {
|
|
|
public void run() {
|
|
|
for (String c : codes) {
|
|
|
Patient p = null;
|
|
|
String name = null;
|
|
|
String openId = null;
|
|
|
String first = null;
|
|
|
try {
|
|
|
p = patientDao.findByCode(c);
|
|
|
name = p.getName();
|
|
|
openId = p.getOpenid();
|
|
|
json.put("keyword2", sdf.format(new Date()));
|
|
|
json.put("survey", wxTemplateCode);
|
|
|
// String first = name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。";
|
|
|
first = templateConfig.getFirst();
|
|
|
first = first.replace("key1",(name==null?"":name));
|
|
|
json.put("first", first);
|
|
|
json.put("remark", remark);
|
|
|
json.put("keyword1", keyword1);
|
|
|
} catch (JSONException e) {
|
|
|
continue;
|
|
|
}
|
|
|
//判断是否判定openId,有没有发则查找家人发送
|
|
|
if (StringUtils.isNotBlank(p.getOpenid())) {
|
|
|
// 添加到发送队列
|
|
|
logger.error("json =======>" + json);
|
|
|
// PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
|
|
|
pushMsgTask.sendWeixinMessage(accessToken, 11, openId, name, json);
|
|
|
}else {
|
|
|
//发送代理人
|
|
|
JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
|
|
|
if (jsonArray != null && jsonArray.length() > 0) {
|
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
|
JSONObject j = jsonArray.getJSONObject(i);
|
|
|
Patient member = (Patient) j.get("member");
|
|
|
if (StringUtils.isNotBlank(member.getOpenid())) {
|
|
|
json.remove("toUser");
|
|
|
json.put("toUser", member.getCode());
|
|
|
json.remove("first");
|
|
|
try {
|
|
|
json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
pushMsgTask.sendWeixinMessage(weiXinAccessTokenUtils.getAccessToken(), 11, member.getOpenid(), p.getName(), json);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}.start();
|
|
|
}
|
|
|
// =====================================================
|
|
|
// 获取标签数组
|
|
|
JSONArray lables = jsonStr.getJSONArray("label");
|
|
|
// 标签保存到wlyy_survey_label_info
|
|
|
for (Object label : lables) {
|
|
|
SurveyLabelInfo surveyLabelInfo = new SurveyLabelInfo();
|
|
|
surveyLabelInfo.setCode(getCode());
|
|
|
surveyLabelInfo.setRelationCode(surveyCode);
|
|
|
surveyLabelInfo.setUseType(useType);
|
|
|
surveyLabelInfo.setLabel(Integer.parseInt(label.toString()));
|
|
|
SurveyLabelInfo ss = surveyLabelInfoDao.save(surveyLabelInfo);
|
|
|
}
|
|
|
// 获取问题数组
|
|
|
JSONArray questions = jsonStr.getJSONArray("questions");
|
|
|
for (Object question : questions) {
|
|
|
JSONObject tempQestion = new JSONObject(question.toString());
|
|
|
// 不分题型都有的属性
|
|
|
String questionnaireCode = tempQestion.get("qstCode").toString();
|
|
|
String title = tempQestion.get("title").toString();
|
|
|
String comment = tempQestion.get("comment").toString();
|
|
|
int type = Integer.parseInt(tempQestion.get("type").toString());
|
|
|
int isRequired = Integer.parseInt(tempQestion.get("isRequired").toString());
|
|
|
int sort = Integer.parseInt(tempQestion.get("sort").toString());
|
|
|
int del = 1;
|
|
|
String qstNextQuestion = null;
|
|
|
// 前提一定要有nextQuestion字段传入,没有为""
|
|
|
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:
|
|
|
// 单选
|
|
|
SurveyQuestionnaire surveyQuestionnaire = new SurveyQuestionnaire();
|
|
|
surveyQuestionnaire.setCode(questionnaireCode);
|
|
|
surveyQuestionnaire.setTitle(title);
|
|
|
surveyQuestionnaire.setQuestionComment(comment);
|
|
|
surveyQuestionnaire.setQuestionType(type);
|
|
|
surveyQuestionnaire.setSurveyCode(surveyCode);
|
|
|
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(qstNextQuestion);
|
|
|
|
|
|
surveyQuestionnaireDao.save(surveyQuestionnaire);
|
|
|
// =======================选项保存=========================
|
|
|
// 选择题
|
|
|
JSONArray options = new JSONArray(tempQestion.get("options").toString());
|
|
|
for (Object option : options) {
|
|
|
// String optionCode = getCode();
|
|
|
JSONObject tempOption = new JSONObject(option.toString());
|
|
|
String optionCode = tempOption.get("optCode").toString();
|
|
|
int haveComment = Integer.parseInt(tempOption.get("haveComment").toString());
|
|
|
String optionComment = tempOption.get("content").toString();
|
|
|
int required = Integer.parseInt(tempOption.get("isRequired").toString());
|
|
|
int optionSort = Integer.parseInt(tempOption.get("sort").toString());
|
|
|
int optionDel = 1;
|
|
|
String optionNextQuestion = null;
|
|
|
if (!StringUtils.isEmpty(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(optionCode, haveComment, questionnaireCode, optionComment,
|
|
|
surveyCode, optionNextQuestion, required, optionSort, optionDel);
|
|
|
/* surveyQuestionnaireOptions.setCode(optionCode);
|
|
|
surveyQuestionnaireOptions.setHaveComment(haveComment);
|
|
|
surveyQuestionnaireOptions.setQuestionnaireCode(questionnaireCode);
|
|
|
surveyQuestionnaireOptions.setContent(optionComment);
|
|
|
surveyQuestionnaireOptions.setSurveyCode(surveyCode);
|
|
|
surveyQuestionnaireOptions.setQuestionCodeNext(optionNextQuestion);
|
|
|
surveyQuestionnaireOptions.setIsRequired(required);
|
|
|
surveyQuestionnaireOptions.setSort(optionSort);
|
|
|
surveyQuestionnaireOptions.setDel(optionDel);*/
|
|
|
surveyQuestionnaireOptionsDao.save(surveyQuestionnaireOptions);
|
|
|
|
|
|
// 单选题保存到统计表
|
|
|
String statisticsCode = getCode();
|
|
|
String questionTitle = surveyQuestionnaireDao.findByIdAndQstId(surveyCode, questionnaireCode).getTitle();
|
|
|
String optcontent = surveyQuestionnaireOptionsDao.findByRelationCode(surveyCode, questionnaireCode, optionCode).getContent();
|
|
|
SurveyStatistics statistics = new SurveyStatistics(statisticsCode, surveyCode, questionnaireCode, questionTitle, optionCode, 0, optcontent, haveComment, type, sort, optionSort);
|
|
|
surveyStatisticsDao.save(statistics);
|
|
|
}
|
|
|
break;
|
|
|
case 1:
|
|
|
// 多选特有属性
|
|
|
Integer maxOptions = null;
|
|
|
Integer minOptions = null;
|
|
|
if (!StringUtils.isEmpty(tempQestion.get("minOptions").toString())) {
|
|
|
minOptions = Integer.parseInt(tempQestion.get("minOptions").toString());
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(tempQestion.get("maxOptions").toString())) {
|
|
|
maxOptions = Integer.parseInt(tempQestion.get("maxOptions").toString());
|
|
|
}
|
|
|
SurveyQuestionnaire surveyQuestionnaire1 = new SurveyQuestionnaire();
|
|
|
surveyQuestionnaire1.setCode(questionnaireCode);
|
|
|
surveyQuestionnaire1.setTitle(title);
|
|
|
surveyQuestionnaire1.setQuestionComment(comment);
|
|
|
surveyQuestionnaire1.setQuestionType(type);
|
|
|
surveyQuestionnaire1.setSurveyCode(surveyCode);
|
|
|
surveyQuestionnaire1.setIsRequired(isRequired);
|
|
|
surveyQuestionnaire1.setMinNum(minOptions);
|
|
|
surveyQuestionnaire1.setMaxNum(maxOptions);
|
|
|
surveyQuestionnaire1.setSort(sort);
|
|
|
surveyQuestionnaire1.setQuestionCodeNext(qstNextQuestion);
|
|
|
surveyQuestionnaire1.setDel(del);
|
|
|
surveyQuestionnaire1.setCreateTime(new Date());
|
|
|
surveyQuestionnaire1.setUpdateTime(new Date());
|
|
|
|
|
|
surveyQuestionnaireDao.save(surveyQuestionnaire1);
|
|
|
|
|
|
// =======================选项保存=========================
|
|
|
// 选择题
|
|
|
JSONArray options1 = new JSONArray(tempQestion.get("options").toString());
|
|
|
for (Object option : options1) {
|
|
|
// String optionCode = getCode();
|
|
|
JSONObject tempOption = new JSONObject(option.toString());
|
|
|
String optionCode = tempOption.get("optCode").toString();
|
|
|
int haveComment = Integer.parseInt(tempOption.get("haveComment").toString());
|
|
|
String optionComment = tempOption.get("content").toString();
|
|
|
int required = Integer.parseInt(tempOption.get("isRequired").toString());
|
|
|
int optionSort = Integer.parseInt(tempOption.get("sort").toString());
|
|
|
int optionDel = 1;
|
|
|
String optionNextQuestion = null;
|
|
|
if (!StringUtils.isEmpty(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.setHaveComment(haveComment);
|
|
|
surveyQuestionnaireOptions.setQuestionnaireCode(questionnaireCode);
|
|
|
surveyQuestionnaireOptions.setContent(optionComment);
|
|
|
surveyQuestionnaireOptions.setSurveyCode(surveyCode);
|
|
|
surveyQuestionnaireOptions.setQuestionCodeNext(optionNextQuestion);
|
|
|
surveyQuestionnaireOptions.setIsRequired(required);
|
|
|
surveyQuestionnaireOptions.setSort(optionSort);
|
|
|
surveyQuestionnaireOptions.setDel(optionDel);
|
|
|
|
|
|
surveyQuestionnaireOptionsDao.save(surveyQuestionnaireOptions);
|
|
|
|
|
|
// 多选题保存到统计表
|
|
|
String statisticsCode = getCode();
|
|
|
String questionTitle = surveyQuestionnaireDao.findByIdAndQstId(surveyCode, questionnaireCode).getTitle();
|
|
|
String optcontent = surveyQuestionnaireOptionsDao.findByRelationCode(surveyCode, questionnaireCode, optionCode).getContent();
|
|
|
SurveyStatistics statistics = new SurveyStatistics(statisticsCode, surveyCode, questionnaireCode, questionTitle, optionCode, 0, optcontent, haveComment, type, sort, optionSort);
|
|
|
surveyStatisticsDao.save(statistics);
|
|
|
}
|
|
|
// ===============================================================
|
|
|
break;
|
|
|
case 2:
|
|
|
// 问答特有属性
|
|
|
/*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);
|
|
|
surveyQuestionnaire2.setQuestionComment(comment);
|
|
|
surveyQuestionnaire2.setQuestionType(type);
|
|
|
surveyQuestionnaire2.setSurveyCode(surveyCode);
|
|
|
surveyQuestionnaire2.setIsRequired(isRequired);
|
|
|
// 单选没有最大最小选项数
|
|
|
surveyQuestionnaire2.setMinNum(null);
|
|
|
surveyQuestionnaire2.setMaxNum(null);
|
|
|
surveyQuestionnaire2.setSort(sort);
|
|
|
surveyQuestionnaire2.setQuestionCodeNext(qstNextQuestion);
|
|
|
surveyQuestionnaire2.setDel(del);
|
|
|
surveyQuestionnaire2.setUpdateTime(new Date());
|
|
|
surveyQuestionnaire2.setCreateTime(new Date());
|
|
|
|
|
|
surveyQuestionnaireDao.save(surveyQuestionnaire2);
|
|
|
|
|
|
// 问答题保存到统计表(只负责更改数量不负责创建)
|
|
|
String statisticsCode = getCode();
|
|
|
String questionTitle = surveyQuestionnaireDao.findByIdAndQstId(surveyCode, questionnaireCode).getTitle();
|
|
|
SurveyStatistics statistics = new SurveyStatistics(statisticsCode, surveyCode, questionnaireCode, questionTitle, null, 0, null, null, type, sort, null);
|
|
|
surveyStatisticsDao.save(statistics);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
// 保存到问卷
|
|
|
Survey survey = new Survey();
|
|
|
survey.setCode(surveyCode);
|
|
|
survey.setTitle(surveyName);
|
|
|
survey.setSurveyComment(surveyComment);
|
|
|
survey.setCreater(doctor);
|
|
|
survey.setTemplateCode(templateCode);
|
|
|
survey.setStatus(status);
|
|
|
survey.setAmount(amount);
|
|
|
survey.setCreateTime(new Date());
|
|
|
survey.setUpdateTime(new Date());
|
|
|
surveyDao.save(survey);
|
|
|
return surveyCode;
|
|
|
}
|
|
|
}
|