123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527 |
- package com.yihu.wlyy.service.survey;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.yihu.wlyy.entity.dict.SystemDict;
- 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.wechat.WechatTemplate;
- import com.yihu.wlyy.entity.wechat.WechatTemplateData;
- import com.yihu.wlyy.repository.dict.SystemDictDao;
- import com.yihu.wlyy.repository.doctor.*;
- import com.yihu.wlyy.repository.patient.PatientDao;
- import com.yihu.wlyy.service.BaseService;
- import com.yihu.wlyy.service.system.SystemDictService;
- import com.yihu.wlyy.task.PushMsgTask;
- import com.yihu.wlyy.util.HttpUtil;
- import com.yihu.wlyy.util.SystemConf;
- import com.yihu.wlyy.web.doctor.survey.ManagerQuestionnaireController;
- import com.yihu.wlyy.wechat.util.WeiXinTempMsgSendUtils;
- import io.swagger.models.auth.In;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.poi.util.StringUtil;
- import org.bouncycastle.jce.provider.symmetric.HC128;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.domain.Page;
- import org.springframework.data.domain.PageRequest;
- import org.springframework.data.domain.Pageable;
- import org.springframework.data.domain.Sort;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * Created by Reece on 2017/3/9.
- */
- @Service
- @Transactional
- public class ManagerQuestionnaireService extends BaseService {
- @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 SurveyTemplateQuestionsDao surveyTemplateQuestionsDao;
- @Autowired
- private SurveyOptionAnswersDao surveyOptionAnswersDao;
- @Autowired
- private SurveyAnswersDao surveyAnswersDao;
- @Autowired
- private SurveyTemplatesDao surveyTemplatesDao;
- @Autowired
- private SurveyStatisticsDao surveyStatisticsDao;
- @Autowired
- private JdbcTemplate jdbcTemplate;
- @Autowired
- private SystemDictDao systemDictDao;
- @Autowired
- private SurveyDimensionDao surveyDimensionDao;
- @Autowired
- private SurveyDimensionDetailDao surveyDimensionDetailDao;
- @Autowired
- private DoctorDao doctorDao;
- @Autowired
- private PatientDao patientDao;
- public String createSurvey(String doctor, JSONObject jsonStr, String accessToken) throws Exception {
- System.out.println("=============>" + jsonStr);
- // 问卷信息
- String surveyCode = getCode();
- String surveyName = jsonStr.getString("surveyName");
- String surveyComment = jsonStr.getString("comment");
- String templateCode = null;
- String send = jsonStr.get("send").toString();
- 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 disease = surveyTarget.getJSONArray("disease");
- JSONArray service = surveyTarget.getJSONArray("service");
- JSONArray healthCondition = surveyTarget.getJSONArray("healthCondition");
- /*String str = "SELECT DISTINCT t.patient " +
- "FROM `wlyy_sign_patient_label_info` t,wlyy_patient p,`wlyy_sign_family` f " +
- "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`!='' ";*/
- // 保存到维度详情表(不限不保存) 维度表(1性别 2疾病类型 3服务类型 4健康状况)
- if (sex != 0) {
- // str += "AND(p.sex=" + sex + ")";
- String dimensionCode = surveyDimensionDao.findByName("性别");
- String dimensionDetailCode = getCode();
- SurveyDimensionDetail surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, sex == 1 ? "男" : "女", sex, "性别", 1, surveyCode);
- surveyDimensionDetailDao.save(surveyDimensionDetail);
- // 保存到筛选表
- SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
- surveyFilterDao.save(surveyFilter);
- }
- // String ser = "";
- // String servi = "";
- for (Object serv : service) {
- if ("0".equals(serv.toString())) {
- // ser += ",";
- break;
- } else {
- // ser += serv.toString() + ",";
- // ===================================
- String dimensionCode = surveyDimensionDao.findByName("服务类型");
- String dimensionDetailCode = getCode();
- SurveyDimensionDetail surveyDimensionDetail = null;
- 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);
- }
- }
- /*ser = ser.substring(0, ser.length() - 1);
- if (ser.length() != 0) {
- servi = "(t.`label_type`=1 AND t.`label`IN(" + ser + "))";
- }*/
- // String heal = "";
- // String healt = "";
- for (Object health : healthCondition) {
- if ("0".equals(health.toString())) {
- // heal += ",";
- break;
- } else {
- // heal += health.toString() + ",";
- String dimensionCode = surveyDimensionDao.findByName("健康状况");
- String dimensionDetailCode = getCode();
- String surveyFilterCode = getCode();
- SurveyDimensionDetail surveyDimensionDetail = null;
- 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);
- }
- }
- /* heal = heal.substring(0, heal.length() - 1);
- if (heal.length() != 0) {
- healt = "(t.`label_type`=2 AND t.`label`IN(" + heal + "))";
- }*/
- // String dise = "";
- // String diseas = "";
- for (Object disea : disease) {
- if ("0".equals(disea.toString())) {
- // dise += ",";
- break;
- } else {
- // dise += disea.toString() + ",";
- // ================================================================
- String dimensionCode = surveyDimensionDao.findByName("疾病类型");
- String dimensionDetailCode = getCode();
- SurveyDimensionDetail surveyDimensionDetail = null;
- 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);
- }
- }
- /*dise = dise.substring(0, dise.length() - 1);
- if (dise.length() != 0) {
- diseas = "(t.`label_type`=3 AND t.`label`IN(" + dise + "))";
- }
- if (servi.length() != 0 & healt.length() != 0 & diseas.length() != 0) {
- str += " AND ( " + servi + " OR " + healt + " OR " + diseas + " )";
- } else if (servi.length() != 0 & healt.length() != 0 & diseas.length() == 0) {
- str += " AND ( " + servi + " OR " + healt + " )";
- } else if (servi.length() != 0 & healt.length() == 0 & diseas.length() != 0) {
- str += " AND ( " + servi + " OR " + diseas + " )";
- } else if (servi.length() == 0 & healt.length() != 0 & diseas.length() != 0) {
- str += " AND ( " + healt + " OR " + diseas + " )";
- } else if (servi.length() != 0 & healt.length() == 0 & diseas.length() == 0) {
- str += " AND " + servi;
- } else if (servi.length() == 0 & healt.length() != 0 & diseas.length() == 0) {
- str += " AND " + healt;
- } else if (servi.length() == 0 & healt.length() == 0 & diseas.length() != 0) {
- str += " AND " + diseas;
- }*/
- /* System.out.println("*****************str***********************" + str);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- sdf.format(new Date());
- String jsonData = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
- JSONObject json = new JSONObject(jsonData);
- json.put("survey_id", surveyCode);*/
- // List<Map<String, Object>> patients = jdbcTemplate.queryForList(str);
- // Map<String, Object> map = jdbcTemplate.queryForMap(str);
- // List<String> codes = jdbcTemplate.queryForList(str, String.class);
- List<String> codes = getCount(surveyTarget.toString());
- 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)) {
- String name = patient.get("name").toString();
- String openId = patient.get("openid").toString();
- // String openId = "o7NFZw1QM4YR1O19mLjwfX1Hh11A";
- json.put("keyword2", sdf.format(new Date()));
- json.put("toUser", code);
- json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
- System.out.println("*************************" + json + "******************");
- System.out.println("********name*********************" + name + "openId" + openId);
- PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
- }*/
- }
- // 发送居民模板 send=1发送
- // ====================================================
- if ("1".equals(send)) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
- JSONObject json = new JSONObject(str);
- codes.stream().forEach(c -> {
- Patient p = patientDao.findByCode(c);
- String name = p.getName();
- String openId = p.getOpenid();
- json.put("keyword2", sdf.format(new Date()));
- json.put("toUser", c);
- json.put("survey_id",surveyCode );
- json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
- PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
- });
- }
- // =====================================================
- // 获取标签数组
- 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;
- 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);
- System.out.println("=====================================");
- // =======================选项保存=========================
- // 选择题
- JSONArray options = new JSONArray(tempQestion.get("options").toString());
- for (Object option : options) {
- String optionCode = getCode();
- JSONObject tempOption = new JSONObject(option.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());
- 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"));
- }
- // 自主创建,插入表
- 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;
- }
- public JSONArray getQuestionnaireList(int pageNo, int pageSize) throws Exception {
- JSONArray jsonArray = new JSONArray();
- // 排序
- Sort sort = new Sort(Sort.Direction.DESC, "createTime");
- PageRequest pageRequest = new PageRequest(pageNo - 1, pageSize, sort);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Page<Survey> surveys = surveyDao.findAll(pageRequest);
- List<Survey> arrays = surveys.getContent();
- for (Survey arr : arrays) {
- Map<String, Object> sur = new HashMap<>();
- String code = arr.getCode();
- String title = arr.getTitle();
- String doctor = arr.getCreater();
- String comment = arr.getSurveyComment();
- String createTime = sdf.format(arr.getCreateTime());
- // String updateTime = sdf.format(arr.getUpdateTime());
- // 查询医生信息
- Doctor doc = doctorDao.findByCode(doctor);
- String name = doc.getName();
- String photo = doc.getPhoto();
- String dept = doc.getDeptName();
- int amount = arr.getAmount();
- //查询居民回答的反馈率
- int complete = surveyUserDao.findBySurveyCode(code);
- sur.put("code", code);
- sur.put("name", name);
- sur.put("photo", photo);
- sur.put("deptName", dept);
- sur.put("percent", (Math.round(((float) complete / amount) * 100)) + "%");
- sur.put("title", title);
- sur.put("comment", comment);
- sur.put("createTime", createTime);
- // sur.put("updateTime", updateTime);
- sur.put("complete", complete);
- sur.put("amount", amount);
- jsonArray.put(sur);
- }
- return jsonArray;
- }
- public JSONObject getQuestionnaireSummary(String id) throws Exception {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Survey survey = surveyDao.findById(id);
- String creater = survey.getCreater();
- Date createTime = survey.getCreateTime();
- int amount = survey.getAmount();
- String comment = survey.getSurveyComment();
- String title = survey.getTitle();
- int status = survey.getStatus();
- List<String> targets = surveyDimensionDetailDao.findByCode(id);
- Map<String, Object> surveyTarget = new HashMap<>();
- for (String target : targets) {
- List<String> labels = surveyDimensionDetailDao.findByCode(id, target);
- List tags = new ArrayList();
- for (String label : labels) {
- tags.add(label);
- }
- switch (target) {
- case "疾病类型":
- target = "disease";
- break;
- case "服务类型":
- target = "service";
- break;
- case "健康状况":
- target = "healthCondition";
- break;
- case "性别":
- target = "sex";
- break;
- }
- surveyTarget.put(target, tags);
- }
- int[] label = surveyLabelInfoDao.findByRelationCode(id);
- String[] labels = new String[label.length];
- for (int i = 0; i < label.length; i++) {
- switch (label[i]) {
- case 1:
- labels[i] = "满意度";
- break;
- case 2:
- labels[i] = "糖尿病";
- break;
- case 3:
- labels[i] = "高血压";
- break;
- case 4:
- labels[i] = "生活日常";
- break;
- }
- }
- // 查询该问卷回答人数
- // int complete = surveyUserDao.findBySurveyCode(id);
- int complete = surveyUserDao.findBySurveyCode(id);
- Map<String, Object> map = new HashMap<>();
- // 获取创建者信息
- Doctor doctor = doctorDao.findByCode(creater);
- String name = doctor.getName();
- String deptName = doctor.getDeptName();
- String photo = doctor.getPhoto();
- map.put("name", name);
- map.put("deptName", deptName);
- map.put("photo", photo);
- map.put("createTime", sdf.format(createTime));
- map.put("amount", amount);
- map.put("complete", complete);
- map.put("percent", (Math.round(((float) complete / amount) * 100)) + "%");
- map.put("comment", comment);
- map.put("title", title);
- map.put("status", status);
- map.put("label", labels);
- map.put("surveyTarget", surveyTarget);
- JSONObject jsonObject = new JSONObject(map);
- return jsonObject;
- }
- public JSONObject getQuestionnaireDetail(String id) throws Exception {
- JSONObject jsonObject = new JSONObject();
- //问卷信息
- Survey survey = surveyDao.findById(id);
- int[] label = surveyLabelInfoDao.findByRelationCode(id);
- String[] labels = new String[label.length];
- for (int i = 0; i < label.length; i++) {
- switch (label[i]) {
- case 1:
- labels[i] = "满意度";
- break;
- case 2:
- labels[i] = "糖尿病";
- break;
- case 3:
- labels[i] = "高血压";
- break;
- case 4:
- labels[i] = "生活日常";
- break;
- }
- }
- //问题信息
- List<SurveyQuestionnaire> surveyQuestionnair = surveyQuestionnaireDao.findById(id);
- List questions = new ArrayList();
- // 问题信息
- for (SurveyQuestionnaire questionnair : surveyQuestionnair) {
- Map<String, Object> question = new HashMap<>();
- String qstcode = questionnair.getCode();
- String title = questionnair.getTitle();
- int isRequired = questionnair.getIsRequired();
- int sort = questionnair.getSort();
- int type = questionnair.getQuestionType();
- if (questionnair.getMaxNum() != null) {
- int maxNum = questionnair.getMaxNum();
- question.put("maxNum", maxNum);
- }
- if (questionnair.getMinNum() != null) {
- int minNum = questionnair.getMinNum();
- question.put("minNum", minNum);
- }
- if (questionnair.getQuestionComment() != null) {
- String comment = questionnair.getQuestionComment();
- question.put("comment", comment);
- }
- if (questionnair.getQuestionCodeNext() != null) {
- String next = questionnair.getQuestionCodeNext();
- SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
- question.put("nextQuestion", sq == null ? 0 : sq.getSort());
- }
- // List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findById(qstcode);
- List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findByIdAndQstCode(id, qstcode);
- List optList = new ArrayList();
- for (SurveyQuestionnaireOptions option : options) {
- Map<String, Object> opt = new HashMap<>();
- String conetent = option.getContent();
- int haveComment = option.getHaveComment();
- int required = option.getIsRequired();
- int st = option.getSort();
- if (option.getQuestionCodeNext() != null) {
- String next = option.getQuestionCodeNext();
- SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
- System.out.println("=============qstcode============== " + qstcode);
- System.out.println("=============optCode============== " + option.getCode());
- System.out.println("=============sq============== " + sq);
- System.out.println("=============next============== " + next);
- opt.put("nextQuestion", sq == null ? 0 : sq.getSort());
- }
- opt.put("content", conetent);
- opt.put("sort", st);
- opt.put("haveComment", haveComment);
- opt.put("isRequired", required);
- optList.add(opt);
- }
- question.put("title", title);
- question.put("type", type);
- question.put("isRequired", isRequired);
- question.put("sort", sort);
- question.put("options", optList);
- questions.add(question);
- }
- String surveyComment = survey.getSurveyComment();
- String surveyTitle = survey.getTitle();
- jsonObject.put("title", surveyTitle);
- jsonObject.put("comment", surveyComment);
- jsonObject.put("questions", questions);
- jsonObject.put("label", labels);
- return jsonObject;
- }
- public int modifyQuestionnaireStatus(String id) throws Exception {
- Survey survey = surveyDao.findById(id);
- int status = survey.getStatus();
- if (status > 1) {
- status = 1;
- surveyDao.modifyStatus(status, id);
- } else {
- status = 2;
- surveyDao.modifyStatus(status, id);
- }
- return status;
- }
- public JSONObject getAnswers(String id) throws Exception {
- JSONObject jsonObject = new JSONObject();
- //一个问卷内的所有问题
- List<SurveyQuestionnaire> questions = surveyQuestionnaireDao.findById(id);
- if (questions.size() == 0) {
- return jsonObject;
- }
- List qstList = new ArrayList();
- for (SurveyQuestionnaire question : questions) {
- // 新造对象
- Map<String, Object> qst = new HashMap<>();
- String qstcode = question.getCode();
- String title = question.getTitle();
- int type = question.getQuestionType();
- // 有效答了该题的人数
- /*int amount = 0;
- int[] sum = surveyStatisticsDao.findByIdAndQstId(id, qstcode);
- for (int count : sum) {
- amount += count;
- }*/
- int amount = 0;
- if (type == 2) {
- // 问卷答案表有效(去重)答题人数
- amount = surveyAnswersDao.countByRelationCode(id, qstcode);
- } else {
- // 问卷选项答案表有效(去重)答题人数
- amount = surveyOptionAnswersDao.countByRelationCode(id, qstcode);
- }
- qst.put("amount", amount);
- qst.put("qstcode", qstcode);
- qst.put("title", title);
- qst.put("type", type);
- // 一个问题内的所有选项
- // List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findById(qstcode);
- List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findByIdAndQstCode(id, qstcode);
- List optList = new ArrayList();
- for (SurveyQuestionnaireOptions option : options) {
- Map<String, Object> opt = new HashMap<>();
- String optcode = option.getCode();
- String optTitle = option.getContent();
- int haveComment = option.getHaveComment();
- int count = surveyStatisticsDao.findByAllId(id, qstcode, optcode);
- opt.put("optcode", optcode);
- opt.put("option", optTitle);
- opt.put("count", count);
- opt.put("percent", (Math.round(((float) count / amount) * 100)) + "%");
- opt.put("haveComment", haveComment);
- optList.add(opt);
- }
- qst.put("options", optList);
- qstList.add(qst);
- }
- jsonObject.put("questions", qstList);
- return jsonObject;
- }
- public JSONObject getOptionsComment(String id, String questionId, String optionId, int pageNo, int pageSize) throws Exception {
- JSONObject jsonObject = new JSONObject();
- SurveyQuestionnaire question = surveyQuestionnaireDao.findByIdAndQstId(id, questionId);
- Sort sort = new Sort(Sort.Direction.ASC, "createTime");
- PageRequest request = new PageRequest(pageNo - 1, pageSize, sort);
- if (!StringUtils.isEmpty(optionId)) {
- // 查看选择题详细答案
- SurveyQuestionnaireOptions opt = surveyQuestionnaireOptionsDao.findByRelationCode(id, questionId, optionId);
- String option = opt.getContent();
- jsonObject.put("option", option);
- // 获取同一个选项的所有回答的说明(分页?)
- Page<String> optionComment = surveyOptionAnswersDao.findByRelationCode(id, questionId, optionId, request);
- jsonObject.put("content", optionComment.getContent());
- int amount = surveyOptionAnswersDao.findByRelationCode(id, questionId, optionId);
- jsonObject.put("amount", amount);
- } else {
- // 查看问答题答案(分页?)
- Page<String> answer = surveyAnswersDao.findByRelationCode(id, questionId, request);
- jsonObject.put("content", answer.getContent());
- int amount = surveyAnswersDao.findByRelationCode(id, questionId);
- jsonObject.put("amount", amount);
- }
- String title = question.getTitle();
- jsonObject.put("title", title);
- return jsonObject;
- }
- public List getTemplateList(int pageNo, int pageSize) throws Exception {
- Sort sort = new Sort(Sort.Direction.DESC, "createTime");
- PageRequest request = new PageRequest(pageNo - 1, pageSize, sort);
- List<SurveyTemplates> templates = surveyTemplatesDao.findAlls(request);
- List list = new ArrayList();
- for (SurveyTemplates template : templates) {
- Map<String, Object> tempMap = new HashMap();
- String title = template.getTitle();
- String templateId = template.getCode();
- String comment = template.getTemplateComment();
- int[] label = surveyLabelInfoDao.findByRelationCode(templateId);
- String[] labels = new String[label.length];
- for (int i = 0; i < label.length; i++) {
- switch (label[i]) {
- case 1:
- labels[i] = "满意度";
- break;
- case 2:
- labels[i] = "糖尿病";
- break;
- case 3:
- labels[i] = "高血压";
- break;
- case 4:
- labels[i] = "生活日常";
- break;
- }
- }
- tempMap.put("templateId", templateId);
- tempMap.put("title", title);
- if (comment.length() > 50) {
- comment = comment.substring(0, 49);
- }
- tempMap.put("comment", comment);
- tempMap.put("label", labels);
- list.add(tempMap);
- }
- return list;
- }
- public List getTemplateLabel() throws Exception {
- List list = new ArrayList();
- List<SystemDict> labels = systemDictDao.findByDictName("SURVEY_LABEL");
- for (SystemDict label : labels) {
- Map<String, Object> map = new HashMap();
- String code = label.getCode();
- String value = label.getValue();
- map.put("code", code);
- map.put("value", value);
- list.add(map);
- }
- return list;
- }
- public JSONObject getQuestionList(String title, int pageNo, int pageSize) throws Exception {
- JSONObject jsonObject = new JSONObject();
- Sort sort = new Sort(Sort.Direction.DESC, "createTime");
- PageRequest request = new PageRequest(pageNo - 1, pageSize, sort);
- List<SurveyQuestions> questions = new ArrayList<>();
- if (StringUtils.isEmpty(title)) {
- questions = surveyQuestionsDao.findByTitle(request);
- } else {
- questions = surveyQuestionsDao.findByTitle("%" + title + "%", request);
- }
- List list = new ArrayList();
- for (SurveyQuestions question : questions) {
- Map<String, Object> map = new HashMap<>();
- String code = question.getCode();
- String qstTitle = question.getTitle();
- if (question.getQuestionComment() != null) {
- String comment = question.getQuestionComment();
- map.put("comment", comment);
- }
- int isRequired = question.getIsRequired();
- int questionType = question.getQuestionType();
- if (questionType != 2) {
- // 获取选择题选项值
- List<SurveyQuestionsOptions> options = surveyQuestionsOptionsDao.findById(code);
- List opts = new ArrayList();
- for (SurveyQuestionsOptions option : options) {
- Map<String, Object> opt = new HashMap<>();
- opt.put("optCode", option.getCode());
- opt.put("content", option.getContent());
- opt.put("haveComment", option.getHaveComment());
- opt.put("isRequired", option.getIsRequired());
- opts.add(opt);
- }
- map.put("options", opts);
- }
- map.put("code", code);
- map.put("title", qstTitle);
- map.put("isRequired", isRequired);
- map.put("questionType", questionType);
- list.add(map);
- }
- jsonObject.put("questions", list);
- return jsonObject;
- }
- public List getTemplateByLabelOrTitle(String name, int pageNo, int pageSize) throws Exception {
- Sort sort = new Sort(Sort.Direction.DESC, "createTime");
- PageRequest request = new PageRequest(pageNo - 1, pageSize, sort);
- String sql = "SELECT DISTINCT s.code " +
- " FROM System_dict s WHERE s.dict_name ='SURVEY_LABEL' and s.value LIKE '%" + name +
- "%'";
- List<Map<String, Object>> labels = jdbcTemplate.queryForList(sql);
- List<SurveyTemplates> surveyTemplates = new ArrayList<>();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if (labels.size() == 0) {
- // 模板标题
- String cql = "select distinct t.* from wlyy_survey_templates t where t.del = 1 and t.title like '%" + name + "%' ";
- List<Map<String, Object>> surveyTemp = jdbcTemplate.queryForList(cql);
- for (Map<String, Object> temp : surveyTemp) {
- String create = temp.get("create_time").toString();
- String update = temp.get("update_time").toString();
- Date createTime = sdf.parse(create);
- Date updateTime = sdf.parse(update);
- SurveyTemplates tem = new SurveyTemplates(temp.get("code").toString(),
- temp.get("title").toString(), temp.get("template_comment").toString(), temp.get("creater").toString(),
- Integer.parseInt(temp.get("del").toString()), createTime, updateTime);
- surveyTemplates.add(tem);
- }
- } else {
- for (Map<String, Object> label : labels) {
- // if ("SURVEY_LABEL".equals(label.get("dict_name").toString())) {
- surveyTemplates = surveyLabelInfoDao.findByLabel(Integer.parseInt(label.get("code").toString()));
- // }
- }
- }
- List list = new ArrayList();
- for (SurveyTemplates template : surveyTemplates) {
- Map<String, Object> map = new HashMap<>();
- String tempCode = template.getCode();
- String title = template.getTitle();
- String comment = template.getTemplateComment();
- Date createTime = template.getCreateTime();
- int[] label = surveyLabelInfoDao.findByRelationCode(tempCode);
- String[] tags = new String[label.length];
- for (int i = 0; i < label.length; i++) {
- switch (label[i]) {
- case 1:
- tags[i] = "满意度";
- break;
- case 2:
- tags[i] = "糖尿病";
- break;
- case 3:
- tags[i] = "高血压";
- break;
- case 4:
- tags[i] = "生活日常";
- break;
- }
- }
- map.put("tempCode", tempCode);
- map.put("title", title);
- map.put("createTime", sdf.format(createTime));
- map.put("label", tags);
- map.put("comment", comment);
- list.add(map);
- }
- return list;
- }
- public List getTemplateByLabel(int pageNo, int pageSize, String labels) throws Exception {
- if (StringUtils.isEmpty(labels)) {
- Sort sort = new Sort(Sort.Direction.DESC, "createTime");
- PageRequest request = new PageRequest(pageNo - 1, pageSize, sort);
- List<SurveyTemplates> templates = surveyTemplatesDao.findAlls(request);
- List list = new ArrayList();
- for (SurveyTemplates template : templates) {
- Map<String, Object> tempMap = new HashMap();
- String title = template.getTitle();
- String templateId = template.getCode();
- String comment = template.getTemplateComment();
- int[] label = surveyLabelInfoDao.findByRelationCode(templateId);
- String[] tags = new String[label.length];
- for (int i = 0; i < label.length; i++) {
- switch (label[i]) {
- case 1:
- tags[i] = "满意度";
- break;
- case 2:
- tags[i] = "糖尿病";
- break;
- case 3:
- tags[i] = "高血压";
- break;
- case 4:
- tags[i] = "生活日常";
- break;
- }
- }
- tempMap.put("templateId", templateId);
- tempMap.put("title", title);
- if (comment.length() > 50) {
- comment = comment.substring(0, 49);
- }
- tempMap.put("comment", comment);
- tempMap.put("label", tags);
- list.add(tempMap);
- }
- return list;
- } else {
- List list = new ArrayList();
- pageNo -= 1;
- String sql = "SELECT DISTINCT t.* " +
- " FROM wlyy_survey_templates t,wlyy_survey_label_info s " +
- " WHERE t.code = s.relation_code " +
- " AND s.use_type= 0 " +
- " AND t.del = 1 " +
- " AND s.label IN (" + labels +
- ") " +
- " ORDER by t.create_time DESC " +
- " limit " + pageNo +
- "," + pageSize;
- List<Map<String, Object>> listMap = jdbcTemplate.queryForList(sql);
- for (Map<String, Object> template : listMap) {
- Map<String, Object> map = new HashMap();
- String code = template.get("code").toString();
- String title = template.get("title").toString();
- String comment = template.get("template_comment").toString();
- if (comment.length() > 50) {
- comment = comment.substring(0, 49);
- }
- // 查询标签
- int[] label = surveyLabelInfoDao.findByRelationCode(code);
- String[] tags = new String[label.length];
- for (int i = 0; i < label.length; i++) {
- switch (label[i]) {
- case 1:
- tags[i] = "满意度";
- break;
- case 2:
- tags[i] = "糖尿病";
- break;
- case 3:
- tags[i] = "高血压";
- break;
- case 4:
- tags[i] = "生活日常";
- break;
- }
- }
- map.put("title", title);
- map.put("templateId", code);
- map.put("comment", comment);
- map.put("label", tags);
- list.add(map);
- }
- return list;
- }
- }
- public Map<String, Object> getTemplateById(String code) throws Exception {
- Map<String, Object> tempMap = new HashMap();
- SurveyTemplates template = surveyTemplatesDao.findById(code);
- String title = template.getTitle();
- String comment = template.getTemplateComment();
- int[] label = surveyLabelInfoDao.findByRelationCode(code);
- String[] labels = new String[label.length];
- for (int i = 0; i < label.length; i++) {
- switch (label[i]) {
- case 1:
- labels[i] = "满意度";
- break;
- case 2:
- labels[i] = "糖尿病";
- break;
- case 3:
- labels[i] = "高血压";
- break;
- case 4:
- labels[i] = "生活日常";
- break;
- }
- }
- tempMap.put("templateId", code);
- tempMap.put("title", title);
- tempMap.put("comment", comment);
- tempMap.put("label", labels);
- return tempMap;
- }
- public JSONObject getTemplateDetail(String id) throws Exception {
- JSONObject jsonObject = new JSONObject();
- //问卷信息
- SurveyTemplates template = surveyTemplatesDao.findById(id);
- int[] label = surveyLabelInfoDao.findByRelationCode(id);
- String[] labels = new String[label.length];
- for (int i = 0; i < label.length; i++) {
- switch (label[i]) {
- case 1:
- labels[i] = "满意度";
- break;
- case 2:
- labels[i] = "糖尿病";
- break;
- case 3:
- labels[i] = "高血压";
- break;
- case 4:
- labels[i] = "生活日常";
- break;
- }
- }
- //问题信息
- List<SurveyTemplateQuestions> surveyQuestionnair = surveyTemplateQuestionsDao.findById(id);
- List questions = new ArrayList();
- // 问题信息
- for (SurveyTemplateQuestions questionnair : surveyQuestionnair) {
- Map<String, Object> question = new HashMap<>();
- String qstcode = questionnair.getCode();
- String title = questionnair.getTitle();
- int isRequired = questionnair.getIsRequired();
- int sort = questionnair.getSort();
- String comment = questionnair.getQuestionComment();
- int type = questionnair.getQuestionType();
- List<SurveyTemplateOptions> options = surveyTemplateOptionsDao.findById(qstcode, id);
- List optList = new ArrayList();
- for (SurveyTemplateOptions option : options) {
- Map<String, Object> opt = new HashMap<>();
- String conetent = option.getContent();
- int haveComment = option.getHaveComment();
- int required = option.getIsRequired();
- int optsort = option.getSort();
- if (!StringUtils.isEmpty(option.getQuestionCodeNext())) {
- String next = option.getQuestionCodeNext();
- SurveyTemplateQuestions tempQst = surveyTemplateQuestionsDao.findById(id, next);
- // 跳题结束怎么办?
- opt.put("nextQuestion", tempQst == null ? 0 : tempQst.getSort());
- }
- opt.put("isRequired", required);
- opt.put("content", conetent);
- opt.put("sort", optsort);
- opt.put("haveComment", haveComment);
- optList.add(opt);
- }
- question.put("title", title);
- question.put("isRequired", isRequired);
- question.put("comment", comment);
- question.put("type", type);
- question.put("options", optList);
- question.put("sort", sort);
- question.put("maxNum", questionnair.getMaxNum());
- question.put("minNum", questionnair.getMinNum());
- if (!StringUtils.isEmpty(questionnair.getQuestionCodeNext())) {
- String next = questionnair.getQuestionCodeNext();
- SurveyTemplateQuestions tempQst = surveyTemplateQuestionsDao.findById(id, next);
- question.put("nextQuestion", tempQst == null ? 0 : tempQst.getSort());
- }
- questions.add(question);
- }
- String tempComment = template.getTemplateComment();
- String tempTitle = template.getTitle();
- jsonObject.put("title", tempTitle);
- jsonObject.put("comment", tempComment);
- jsonObject.put("label", labels);
- jsonObject.put("questions", questions);
- System.out.println("==========jsonObject============" + jsonObject);
- return jsonObject;
- }
- public int savaSurveyAsTemplate(String code, String modifyTitle) throws Exception {
- Survey survey = surveyDao.findById(code);
- String tempCode = getCode();
- String title = survey.getTitle();
- String templateComment = survey.getSurveyComment();
- String creater = survey.getCreater();
- Date createTime = survey.getCreateTime();
- Date updateTime = survey.getUpdateTime();
- // 查询问卷标题重复情况
- int number = 0;
- if (StringUtils.isEmpty(modifyTitle)) {
- number = surveyTemplatesDao.distinctByTitle(title);
- } else {
- number = surveyTemplatesDao.distinctByTitle(modifyTitle);
- title = modifyTitle;
- }
- if (number != 0 && StringUtils.isEmpty(modifyTitle)) {
- int likeNum = surveyTemplatesDao.distinctLikeTitle(title + "%");
- return likeNum;
- }
- if (number != 0 && !StringUtils.isEmpty(modifyTitle)) {
- int likeNum = surveyTemplatesDao.distinctLikeTitle(modifyTitle + "%");
- return likeNum;
- }
- SurveyTemplates surveyTemplates = new SurveyTemplates(tempCode, title, templateComment, creater, 1, createTime, updateTime);
- // 保存模板信息
- surveyTemplatesDao.save(surveyTemplates);
- List<SurveyLabelInfo> surveyLabelInfos = surveyLabelInfoDao.findByCode(code);
- for (SurveyLabelInfo surveyLabelInfo : surveyLabelInfos) {
- // 保存模板标签信息
- SurveyLabelInfo surveyLabelInfo1 = new SurveyLabelInfo(getCode(), tempCode, 0, surveyLabelInfo.getLabel());
- surveyLabelInfoDao.save(surveyLabelInfo1);
- }
- List<SurveyQuestionnaire> surveyQuestionnaires = surveyQuestionnaireDao.findById(survey.getCode());
- for (SurveyQuestionnaire question : surveyQuestionnaires) {
- String qstCode = getCode();
- String qstTitle = question.getTitle();
- String qstComment = question.getQuestionComment();
- Integer qstType = question.getQuestionType();
- Integer isRequired = question.getIsRequired();
- Integer minNum = question.getMinNum();
- Integer maxNum = question.getMaxNum();
- Date createTiem = question.getCreateTime();
- Date updateTiem = question.getUpdateTime();
- Integer sort = question.getSort();
- Integer de = question.getDel();
- String next = question.getQuestionCodeNext();
- SurveyTemplateQuestions surveyTemplateQuestions = new SurveyTemplateQuestions(qstCode, qstTitle, qstComment, qstType, tempCode, isRequired, minNum, maxNum, sort, next, null, de, createTiem, updateTiem);
- // 保存问题到模板问题表
- surveyTemplateQuestionsDao.save(surveyTemplateQuestions);
- if (qstType != 2) {
- List<SurveyQuestionnaireOptions> surveyQuestionnaireOptions = surveyQuestionnaireOptionsDao.findByIdAndQstCode(code, question.getCode());
- for (SurveyQuestionnaireOptions option : surveyQuestionnaireOptions) {
- SurveyTemplateOptions surveyTemplateOptions = new SurveyTemplateOptions(getCode(), option.getHaveComment(), qstCode, option.getContent(),
- tempCode, option.getQuestionCodeNext(), null, option.getIsRequired(), option.getSort(), option.getDel());
- // 保存到模板选项表 survey_template_options
- surveyTemplateOptionsDao.save(surveyTemplateOptions);
- }
- }
- }
- return 0;
- }
- public int modifyTemplate(String code, String templateCode, String modifyTitle) throws Exception {
- Survey survey = surveyDao.findById(code);
- String title = survey.getTitle();
- String templateComment = survey.getSurveyComment();
- // 查询问卷标题重复情况
- int number = 0;
- if (StringUtils.isEmpty(modifyTitle)) {
- number = surveyTemplatesDao.distinctByTitle(title);
- } else {
- number = surveyTemplatesDao.distinctByTitle(modifyTitle);
- title = modifyTitle;
- }
- if (number != 0 && StringUtils.isEmpty(modifyTitle)) {
- int likeNum = surveyTemplatesDao.distinctLikeTitle(title + "%");
- return likeNum;
- }
- if (number != 0 && !StringUtils.isEmpty(modifyTitle)) {
- int likeNum = surveyTemplatesDao.distinctLikeTitle(modifyTitle + "%");
- return likeNum;
- }
- // SurveyTemplates surveyTemplates = new SurveyTemplates(templateCode, title, templateComment, creater, 1, creater, updateTime);
- // 更改模板信息
- // surveyTemplatesDao.save(surveyTemplates);
- surveyTemplatesDao.modifyTemplate(templateCode, title, templateComment);
- List<SurveyLabelInfo> surveyLabelInfos = surveyLabelInfoDao.findByCode(code);
- for (SurveyLabelInfo surveyLabelInfo : surveyLabelInfos) {
- // 更改模板标签信息
- // SurveyLabelInfo surveyLabelInfo1 = new SurveyLabelInfo(getCode(), templateCode, 0, surveyLabelInfo.getLabel());
- // surveyLabelInfoDao.save(surveyLabelInfo1);
- surveyLabelInfoDao.modifyLabel(templateCode, surveyLabelInfo.getLabel());
- }
- List<SurveyQuestionnaire> surveyQuestionnaires = surveyQuestionnaireDao.findById(survey.getCode());
- for (SurveyQuestionnaire question : surveyQuestionnaires) {
- String qstCode = getCode();
- String qstTitle = question.getTitle();
- String qstComment = question.getQuestionComment();
- Integer qstType = question.getQuestionType();
- Integer isRequired = question.getIsRequired();
- Integer minNum = question.getMinNum();
- Integer maxNum = question.getMaxNum();
- // Date createTiem = question.getCreateTime();
- // Date updateTiem = question.getUpdateTime();
- Integer sort = question.getSort();
- // Integer de = question.getDel();
- String next = question.getQuestionCodeNext();
- // SurveyTemplateQuestions surveyTemplateQuestions = new SurveyTemplateQuestions(qstCode, qstTitle, qstComment, qstType, templateCode, isRequired, minNum, maxNum, sort, next, null, de, createTiem, updateTiem);
- // 更改问题到模板问题表
- // surveyTemplateQuestionsDao.save(surveyTemplateQuestions);
- surveyTemplateQuestionsDao.modifyQuestion(templateCode, qstCode, qstTitle, qstComment, qstType, isRequired, minNum, maxNum, sort, next);
- if (qstType != 2) {
- List<SurveyQuestionnaireOptions> surveyQuestionnaireOptions = surveyQuestionnaireOptionsDao.findByIdAndQstCode(code, question.getCode());
- for (SurveyQuestionnaireOptions option : surveyQuestionnaireOptions) {
- SurveyTemplateOptions surveyTemplateOptions = new SurveyTemplateOptions(getCode(), option.getHaveComment(), qstCode, option.getContent(),
- templateCode, option.getQuestionCodeNext(), null, option.getIsRequired(), option.getSort(), option.getDel());
- // 更改到模板选项表 survey_template_options
- // surveyTemplateOptionsDao.save(surveyTemplateOptions);
- surveyTemplateOptionsDao.modifyOption(templateCode, qstCode, option.getCode(),
- option.getHaveComment(), option.getContent(), option.getQuestionCodeNext(), option.getIsRequired(), option.getSort());
- }
- }
- }
- return 0;
- }
- public Map getFilter() {
- JSONObject jsonObject = new JSONObject();
- // List lis = new ArrayList();
- Iterable<SurveyDimension> surveyDimension = surveyDimensionDao.findAll();
- Map<String, Object> map = new HashMap<>();
- for (SurveyDimension dimension : surveyDimension) {
- // Map<String, Object> map = new HashMap<>();
- String name = dimension.getName();
- int value = dimension.getValue();
- switch (value) {
- case 1:
- name = "sex";
- break;
- case 2:
- name = "disease";
- break;
- case 3:
- name = "service";
- break;
- case 4:
- name = "healthCondition";
- break;
- }
- String sql = "SELECT t.value,t.`name` " +
- " FROM wlyy_survey_dimension_option t\n" +
- " WHERE t.`dimension_value`= " + value;
- List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
- List subLabel = new ArrayList();
- for (Map<String, Object> li : list) {
- Map<String, Object> map1 = new HashMap<>();
- int var = Integer.parseInt(li.get("value").toString());
- String nm = li.get("name").toString();
- map1.put("key", var);
- map1.put("value", nm);
- subLabel.add(map1);
- }
- map.put(name, subLabel);
- // lis.add(map);
- }
- return map;
- }
- public int getAmount(String json) {
- return getCount(json).size();
- }
- public List<String> getCount(String json) {
- // 1.服务 2.健康 3疾病
- JSONObject jsonObject = new JSONObject(json);
- String sex = jsonObject.get("sex").toString();
- String str = "SELECT s.patient FROM ( " +
- "SELECT t.patient,GROUP_CONCAT(t.label_name) label_name FROM wlyy_sign_patient_label_info t " +
- "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`!='' ";
- if (!"0".equals(sex)) {
- str += " AND b.sex= " + sex + " ) GROUP BY t.patient ) s WHERE 1=1 ";
- } else {
- str += " ) GROUP BY t.patient ) s WHERE 1=1 ";
- }
- JSONArray service = jsonObject.getJSONArray("service");
- String ser = "";
- service:
- for (Object serv : service) {
- String type = serv.toString();
- switch (type) {
- // AND (s.label_name LIKE '%普通人群%'OR s.label_name LIKE '%慢病人群%'OR s.label_name LIKE '%65岁以上人群%')
- case "0":
- break service;
- case "1":
- ser += " s.label_name LIKE '%普通人群%' ";
- break;
- case "2":
- ser += " s.label_name LIKE '%慢病人群%' ";
- break;
- case "3":
- ser += " s.label_name LIKE '%65岁以上人群%' ";
- break;
- }
- ser += " OR ";
- }
- if (!StringUtils.isEmpty(ser)) {
- str += " AND ( " + ser.substring(0, ser.lastIndexOf("OR")) + " ) ";
- }
- JSONArray healthCondition = jsonObject.getJSONArray("healthCondition");
- String heal = "";
- health:
- for (Object health : healthCondition) {
- String type = health.toString();
- switch (type) {
- // AND (s.label_name LIKE '%普通人群%'OR s.label_name LIKE '%慢病人群%'OR s.label_name LIKE '%65岁以上人群%')
- case "0":
- break health;
- case "1":
- heal += " s.label_name LIKE '%健康人群%' ";
- break;
- case "2":
- heal += " s.label_name LIKE '%患病人群%' ";
- break;
- case "3":
- heal += " s.label_name LIKE '%高危人群%' ";
- break;
- case "4":
- heal += " s.label_name LIKE '%恢复期人群%' ";
- break;
- }
- heal += " OR ";
- }
- if (!StringUtils.isEmpty(heal)) {
- str += " AND ( " + heal.substring(0, heal.lastIndexOf("OR")) + " ) ";
- }
- JSONArray disease = jsonObject.getJSONArray("disease");
- String dis = "";
- disea:
- for (Object disea : disease) {
- String type = disea.toString();
- switch (type) {
- // AND (s.label_name LIKE '%普通人群%'OR s.label_name LIKE '%慢病人群%'OR s.label_name LIKE '%65岁以上人群%')
- case "0":
- break disea;
- case "1":
- dis += " s.label_name LIKE '%高血压%' ";
- break;
- case "2":
- dis += " s.label_name LIKE '%糖尿病%' ";
- break;
- }
- dis += " OR ";
- }
- if (!StringUtils.isEmpty(dis)) {
- str += " AND ( " + dis.substring(0, dis.lastIndexOf("OR")) + " ) ";
- }
- /* if (Integer.parseInt(sex) != 0) {
- str += "and t.sex = " + sex;
- }
- JSONArray service = jsonObject.getJSONArray("service");
- String ser = "";
- String servi = "";
- for (Object serv : service) {
- if ("0".equals(serv.toString())) {
- ser += ",";
- break;
- } else {
- ser += serv.toString() + ",";
- }
- }
- ser = ser.substring(0, ser.length() - 1);
- if (ser.length() != 0) {
- servi = "(t.`label_type`=1 AND t.`label`IN(" + ser + "))";
- }
- JSONArray healthCondition = jsonObject.getJSONArray("healthCondition");
- String heal = "";
- String healt = "";
- for (Object health : healthCondition) {
- if ("0".equals(health.toString())) {
- heal += ",";
- break;
- } else {
- heal += health.toString() + ",";
- }
- }
- heal = heal.substring(0, heal.length() - 1);
- if (heal.length() != 0) {
- healt = "(t.`label_type`=2 AND t.`label`IN(" + heal + "))";
- }
- JSONArray disease = jsonObject.getJSONArray("disease");
- String dise = "";
- String diseas = "";
- for (Object disea : disease) {
- if ("0".equals(disea.toString())) {
- dise += ",";
- break;
- } else {
- dise += disea.toString() + ",";
- }
- }
- dise = dise.substring(0, dise.length() - 1);
- if (dise.length() != 0) {
- diseas = "(t.`label_type`=3 AND t.`label`IN(" + dise + "))";
- }
- if (servi.length() != 0 & healt.length() != 0 & diseas.length() != 0) {
- str += "AND ( " + servi + "OR" + healt + "OR" + diseas + " )";
- } else if (servi.length() != 0 & healt.length() != 0 & diseas.length() == 0) {
- str += "AND ( " + servi + "OR" + healt + " )";
- } else if (servi.length() != 0 & healt.length() == 0 & diseas.length() != 0) {
- str += "AND ( " + servi + "OR" + diseas + " )";
- } else if (servi.length() == 0 & healt.length() != 0 & diseas.length() != 0) {
- str += "AND ( " + healt + "OR" + diseas + " )";
- } else if (servi.length() != 0 & healt.length() == 0 & diseas.length() == 0) {
- str += "AND " + servi;
- } else if (servi.length() == 0 & healt.length() != 0 & diseas.length() == 0) {
- str += "AND " + healt;
- } else if (servi.length() == 0 & healt.length() == 0 & diseas.length() != 0) {
- str += "AND " + diseas;
- }*/
- // Map<String, Object> patients = jdbcTemplate.queryForMap(str);
- System.out.println("=====query sql =======>>>>" + str);
- List<String> patients = jdbcTemplate.queryForList(str, String.class);
- return patients;
- }
- }
|