ManagerQuestionnaireService.java 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527
  1. package com.yihu.wlyy.service.survey;
  2. import com.fasterxml.jackson.databind.ObjectMapper;
  3. import com.yihu.wlyy.entity.dict.SystemDict;
  4. import com.yihu.wlyy.entity.doctor.profile.Doctor;
  5. import com.yihu.wlyy.entity.doctor.survey.*;
  6. import com.yihu.wlyy.entity.patient.Patient;
  7. import com.yihu.wlyy.entity.wechat.WechatTemplate;
  8. import com.yihu.wlyy.entity.wechat.WechatTemplateData;
  9. import com.yihu.wlyy.repository.dict.SystemDictDao;
  10. import com.yihu.wlyy.repository.doctor.*;
  11. import com.yihu.wlyy.repository.patient.PatientDao;
  12. import com.yihu.wlyy.service.BaseService;
  13. import com.yihu.wlyy.service.system.SystemDictService;
  14. import com.yihu.wlyy.task.PushMsgTask;
  15. import com.yihu.wlyy.util.HttpUtil;
  16. import com.yihu.wlyy.util.SystemConf;
  17. import com.yihu.wlyy.web.doctor.survey.ManagerQuestionnaireController;
  18. import com.yihu.wlyy.wechat.util.WeiXinTempMsgSendUtils;
  19. import io.swagger.models.auth.In;
  20. import org.apache.commons.lang3.StringUtils;
  21. import org.apache.poi.util.StringUtil;
  22. import org.bouncycastle.jce.provider.symmetric.HC128;
  23. import org.json.JSONArray;
  24. import org.json.JSONObject;
  25. import org.slf4j.Logger;
  26. import org.slf4j.LoggerFactory;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.data.domain.Page;
  29. import org.springframework.data.domain.PageRequest;
  30. import org.springframework.data.domain.Pageable;
  31. import org.springframework.data.domain.Sort;
  32. import org.springframework.jdbc.core.JdbcTemplate;
  33. import org.springframework.stereotype.Service;
  34. import org.springframework.transaction.annotation.Transactional;
  35. import java.text.SimpleDateFormat;
  36. import java.util.*;
  37. /**
  38. * Created by Reece on 2017/3/9.
  39. */
  40. @Service
  41. @Transactional
  42. public class ManagerQuestionnaireService extends BaseService {
  43. @Autowired
  44. private SurveyDao surveyDao;
  45. @Autowired
  46. private SurveyQuestionsDao surveyQuestionsDao;
  47. @Autowired
  48. private SurveyLabelInfoDao surveyLabelInfoDao;
  49. @Autowired
  50. private SurveyQuestionsOptionsDao surveyQuestionsOptionsDao;
  51. @Autowired
  52. private SurveyUserDao surveyUserDao;
  53. @Autowired
  54. private SurveyFilterDao surveyFilterDao;
  55. @Autowired
  56. private SurveyQuestionnaireOptionsDao surveyQuestionnaireOptionsDao;
  57. @Autowired
  58. private SurveyQuestionnaireDao surveyQuestionnaireDao;
  59. @Autowired
  60. private SurveyTemplateOptionsDao surveyTemplateOptionsDao;
  61. @Autowired
  62. private SurveyTemplateQuestionsDao surveyTemplateQuestionsDao;
  63. @Autowired
  64. private SurveyOptionAnswersDao surveyOptionAnswersDao;
  65. @Autowired
  66. private SurveyAnswersDao surveyAnswersDao;
  67. @Autowired
  68. private SurveyTemplatesDao surveyTemplatesDao;
  69. @Autowired
  70. private SurveyStatisticsDao surveyStatisticsDao;
  71. @Autowired
  72. private JdbcTemplate jdbcTemplate;
  73. @Autowired
  74. private SystemDictDao systemDictDao;
  75. @Autowired
  76. private SurveyDimensionDao surveyDimensionDao;
  77. @Autowired
  78. private SurveyDimensionDetailDao surveyDimensionDetailDao;
  79. @Autowired
  80. private DoctorDao doctorDao;
  81. @Autowired
  82. private PatientDao patientDao;
  83. public String createSurvey(String doctor, JSONObject jsonStr, String accessToken) throws Exception {
  84. System.out.println("=============>" + jsonStr);
  85. // 问卷信息
  86. String surveyCode = getCode();
  87. String surveyName = jsonStr.getString("surveyName");
  88. String surveyComment = jsonStr.getString("comment");
  89. String templateCode = null;
  90. String send = jsonStr.get("send").toString();
  91. int status = 1;
  92. // 自主创建
  93. int useType = 1;
  94. if (!StringUtils.isEmpty(jsonStr.getString("templateCode"))) {
  95. // 模板创建
  96. useType = 0;
  97. templateCode = jsonStr.getString("templateCode");
  98. }
  99. // 获取调查对象
  100. JSONObject surveyTarget = jsonStr.getJSONObject("surveyTarget");
  101. // 0不限 1男 2女
  102. int sex = Integer.parseInt(surveyTarget.get("sex").toString());
  103. JSONArray disease = surveyTarget.getJSONArray("disease");
  104. JSONArray service = surveyTarget.getJSONArray("service");
  105. JSONArray healthCondition = surveyTarget.getJSONArray("healthCondition");
  106. /*String str = "SELECT DISTINCT t.patient " +
  107. "FROM `wlyy_sign_patient_label_info` t,wlyy_patient p,`wlyy_sign_family` f " +
  108. "WHERE t.`patient` = p.`code` AND f.`patient`=t.`patient` AND f.`status` IN (1,2,3) AND p.`openid` IS NOT NULL AND p.`openid`!='' ";*/
  109. // 保存到维度详情表(不限不保存) 维度表(1性别 2疾病类型 3服务类型 4健康状况)
  110. if (sex != 0) {
  111. // str += "AND(p.sex=" + sex + ")";
  112. String dimensionCode = surveyDimensionDao.findByName("性别");
  113. String dimensionDetailCode = getCode();
  114. SurveyDimensionDetail surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, sex == 1 ? "男" : "女", sex, "性别", 1, surveyCode);
  115. surveyDimensionDetailDao.save(surveyDimensionDetail);
  116. // 保存到筛选表
  117. SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
  118. surveyFilterDao.save(surveyFilter);
  119. }
  120. // String ser = "";
  121. // String servi = "";
  122. for (Object serv : service) {
  123. if ("0".equals(serv.toString())) {
  124. // ser += ",";
  125. break;
  126. } else {
  127. // ser += serv.toString() + ",";
  128. // ===================================
  129. String dimensionCode = surveyDimensionDao.findByName("服务类型");
  130. String dimensionDetailCode = getCode();
  131. SurveyDimensionDetail surveyDimensionDetail = null;
  132. switch (Integer.parseInt(serv.toString())) {
  133. // 1.普通人群 2.慢病人群 3.65岁以上人群
  134. case 1:
  135. surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "普通人群", 1, "服务类型", 3, surveyCode);
  136. break;
  137. case 2:
  138. surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "慢病人群", 2, "服务类型", 3, surveyCode);
  139. break;
  140. case 3:
  141. surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "65岁以上人群", 3, "服务类型", 3, surveyCode);
  142. break;
  143. }
  144. surveyDimensionDetailDao.save(surveyDimensionDetail);
  145. SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
  146. surveyFilterDao.save(surveyFilter);
  147. }
  148. }
  149. /*ser = ser.substring(0, ser.length() - 1);
  150. if (ser.length() != 0) {
  151. servi = "(t.`label_type`=1 AND t.`label`IN(" + ser + "))";
  152. }*/
  153. // String heal = "";
  154. // String healt = "";
  155. for (Object health : healthCondition) {
  156. if ("0".equals(health.toString())) {
  157. // heal += ",";
  158. break;
  159. } else {
  160. // heal += health.toString() + ",";
  161. String dimensionCode = surveyDimensionDao.findByName("健康状况");
  162. String dimensionDetailCode = getCode();
  163. String surveyFilterCode = getCode();
  164. SurveyDimensionDetail surveyDimensionDetail = null;
  165. switch (Integer.parseInt(health.toString())) {
  166. // 1.健康人群 2.患病人群 3.高危人群 4.恢复期人群
  167. case 1:
  168. surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "健康人群", 1, "健康状况", 4, surveyCode);
  169. break;
  170. case 2:
  171. surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "患病人群", 2, "健康状况", 4, surveyCode);
  172. break;
  173. case 3:
  174. surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "高危人群", 3, "健康状况", 4, surveyCode);
  175. break;
  176. case 4:
  177. surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "恢复期人群", 4, "健康状况", 4, surveyCode);
  178. break;
  179. }
  180. surveyDimensionDetailDao.save(surveyDimensionDetail);
  181. SurveyFilter surveyFilter = new SurveyFilter(surveyFilterCode, surveyCode, dimensionDetailCode);
  182. surveyFilterDao.save(surveyFilter);
  183. }
  184. }
  185. /* heal = heal.substring(0, heal.length() - 1);
  186. if (heal.length() != 0) {
  187. healt = "(t.`label_type`=2 AND t.`label`IN(" + heal + "))";
  188. }*/
  189. // String dise = "";
  190. // String diseas = "";
  191. for (Object disea : disease) {
  192. if ("0".equals(disea.toString())) {
  193. // dise += ",";
  194. break;
  195. } else {
  196. // dise += disea.toString() + ",";
  197. // ================================================================
  198. String dimensionCode = surveyDimensionDao.findByName("疾病类型");
  199. String dimensionDetailCode = getCode();
  200. SurveyDimensionDetail surveyDimensionDetail = null;
  201. switch (Integer.parseInt(disea.toString())) {
  202. // 1.高血压 2糖尿病 3.高血压+糖尿病
  203. case 1:
  204. surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "高血压", 1, "疾病类型", 2, surveyCode);
  205. break;
  206. case 2:
  207. surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "糖尿病", 2, "疾病类型", 2, surveyCode);
  208. break;
  209. }
  210. surveyDimensionDetailDao.save(surveyDimensionDetail);
  211. SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
  212. surveyFilterDao.save(surveyFilter);
  213. }
  214. }
  215. /*dise = dise.substring(0, dise.length() - 1);
  216. if (dise.length() != 0) {
  217. diseas = "(t.`label_type`=3 AND t.`label`IN(" + dise + "))";
  218. }
  219. if (servi.length() != 0 & healt.length() != 0 & diseas.length() != 0) {
  220. str += " AND ( " + servi + " OR " + healt + " OR " + diseas + " )";
  221. } else if (servi.length() != 0 & healt.length() != 0 & diseas.length() == 0) {
  222. str += " AND ( " + servi + " OR " + healt + " )";
  223. } else if (servi.length() != 0 & healt.length() == 0 & diseas.length() != 0) {
  224. str += " AND ( " + servi + " OR " + diseas + " )";
  225. } else if (servi.length() == 0 & healt.length() != 0 & diseas.length() != 0) {
  226. str += " AND ( " + healt + " OR " + diseas + " )";
  227. } else if (servi.length() != 0 & healt.length() == 0 & diseas.length() == 0) {
  228. str += " AND " + servi;
  229. } else if (servi.length() == 0 & healt.length() != 0 & diseas.length() == 0) {
  230. str += " AND " + healt;
  231. } else if (servi.length() == 0 & healt.length() == 0 & diseas.length() != 0) {
  232. str += " AND " + diseas;
  233. }*/
  234. /* System.out.println("*****************str***********************" + str);
  235. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  236. sdf.format(new Date());
  237. String jsonData = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
  238. JSONObject json = new JSONObject(jsonData);
  239. json.put("survey_id", surveyCode);*/
  240. // List<Map<String, Object>> patients = jdbcTemplate.queryForList(str);
  241. // Map<String, Object> map = jdbcTemplate.queryForMap(str);
  242. // List<String> codes = jdbcTemplate.queryForList(str, String.class);
  243. List<String> codes = getCount(surveyTarget.toString());
  244. int amount = codes.size();
  245. for (String code : codes) {
  246. // String code = patient.get("patient").toString();
  247. SurveyUser user = new SurveyUser(surveyCode, code, 0, 1, new Date(), new Date());
  248. surveyUserDao.save(user);
  249. // 发送居民模板 send=1发送
  250. /* if ("1".equals(send)) {
  251. String name = patient.get("name").toString();
  252. String openId = patient.get("openid").toString();
  253. // String openId = "o7NFZw1QM4YR1O19mLjwfX1Hh11A";
  254. json.put("keyword2", sdf.format(new Date()));
  255. json.put("toUser", code);
  256. json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
  257. System.out.println("*************************" + json + "******************");
  258. System.out.println("********name*********************" + name + "openId" + openId);
  259. PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
  260. }*/
  261. }
  262. // 发送居民模板 send=1发送
  263. // ====================================================
  264. if ("1".equals(send)) {
  265. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  266. String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
  267. JSONObject json = new JSONObject(str);
  268. codes.stream().forEach(c -> {
  269. Patient p = patientDao.findByCode(c);
  270. String name = p.getName();
  271. String openId = p.getOpenid();
  272. json.put("keyword2", sdf.format(new Date()));
  273. json.put("toUser", c);
  274. json.put("survey_id",surveyCode );
  275. json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
  276. PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
  277. });
  278. }
  279. // =====================================================
  280. // 获取标签数组
  281. JSONArray lables = jsonStr.getJSONArray("label");
  282. // 标签保存到wlyy_survey_label_info
  283. for (Object label : lables) {
  284. SurveyLabelInfo surveyLabelInfo = new SurveyLabelInfo();
  285. surveyLabelInfo.setCode(getCode());
  286. surveyLabelInfo.setRelationCode(surveyCode);
  287. surveyLabelInfo.setUseType(useType);
  288. surveyLabelInfo.setLabel(Integer.parseInt(label.toString()));
  289. SurveyLabelInfo ss = surveyLabelInfoDao.save(surveyLabelInfo);
  290. }
  291. // 获取问题数组
  292. JSONArray questions = jsonStr.getJSONArray("questions");
  293. for (Object question : questions) {
  294. JSONObject tempQestion = new JSONObject(question.toString());
  295. // 不分题型都有的属性
  296. String questionnaireCode = tempQestion.get("qstCode").toString();
  297. String title = tempQestion.get("title").toString();
  298. String comment = tempQestion.get("comment").toString();
  299. int type = Integer.parseInt(tempQestion.get("type").toString());
  300. int isRequired = Integer.parseInt(tempQestion.get("isRequired").toString());
  301. int sort = Integer.parseInt(tempQestion.get("sort").toString());
  302. int del = 1;
  303. String qstNextQuestion = null;
  304. if (!StringUtils.isEmpty(tempQestion.get("nextQuestion").toString())) {
  305. // optionNextQuestion = tempOption.get("nextQuestion").toString();
  306. qstNextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode, tempQestion.get("nextQuestion"));
  307. qstNextQuestion = (qstNextQuestion == null ? "0" : qstNextQuestion);
  308. }
  309. switch (type) {
  310. case 0:
  311. // 单选
  312. SurveyQuestionnaire surveyQuestionnaire = new SurveyQuestionnaire();
  313. surveyQuestionnaire.setCode(questionnaireCode);
  314. surveyQuestionnaire.setTitle(title);
  315. surveyQuestionnaire.setQuestionComment(comment);
  316. surveyQuestionnaire.setQuestionType(type);
  317. surveyQuestionnaire.setSurveyCode(surveyCode);
  318. surveyQuestionnaire.setIsRequired(isRequired);
  319. surveyQuestionnaire.setDel(del);
  320. surveyQuestionnaire.setSort(sort);
  321. surveyQuestionnaire.setCreateTime(new Date());
  322. surveyQuestionnaire.setUpdateTime(new Date());
  323. // 单选没有最大最小选项数及题目逻辑跳转
  324. surveyQuestionnaire.setMinNum(null);
  325. surveyQuestionnaire.setMaxNum(null);
  326. surveyQuestionnaire.setQuestionCodeNext(qstNextQuestion);
  327. surveyQuestionnaireDao.save(surveyQuestionnaire);
  328. System.out.println("=====================================");
  329. // =======================选项保存=========================
  330. // 选择题
  331. JSONArray options = new JSONArray(tempQestion.get("options").toString());
  332. for (Object option : options) {
  333. String optionCode = getCode();
  334. JSONObject tempOption = new JSONObject(option.toString());
  335. int haveComment = Integer.parseInt(tempOption.get("haveComment").toString());
  336. String optionComment = tempOption.get("content").toString();
  337. int required = Integer.parseInt(tempOption.get("isRequired").toString());
  338. int optionSort = Integer.parseInt(tempOption.get("sort").toString());
  339. int optionDel = 1;
  340. String optionNextQuestion = null;
  341. if (!StringUtils.isEmpty(tempOption.get("nextQuestion").toString())) {
  342. // optionNextQuestion = tempOption.get("nextQuestion").toString();
  343. optionNextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode, tempOption.get("nextQuestion"));
  344. optionNextQuestion = (optionNextQuestion == null ? "0" : optionNextQuestion);
  345. }
  346. // 自主创建,插入表
  347. SurveyQuestionnaireOptions surveyQuestionnaireOptions = new SurveyQuestionnaireOptions(optionCode, haveComment, questionnaireCode, optionComment,
  348. surveyCode, optionNextQuestion, required, optionSort, optionDel);
  349. /* surveyQuestionnaireOptions.setCode(optionCode);
  350. surveyQuestionnaireOptions.setHaveComment(haveComment);
  351. surveyQuestionnaireOptions.setQuestionnaireCode(questionnaireCode);
  352. surveyQuestionnaireOptions.setContent(optionComment);
  353. surveyQuestionnaireOptions.setSurveyCode(surveyCode);
  354. surveyQuestionnaireOptions.setQuestionCodeNext(optionNextQuestion);
  355. surveyQuestionnaireOptions.setIsRequired(required);
  356. surveyQuestionnaireOptions.setSort(optionSort);
  357. surveyQuestionnaireOptions.setDel(optionDel);*/
  358. surveyQuestionnaireOptionsDao.save(surveyQuestionnaireOptions);
  359. // 单选题保存到统计表
  360. String statisticsCode = getCode();
  361. String questionTitle = surveyQuestionnaireDao.findByIdAndQstId(surveyCode, questionnaireCode).getTitle();
  362. String optcontent = surveyQuestionnaireOptionsDao.findByRelationCode(surveyCode, questionnaireCode, optionCode).getContent();
  363. SurveyStatistics statistics = new SurveyStatistics(statisticsCode, surveyCode, questionnaireCode, questionTitle, optionCode, 0, optcontent, haveComment, type, sort, optionSort);
  364. surveyStatisticsDao.save(statistics);
  365. }
  366. // ===============================================================
  367. break;
  368. case 1:
  369. // 多选特有属性
  370. Integer maxOptions = null;
  371. Integer minOptions = null;
  372. if (!StringUtils.isEmpty(tempQestion.get("minOptions").toString())) {
  373. minOptions = Integer.parseInt(tempQestion.get("minOptions").toString());
  374. }
  375. if (!StringUtils.isEmpty(tempQestion.get("maxOptions").toString())) {
  376. maxOptions = Integer.parseInt(tempQestion.get("maxOptions").toString());
  377. }
  378. SurveyQuestionnaire surveyQuestionnaire1 = new SurveyQuestionnaire();
  379. surveyQuestionnaire1.setCode(questionnaireCode);
  380. surveyQuestionnaire1.setTitle(title);
  381. surveyQuestionnaire1.setQuestionComment(comment);
  382. surveyQuestionnaire1.setQuestionType(type);
  383. surveyQuestionnaire1.setSurveyCode(surveyCode);
  384. surveyQuestionnaire1.setIsRequired(isRequired);
  385. surveyQuestionnaire1.setMinNum(minOptions);
  386. surveyQuestionnaire1.setMaxNum(maxOptions);
  387. surveyQuestionnaire1.setSort(sort);
  388. surveyQuestionnaire1.setQuestionCodeNext(qstNextQuestion);
  389. surveyQuestionnaire1.setDel(del);
  390. surveyQuestionnaire1.setCreateTime(new Date());
  391. surveyQuestionnaire1.setUpdateTime(new Date());
  392. surveyQuestionnaireDao.save(surveyQuestionnaire1);
  393. // =======================选项保存=========================
  394. // 选择题
  395. JSONArray options1 = new JSONArray(tempQestion.get("options").toString());
  396. for (Object option : options1) {
  397. String optionCode = getCode();
  398. JSONObject tempOption = new JSONObject(option.toString());
  399. int haveComment = Integer.parseInt(tempOption.get("haveComment").toString());
  400. String optionComment = tempOption.get("content").toString();
  401. int required = Integer.parseInt(tempOption.get("isRequired").toString());
  402. int optionSort = Integer.parseInt(tempOption.get("sort").toString());
  403. int optionDel = 1;
  404. String optionNextQuestion = null;
  405. if (!StringUtils.isEmpty(tempOption.get("nextQuestion").toString())) {
  406. // optionNextQuestion = tempOption.get("nextQuestion").toString();
  407. optionNextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode, tempOption.get("nextQuestion"));
  408. }
  409. // 自主创建,插入表
  410. SurveyQuestionnaireOptions surveyQuestionnaireOptions = new SurveyQuestionnaireOptions();
  411. surveyQuestionnaireOptions.setCode(optionCode);
  412. surveyQuestionnaireOptions.setHaveComment(haveComment);
  413. surveyQuestionnaireOptions.setQuestionnaireCode(questionnaireCode);
  414. surveyQuestionnaireOptions.setContent(optionComment);
  415. surveyQuestionnaireOptions.setSurveyCode(surveyCode);
  416. surveyQuestionnaireOptions.setQuestionCodeNext(optionNextQuestion);
  417. surveyQuestionnaireOptions.setIsRequired(required);
  418. surveyQuestionnaireOptions.setSort(optionSort);
  419. surveyQuestionnaireOptions.setDel(optionDel);
  420. surveyQuestionnaireOptionsDao.save(surveyQuestionnaireOptions);
  421. // 多选题保存到统计表
  422. String statisticsCode = getCode();
  423. String questionTitle = surveyQuestionnaireDao.findByIdAndQstId(surveyCode, questionnaireCode).getTitle();
  424. String optcontent = surveyQuestionnaireOptionsDao.findByRelationCode(surveyCode, questionnaireCode, optionCode).getContent();
  425. SurveyStatistics statistics = new SurveyStatistics(statisticsCode, surveyCode, questionnaireCode, questionTitle, optionCode, 0, optcontent, haveComment, type, sort, optionSort);
  426. surveyStatisticsDao.save(statistics);
  427. }
  428. // ===============================================================
  429. break;
  430. case 2:
  431. // 问答特有属性
  432. /*String nextQuestion = null;
  433. if (StringUtils.isEmpty(tempQestion.get("nextQuestion").toString())) {
  434. nextQuestion = tempQestion.get("nextQuestion").toString();
  435. }else {
  436. nextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode,tempQestion.get("nextQuestion"));
  437. }*/
  438. SurveyQuestionnaire surveyQuestionnaire2 = new SurveyQuestionnaire();
  439. surveyQuestionnaire2.setCode(questionnaireCode);
  440. surveyQuestionnaire2.setTitle(title);
  441. surveyQuestionnaire2.setQuestionComment(comment);
  442. surveyQuestionnaire2.setQuestionType(type);
  443. surveyQuestionnaire2.setSurveyCode(surveyCode);
  444. surveyQuestionnaire2.setIsRequired(isRequired);
  445. // 单选没有最大最小选项数
  446. surveyQuestionnaire2.setMinNum(null);
  447. surveyQuestionnaire2.setMaxNum(null);
  448. surveyQuestionnaire2.setSort(sort);
  449. surveyQuestionnaire2.setQuestionCodeNext(qstNextQuestion);
  450. surveyQuestionnaire2.setDel(del);
  451. surveyQuestionnaire2.setUpdateTime(new Date());
  452. surveyQuestionnaire2.setCreateTime(new Date());
  453. surveyQuestionnaireDao.save(surveyQuestionnaire2);
  454. // 问答题保存到统计表(只负责更改数量不负责创建)
  455. String statisticsCode = getCode();
  456. String questionTitle = surveyQuestionnaireDao.findByIdAndQstId(surveyCode, questionnaireCode).getTitle();
  457. SurveyStatistics statistics = new SurveyStatistics(statisticsCode, surveyCode, questionnaireCode, questionTitle, null, 0, null, null, type, sort, null);
  458. surveyStatisticsDao.save(statistics);
  459. break;
  460. }
  461. }
  462. // 保存到问卷
  463. Survey survey = new Survey();
  464. survey.setCode(surveyCode);
  465. survey.setTitle(surveyName);
  466. survey.setSurveyComment(surveyComment);
  467. survey.setCreater(doctor);
  468. survey.setTemplateCode(templateCode);
  469. survey.setStatus(status);
  470. survey.setAmount(amount);
  471. survey.setCreateTime(new Date());
  472. survey.setUpdateTime(new Date());
  473. surveyDao.save(survey);
  474. return surveyCode;
  475. }
  476. public JSONArray getQuestionnaireList(int pageNo, int pageSize) throws Exception {
  477. JSONArray jsonArray = new JSONArray();
  478. // 排序
  479. Sort sort = new Sort(Sort.Direction.DESC, "createTime");
  480. PageRequest pageRequest = new PageRequest(pageNo - 1, pageSize, sort);
  481. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  482. Page<Survey> surveys = surveyDao.findAll(pageRequest);
  483. List<Survey> arrays = surveys.getContent();
  484. for (Survey arr : arrays) {
  485. Map<String, Object> sur = new HashMap<>();
  486. String code = arr.getCode();
  487. String title = arr.getTitle();
  488. String doctor = arr.getCreater();
  489. String comment = arr.getSurveyComment();
  490. String createTime = sdf.format(arr.getCreateTime());
  491. // String updateTime = sdf.format(arr.getUpdateTime());
  492. // 查询医生信息
  493. Doctor doc = doctorDao.findByCode(doctor);
  494. String name = doc.getName();
  495. String photo = doc.getPhoto();
  496. String dept = doc.getDeptName();
  497. int amount = arr.getAmount();
  498. //查询居民回答的反馈率
  499. int complete = surveyUserDao.findBySurveyCode(code);
  500. sur.put("code", code);
  501. sur.put("name", name);
  502. sur.put("photo", photo);
  503. sur.put("deptName", dept);
  504. sur.put("percent", (Math.round(((float) complete / amount) * 100)) + "%");
  505. sur.put("title", title);
  506. sur.put("comment", comment);
  507. sur.put("createTime", createTime);
  508. // sur.put("updateTime", updateTime);
  509. sur.put("complete", complete);
  510. sur.put("amount", amount);
  511. jsonArray.put(sur);
  512. }
  513. return jsonArray;
  514. }
  515. public JSONObject getQuestionnaireSummary(String id) throws Exception {
  516. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  517. Survey survey = surveyDao.findById(id);
  518. String creater = survey.getCreater();
  519. Date createTime = survey.getCreateTime();
  520. int amount = survey.getAmount();
  521. String comment = survey.getSurveyComment();
  522. String title = survey.getTitle();
  523. int status = survey.getStatus();
  524. List<String> targets = surveyDimensionDetailDao.findByCode(id);
  525. Map<String, Object> surveyTarget = new HashMap<>();
  526. for (String target : targets) {
  527. List<String> labels = surveyDimensionDetailDao.findByCode(id, target);
  528. List tags = new ArrayList();
  529. for (String label : labels) {
  530. tags.add(label);
  531. }
  532. switch (target) {
  533. case "疾病类型":
  534. target = "disease";
  535. break;
  536. case "服务类型":
  537. target = "service";
  538. break;
  539. case "健康状况":
  540. target = "healthCondition";
  541. break;
  542. case "性别":
  543. target = "sex";
  544. break;
  545. }
  546. surveyTarget.put(target, tags);
  547. }
  548. int[] label = surveyLabelInfoDao.findByRelationCode(id);
  549. String[] labels = new String[label.length];
  550. for (int i = 0; i < label.length; i++) {
  551. switch (label[i]) {
  552. case 1:
  553. labels[i] = "满意度";
  554. break;
  555. case 2:
  556. labels[i] = "糖尿病";
  557. break;
  558. case 3:
  559. labels[i] = "高血压";
  560. break;
  561. case 4:
  562. labels[i] = "生活日常";
  563. break;
  564. }
  565. }
  566. // 查询该问卷回答人数
  567. // int complete = surveyUserDao.findBySurveyCode(id);
  568. int complete = surveyUserDao.findBySurveyCode(id);
  569. Map<String, Object> map = new HashMap<>();
  570. // 获取创建者信息
  571. Doctor doctor = doctorDao.findByCode(creater);
  572. String name = doctor.getName();
  573. String deptName = doctor.getDeptName();
  574. String photo = doctor.getPhoto();
  575. map.put("name", name);
  576. map.put("deptName", deptName);
  577. map.put("photo", photo);
  578. map.put("createTime", sdf.format(createTime));
  579. map.put("amount", amount);
  580. map.put("complete", complete);
  581. map.put("percent", (Math.round(((float) complete / amount) * 100)) + "%");
  582. map.put("comment", comment);
  583. map.put("title", title);
  584. map.put("status", status);
  585. map.put("label", labels);
  586. map.put("surveyTarget", surveyTarget);
  587. JSONObject jsonObject = new JSONObject(map);
  588. return jsonObject;
  589. }
  590. public JSONObject getQuestionnaireDetail(String id) throws Exception {
  591. JSONObject jsonObject = new JSONObject();
  592. //问卷信息
  593. Survey survey = surveyDao.findById(id);
  594. int[] label = surveyLabelInfoDao.findByRelationCode(id);
  595. String[] labels = new String[label.length];
  596. for (int i = 0; i < label.length; i++) {
  597. switch (label[i]) {
  598. case 1:
  599. labels[i] = "满意度";
  600. break;
  601. case 2:
  602. labels[i] = "糖尿病";
  603. break;
  604. case 3:
  605. labels[i] = "高血压";
  606. break;
  607. case 4:
  608. labels[i] = "生活日常";
  609. break;
  610. }
  611. }
  612. //问题信息
  613. List<SurveyQuestionnaire> surveyQuestionnair = surveyQuestionnaireDao.findById(id);
  614. List questions = new ArrayList();
  615. // 问题信息
  616. for (SurveyQuestionnaire questionnair : surveyQuestionnair) {
  617. Map<String, Object> question = new HashMap<>();
  618. String qstcode = questionnair.getCode();
  619. String title = questionnair.getTitle();
  620. int isRequired = questionnair.getIsRequired();
  621. int sort = questionnair.getSort();
  622. int type = questionnair.getQuestionType();
  623. if (questionnair.getMaxNum() != null) {
  624. int maxNum = questionnair.getMaxNum();
  625. question.put("maxNum", maxNum);
  626. }
  627. if (questionnair.getMinNum() != null) {
  628. int minNum = questionnair.getMinNum();
  629. question.put("minNum", minNum);
  630. }
  631. if (questionnair.getQuestionComment() != null) {
  632. String comment = questionnair.getQuestionComment();
  633. question.put("comment", comment);
  634. }
  635. if (questionnair.getQuestionCodeNext() != null) {
  636. String next = questionnair.getQuestionCodeNext();
  637. SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
  638. question.put("nextQuestion", sq == null ? 0 : sq.getSort());
  639. }
  640. // List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findById(qstcode);
  641. List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findByIdAndQstCode(id, qstcode);
  642. List optList = new ArrayList();
  643. for (SurveyQuestionnaireOptions option : options) {
  644. Map<String, Object> opt = new HashMap<>();
  645. String conetent = option.getContent();
  646. int haveComment = option.getHaveComment();
  647. int required = option.getIsRequired();
  648. int st = option.getSort();
  649. if (option.getQuestionCodeNext() != null) {
  650. String next = option.getQuestionCodeNext();
  651. SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
  652. System.out.println("=============qstcode============== " + qstcode);
  653. System.out.println("=============optCode============== " + option.getCode());
  654. System.out.println("=============sq============== " + sq);
  655. System.out.println("=============next============== " + next);
  656. opt.put("nextQuestion", sq == null ? 0 : sq.getSort());
  657. }
  658. opt.put("content", conetent);
  659. opt.put("sort", st);
  660. opt.put("haveComment", haveComment);
  661. opt.put("isRequired", required);
  662. optList.add(opt);
  663. }
  664. question.put("title", title);
  665. question.put("type", type);
  666. question.put("isRequired", isRequired);
  667. question.put("sort", sort);
  668. question.put("options", optList);
  669. questions.add(question);
  670. }
  671. String surveyComment = survey.getSurveyComment();
  672. String surveyTitle = survey.getTitle();
  673. jsonObject.put("title", surveyTitle);
  674. jsonObject.put("comment", surveyComment);
  675. jsonObject.put("questions", questions);
  676. jsonObject.put("label", labels);
  677. return jsonObject;
  678. }
  679. public int modifyQuestionnaireStatus(String id) throws Exception {
  680. Survey survey = surveyDao.findById(id);
  681. int status = survey.getStatus();
  682. if (status > 1) {
  683. status = 1;
  684. surveyDao.modifyStatus(status, id);
  685. } else {
  686. status = 2;
  687. surveyDao.modifyStatus(status, id);
  688. }
  689. return status;
  690. }
  691. public JSONObject getAnswers(String id) throws Exception {
  692. JSONObject jsonObject = new JSONObject();
  693. //一个问卷内的所有问题
  694. List<SurveyQuestionnaire> questions = surveyQuestionnaireDao.findById(id);
  695. if (questions.size() == 0) {
  696. return jsonObject;
  697. }
  698. List qstList = new ArrayList();
  699. for (SurveyQuestionnaire question : questions) {
  700. // 新造对象
  701. Map<String, Object> qst = new HashMap<>();
  702. String qstcode = question.getCode();
  703. String title = question.getTitle();
  704. int type = question.getQuestionType();
  705. // 有效答了该题的人数
  706. /*int amount = 0;
  707. int[] sum = surveyStatisticsDao.findByIdAndQstId(id, qstcode);
  708. for (int count : sum) {
  709. amount += count;
  710. }*/
  711. int amount = 0;
  712. if (type == 2) {
  713. // 问卷答案表有效(去重)答题人数
  714. amount = surveyAnswersDao.countByRelationCode(id, qstcode);
  715. } else {
  716. // 问卷选项答案表有效(去重)答题人数
  717. amount = surveyOptionAnswersDao.countByRelationCode(id, qstcode);
  718. }
  719. qst.put("amount", amount);
  720. qst.put("qstcode", qstcode);
  721. qst.put("title", title);
  722. qst.put("type", type);
  723. // 一个问题内的所有选项
  724. // List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findById(qstcode);
  725. List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findByIdAndQstCode(id, qstcode);
  726. List optList = new ArrayList();
  727. for (SurveyQuestionnaireOptions option : options) {
  728. Map<String, Object> opt = new HashMap<>();
  729. String optcode = option.getCode();
  730. String optTitle = option.getContent();
  731. int haveComment = option.getHaveComment();
  732. int count = surveyStatisticsDao.findByAllId(id, qstcode, optcode);
  733. opt.put("optcode", optcode);
  734. opt.put("option", optTitle);
  735. opt.put("count", count);
  736. opt.put("percent", (Math.round(((float) count / amount) * 100)) + "%");
  737. opt.put("haveComment", haveComment);
  738. optList.add(opt);
  739. }
  740. qst.put("options", optList);
  741. qstList.add(qst);
  742. }
  743. jsonObject.put("questions", qstList);
  744. return jsonObject;
  745. }
  746. public JSONObject getOptionsComment(String id, String questionId, String optionId, int pageNo, int pageSize) throws Exception {
  747. JSONObject jsonObject = new JSONObject();
  748. SurveyQuestionnaire question = surveyQuestionnaireDao.findByIdAndQstId(id, questionId);
  749. Sort sort = new Sort(Sort.Direction.ASC, "createTime");
  750. PageRequest request = new PageRequest(pageNo - 1, pageSize, sort);
  751. if (!StringUtils.isEmpty(optionId)) {
  752. // 查看选择题详细答案
  753. SurveyQuestionnaireOptions opt = surveyQuestionnaireOptionsDao.findByRelationCode(id, questionId, optionId);
  754. String option = opt.getContent();
  755. jsonObject.put("option", option);
  756. // 获取同一个选项的所有回答的说明(分页?)
  757. Page<String> optionComment = surveyOptionAnswersDao.findByRelationCode(id, questionId, optionId, request);
  758. jsonObject.put("content", optionComment.getContent());
  759. int amount = surveyOptionAnswersDao.findByRelationCode(id, questionId, optionId);
  760. jsonObject.put("amount", amount);
  761. } else {
  762. // 查看问答题答案(分页?)
  763. Page<String> answer = surveyAnswersDao.findByRelationCode(id, questionId, request);
  764. jsonObject.put("content", answer.getContent());
  765. int amount = surveyAnswersDao.findByRelationCode(id, questionId);
  766. jsonObject.put("amount", amount);
  767. }
  768. String title = question.getTitle();
  769. jsonObject.put("title", title);
  770. return jsonObject;
  771. }
  772. public List getTemplateList(int pageNo, int pageSize) throws Exception {
  773. Sort sort = new Sort(Sort.Direction.DESC, "createTime");
  774. PageRequest request = new PageRequest(pageNo - 1, pageSize, sort);
  775. List<SurveyTemplates> templates = surveyTemplatesDao.findAlls(request);
  776. List list = new ArrayList();
  777. for (SurveyTemplates template : templates) {
  778. Map<String, Object> tempMap = new HashMap();
  779. String title = template.getTitle();
  780. String templateId = template.getCode();
  781. String comment = template.getTemplateComment();
  782. int[] label = surveyLabelInfoDao.findByRelationCode(templateId);
  783. String[] labels = new String[label.length];
  784. for (int i = 0; i < label.length; i++) {
  785. switch (label[i]) {
  786. case 1:
  787. labels[i] = "满意度";
  788. break;
  789. case 2:
  790. labels[i] = "糖尿病";
  791. break;
  792. case 3:
  793. labels[i] = "高血压";
  794. break;
  795. case 4:
  796. labels[i] = "生活日常";
  797. break;
  798. }
  799. }
  800. tempMap.put("templateId", templateId);
  801. tempMap.put("title", title);
  802. if (comment.length() > 50) {
  803. comment = comment.substring(0, 49);
  804. }
  805. tempMap.put("comment", comment);
  806. tempMap.put("label", labels);
  807. list.add(tempMap);
  808. }
  809. return list;
  810. }
  811. public List getTemplateLabel() throws Exception {
  812. List list = new ArrayList();
  813. List<SystemDict> labels = systemDictDao.findByDictName("SURVEY_LABEL");
  814. for (SystemDict label : labels) {
  815. Map<String, Object> map = new HashMap();
  816. String code = label.getCode();
  817. String value = label.getValue();
  818. map.put("code", code);
  819. map.put("value", value);
  820. list.add(map);
  821. }
  822. return list;
  823. }
  824. public JSONObject getQuestionList(String title, int pageNo, int pageSize) throws Exception {
  825. JSONObject jsonObject = new JSONObject();
  826. Sort sort = new Sort(Sort.Direction.DESC, "createTime");
  827. PageRequest request = new PageRequest(pageNo - 1, pageSize, sort);
  828. List<SurveyQuestions> questions = new ArrayList<>();
  829. if (StringUtils.isEmpty(title)) {
  830. questions = surveyQuestionsDao.findByTitle(request);
  831. } else {
  832. questions = surveyQuestionsDao.findByTitle("%" + title + "%", request);
  833. }
  834. List list = new ArrayList();
  835. for (SurveyQuestions question : questions) {
  836. Map<String, Object> map = new HashMap<>();
  837. String code = question.getCode();
  838. String qstTitle = question.getTitle();
  839. if (question.getQuestionComment() != null) {
  840. String comment = question.getQuestionComment();
  841. map.put("comment", comment);
  842. }
  843. int isRequired = question.getIsRequired();
  844. int questionType = question.getQuestionType();
  845. if (questionType != 2) {
  846. // 获取选择题选项值
  847. List<SurveyQuestionsOptions> options = surveyQuestionsOptionsDao.findById(code);
  848. List opts = new ArrayList();
  849. for (SurveyQuestionsOptions option : options) {
  850. Map<String, Object> opt = new HashMap<>();
  851. opt.put("optCode", option.getCode());
  852. opt.put("content", option.getContent());
  853. opt.put("haveComment", option.getHaveComment());
  854. opt.put("isRequired", option.getIsRequired());
  855. opts.add(opt);
  856. }
  857. map.put("options", opts);
  858. }
  859. map.put("code", code);
  860. map.put("title", qstTitle);
  861. map.put("isRequired", isRequired);
  862. map.put("questionType", questionType);
  863. list.add(map);
  864. }
  865. jsonObject.put("questions", list);
  866. return jsonObject;
  867. }
  868. public List getTemplateByLabelOrTitle(String name, int pageNo, int pageSize) throws Exception {
  869. Sort sort = new Sort(Sort.Direction.DESC, "createTime");
  870. PageRequest request = new PageRequest(pageNo - 1, pageSize, sort);
  871. String sql = "SELECT DISTINCT s.code " +
  872. " FROM System_dict s WHERE s.dict_name ='SURVEY_LABEL' and s.value LIKE '%" + name +
  873. "%'";
  874. List<Map<String, Object>> labels = jdbcTemplate.queryForList(sql);
  875. List<SurveyTemplates> surveyTemplates = new ArrayList<>();
  876. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  877. if (labels.size() == 0) {
  878. // 模板标题
  879. String cql = "select distinct t.* from wlyy_survey_templates t where t.del = 1 and t.title like '%" + name + "%' ";
  880. List<Map<String, Object>> surveyTemp = jdbcTemplate.queryForList(cql);
  881. for (Map<String, Object> temp : surveyTemp) {
  882. String create = temp.get("create_time").toString();
  883. String update = temp.get("update_time").toString();
  884. Date createTime = sdf.parse(create);
  885. Date updateTime = sdf.parse(update);
  886. SurveyTemplates tem = new SurveyTemplates(temp.get("code").toString(),
  887. temp.get("title").toString(), temp.get("template_comment").toString(), temp.get("creater").toString(),
  888. Integer.parseInt(temp.get("del").toString()), createTime, updateTime);
  889. surveyTemplates.add(tem);
  890. }
  891. } else {
  892. for (Map<String, Object> label : labels) {
  893. // if ("SURVEY_LABEL".equals(label.get("dict_name").toString())) {
  894. surveyTemplates = surveyLabelInfoDao.findByLabel(Integer.parseInt(label.get("code").toString()));
  895. // }
  896. }
  897. }
  898. List list = new ArrayList();
  899. for (SurveyTemplates template : surveyTemplates) {
  900. Map<String, Object> map = new HashMap<>();
  901. String tempCode = template.getCode();
  902. String title = template.getTitle();
  903. String comment = template.getTemplateComment();
  904. Date createTime = template.getCreateTime();
  905. int[] label = surveyLabelInfoDao.findByRelationCode(tempCode);
  906. String[] tags = new String[label.length];
  907. for (int i = 0; i < label.length; i++) {
  908. switch (label[i]) {
  909. case 1:
  910. tags[i] = "满意度";
  911. break;
  912. case 2:
  913. tags[i] = "糖尿病";
  914. break;
  915. case 3:
  916. tags[i] = "高血压";
  917. break;
  918. case 4:
  919. tags[i] = "生活日常";
  920. break;
  921. }
  922. }
  923. map.put("tempCode", tempCode);
  924. map.put("title", title);
  925. map.put("createTime", sdf.format(createTime));
  926. map.put("label", tags);
  927. map.put("comment", comment);
  928. list.add(map);
  929. }
  930. return list;
  931. }
  932. public List getTemplateByLabel(int pageNo, int pageSize, String labels) throws Exception {
  933. if (StringUtils.isEmpty(labels)) {
  934. Sort sort = new Sort(Sort.Direction.DESC, "createTime");
  935. PageRequest request = new PageRequest(pageNo - 1, pageSize, sort);
  936. List<SurveyTemplates> templates = surveyTemplatesDao.findAlls(request);
  937. List list = new ArrayList();
  938. for (SurveyTemplates template : templates) {
  939. Map<String, Object> tempMap = new HashMap();
  940. String title = template.getTitle();
  941. String templateId = template.getCode();
  942. String comment = template.getTemplateComment();
  943. int[] label = surveyLabelInfoDao.findByRelationCode(templateId);
  944. String[] tags = new String[label.length];
  945. for (int i = 0; i < label.length; i++) {
  946. switch (label[i]) {
  947. case 1:
  948. tags[i] = "满意度";
  949. break;
  950. case 2:
  951. tags[i] = "糖尿病";
  952. break;
  953. case 3:
  954. tags[i] = "高血压";
  955. break;
  956. case 4:
  957. tags[i] = "生活日常";
  958. break;
  959. }
  960. }
  961. tempMap.put("templateId", templateId);
  962. tempMap.put("title", title);
  963. if (comment.length() > 50) {
  964. comment = comment.substring(0, 49);
  965. }
  966. tempMap.put("comment", comment);
  967. tempMap.put("label", tags);
  968. list.add(tempMap);
  969. }
  970. return list;
  971. } else {
  972. List list = new ArrayList();
  973. pageNo -= 1;
  974. String sql = "SELECT DISTINCT t.* " +
  975. " FROM wlyy_survey_templates t,wlyy_survey_label_info s " +
  976. " WHERE t.code = s.relation_code " +
  977. " AND s.use_type= 0 " +
  978. " AND t.del = 1 " +
  979. " AND s.label IN (" + labels +
  980. ") " +
  981. " ORDER by t.create_time DESC " +
  982. " limit " + pageNo +
  983. "," + pageSize;
  984. List<Map<String, Object>> listMap = jdbcTemplate.queryForList(sql);
  985. for (Map<String, Object> template : listMap) {
  986. Map<String, Object> map = new HashMap();
  987. String code = template.get("code").toString();
  988. String title = template.get("title").toString();
  989. String comment = template.get("template_comment").toString();
  990. if (comment.length() > 50) {
  991. comment = comment.substring(0, 49);
  992. }
  993. // 查询标签
  994. int[] label = surveyLabelInfoDao.findByRelationCode(code);
  995. String[] tags = new String[label.length];
  996. for (int i = 0; i < label.length; i++) {
  997. switch (label[i]) {
  998. case 1:
  999. tags[i] = "满意度";
  1000. break;
  1001. case 2:
  1002. tags[i] = "糖尿病";
  1003. break;
  1004. case 3:
  1005. tags[i] = "高血压";
  1006. break;
  1007. case 4:
  1008. tags[i] = "生活日常";
  1009. break;
  1010. }
  1011. }
  1012. map.put("title", title);
  1013. map.put("templateId", code);
  1014. map.put("comment", comment);
  1015. map.put("label", tags);
  1016. list.add(map);
  1017. }
  1018. return list;
  1019. }
  1020. }
  1021. public Map<String, Object> getTemplateById(String code) throws Exception {
  1022. Map<String, Object> tempMap = new HashMap();
  1023. SurveyTemplates template = surveyTemplatesDao.findById(code);
  1024. String title = template.getTitle();
  1025. String comment = template.getTemplateComment();
  1026. int[] label = surveyLabelInfoDao.findByRelationCode(code);
  1027. String[] labels = new String[label.length];
  1028. for (int i = 0; i < label.length; i++) {
  1029. switch (label[i]) {
  1030. case 1:
  1031. labels[i] = "满意度";
  1032. break;
  1033. case 2:
  1034. labels[i] = "糖尿病";
  1035. break;
  1036. case 3:
  1037. labels[i] = "高血压";
  1038. break;
  1039. case 4:
  1040. labels[i] = "生活日常";
  1041. break;
  1042. }
  1043. }
  1044. tempMap.put("templateId", code);
  1045. tempMap.put("title", title);
  1046. tempMap.put("comment", comment);
  1047. tempMap.put("label", labels);
  1048. return tempMap;
  1049. }
  1050. public JSONObject getTemplateDetail(String id) throws Exception {
  1051. JSONObject jsonObject = new JSONObject();
  1052. //问卷信息
  1053. SurveyTemplates template = surveyTemplatesDao.findById(id);
  1054. int[] label = surveyLabelInfoDao.findByRelationCode(id);
  1055. String[] labels = new String[label.length];
  1056. for (int i = 0; i < label.length; i++) {
  1057. switch (label[i]) {
  1058. case 1:
  1059. labels[i] = "满意度";
  1060. break;
  1061. case 2:
  1062. labels[i] = "糖尿病";
  1063. break;
  1064. case 3:
  1065. labels[i] = "高血压";
  1066. break;
  1067. case 4:
  1068. labels[i] = "生活日常";
  1069. break;
  1070. }
  1071. }
  1072. //问题信息
  1073. List<SurveyTemplateQuestions> surveyQuestionnair = surveyTemplateQuestionsDao.findById(id);
  1074. List questions = new ArrayList();
  1075. // 问题信息
  1076. for (SurveyTemplateQuestions questionnair : surveyQuestionnair) {
  1077. Map<String, Object> question = new HashMap<>();
  1078. String qstcode = questionnair.getCode();
  1079. String title = questionnair.getTitle();
  1080. int isRequired = questionnair.getIsRequired();
  1081. int sort = questionnair.getSort();
  1082. String comment = questionnair.getQuestionComment();
  1083. int type = questionnair.getQuestionType();
  1084. List<SurveyTemplateOptions> options = surveyTemplateOptionsDao.findById(qstcode, id);
  1085. List optList = new ArrayList();
  1086. for (SurveyTemplateOptions option : options) {
  1087. Map<String, Object> opt = new HashMap<>();
  1088. String conetent = option.getContent();
  1089. int haveComment = option.getHaveComment();
  1090. int required = option.getIsRequired();
  1091. int optsort = option.getSort();
  1092. if (!StringUtils.isEmpty(option.getQuestionCodeNext())) {
  1093. String next = option.getQuestionCodeNext();
  1094. SurveyTemplateQuestions tempQst = surveyTemplateQuestionsDao.findById(id, next);
  1095. // 跳题结束怎么办?
  1096. opt.put("nextQuestion", tempQst == null ? 0 : tempQst.getSort());
  1097. }
  1098. opt.put("isRequired", required);
  1099. opt.put("content", conetent);
  1100. opt.put("sort", optsort);
  1101. opt.put("haveComment", haveComment);
  1102. optList.add(opt);
  1103. }
  1104. question.put("title", title);
  1105. question.put("isRequired", isRequired);
  1106. question.put("comment", comment);
  1107. question.put("type", type);
  1108. question.put("options", optList);
  1109. question.put("sort", sort);
  1110. question.put("maxNum", questionnair.getMaxNum());
  1111. question.put("minNum", questionnair.getMinNum());
  1112. if (!StringUtils.isEmpty(questionnair.getQuestionCodeNext())) {
  1113. String next = questionnair.getQuestionCodeNext();
  1114. SurveyTemplateQuestions tempQst = surveyTemplateQuestionsDao.findById(id, next);
  1115. question.put("nextQuestion", tempQst == null ? 0 : tempQst.getSort());
  1116. }
  1117. questions.add(question);
  1118. }
  1119. String tempComment = template.getTemplateComment();
  1120. String tempTitle = template.getTitle();
  1121. jsonObject.put("title", tempTitle);
  1122. jsonObject.put("comment", tempComment);
  1123. jsonObject.put("label", labels);
  1124. jsonObject.put("questions", questions);
  1125. System.out.println("==========jsonObject============" + jsonObject);
  1126. return jsonObject;
  1127. }
  1128. public int savaSurveyAsTemplate(String code, String modifyTitle) throws Exception {
  1129. Survey survey = surveyDao.findById(code);
  1130. String tempCode = getCode();
  1131. String title = survey.getTitle();
  1132. String templateComment = survey.getSurveyComment();
  1133. String creater = survey.getCreater();
  1134. Date createTime = survey.getCreateTime();
  1135. Date updateTime = survey.getUpdateTime();
  1136. // 查询问卷标题重复情况
  1137. int number = 0;
  1138. if (StringUtils.isEmpty(modifyTitle)) {
  1139. number = surveyTemplatesDao.distinctByTitle(title);
  1140. } else {
  1141. number = surveyTemplatesDao.distinctByTitle(modifyTitle);
  1142. title = modifyTitle;
  1143. }
  1144. if (number != 0 && StringUtils.isEmpty(modifyTitle)) {
  1145. int likeNum = surveyTemplatesDao.distinctLikeTitle(title + "%");
  1146. return likeNum;
  1147. }
  1148. if (number != 0 && !StringUtils.isEmpty(modifyTitle)) {
  1149. int likeNum = surveyTemplatesDao.distinctLikeTitle(modifyTitle + "%");
  1150. return likeNum;
  1151. }
  1152. SurveyTemplates surveyTemplates = new SurveyTemplates(tempCode, title, templateComment, creater, 1, createTime, updateTime);
  1153. // 保存模板信息
  1154. surveyTemplatesDao.save(surveyTemplates);
  1155. List<SurveyLabelInfo> surveyLabelInfos = surveyLabelInfoDao.findByCode(code);
  1156. for (SurveyLabelInfo surveyLabelInfo : surveyLabelInfos) {
  1157. // 保存模板标签信息
  1158. SurveyLabelInfo surveyLabelInfo1 = new SurveyLabelInfo(getCode(), tempCode, 0, surveyLabelInfo.getLabel());
  1159. surveyLabelInfoDao.save(surveyLabelInfo1);
  1160. }
  1161. List<SurveyQuestionnaire> surveyQuestionnaires = surveyQuestionnaireDao.findById(survey.getCode());
  1162. for (SurveyQuestionnaire question : surveyQuestionnaires) {
  1163. String qstCode = getCode();
  1164. String qstTitle = question.getTitle();
  1165. String qstComment = question.getQuestionComment();
  1166. Integer qstType = question.getQuestionType();
  1167. Integer isRequired = question.getIsRequired();
  1168. Integer minNum = question.getMinNum();
  1169. Integer maxNum = question.getMaxNum();
  1170. Date createTiem = question.getCreateTime();
  1171. Date updateTiem = question.getUpdateTime();
  1172. Integer sort = question.getSort();
  1173. Integer de = question.getDel();
  1174. String next = question.getQuestionCodeNext();
  1175. SurveyTemplateQuestions surveyTemplateQuestions = new SurveyTemplateQuestions(qstCode, qstTitle, qstComment, qstType, tempCode, isRequired, minNum, maxNum, sort, next, null, de, createTiem, updateTiem);
  1176. // 保存问题到模板问题表
  1177. surveyTemplateQuestionsDao.save(surveyTemplateQuestions);
  1178. if (qstType != 2) {
  1179. List<SurveyQuestionnaireOptions> surveyQuestionnaireOptions = surveyQuestionnaireOptionsDao.findByIdAndQstCode(code, question.getCode());
  1180. for (SurveyQuestionnaireOptions option : surveyQuestionnaireOptions) {
  1181. SurveyTemplateOptions surveyTemplateOptions = new SurveyTemplateOptions(getCode(), option.getHaveComment(), qstCode, option.getContent(),
  1182. tempCode, option.getQuestionCodeNext(), null, option.getIsRequired(), option.getSort(), option.getDel());
  1183. // 保存到模板选项表 survey_template_options
  1184. surveyTemplateOptionsDao.save(surveyTemplateOptions);
  1185. }
  1186. }
  1187. }
  1188. return 0;
  1189. }
  1190. public int modifyTemplate(String code, String templateCode, String modifyTitle) throws Exception {
  1191. Survey survey = surveyDao.findById(code);
  1192. String title = survey.getTitle();
  1193. String templateComment = survey.getSurveyComment();
  1194. // 查询问卷标题重复情况
  1195. int number = 0;
  1196. if (StringUtils.isEmpty(modifyTitle)) {
  1197. number = surveyTemplatesDao.distinctByTitle(title);
  1198. } else {
  1199. number = surveyTemplatesDao.distinctByTitle(modifyTitle);
  1200. title = modifyTitle;
  1201. }
  1202. if (number != 0 && StringUtils.isEmpty(modifyTitle)) {
  1203. int likeNum = surveyTemplatesDao.distinctLikeTitle(title + "%");
  1204. return likeNum;
  1205. }
  1206. if (number != 0 && !StringUtils.isEmpty(modifyTitle)) {
  1207. int likeNum = surveyTemplatesDao.distinctLikeTitle(modifyTitle + "%");
  1208. return likeNum;
  1209. }
  1210. // SurveyTemplates surveyTemplates = new SurveyTemplates(templateCode, title, templateComment, creater, 1, creater, updateTime);
  1211. // 更改模板信息
  1212. // surveyTemplatesDao.save(surveyTemplates);
  1213. surveyTemplatesDao.modifyTemplate(templateCode, title, templateComment);
  1214. List<SurveyLabelInfo> surveyLabelInfos = surveyLabelInfoDao.findByCode(code);
  1215. for (SurveyLabelInfo surveyLabelInfo : surveyLabelInfos) {
  1216. // 更改模板标签信息
  1217. // SurveyLabelInfo surveyLabelInfo1 = new SurveyLabelInfo(getCode(), templateCode, 0, surveyLabelInfo.getLabel());
  1218. // surveyLabelInfoDao.save(surveyLabelInfo1);
  1219. surveyLabelInfoDao.modifyLabel(templateCode, surveyLabelInfo.getLabel());
  1220. }
  1221. List<SurveyQuestionnaire> surveyQuestionnaires = surveyQuestionnaireDao.findById(survey.getCode());
  1222. for (SurveyQuestionnaire question : surveyQuestionnaires) {
  1223. String qstCode = getCode();
  1224. String qstTitle = question.getTitle();
  1225. String qstComment = question.getQuestionComment();
  1226. Integer qstType = question.getQuestionType();
  1227. Integer isRequired = question.getIsRequired();
  1228. Integer minNum = question.getMinNum();
  1229. Integer maxNum = question.getMaxNum();
  1230. // Date createTiem = question.getCreateTime();
  1231. // Date updateTiem = question.getUpdateTime();
  1232. Integer sort = question.getSort();
  1233. // Integer de = question.getDel();
  1234. String next = question.getQuestionCodeNext();
  1235. // SurveyTemplateQuestions surveyTemplateQuestions = new SurveyTemplateQuestions(qstCode, qstTitle, qstComment, qstType, templateCode, isRequired, minNum, maxNum, sort, next, null, de, createTiem, updateTiem);
  1236. // 更改问题到模板问题表
  1237. // surveyTemplateQuestionsDao.save(surveyTemplateQuestions);
  1238. surveyTemplateQuestionsDao.modifyQuestion(templateCode, qstCode, qstTitle, qstComment, qstType, isRequired, minNum, maxNum, sort, next);
  1239. if (qstType != 2) {
  1240. List<SurveyQuestionnaireOptions> surveyQuestionnaireOptions = surveyQuestionnaireOptionsDao.findByIdAndQstCode(code, question.getCode());
  1241. for (SurveyQuestionnaireOptions option : surveyQuestionnaireOptions) {
  1242. SurveyTemplateOptions surveyTemplateOptions = new SurveyTemplateOptions(getCode(), option.getHaveComment(), qstCode, option.getContent(),
  1243. templateCode, option.getQuestionCodeNext(), null, option.getIsRequired(), option.getSort(), option.getDel());
  1244. // 更改到模板选项表 survey_template_options
  1245. // surveyTemplateOptionsDao.save(surveyTemplateOptions);
  1246. surveyTemplateOptionsDao.modifyOption(templateCode, qstCode, option.getCode(),
  1247. option.getHaveComment(), option.getContent(), option.getQuestionCodeNext(), option.getIsRequired(), option.getSort());
  1248. }
  1249. }
  1250. }
  1251. return 0;
  1252. }
  1253. public Map getFilter() {
  1254. JSONObject jsonObject = new JSONObject();
  1255. // List lis = new ArrayList();
  1256. Iterable<SurveyDimension> surveyDimension = surveyDimensionDao.findAll();
  1257. Map<String, Object> map = new HashMap<>();
  1258. for (SurveyDimension dimension : surveyDimension) {
  1259. // Map<String, Object> map = new HashMap<>();
  1260. String name = dimension.getName();
  1261. int value = dimension.getValue();
  1262. switch (value) {
  1263. case 1:
  1264. name = "sex";
  1265. break;
  1266. case 2:
  1267. name = "disease";
  1268. break;
  1269. case 3:
  1270. name = "service";
  1271. break;
  1272. case 4:
  1273. name = "healthCondition";
  1274. break;
  1275. }
  1276. String sql = "SELECT t.value,t.`name` " +
  1277. " FROM wlyy_survey_dimension_option t\n" +
  1278. " WHERE t.`dimension_value`= " + value;
  1279. List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
  1280. List subLabel = new ArrayList();
  1281. for (Map<String, Object> li : list) {
  1282. Map<String, Object> map1 = new HashMap<>();
  1283. int var = Integer.parseInt(li.get("value").toString());
  1284. String nm = li.get("name").toString();
  1285. map1.put("key", var);
  1286. map1.put("value", nm);
  1287. subLabel.add(map1);
  1288. }
  1289. map.put(name, subLabel);
  1290. // lis.add(map);
  1291. }
  1292. return map;
  1293. }
  1294. public int getAmount(String json) {
  1295. return getCount(json).size();
  1296. }
  1297. public List<String> getCount(String json) {
  1298. // 1.服务 2.健康 3疾病
  1299. JSONObject jsonObject = new JSONObject(json);
  1300. String sex = jsonObject.get("sex").toString();
  1301. String str = "SELECT s.patient FROM ( " +
  1302. "SELECT t.patient,GROUP_CONCAT(t.label_name) label_name FROM wlyy_sign_patient_label_info t " +
  1303. "WHERE t.patient IN (SELECT a.patient FROM wlyy_sign_family a WHERE a.status IN(1,2,3)) AND t.patient IN (SELECT b.`code` FROM wlyy_patient b WHERE b.`openid` IS NOT NULL AND b.`openid`!='' ";
  1304. if (!"0".equals(sex)) {
  1305. str += " AND b.sex= " + sex + " ) GROUP BY t.patient ) s WHERE 1=1 ";
  1306. } else {
  1307. str += " ) GROUP BY t.patient ) s WHERE 1=1 ";
  1308. }
  1309. JSONArray service = jsonObject.getJSONArray("service");
  1310. String ser = "";
  1311. service:
  1312. for (Object serv : service) {
  1313. String type = serv.toString();
  1314. switch (type) {
  1315. // AND (s.label_name LIKE '%普通人群%'OR s.label_name LIKE '%慢病人群%'OR s.label_name LIKE '%65岁以上人群%')
  1316. case "0":
  1317. break service;
  1318. case "1":
  1319. ser += " s.label_name LIKE '%普通人群%' ";
  1320. break;
  1321. case "2":
  1322. ser += " s.label_name LIKE '%慢病人群%' ";
  1323. break;
  1324. case "3":
  1325. ser += " s.label_name LIKE '%65岁以上人群%' ";
  1326. break;
  1327. }
  1328. ser += " OR ";
  1329. }
  1330. if (!StringUtils.isEmpty(ser)) {
  1331. str += " AND ( " + ser.substring(0, ser.lastIndexOf("OR")) + " ) ";
  1332. }
  1333. JSONArray healthCondition = jsonObject.getJSONArray("healthCondition");
  1334. String heal = "";
  1335. health:
  1336. for (Object health : healthCondition) {
  1337. String type = health.toString();
  1338. switch (type) {
  1339. // AND (s.label_name LIKE '%普通人群%'OR s.label_name LIKE '%慢病人群%'OR s.label_name LIKE '%65岁以上人群%')
  1340. case "0":
  1341. break health;
  1342. case "1":
  1343. heal += " s.label_name LIKE '%健康人群%' ";
  1344. break;
  1345. case "2":
  1346. heal += " s.label_name LIKE '%患病人群%' ";
  1347. break;
  1348. case "3":
  1349. heal += " s.label_name LIKE '%高危人群%' ";
  1350. break;
  1351. case "4":
  1352. heal += " s.label_name LIKE '%恢复期人群%' ";
  1353. break;
  1354. }
  1355. heal += " OR ";
  1356. }
  1357. if (!StringUtils.isEmpty(heal)) {
  1358. str += " AND ( " + heal.substring(0, heal.lastIndexOf("OR")) + " ) ";
  1359. }
  1360. JSONArray disease = jsonObject.getJSONArray("disease");
  1361. String dis = "";
  1362. disea:
  1363. for (Object disea : disease) {
  1364. String type = disea.toString();
  1365. switch (type) {
  1366. // AND (s.label_name LIKE '%普通人群%'OR s.label_name LIKE '%慢病人群%'OR s.label_name LIKE '%65岁以上人群%')
  1367. case "0":
  1368. break disea;
  1369. case "1":
  1370. dis += " s.label_name LIKE '%高血压%' ";
  1371. break;
  1372. case "2":
  1373. dis += " s.label_name LIKE '%糖尿病%' ";
  1374. break;
  1375. }
  1376. dis += " OR ";
  1377. }
  1378. if (!StringUtils.isEmpty(dis)) {
  1379. str += " AND ( " + dis.substring(0, dis.lastIndexOf("OR")) + " ) ";
  1380. }
  1381. /* if (Integer.parseInt(sex) != 0) {
  1382. str += "and t.sex = " + sex;
  1383. }
  1384. JSONArray service = jsonObject.getJSONArray("service");
  1385. String ser = "";
  1386. String servi = "";
  1387. for (Object serv : service) {
  1388. if ("0".equals(serv.toString())) {
  1389. ser += ",";
  1390. break;
  1391. } else {
  1392. ser += serv.toString() + ",";
  1393. }
  1394. }
  1395. ser = ser.substring(0, ser.length() - 1);
  1396. if (ser.length() != 0) {
  1397. servi = "(t.`label_type`=1 AND t.`label`IN(" + ser + "))";
  1398. }
  1399. JSONArray healthCondition = jsonObject.getJSONArray("healthCondition");
  1400. String heal = "";
  1401. String healt = "";
  1402. for (Object health : healthCondition) {
  1403. if ("0".equals(health.toString())) {
  1404. heal += ",";
  1405. break;
  1406. } else {
  1407. heal += health.toString() + ",";
  1408. }
  1409. }
  1410. heal = heal.substring(0, heal.length() - 1);
  1411. if (heal.length() != 0) {
  1412. healt = "(t.`label_type`=2 AND t.`label`IN(" + heal + "))";
  1413. }
  1414. JSONArray disease = jsonObject.getJSONArray("disease");
  1415. String dise = "";
  1416. String diseas = "";
  1417. for (Object disea : disease) {
  1418. if ("0".equals(disea.toString())) {
  1419. dise += ",";
  1420. break;
  1421. } else {
  1422. dise += disea.toString() + ",";
  1423. }
  1424. }
  1425. dise = dise.substring(0, dise.length() - 1);
  1426. if (dise.length() != 0) {
  1427. diseas = "(t.`label_type`=3 AND t.`label`IN(" + dise + "))";
  1428. }
  1429. if (servi.length() != 0 & healt.length() != 0 & diseas.length() != 0) {
  1430. str += "AND ( " + servi + "OR" + healt + "OR" + diseas + " )";
  1431. } else if (servi.length() != 0 & healt.length() != 0 & diseas.length() == 0) {
  1432. str += "AND ( " + servi + "OR" + healt + " )";
  1433. } else if (servi.length() != 0 & healt.length() == 0 & diseas.length() != 0) {
  1434. str += "AND ( " + servi + "OR" + diseas + " )";
  1435. } else if (servi.length() == 0 & healt.length() != 0 & diseas.length() != 0) {
  1436. str += "AND ( " + healt + "OR" + diseas + " )";
  1437. } else if (servi.length() != 0 & healt.length() == 0 & diseas.length() == 0) {
  1438. str += "AND " + servi;
  1439. } else if (servi.length() == 0 & healt.length() != 0 & diseas.length() == 0) {
  1440. str += "AND " + healt;
  1441. } else if (servi.length() == 0 & healt.length() == 0 & diseas.length() != 0) {
  1442. str += "AND " + diseas;
  1443. }*/
  1444. // Map<String, Object> patients = jdbcTemplate.queryForMap(str);
  1445. System.out.println("=====query sql =======>>>>" + str);
  1446. List<String> patients = jdbcTemplate.queryForList(str, String.class);
  1447. return patients;
  1448. }
  1449. }