Browse Source

问卷调查管理端,居民端

wujunjie 8 years ago
parent
commit
3200afc65c
40 changed files with 4243 additions and 4 deletions
  1. 123 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/Survey.java
  2. 88 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyAnswers.java
  3. 54 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyDimension.java
  4. 98 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyDimensionDetail.java
  5. 54 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyFilter.java
  6. 65 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyLabelInfo.java
  7. 110 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyOptionAnswers.java
  8. 165 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyQuestionnaire.java
  9. 120 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyQuestionnaireOptions.java
  10. 138 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyQuestions.java
  11. 103 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyQuestionsOptions.java
  12. 143 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyStatistics.java
  13. 121 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyTemplateOptions.java
  14. 165 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyTemplateQuestions.java
  15. 100 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyTemplates.java
  16. 90 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyUser.java
  17. 3 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/dict/SystemDictDao.java
  18. 15 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyAnswersDao.java
  19. 31 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyDao.java
  20. 13 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyDimensionDao.java
  21. 21 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyDimensionDetailDao.java
  22. 16 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyFilterDao.java
  23. 30 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyLabelInfoDao.java
  24. 15 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyOptionAnswersDao.java
  25. 32 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyQuestionnaireDao.java
  26. 22 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyQuestionnaireOptionsDao.java
  27. 19 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyQuestionsDao.java
  28. 15 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyQuestionsOptionsDao.java
  29. 25 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyStatisticsDao.java
  30. 15 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateOptionsDao.java
  31. 18 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateQuestionsDao.java
  32. 23 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplatesDao.java
  33. 24 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyUserDao.java
  34. 3 3
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientDao.java
  35. 1273 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java
  36. 280 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/PatientQuestionnaireService.java
  37. 30 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java
  38. 455 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/ManagerQuestionnaireController.java
  39. 122 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/survey/PatientQuestionnaireController.java
  40. 6 0
      patient-co-wlyy/src/main/resources/system.properties

+ 123 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/Survey.java

@ -0,0 +1,123 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * Created by Reece on 2017/3/8.
 */
@Entity
@Table(name = "wlyy_survey")
public class Survey extends IdEntity implements Serializable {
//  问卷编码(使用模板为模板编码)
    private String code;
//  标题
    private String title;
//  说明
    private String surveyComment;
//    创建人(医生编码)
    private String creater;
//    模板编码(使用模板是有值否则为空)
    private String templateCode;
//    调查状态(发送后正常为1 暂停为2)
    private int status;
//    调查对象数量
    private int amount;
//    创建时间
    private Date createTime;
//        修改时间
    private Date updateTime;
    public Survey() {
    }
    public Survey(String code, String title, String surveyComment, String creater, String templateCode, int status, int amount, Date createTime, Date updateTime) {
        this.code = code;
        this.title = title;
        this.surveyComment = surveyComment;
        this.creater = creater;
        this.templateCode = templateCode;
        this.status = status;
        this.amount = amount;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getSurveyComment() {
        return surveyComment;
    }
    public void setSurveyComment(String surveyComment) {
        this.surveyComment = surveyComment;
    }
    public String getCreater() {
        return creater;
    }
    public void setCreater(String creater) {
        this.creater = creater;
    }
    public String getTemplateCode() {
        return templateCode;
    }
    public void setTemplateCode(String templateCode) {
        this.templateCode = templateCode;
    }
    public int getStatus() {
        return status;
    }
    public void setStatus(int status) {
        this.status = status;
    }
    public int getAmount() {
        return amount;
    }
    public void setAmount(int amount) {
        this.amount = amount;
    }
}

+ 88 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyAnswers.java

@ -0,0 +1,88 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * Created by Reece on 2017/3/9.
 */
@Entity
@Table(name = "wlyy_survey_answers")
public class SurveyAnswers extends IdEntity implements Serializable {
    //    问答题答案编码
    private String code;
    //      问卷编码
    private String surveyCode;
    //  患者ID
    private String patient;
    //    	问答题题目编码
    private String questionCode;
    //    问答题答案
    private String content;
//    创建时间
    private Date createTime;
    public SurveyAnswers() {
    }
    public SurveyAnswers(String code, String surveyCode, String patient, String questionCode, String content, Date createTime) {
        this.code = code;
        this.surveyCode = surveyCode;
        this.patient = patient;
        this.questionCode = questionCode;
        this.content = content;
        this.createTime = createTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getSurveyCode() {
        return surveyCode;
    }
    public void setSurveyCode(String surveyCode) {
        this.surveyCode = surveyCode;
    }
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public String getQuestionCode() {
        return questionCode;
    }
    public void setQuestionCode(String questionCode) {
        this.questionCode = questionCode;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
}

+ 54 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyDimension.java

@ -0,0 +1,54 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * Created by Reece on 2017/3/17.
 */
@Entity
@Table(name = "wlyy_survey_dimension")
public class SurveyDimension  extends IdEntity implements Serializable {
//    	维度编码
    private  String code;
//    	维度名称
    private  String name;
//    	(1性别 2疾病类型 3服务类型 4健康状况)
    private  Integer value;
    public SurveyDimension() {
    }
    public SurveyDimension(String code, String name, Integer value) {
        this.code = code;
        this.name = name;
        this.value = value;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getValue() {
        return value;
    }
    public void setValue(Integer value) {
        this.value = value;
    }
}

+ 98 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyDimensionDetail.java

@ -0,0 +1,98 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * Created by Reece on 2017/3/17.
 */
@Entity
@Table(name = "wlyy_survey_dimension_detail")
public class SurveyDimensionDetail extends IdEntity implements Serializable {
//      	维度项目编码
    private  String code;
//    维度表编码
    private String dimensionCode;
//    属性名(子维度)
    private String name;
//    属性值(子维度)
    private Integer value;
//    属性名(父维度)
    private  String dimensionName;
//    属性值(父维度)
    private  Integer dimensionValue;
//         	维度项目编码
    private  String surveyCode;
    public SurveyDimensionDetail() {
    }
    public SurveyDimensionDetail(String code, String dimensionCode, String name, Integer value, String dimensionName, Integer dimensionValue, String surveyCode) {
        this.code = code;
        this.dimensionCode = dimensionCode;
        this.name = name;
        this.value = value;
        this.dimensionName = dimensionName;
        this.dimensionValue = dimensionValue;
        this.surveyCode = surveyCode;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getDimensionCode() {
        return dimensionCode;
    }
    public void setDimensionCode(String dimensionCode) {
        this.dimensionCode = dimensionCode;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getValue() {
        return value;
    }
    public void setValue(Integer value) {
        this.value = value;
    }
    public String getDimensionName() {
        return dimensionName;
    }
    public void setDimensionName(String dimensionName) {
        this.dimensionName = dimensionName;
    }
    public Integer getDimensionValue() {
        return dimensionValue;
    }
    public void setDimensionValue(Integer dimensionValue) {
        this.dimensionValue = dimensionValue;
    }
    public String getSurveyCode() {
        return surveyCode;
    }
    public void setSurveyCode(String surveyCode) {
        this.surveyCode = surveyCode;
    }
}

+ 54 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyFilter.java

@ -0,0 +1,54 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * Created by Reece on 2017/3/9.
 */
@Entity
@Table(name = "wlyy_survey_filter")
public class SurveyFilter extends IdEntity implements Serializable {
//   业务主键
    private  String code;
//    问卷编码
    private String surveyCode;
//    维度项目编码
    private String dimensionDetailCode;
    public SurveyFilter() {
    }
    public SurveyFilter(String code, String surveyCode, String dimensionDetailCode) {
        this.code = code;
        this.surveyCode = surveyCode;
        this.dimensionDetailCode = dimensionDetailCode;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getSurveyCode() {
        return surveyCode;
    }
    public void setSurveyCode(String surveyCode) {
        this.surveyCode = surveyCode;
    }
    public String getDimensionDetailCode() {
        return dimensionDetailCode;
    }
    public void setDimensionDetailCode(String dimensionDetailCode) {
        this.dimensionDetailCode = dimensionDetailCode;
    }
}

+ 65 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyLabelInfo.java

@ -0,0 +1,65 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * Created by Reece on 2017/3/9.
 */
@Entity
@Table(name = "wlyy_survey_label_info")
public class SurveyLabelInfo extends IdEntity implements Serializable {
    //    业务主键
    private String code;
    //  关联编码
    private String relationCode;
    //被使用场景(0模板 1问卷)
    private Integer useType;
    //    字典中的标签值(1满意度、2糖尿病、3高血压、4生活日常)
    private Integer label;
    public SurveyLabelInfo() {
    }
    public SurveyLabelInfo(String code, String relationCode, Integer useType, Integer label) {
        this.code = code;
        this.relationCode = relationCode;
        this.useType = useType;
        this.label = label;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getRelationCode() {
        return relationCode;
    }
    public void setRelationCode(String relationCode) {
        this.relationCode = relationCode;
    }
    public Integer getUseType() {
        return useType;
    }
    public void setUseType(Integer useType) {
        this.useType = useType;
    }
    public Integer getLabel() {
        return label;
    }
    public void setLabel(Integer label) {
        this.label = label;
    }
}

+ 110 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyOptionAnswers.java

@ -0,0 +1,110 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * Created by Reece on 2017/3/9.
 */
@Entity
@Table(name = "wlyy_survey_option_answers")
public class SurveyOptionAnswers extends IdEntity implements Serializable {
//    选择答案编码
    private String code;
//  患者ID
    private  String patient;
//    问卷编码
    private String surveyCode;
//    选择题题目编码
    private String questionCode;
//    选项编码
    private String optionsCode;
//    选项说明(可为null)
    private String optionComment;
//    答案类型(0单选 1多选)
    private  int answerType;
//    创建时间
    private Date createTime;
    public SurveyOptionAnswers() {
    }
    public SurveyOptionAnswers(String code, String patient, String surveyCode, String questionCode, String optionsCode, String optionComment, int answerType, Date createTime) {
        this.code = code;
        this.patient = patient;
        this.surveyCode = surveyCode;
        this.questionCode = questionCode;
        this.optionsCode = optionsCode;
        this.optionComment = optionComment;
        this.answerType = answerType;
        this.createTime = createTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public String getSurveyCode() {
        return surveyCode;
    }
    public void setSurveyCode(String surveyCode) {
        this.surveyCode = surveyCode;
    }
    public String getQuestionCode() {
        return questionCode;
    }
    public void setQuestionCode(String questionCode) {
        this.questionCode = questionCode;
    }
    public String getOptionsCode() {
        return optionsCode;
    }
    public void setOptionsCode(String optionsCode) {
        this.optionsCode = optionsCode;
    }
    public String getOptionComment() {
        return optionComment;
    }
    public void setOptionComment(String optionComment) {
        this.optionComment = optionComment;
    }
    public int getAnswerType() {
        return answerType;
    }
    public void setAnswerType(int answerType) {
        this.answerType = answerType;
    }
}

+ 165 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyQuestionnaire.java

@ -0,0 +1,165 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * Created by Reece on 2017/3/10.
 */
@Entity
@Table(name = "wlyy_survey_questionnaire")
public class SurveyQuestionnaire extends IdEntity implements Serializable {
    //    问题编码
    private String code;
    //            问题标题
    private String title;
    //    问题说明(可为null)
    private String questionComment;
    //    问题类型(0单选 1多选 2问答)
    private int questionType;
    //    关联编码(按使用类型分类)
    private String surveyCode;
    //    是否必答(0否 1是)
    private int isRequired;
    //    最小答案个数(多选有效)
    private Integer minNum;
    //    最大答案个数(多选有效)
    private Integer maxNum;
    //            排序
    private int sort;
    //    下一题问题编码(问答题逻辑跳转)
    private String questionCodeNext;
    //    删除标志(1正常,0删除)
    private int del;
//    创建时间
    private Date createTime;
//    修改时间
    private Date updateTime;
    public SurveyQuestionnaire() {
    }
    public SurveyQuestionnaire(String code, String title, String questionComment, int questionType, String surveyCode, int isRequired, Integer minNum, Integer maxNum, int sort, String questionCodeNext, int del, Date createTime, Date updateTime) {
        this.code = code;
        this.title = title;
        this.questionComment = questionComment;
        this.questionType = questionType;
        this.surveyCode = surveyCode;
        this.isRequired = isRequired;
        this.minNum = minNum;
        this.maxNum = maxNum;
        this.sort = sort;
        this.questionCodeNext = questionCodeNext;
        this.del = del;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getQuestionComment() {
        return questionComment;
    }
    public void setQuestionComment(String questionComment) {
        this.questionComment = questionComment;
    }
    public int getQuestionType() {
        return questionType;
    }
    public void setQuestionType(int questionType) {
        this.questionType = questionType;
    }
    public String getSurveyCode() {
        return surveyCode;
    }
    public void setSurveyCode(String surveyCode) {
        this.surveyCode = surveyCode;
    }
    public int getIsRequired() {
        return isRequired;
    }
    public void setIsRequired(int isRequired) {
        this.isRequired = isRequired;
    }
    public Integer getMinNum() {
        return minNum;
    }
    public void setMinNum(Integer minNum) {
        this.minNum = minNum;
    }
    public Integer getMaxNum() {
        return maxNum;
    }
    public void setMaxNum(Integer maxNum) {
        this.maxNum = maxNum;
    }
    public int getSort() {
        return sort;
    }
    public void setSort(int sort) {
        this.sort = sort;
    }
    public String getQuestionCodeNext() {
        return questionCodeNext;
    }
    public void setQuestionCodeNext(String questionCodeNext) {
        this.questionCodeNext = questionCodeNext;
    }
    public int getDel() {
        return del;
    }
    public void setDel(int del) {
        this.del = del;
    }
}

+ 120 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyQuestionnaireOptions.java

@ -0,0 +1,120 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * Created by Reece on 2017/3/10.
 */
@Entity
@Table(name = "wlyy_survey_questionnaire_options")
public class SurveyQuestionnaireOptions extends IdEntity implements Serializable {
    //选项编码
    private String code;
    //    是否有选项说明(0没有 1有)
    private int haveComment;
    //    	所属问题编码
    private String questionnaireCode;
    //    选项内容
    private String content;
    //        问卷编码
    private String surveyCode;
    //    下一题问题编码(逻辑跳转)
    private String questionCodeNext;
    //    选项说明是否必填(0否 1是)
    private int isRequired;
    //    单题内排序
    private int sort;
    //    删除标志(1正常,0删除)
    private int del;
    public SurveyQuestionnaireOptions() {
    }
    public SurveyQuestionnaireOptions(String code, int haveComment, String questionnaireCode, String content, String surveyCode, String questionCodeNext, int isRequired, int sort, int del) {
        this.code = code;
        this.haveComment = haveComment;
        this.questionnaireCode = questionnaireCode;
        this.content = content;
        this.surveyCode = surveyCode;
        this.questionCodeNext = questionCodeNext;
        this.isRequired = isRequired;
        this.sort = sort;
        this.del = del;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public int getHaveComment() {
        return haveComment;
    }
    public void setHaveComment(int haveComment) {
        this.haveComment = haveComment;
    }
    public String getQuestionnaireCode() {
        return questionnaireCode;
    }
    public void setQuestionnaireCode(String questionnaireCode) {
        this.questionnaireCode = questionnaireCode;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public String getSurveyCode() {
        return surveyCode;
    }
    public void setSurveyCode(String surveyCode) {
        this.surveyCode = surveyCode;
    }
    public String getQuestionCodeNext() {
        return questionCodeNext;
    }
    public void setQuestionCodeNext(String questionCodeNext) {
        this.questionCodeNext = questionCodeNext;
    }
    public int getIsRequired() {
        return isRequired;
    }
    public void setIsRequired(int isRequired) {
        this.isRequired = isRequired;
    }
    public int getSort() {
        return sort;
    }
    public void setSort(int sort) {
        this.sort = sort;
    }
    public int getDel() {
        return del;
    }
    public void setDel(int del) {
        this.del = del;
    }
}

+ 138 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyQuestions.java

@ -0,0 +1,138 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * 问卷调查题库问题表 wlyy_survey_questions
 * Created by Reece on 2017/3/6.
 */
@Entity
@Table(name = "wlyy_survey_questions")
public class SurveyQuestions extends IdEntity implements Serializable {
    //    问题编码
    private String code;
    //    问题标题
    private String title;
    //    问题说明(可为null)
    private String questionComment;
    //    问题类型(0单选 1多选 2问答)
    private Integer questionType;
    //    关联编码(按使用类型分类)
//    private  String relationCode;
//    是否必答(0否 1是)
    private Integer isRequired;
    //     最小答案个数(多选有效)
    private Integer minNum;
    //    最大答案个数(多选有效)
    private Integer maxNum;
    //   排序
//    private int sort;
    //    删除标志(1正常,0删除)
    private Integer del;
    //    创建时间
    private Date createTime;
    //    修改时间
    private Date updateTime;
    public SurveyQuestions() {
    }
    public SurveyQuestions(String code, String title, String questionComment, Integer questionType, Integer isRequired, Integer minNum, Integer maxNum, Integer del, Date createTime, Date updateTime) {
        this.code = code;
        this.title = title;
        this.questionComment = questionComment;
        this.questionType = questionType;
        this.isRequired = isRequired;
        this.minNum = minNum;
        this.maxNum = maxNum;
        this.del = del;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getQuestionComment() {
        return questionComment;
    }
    public void setQuestionComment(String questionComment) {
        this.questionComment = questionComment;
    }
    public Integer getQuestionType() {
        return questionType;
    }
    public void setQuestionType(Integer questionType) {
        this.questionType = questionType;
    }
    public Integer getIsRequired() {
        return isRequired;
    }
    public void setIsRequired(Integer isRequired) {
        this.isRequired = isRequired;
    }
    public Integer getMinNum() {
        return minNum;
    }
    public void setMinNum(Integer minNum) {
        this.minNum = minNum;
    }
    public Integer getMaxNum() {
        return maxNum;
    }
    public void setMaxNum(Integer maxNum) {
        this.maxNum = maxNum;
    }
    public Integer getDel() {
        return del;
    }
    public void setDel(Integer del) {
        this.del = del;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}

+ 103 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyQuestionsOptions.java

@ -0,0 +1,103 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * Created by Reece on 2017/3/8.
 */
@Entity
@Table(name = "wlyy_survey_questions_options")
public class SurveyQuestionsOptions extends IdEntity implements Serializable {
//  选项编码
    private String code;
//    是否有选项说明(0没有 1有)
    private Integer haveComment;
//    	题库问题编码
    private String questionCode;
//    选项内容
    private String content;
//    题库题目编码
//    private String questionsCode;
//    下一题问题编码(逻辑跳转)
//    private String questionCodeNext;
//  选项说明是否必填(0否 1是)
    private Integer isRequired;
//    单题内排序
    private Integer sort;
//    删除标志(1正常,0删除)
    private Integer del;
    public SurveyQuestionsOptions() {
    }
    public SurveyQuestionsOptions(String code, Integer haveComment, String questionCode, String content, Integer isRequired, Integer sort, Integer del) {
        this.code = code;
        this.haveComment = haveComment;
        this.questionCode = questionCode;
        this.content = content;
        this.isRequired = isRequired;
        this.sort = sort;
        this.del = del;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public Integer getHaveComment() {
        return haveComment;
    }
    public void setHaveComment(Integer haveComment) {
        this.haveComment = haveComment;
    }
    public String getQuestionCode() {
        return questionCode;
    }
    public void setQuestionCode(String questionCode) {
        this.questionCode = questionCode;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public Integer getIsRequired() {
        return isRequired;
    }
    public void setIsRequired(Integer isRequired) {
        this.isRequired = isRequired;
    }
    public Integer getSort() {
        return sort;
    }
    public void setSort(Integer sort) {
        this.sort = sort;
    }
    public Integer getDel() {
        return del;
    }
    public void setDel(Integer del) {
        this.del = del;
    }
}

+ 143 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyStatistics.java

@ -0,0 +1,143 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * Created by Reece on 2017/3/9.
 */
@Entity
@Table(name = "wlyy_survey_statistics")
public class SurveyStatistics extends IdEntity implements Serializable{
//    业务主键
    private String code;
//    问卷编码
    private String surveyCode;
//    题目编码
    private String questionCode;
//    题目名称
    private  String questionTitle;
//    选项编码
    private String optionsCode;
//    人数(加1)
   private Integer amount;
//   选项内容可为null
    private  String content;
//    是否有选项说明(0没有 1有)可为null
    private  Integer haveComment;
//    问题类型(0单选 1多选 2问答)
    private Integer type;
//    问题排序
    private  Integer qstSort;
//    选项排序可为null
    private  Integer optSort;
    public SurveyStatistics() {
    }
    public SurveyStatistics(String code, String surveyCode, String questionCode, String questionTitle, String optionsCode, Integer amount, String content, Integer haveComment, Integer type, Integer qstSort, Integer optSort) {
        this.code = code;
        this.surveyCode = surveyCode;
        this.questionCode = questionCode;
        this.questionTitle = questionTitle;
        this.optionsCode = optionsCode;
        this.amount = amount;
        this.content = content;
        this.haveComment = haveComment;
        this.type = type;
        this.qstSort = qstSort;
        this.optSort = optSort;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getSurveyCode() {
        return surveyCode;
    }
    public void setSurveyCode(String surveyCode) {
        this.surveyCode = surveyCode;
    }
    public String getQuestionCode() {
        return questionCode;
    }
    public void setQuestionCode(String questionCode) {
        this.questionCode = questionCode;
    }
    public String getQuestionTitle() {
        return questionTitle;
    }
    public void setQuestionTitle(String questionTitle) {
        this.questionTitle = questionTitle;
    }
    public String getOptionsCode() {
        return optionsCode;
    }
    public void setOptionsCode(String optionsCode) {
        this.optionsCode = optionsCode;
    }
    public Integer getAmount() {
        return amount;
    }
    public void setAmount(Integer amount) {
        this.amount = amount;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public Integer getHaveComment() {
        return haveComment;
    }
    public void setHaveComment(Integer haveComment) {
        this.haveComment = haveComment;
    }
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    public Integer getQstSort() {
        return qstSort;
    }
    public void setQstSort(Integer qstSort) {
        this.qstSort = qstSort;
    }
    public Integer getOptSort() {
        return optSort;
    }
    public void setOptSort(Integer optSort) {
        this.optSort = optSort;
    }
}

+ 121 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyTemplateOptions.java

@ -0,0 +1,121 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * Created by Reece on 2017/3/10.
 */
@Entity
@Table(name = "wlyy_survey_template_options")
public class SurveyTemplateOptions extends IdEntity implements Serializable {
    //选项编码
    private String code;
    //    是否有选项说明(0没有 1有)
    private Integer haveComment;
    //    	所属问题编码
    private String templateQuestionCode;
    //    选项内容
    private String content;
    //        模板编码
    private String templateCode;
    //    下一题问题编码(逻辑跳转)
    private String questionCodeNext;
    //    选项说明是否必填(0否 1是)
    private Integer isRequired;
    //    单题内排序
    private Integer sort;
    //    删除标志(1正常,0删除)
    private Integer del;
    public SurveyTemplateOptions() {
    }
    public SurveyTemplateOptions(String code, Integer haveComment, String templateQuestionCode, String content, String templateCode, String questionCodeNext, Integer isRequired, Integer sort, Integer del) {
        this.code = code;
        this.haveComment = haveComment;
        this.templateQuestionCode = templateQuestionCode;
        this.content = content;
        this.templateCode = templateCode;
        this.questionCodeNext = questionCodeNext;
        this.isRequired = isRequired;
        this.sort = sort;
        this.del = del;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public Integer getHaveComment() {
        return haveComment;
    }
    public void setHaveComment(Integer haveComment) {
        this.haveComment = haveComment;
    }
    public String getTemplateQuestionCode() {
        return templateQuestionCode;
    }
    public void setTemplateQuestionCode(String templateQuestionCode) {
        this.templateQuestionCode = templateQuestionCode;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public String getTemplateCode() {
        return templateCode;
    }
    public void setTemplateCode(String templateCode) {
        this.templateCode = templateCode;
    }
    public String getQuestionCodeNext() {
        return questionCodeNext;
    }
    public void setQuestionCodeNext(String questionCodeNext) {
        this.questionCodeNext = questionCodeNext;
    }
    public Integer getIsRequired() {
        return isRequired;
    }
    public void setIsRequired(Integer isRequired) {
        this.isRequired = isRequired;
    }
    public Integer getSort() {
        return sort;
    }
    public void setSort(Integer sort) {
        this.sort = sort;
    }
    public Integer getDel() {
        return del;
    }
    public void setDel(Integer del) {
        this.del = del;
    }
}

+ 165 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyTemplateQuestions.java

@ -0,0 +1,165 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * Created by Reece on 2017/3/10.
 */
@Entity
@Table(name = "wlyy_survey_template_questions")
public class SurveyTemplateQuestions extends IdEntity implements Serializable{
    //    问题编码
    private String code;
    //            问题标题
    private String title;
    //    问题说明(可为null)
    private String questionComment;
    //    问题类型(0单选 1多选 2问答)
    private Integer questionType;
    //    模板编码
    private String templateCode;
    //    是否必答(0否 1是)
    private Integer isRequired;
    //    最小答案个数(多选有效)
    private Integer minNum;
    //    最大答案个数(多选有效)
    private Integer maxNum;
    //            排序
    private Integer sort;
    //    下一题问题编码(问答题逻辑跳转)
    private String questionCodeNext;
    //    删除标志(1正常,0删除)
    private Integer del;
//创建时间
    private Date createTime;
//修改时间
    private Date updateTime;
    public SurveyTemplateQuestions() {
    }
    public SurveyTemplateQuestions(String code, String title, String questionComment, Integer questionType, String templateCode, Integer isRequired, Integer minNum, Integer maxNum, Integer sort, String questionCodeNext, Integer del, Date createTime, Date updateTime) {
        this.code = code;
        this.title = title;
        this.questionComment = questionComment;
        this.questionType = questionType;
        this.templateCode = templateCode;
        this.isRequired = isRequired;
        this.minNum = minNum;
        this.maxNum = maxNum;
        this.sort = sort;
        this.questionCodeNext = questionCodeNext;
        this.del = del;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getQuestionComment() {
        return questionComment;
    }
    public void setQuestionComment(String questionComment) {
        this.questionComment = questionComment;
    }
    public Integer getQuestionType() {
        return questionType;
    }
    public void setQuestionType(Integer questionType) {
        this.questionType = questionType;
    }
    public String getTemplateCode() {
        return templateCode;
    }
    public void setTemplateCode(String templateCode) {
        this.templateCode = templateCode;
    }
    public Integer getIsRequired() {
        return isRequired;
    }
    public void setIsRequired(Integer isRequired) {
        this.isRequired = isRequired;
    }
    public Integer getMinNum() {
        return minNum;
    }
    public void setMinNum(Integer minNum) {
        this.minNum = minNum;
    }
    public Integer getMaxNum() {
        return maxNum;
    }
    public void setMaxNum(Integer maxNum) {
        this.maxNum = maxNum;
    }
    public Integer getSort() {
        return sort;
    }
    public void setSort(Integer sort) {
        this.sort = sort;
    }
    public String getQuestionCodeNext() {
        return questionCodeNext;
    }
    public void setQuestionCodeNext(String questionCodeNext) {
        this.questionCodeNext = questionCodeNext;
    }
    public Integer getDel() {
        return del;
    }
    public void setDel(Integer del) {
        this.del = del;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}

+ 100 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyTemplates.java

@ -0,0 +1,100 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * Created by Reece on 2017/3/8.
 */
@Entity
@Table(name = "wlyy_survey_templates")
public class SurveyTemplates extends IdEntity implements Serializable{
//    模板编码
    private String code;
//    模板标题
    private  String title;
//    模板说明
    private String templateComment;
//    创建人(医生编码)
    private String creater;
//    删除标志(1正常,0删除)
    private int del;
//创建时间
    private Date createTime;
//修改时间
    private  Date updateTime;
    public SurveyTemplates() {
    }
    public SurveyTemplates(String code, String title, String templateComment, String creater, int del, Date createTime, Date updateTime) {
        this.code = code;
        this.title = title;
        this.templateComment = templateComment;
        this.creater = creater;
        this.del = del;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getTemplateComment() {
        return templateComment;
    }
    public void setTemplateComment(String templateComment) {
        this.templateComment = templateComment;
    }
    public String getCreater() {
        return creater;
    }
    public void setCreater(String creater) {
        this.creater = creater;
    }
    public int getDel() {
        return del;
    }
    public void setDel(int del) {
        this.del = del;
    }
}

+ 90 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyUser.java

@ -0,0 +1,90 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * Created by Reece on 2017/3/9.
 */
@Entity
@Table(name = "wlyy_survey_user")
public class SurveyUser extends IdEntity implements Serializable {
    //	问卷编码
    private String surveyCode;
    //    患者ID
    private String patient;
    //    筛选条件编码
//    private String filterCode;
    //    是否已答(0未答 1已答 2放弃)
    private int status;
    //    是否有效(0无效 1有效)
    private int isWork;
//    接受调查时间
    private Date createTime;
//    调查完成时间
    private  Date endTime;
    public SurveyUser() {
    }
    public SurveyUser(String surveyCode, String patient, int status, int isWork, Date createTime, Date endTime) {
        this.surveyCode = surveyCode;
        this.patient = patient;
        this.status = status;
        this.isWork = isWork;
        this.createTime = createTime;
        this.endTime = endTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getEndTime() {
        return endTime;
    }
    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }
    public String getSurveyCode() {
        return surveyCode;
    }
    public void setSurveyCode(String surveyCode) {
        this.surveyCode = surveyCode;
    }
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public int getStatus() {
        return status;
    }
    public void setStatus(int status) {
        this.status = status;
    }
    public int getIsWork() {
        return isWork;
    }
    public void setIsWork(int isWork) {
        this.isWork = isWork;
    }
}

+ 3 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/dict/SystemDictDao.java

@ -17,4 +17,7 @@ public interface SystemDictDao extends PagingAndSortingRepository<SystemDict, Lo
    @Query("select s.value from SystemDict s where s.dictName=?1 and s.code =?2")
    String findByDictNameAndCode(String dictName,String code);
    @Query("select s from SystemDict s where s.value like ?1 ")
    List<SystemDict> findByLikeName(String name);
}

+ 15 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyAnswersDao.java

@ -0,0 +1,15 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyAnswers;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Reece on 2017/3/9.
 */
public interface SurveyAnswersDao extends PagingAndSortingRepository<SurveyAnswers,Long> {
    @Query("select  t.content from SurveyAnswers t where t.content is not null and t.surveyCode=?1 and t.questionCode=?2 order by t.createTime asc ")
    List<String> findByRelationCode(String id, String questionId);
}

+ 31 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyDao.java

@ -0,0 +1,31 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.Survey;
import com.yihu.wlyy.entity.patient.SignWeb;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by Reece on 2017/3/9.
 */
public interface SurveyDao extends PagingAndSortingRepository<Survey, Long> {
    @Query("select t from Survey t")
    Page<Survey> findAll(Pageable request);
    @Query("select t from Survey t where t.code = ?1")
    Survey findById(String code);
    @Modifying
    @Query("update Survey t set t.status = ?1 where t.code = ?2 ")
    void modifyStatus(int status ,String code);
}

+ 13 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyDimensionDao.java

@ -0,0 +1,13 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyDimension;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Reece on 2017/3/17.
 */
public interface SurveyDimensionDao extends PagingAndSortingRepository<SurveyDimension,Long> {
    @Query("select t.code from SurveyDimension t where t.name = ?1 ")
   String findByName(String name);
}

+ 21 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyDimensionDetailDao.java

@ -0,0 +1,21 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyDimension;
import com.yihu.wlyy.entity.doctor.survey.SurveyDimensionDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Reece on 2017/3/17.
 */
public interface SurveyDimensionDetailDao extends PagingAndSortingRepository<SurveyDimensionDetail, Long> {
    @Query("select d.dimensionName from SurveyDimensionDetail d where d.surveyCode = ?1 group by d.dimensionValue ")
    List<String> findByCode(String code);
    @Query("SELECT t.name FROM SurveyDimensionDetail t WHERE t.surveyCode=?1  AND t.dimensionName=?2 ")
    List<String> findByCode(String surveyCode,String dimensionName);
}

+ 16 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyFilterDao.java

@ -0,0 +1,16 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyFilter;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Reece on 2017/3/9.
 */
public interface SurveyFilterDao extends PagingAndSortingRepository<SurveyFilter, Long> {
    @Query("select  t from SurveyFilter t where t.surveyCode = ?1")
    List<SurveyFilter> findBySurveyCode(String surveyCode);
}

+ 30 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyLabelInfoDao.java

@ -0,0 +1,30 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyLabelInfo;
import com.yihu.wlyy.entity.doctor.survey.SurveyTemplates;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Reece on 2017/3/9.
 */
public interface SurveyLabelInfoDao extends PagingAndSortingRepository<SurveyLabelInfo, Long> {
    @Query("select t.label from SurveyLabelInfo t where t.relationCode = ?1 ")
    int[] findByRelationCode(String code);
    @Query("select t from SurveyLabelInfo t where t.relationCode = ?1 ")
    List<SurveyLabelInfo> findByCode(String code);
    @Query("select distinct t.label from SurveyLabelInfo t where  t.useType=?1 ")
    List<Object> findByUseType(int useType);
    @Query("select t from SurveyLabelInfo s,SurveyTemplates t where s.relationCode = t.code and s.useType=0 and s.label = ?1 ")
    List<SurveyTemplates> findByLabel(int label);
}

+ 15 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyOptionAnswersDao.java

@ -0,0 +1,15 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyOptionAnswers;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Reece on 2017/3/9.
 */
public interface SurveyOptionAnswersDao extends PagingAndSortingRepository<SurveyOptionAnswers,Long> {
    @Query("select  t.optionComment from SurveyOptionAnswers t where t.optionComment is not null and t.surveyCode =?1 and t.questionCode=?2 and t.optionsCode=?3 order by t.createTime asc ")
    List<Object> findByRelationCode(String id, String questionId, String optionId);
}

+ 32 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyQuestionnaireDao.java

@ -0,0 +1,32 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyQuestionnaire;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Reece on 2017/3/10.
 */
public interface SurveyQuestionnaireDao extends PagingAndSortingRepository<SurveyQuestionnaire, Long> {
    @Query("select  t from SurveyQuestionnaire t where t.surveyCode = ?1")
    List<SurveyQuestionnaire> findById(String id);
    @Query("select  t from SurveyQuestionnaire t where t.surveyCode = ?1")
    List<SurveyQuestionnaire> findById(String id, Pageable request);
    @Query("select  t from SurveyQuestionnaire t where t.surveyCode = ?1 and t.code = ?2")
    SurveyQuestionnaire findByIdAndQstId(String id, String questionId);
    @Query("select  t from SurveyQuestionnaire t where t.surveyCode = ?1 and t.sort = ?2")
    SurveyQuestionnaire findByIdAndSort(String id, int sort);
    @Query("select  max(t.sort) from SurveyQuestionnaire t where t.surveyCode = ?1 ")
    int findTotalById(String id);
    @Query("select t from SurveyQuestionnaire t where t.surveyCode = ?1 and t.sort = ?2 ")
    SurveyQuestionnaire findTotalByIdAndSort(String id, int sort);
}

+ 22 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyQuestionnaireOptionsDao.java

@ -0,0 +1,22 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyQuestionnaireOptions;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import javax.persistence.Entity;
import java.util.List;
/**
 * Created by Reece on 2017/3/10.
 */
public interface SurveyQuestionnaireOptionsDao extends PagingAndSortingRepository<SurveyQuestionnaireOptions, Long> {
    @Query("select t  from SurveyQuestionnaireOptions t where  t.questionnaireCode = ?1")
    List<SurveyQuestionnaireOptions> findById(String qstcode);
    @Query("select t  from SurveyQuestionnaireOptions t where  t.surveyCode =?1 and t.questionnaireCode = ?2")
    List<SurveyQuestionnaireOptions> findByIdAndQstCode(String surveycode,String qstcode);
    @Query("select t  from SurveyQuestionnaireOptions t where  t.surveyCode = ?1 and t.questionnaireCode = ?2 and t.code =?3 ")
    SurveyQuestionnaireOptions findByRelationCode(String id, String questionId, String optionId);
}

+ 19 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyQuestionsDao.java

@ -0,0 +1,19 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyQuestions;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Reece on 2017/3/9.
 */
public interface SurveyQuestionsDao extends PagingAndSortingRepository<SurveyQuestions, Long> {
    @Query("select  t from SurveyQuestions t where t.title like ?1 ")
    List<SurveyQuestions> findByTitle(String title, Pageable request);
    @Query("select  t from SurveyQuestions t ")
    List<SurveyQuestions> findByTitle(Pageable request);
}

+ 15 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyQuestionsOptionsDao.java

@ -0,0 +1,15 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyQuestionsOptions;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Reece on 2017/3/9.
 */
public interface SurveyQuestionsOptionsDao extends PagingAndSortingRepository<SurveyQuestionsOptions,Long> {
    @Query("select t from  SurveyQuestionsOptions t where  t.questionCode = ?1 ")
    List<SurveyQuestionsOptions> findById(String id);
}

+ 25 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyStatisticsDao.java

@ -0,0 +1,25 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyStatistics;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Reece on 2017/3/9.
 */
public interface SurveyStatisticsDao extends PagingAndSortingRepository<SurveyStatistics, Long> {
    @Modifying
    @Query("update SurveyStatistics t set t.amount = amount+1 where t.surveyCode = ?1 and  t.questionCode = ?2 and t.optionsCode = ?3 ")
    void modifyAmount(String surveyCode, String qstCode, String optCode);
    @Modifying
    @Query("update SurveyStatistics t set t.amount = amount+1 where t.surveyCode = ?1 and  t.questionCode = ?2 ")
    void modifyAmount(String surveyCode, String qstCode);
    @Query("select t.amount from SurveyStatistics t where t.surveyCode = ?1 and  t.questionCode = ?2 ")
    int findByIdAndQstId(String surveyCode, String qstCode);
    @Query("select t.amount from SurveyStatistics t where t.surveyCode = ?1 and  t.questionCode = ?2 and t.optionsCode = ?3 ")
    int findByAllId(String surveyCode, String qstCode,String optCode);
}

+ 15 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateOptionsDao.java

@ -0,0 +1,15 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyTemplateOptions;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Reece on 2017/3/10.
 */
public interface SurveyTemplateOptionsDao extends PagingAndSortingRepository<SurveyTemplateOptions,Long>{
    @Query("select t from  SurveyTemplateOptions t where  t.templateQuestionCode = ?1 and t.templateCode = ?2 ")
    List<SurveyTemplateOptions> findById(String qstcode,String tempCode);
}

+ 18 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateQuestionsDao.java

@ -0,0 +1,18 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyTemplateQuestions;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Reece on 2017/3/10.
 */
public interface SurveyTemplateQuestionsDao extends PagingAndSortingRepository<SurveyTemplateQuestions, Long> {
    @Query("select  t from SurveyTemplateQuestions t where t.templateCode = ?1 ")
    List<SurveyTemplateQuestions> findById(String tempCode);
    @Query("select  t from SurveyTemplateQuestions t where t.templateCode = ?1 and t.code = ?2 ")
    SurveyTemplateQuestions findById(String tempCode,String qstCode);
}

+ 23 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplatesDao.java

@ -0,0 +1,23 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyTemplates;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Reece on 2017/3/9.
 */
public interface SurveyTemplatesDao extends PagingAndSortingRepository<SurveyTemplates, Long> {
    @Query("select  t from SurveyTemplates t")
    List<SurveyTemplates> findAlls(Pageable request);
    @Query("select  distinct t from SurveyTemplates t where t.title like?1 ")
    List<SurveyTemplates> findByTitle(String title, Pageable request);
    @Query("select  t from SurveyTemplates t where t.code = ?1 ")
    SurveyTemplates findById(String code);
}

+ 24 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyUserDao.java

@ -0,0 +1,24 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyUser;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Reece on 2017/3/9.
 */
public interface SurveyUserDao extends PagingAndSortingRepository<SurveyUser, Long> {
    @Query("select t.patient from SurveyUser t where t.status=?1")
    List<Object> findByStatus(int status);
    @Query("select  t.status from SurveyUser t where t.patient = ?1 and t.surveyCode = ?2 ")
    int findByPatient(String patient, String surveyId);
    @Query("select  count(t.patient) from SurveyUser t where t.surveyCode = ?1 and t.status!=0  ")
    int findBySurveyCode(String surveyId);
    @Query("select t.patient from SurveyUser t where t.surveyCode=?1 and t.status = 0 and t.isWork = 1  ")
    List<String> findBySurveyCodeAndStatus(String id);
}

+ 3 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientDao.java

@ -29,7 +29,7 @@ public interface PatientDao extends PagingAndSortingRepository<Patient, Long> {
	// 根據身份證號查詢患者信息
	@Query("select p from Patient p where p.idcard=?1 and p.status=1")
	Patient findByIdcard(String idcard);
	
	@Query("select p from Patient p where p.ssc=?1 and p.status=1")
	Patient findBySsc(String ssc);
@ -43,10 +43,10 @@ public interface PatientDao extends PagingAndSortingRepository<Patient, Long> {
	@Query("select p from Patient p where p.openid=?1 and p.status=1")
	Patient findByOpenid(String openid);
	
	@Query("select count(1) from Patient p where p.openid=?1 and p.status=1")
	int countByOpenid(String openid);
	
	//清空openid
	@Modifying
	@Query("update Patient p set p.openid = null where p.code <> ?1 and p.openid = ?2 and p.status=1")

+ 1273 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java

@ -0,0 +1,1273 @@
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.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.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;
    public String createSurvey(String doctor, String accessToken, JSONObject jsonStr) throws Exception {
//        问卷信息
        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 AS patient,p.name,p.openid " +
                " FROM `wlyy_sign_patient_label_info` t,wlyy_patient p " +
                " WHERE t.`patient` =  p.`code` " +
                " AND p.`openid` IS NOT NULL ";
        //      保存到维度详情表(不限不保存)  维度表(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;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        sdf.format(new Date());
        String jsonData = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
        JSONObject json = new JSONObject(jsonData);
        List<Map<String, Object>> patients = jdbcTemplate.queryForList(str);
        int amount = patients.size();
//        int amount = 1234;
        for (Map<String, Object> patient : patients) {
            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 = "orrOgwATDaljVunlAq_Tdx3imhYg";
                json.put("keyword2", sdf.format(new Date()));
                json.put("toUser", code);
                json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                PushMsgTask.getInstance().sendWeixinMessage(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;
                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.setMinNum(null);
                        surveyQuestionnaire.setMinNum(null);
                        surveyQuestionnaire.setQuestionCodeNext(null);
                        surveyQuestionnaireDao.save(surveyQuestionnaire);
                        //                        =======================选项保存=========================
                        //                选择题
                        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();
                            }
//                        自主创建,插入表
                            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 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.setMinNum(maxOptions);
                        surveyQuestionnaire1.setSort(sort);
                        surveyQuestionnaire1.setQuestionCodeNext(null);
                        surveyQuestionnaire1.setDel(del);
                        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();
                            }
//                        自主创建,插入表
                            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 (tempQestion.has("nextQuestion")) {
                            nextQuestion = tempQestion.get("nextQuestion").toString();
                        }
                        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.setMinNum(null);
                        surveyQuestionnaire2.setSort(sort);
                        surveyQuestionnaire2.setQuestionCodeNext(nextQuestion);
                        surveyQuestionnaire2.setDel(del);
                        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);
        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);
        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.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.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);
                    opt.put("nextQuestion", 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);
        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 = surveyStatisticsDao.findByIdAndQstId(id, qstcode);
            qst.put("qstcode", qstcode);
            qst.put("title", title);
            qst.put("amount", amount);
            qst.put("type", type);
//            一个问题内的所有选项
            List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findById(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) throws Exception {
        JSONObject jsonObject = new JSONObject();
        SurveyQuestionnaire question = surveyQuestionnaireDao.findByIdAndQstId(id, questionId);
        if (optionId != null && optionId.length() != 0) {
//            查看选择题详细答案
            SurveyQuestionnaireOptions opt = surveyQuestionnaireOptionsDao.findByRelationCode(id, questionId, optionId);
            String option = opt.getContent();
            jsonObject.put("option", option);
//        获取同一个选项的所有回答的说明(分页?)
            List<Object> optionComment = surveyOptionAnswersDao.findByRelationCode(id, questionId, optionId);
            jsonObject.put("content", optionComment);
            jsonObject.put("amount", optionComment.size());
        } else {
//            查看问答题答案(分页?)
            List<String> answer = surveyAnswersDao.findByRelationCode(id, questionId);
            jsonObject.put("content", answer);
            jsonObject.put("amount", answer.size());
        }
        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.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 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();
                if (!StringUtils.isEmpty(option.getQuestionCodeNext())) {
                    String next = option.getQuestionCodeNext();
                    SurveyTemplateQuestions tempQst = surveyTemplateQuestionsDao.findById(id, next);
//                    opt.put("nextQuestion", tempQst.getSort());
                }
                opt.put("isRequired", required);
                opt.put("content", conetent);
                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);
            if (!StringUtils.isEmpty(questionnair.getQuestionCodeNext())) {
                String next = questionnair.getQuestionCodeNext();
                SurveyTemplateQuestions tempQst = surveyTemplateQuestionsDao.findById(id, next);
//                question.put("nextQuestion", 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);
        return jsonObject;
    }
    public void savaSurveyAsTemplate(String code) 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();
        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, 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, question.getTitle(),
                            tempCode, question.getQuestionCodeNext(), question.getIsRequired(), question.getSort(), option.getDel());
                    //         保存到模板选项表   survey_template_options
                    surveyTemplateOptionsDao.save(surveyTemplateOptions);
                }
            }
        }
    }
    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) {
//        1.服务 2.健康 3疾病
        JSONObject jsonObject = new JSONObject(json);
        String str = "SELECT COUNT(DISTINCT t.patient) AS amount" +
                " FROM `wlyy_sign_patient_label_info` t,wlyy_patient p " +
                " WHERE t.`patient` =  p.`code` " +
                " AND p.`openid` IS NOT NULL ";
        String sex = jsonObject.get("sex").toString();
        if (!"0".equals(sex)) {
            str += "AND(p.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);
        int amount = Integer.parseInt(patients.get("amount").toString());
        return amount;
    }
}

+ 280 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/PatientQuestionnaireService.java

@ -0,0 +1,280 @@
package com.yihu.wlyy.service.survey;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import com.mchange.v2.util.DoubleWeakHashMap;
import com.yihu.wlyy.entity.doctor.survey.*;
import com.yihu.wlyy.repository.doctor.*;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.MapUtill;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * Created by Reece on 2017/3/14.
 */
@Service
@Transactional
public class PatientQuestionnaireService extends BaseService {
    @Autowired
    private SurveyQuestionnaireDao surveyQuestionnaireDao;
    @Autowired
    private SurveyQuestionnaireOptionsDao surveyQuestionnaireOptionsDao;
    @Autowired
    private SurveyDao surveyDao;
    @Autowired
    private SurveyUserDao surveyUserDao;
    @Autowired
    private SurveyOptionAnswersDao surveyOptionAnswersDao;
    @Autowired
    private SurveyAnswersDao surveyAnswersDao;
    @Autowired
    SurveyStatisticsDao surveyStatisticsDao;
    public JSONObject getSurveySummary(String patient, String id) throws Exception {
        JSONObject jsonObject = new JSONObject();
        Survey survey = surveyDao.findById(id);
//        int complete = surveyUserDao.findByPatient(patient, id);
        String title = survey.getTitle();
        String comment = survey.getSurveyComment();
        int status = survey.getStatus();
        jsonObject.put("title", title);
        jsonObject.put("comment", comment);
        jsonObject.put("status", status);
//        jsonObject.put("complete", complete);
        return jsonObject;
    }
   /* public void getQuestions(String id,Integer sort,Integer pageNo,Integer total,String nextCode){
        JSONObject json = new JSONObject();
        if(StringUtils.isEmpty(nextCode)){
            //不跳题
            if(total==null){
                total = surveyQuestionnaireDao.findTotalById(id);
            }
            sort = pageNo+1;
            json.put("total",total);
            json.put("sort",sort);
        }else{
            //跳题
            SurveyQuestionnaire question = surveyQuestionnaireDao.findByIdAndQstId(id,nextCode);
            total = total - (sort+1);
            json.put("total",total);
            json.put("sort",question.getSort());
        }
    }*/
    /**
     * @param id   问卷id
     * @param sort 当前问题的sort(初始为1)
     */
    public JSONObject getQuestions(String id, Integer sort) throws Exception {
        JSONObject jsonObject = new JSONObject();
        SurveyQuestionnaire question = null;
        //      该套问卷总题目数
        int total = surveyQuestionnaireDao.findTotalById(id);
        question = surveyQuestionnaireDao.findTotalByIdAndSort(id, sort);
        int sorts = question.getSort();
        String qstCode = question.getCode();
        String qstTitle = question.getTitle();
        int isRequired = question.getIsRequired();
        int type = question.getQuestionType();
//        int sorts = question.getSort();
        switch (type)
        {
            case 0:
                List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findById(qstCode);
                for (SurveyQuestionnaireOptions option : options) {
                    String content = option.getContent();
//                        可构造集合,返回选项特定值
                    if (option.getQuestionCodeNext() != null) {
                        String next = option.getQuestionCodeNext();
                        SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
                        jsonObject.put("questionCodeNext", sq.getSort());
                    }
                }
                jsonObject.put("options", options);
                break;
            case 1:
                List<SurveyQuestionnaireOptions> optionss = surveyQuestionnaireOptionsDao.findById(qstCode);
                for (SurveyQuestionnaireOptions option : optionss) {
                    String content = option.getContent();
                    if (option.getQuestionCodeNext() != null) {
                        String next = option.getQuestionCodeNext();
                        SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
                        jsonObject.put("questionCodeNext", sq.getSort());
                    }
                }
                int maxNum = question.getMaxNum();
                int minNum = question.getMinNum();
                jsonObject.put("maxNum", maxNum);
                jsonObject.put("minNum", minNum);
                jsonObject.put("options", optionss);
                break;
            case 2:
                if (question.getQuestionCodeNext() != null) {
                    String next = question.getQuestionCodeNext();
                    SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
                    jsonObject.put("questionCodeNext", sq.getSort());
                }
                break;
        }
        jsonObject.put("qstCode", qstCode);
        jsonObject.put("qstTitle", qstTitle);
        jsonObject.put("isRequired", isRequired);
        jsonObject.put("type", type);
        jsonObject.put("sort", sorts);
//        题目数量是变量
        jsonObject.put("totalNum", total);
        return jsonObject;
    }
//==================================原来========================================
/*public JSONObject getQuestions(String id, Integer sort, Integer pageNo, Integer total, String nextCode) throws  Exception{
    JSONObject jsonObject = new JSONObject();
    SurveyQuestionnaire question = null;
    int sorts = 0;
    if (!StringUtils.isEmpty(nextCode)) {
//            跳题
//            question = surveyQuestionnaireDao.findByIdAndSort(id, Integer.parseInt(nextCode));
        question = surveyQuestionnaireDao.findByIdAndQstId(id,nextCode);
        sorts = question.getSort();
        total = total - (sorts -(sort + 1));
    } else {
//            不跳题
        if (total == null) {
            //      该套问卷总题目数
            total = surveyQuestionnaireDao.findTotalById(id);
        }
        question = surveyQuestionnaireDao.findTotalByIdAndSort(id, sort + 1);
        sorts = question.getSort();
    }
    String qstCode = question.getCode();
    String qstTitle = question.getTitle();
    int isRequired = question.getIsRequired();
    int type = question.getQuestionType();
//        int sorts = question.getSort();
    switch (type) {
        case 0:
            List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findById(qstCode);
            for (SurveyQuestionnaireOptions option : options) {
                String content = option.getContent();
//                        可构造集合,返回选项特定值
            }
            jsonObject.put("options", options);
            break;
        case 1:
            List<SurveyQuestionnaireOptions> optionss = surveyQuestionnaireOptionsDao.findById(qstCode);
            for (SurveyQuestionnaireOptions option : optionss) {
                String content = option.getContent();
            }
            int maxNum = question.getMaxNum();
            int minNum = question.getMinNum();
            jsonObject.put("maxNum", maxNum);
            jsonObject.put("minNum", minNum);
            jsonObject.put("options", optionss);
            break;
        case 2:
            String questionCodeNext = question.getQuestionCodeNext();
            jsonObject.put("questionCodeNext", questionCodeNext);
            break;
    }
    jsonObject.put("qstCode", qstCode);
    jsonObject.put("qstTitle", qstTitle);
    jsonObject.put("isRequired", isRequired);
    jsonObject.put("type", type);
    jsonObject.put("sort", sorts);
//        题目数量是变量
    jsonObject.put("totalNum", total);
    jsonObject.put("percent", (Math.round(((float) pageNo / total) * 100)) + "%");
    return jsonObject;
}*/
//    ======================================================================================
    public void saveAnswer(String patient, JSONObject jsonData) throws Exception {
        //解析json保存各种答案
        String surveyCode = jsonData.get("surveyCode").toString();
        Date createTime = new Date();
//        获取一维数组
        JSONArray questions = jsonData.getJSONArray("questions");
        for (int i = 0; i < questions.length(); i++) {
//            获取每一道题的信息
            JSONObject question = new JSONObject(questions.get(i).toString());
            String qstCode = question.get("qstCode").toString();
            int qstsort = Integer.parseInt(question.get("sort").toString());
            int type = Integer.parseInt(question.get("type").toString());
            String content = null;
            if (question.has("content")) {
                content = question.get("content").toString();
            }
            if (question.has("options")) {
//               获取每道题的所有选项
                JSONArray options = question.getJSONArray("options");
                for (int j = 0; j < options.length(); j++) {
                    JSONObject option = new JSONObject(options.get(j).toString());
                    String code = getCode();
                    String optionCode = option.get("optionCode").toString();
                    int optsort = Integer.parseInt(option.get("sort").toString());
                    String comment = null;
                    int haveComment = 0;
                    if (option.has("comment")) {
                        comment = option.get("comment").toString();
                        haveComment = 1;
                    }
//                 保存到选择题答案表
                    SurveyOptionAnswers optionAnswer = new SurveyOptionAnswers(code, patient, surveyCode, qstCode, optionCode, comment, type, createTime);
                    surveyOptionAnswersDao.save(optionAnswer);
/*//                选择题修改统计表数量
                    String statisticsCode = getCode();
                    String questionTitle = surveyQuestionnaireDao.findByIdAndQstId(surveyCode,qstCode).getTitle();
                    String optcontent = surveyQuestionnaireOptionsDao.findByRelationCode(surveyCode,qstCode,optionCode).getContent();
                    int amount =0;
                    ++amount;
                    SurveyStatistics statistics = new SurveyStatistics(statisticsCode, surveyCode, qstCode, questionTitle, optionCode, amount, optcontent, haveComment, type, qstsort, optsort);
                    surveyStatisticsDao.save(statistics);*/
                    surveyStatisticsDao.modifyAmount(surveyCode, qstCode, optionCode);
                }
            } else {
//               保存到问答题答案表
                String code = getCode();
                SurveyAnswers surveyAnswer = new SurveyAnswers(code, surveyCode, patient, qstCode, content, createTime);
                surveyAnswersDao.save(surveyAnswer);
//                问答题保存到统计表(只负责更改数量不负责创建)
                /*String statisticsCode = getCode();
                String questionTitle = surveyQuestionnaireDao.findByIdAndQstId(surveyCode,qstCode).getTitle();
                int amount = 0;
                ++amount;
                SurveyStatistics statistics = new SurveyStatistics(statisticsCode, surveyCode, qstCode, questionTitle, null, amount, null, null, type, qstsort, null);
                surveyStatisticsDao.save(statistics);*/
                surveyStatisticsDao.modifyAmount(surveyCode, qstCode);
            }
        }
    }
}

+ 30 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java

@ -185,9 +185,12 @@ public class PushMsgTask {
     *             type==7时:{"first":"消息主题","name":"就诊人名","date":"预约时间","doctorName":"医生名","orgName":"预约医院","remark":"消息备注"}
     *             type==9时:{"first":"消息主题","name":"患教标题","doctorName":"医生名","date":"发送时间","remark":"消息备注"}
     *             type==10时:{"first":"消息主题","name":"患教标题","doctorName":"医生名","date":"发送时间","remark":"消息备注"}
     *
     *             type==11时:{"first":"消息主题","name":"患教标题","doctorName":"医生名","date":"发送时间","remark":"消息备注"}
     * @return
     */
    private boolean sendWeixinMessage(String access_token, int type, String openid, String name, JSONObject json) {
//    private boolean sendWeixinMessage(String access_token, int type, String openid, String name, JSONObject json) {
    public boolean sendWeixinMessage(String access_token, int type, String openid, String name, JSONObject json) {
        try {
            if (StringUtils.isEmpty(openid)) {
                logger.error("send wechat message failed:openid is empty");
@ -433,7 +436,33 @@ public class PushMsgTask {
                keyword3.setColor("#000000");
                keyword3.setValue(json.getString("keyword3"));
                m.put("keyword3", keyword3);
            } else if (type == 11) {
                temp.setUrl(url + "/survey/html/survey_info.html?openid=" + openid + "&state=" + openid + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                temp.setTemplate_id(SystemConf.getInstance().getSystemProperties()
                        .getProperty("template_doctor_survey"));
                WechatTemplateData keyword1 = new WechatTemplateData();
                keyword1.setColor("#000000");
                keyword1.setValue(json.getString("keyword1"));
                m.put("keyword1", keyword1);
                WechatTemplateData keyword2 = new WechatTemplateData();
                keyword2.setColor("#000000");
                keyword2.setValue(json.getString("keyword2"));
                m.put("keyword2", keyword2);
                /*WechatTemplateData keyword3 = new WechatTemplateData();
                keyword3.setColor("#000000");
                keyword3.setValue(json.getString("keyword3"));
                m.put("keyword3", keyword3);
                WechatTemplateData keyword4 = new WechatTemplateData();
                keyword4.setColor("#000000");
                keyword4.setValue(json.getString("keyword4"));
                m.put("keyword4", keyword4);*/
            }
            temp.setData(m);
            ObjectMapper mapper = new ObjectMapper();
            String strJson = mapper.writeValueAsString(temp);

File diff suppressed because it is too large
+ 455 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/ManagerQuestionnaireController.java


+ 122 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/survey/PatientQuestionnaireController.java

@ -0,0 +1,122 @@
package com.yihu.wlyy.web.patient.survey;
import com.yihu.wlyy.service.survey.PatientQuestionnaireService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * Created by Reece on 2017/3/14.
 */
@Controller
@RequestMapping(value = "/patient/questionnaire")
@Api(description = "居民端问卷调查")
public class PatientQuestionnaireController extends BaseController {
    @Autowired
    private PatientQuestionnaireService patientQuestionnaireService;
    @RequestMapping(value = "getSurveySummary", method = RequestMethod.GET)
    @ApiOperation(value = "居民端获取问卷概述")
    @ResponseBody
    public String getSurveySummary(
            @ApiParam(value = "问卷编码")
            @RequestParam String id) {
        try {
            String patient = getUID();
            JSONObject jsonObject = patientQuestionnaireService.getSurveySummary(patient, id);
            return write(200, "查询成功!", "data", jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "查询失败!");
        }
    }
    @RequestMapping(value = "getQuestions", method = RequestMethod.GET)
    @ApiOperation(value = "按升序获取问卷的问题")
    @ResponseBody
    public String getQuestions(
            @ApiParam(value = "问卷编码")
            @RequestParam String id,
            @ApiParam(value = "当前问题的sort(初始为1)")
            @RequestParam Integer sort) {
        try {
            JSONObject jsonObject = patientQuestionnaireService.getQuestions(id, sort);
            return write(200, "查询成功!", "data", jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "查询失败!");
        }
    }
    @RequestMapping(value = "saveAnswer", method = RequestMethod.POST)
    @ApiOperation(value = "保存用户答案")
    @ResponseBody
    public String saveAnswer(
            @ApiParam(allowMultiple = true, defaultValue = "{\n" +
                    "    \"surveyCode\": \"问卷id\",\n" +
                    "    \"questions\": [\n" +
                    "        {\n" +
                    "            \"qstCode\": \"问题id\",\n" +
                    "            \"sort\": \"1\",\n" +
                    "            \"type\": \"0\",\n" +
                    "            \"options\": [\n" +
                    "                {\n" +
                    "                    \"optionCode\": \"选项id\",\n" +
                    "                    \"sort\": \"2\"\n" +
                    "                }\n" +
                    "            ]\n" +
                    "        },\n" +
                    "        {\n" +
                    "            \"qstCode\": \"问题id\",\n" +
                    "            \"type\": \"1\",\n" +
                    "            \"sort\": \"2\",\n" +
                    "            \"options\": [\n" +
                    "                {\n" +
                    "                    \"optionCode\": \"选项id\",\n" +
                    "                    \"sort\": \"1\",\n" +
                    "                    \"comment\": \"选项说明可为null\"\n" +
                    "                },\n" +
                    "                {\n" +
                    "                    \"optionCode\": \"选项id\",\n" +
                    "                    \"sort\": \"3\",\n" +
                    "                    \"comment\": \"选项说明可为null\"\n" +
                    "                },\n" +
                    "                {\n" +
                    "                    \"optionCode\": \"选项id\",\n" +
                    "                    \"sort\": \"5\",\n" +
                    "                    \"comment\": \"选项说明可为null\"\n" +
                    "                }\n" +
                    "            ]\n" +
                    "        },\n" +
                    "        {\n" +
                    "            \"qstCode\": \"问答题题目ID\",\n" +
                    "            \"content\": \"问答题答案\",\n" +
                    "            \"sort\": \"3\",\n" +
                    "            \"type\": \"2\"\n" +
                    "        }\n" +
                    "    ]\n" +
                    "}")
            @RequestParam String jsonData) {
        try {
            String patient = getUID();
            JSONObject json = new JSONObject(jsonData);
            patientQuestionnaireService.saveAnswer(patient, json);
            return write(200, "保存成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "保存失败!");
        }
    }
}

+ 6 - 0
patient-co-wlyy/src/main/resources/system.properties

@ -101,6 +101,8 @@ template_expenses_remind=BkTGJ8S18qZ3DfaptAXnZznAk8RJjx9v93og5vyO0bs
template_healthy_article=LA7erINJ0CSsG2G_ZCrgsDaX3krhsI4qg_NSHEyL_l4
#医生变更
template_doctor_change=TNIDMjduVKgVL4-k71umYLpHROvFB8K6mmm8aZC_EH8
#问卷调查
template_doctor_survey=OqQXrb-e43_TJpq_70_K_y6vYJgY5mpjFYY4c5RWFP4
#健康之路开放平台
yihu_OpenPlatform_url=http://ssotest.yihu.cn/OpenPlatform/cgiBin/1.0/
@ -161,6 +163,8 @@ fastdfs_file_url=http://172.19.103.54:80/
#template_healthy_article=aO_qqk5nAXaGXhsikPVLNelqzwlrp1LTPfIQ1qRMpxo
##医生变更
#template_doctor_change=V5h0F84t972kUzQvWy8qYrgdaYGJVj10pFeFVl19Nb8
#问卷调查
#template_doctor_survey=OqQXrb-e43_TJpq_70_K_y6vYJgY5mpjFYY4c5RWFP4
## FastDFS文件Http访问地址
#fastdfs_file_url=http://172.19.103.54:80/
@ -219,6 +223,8 @@ fastdfs_file_url=http://172.19.103.54:80/
#template_healthy_article=a5-ZGf-IUUULsuRNoHWQiBMU6pSYhLgPPqV67SjdLRo
##医生变更
#template_doctor_change=dtzSHImbPKfwcrjWlJEjAw3lGlvrLjsobSOE8g4adZA
#问卷调查
#template_doctor_survey=8ZWKJmoJ7VR7Uk4YS7aa0Z94QzCkxsyTW6R4CHhUJII
## FastDFS文件Http访问地址
#fastdfs_file_url=http://www.xmtyw.cn/