Przeglądaj źródła

问卷调查管理端,居民端

wujunjie 8 lat temu
rodzic
commit
cf66d5a2ce
18 zmienionych plików z 487 dodań i 175 usunięć
  1. 5 0
      patient-co-wlyy/pom.xml
  2. 12 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyTemplateOptions.java
  3. 12 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyTemplateQuestions.java
  4. 3 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyAnswersDao.java
  5. 4 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyLabelInfoDao.java
  6. 3 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyOptionAnswersDao.java
  7. 2 2
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyQuestionsDao.java
  8. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyStatisticsDao.java
  9. 8 2
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateOptionsDao.java
  10. 8 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateQuestionsDao.java
  11. 13 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplatesDao.java
  12. 266 52
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java
  13. 81 52
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/PatientQuestionnaireService.java
  14. 6 7
      patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java
  15. 57 10
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/ManagerQuestionnaireController.java
  16. 0 44
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/survey/PatientQuestionnaireController.java
  17. 4 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/process/WeiXinEventProcess.java
  18. 2 0
      patient-co-wlyy/src/main/resources/system.properties

+ 5 - 0
patient-co-wlyy/pom.xml

@ -489,6 +489,11 @@
            <artifactId>fastdfs_lib</artifactId>
            <version>1.25</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>RELEASE</version>
        </dependency>
    </dependencies>
    <dependencyManagement>

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

@ -25,6 +25,8 @@ public class SurveyTemplateOptions extends IdEntity implements Serializable {
    private String templateCode;
    //    下一题问题编码(逻辑跳转)
    private String questionCodeNext;
    //    下一题问题编码(逻辑跳转)
    private String questionSortNext;
    //    选项说明是否必填(0否 1是)
    private Integer isRequired;
    //    单题内排序
@ -35,18 +37,27 @@ public class SurveyTemplateOptions extends IdEntity implements Serializable {
    public SurveyTemplateOptions() {
    }
    public SurveyTemplateOptions(String code, Integer haveComment, String templateQuestionCode, String content, String templateCode, String questionCodeNext, Integer isRequired, Integer sort, Integer del) {
    public SurveyTemplateOptions(String code, Integer haveComment, String templateQuestionCode, String content, String templateCode, String questionCodeNext, String questionSortNext, 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.questionSortNext = questionSortNext;
        this.isRequired = isRequired;
        this.sort = sort;
        this.del = del;
    }
    public String getQuestionSortNext() {
        return questionSortNext;
    }
    public void setQuestionSortNext(String questionSortNext) {
        this.questionSortNext = questionSortNext;
    }
    public String getCode() {
        return code;
    }

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

@ -33,6 +33,8 @@ public class SurveyTemplateQuestions extends IdEntity implements Serializable{
    private Integer sort;
    //    下一题问题编码(问答题逻辑跳转)
    private String questionCodeNext;
    //    下一题问题编码(问答题逻辑跳转)
    private String questionSortNext;
    //    删除标志(1正常,0删除)
    private Integer del;
//创建时间
@ -43,7 +45,7 @@ public class SurveyTemplateQuestions extends IdEntity implements Serializable{
    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) {
    public SurveyTemplateQuestions(String code, String title, String questionComment, Integer questionType, String templateCode, Integer isRequired, Integer minNum, Integer maxNum, Integer sort, String questionCodeNext, String questionSortNext, Integer del, Date createTime, Date updateTime) {
        this.code = code;
        this.title = title;
        this.questionComment = questionComment;
@ -54,11 +56,20 @@ public class SurveyTemplateQuestions extends IdEntity implements Serializable{
        this.maxNum = maxNum;
        this.sort = sort;
        this.questionCodeNext = questionCodeNext;
        this.questionSortNext = questionSortNext;
        this.del = del;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }
    public String getQuestionSortNext() {
        return questionSortNext;
    }
    public void setQuestionSortNext(String questionSortNext) {
        this.questionSortNext = questionSortNext;
    }
    public String getCode() {
        return code;
    }

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

@ -17,4 +17,7 @@ public interface SurveyAnswersDao extends PagingAndSortingRepository<SurveyAnswe
    @Query("select  count(t.surveyCode) from SurveyAnswers t where t.content is not null and t.surveyCode=?1 and t.questionCode=?2 ")
    int findByRelationCode(String id, String questionId);
    @Query("select  count(distinct t.patient) from SurveyAnswers t where t.content is not null and t.surveyCode=?1 and t.questionCode=?2 ")
    int countByRelationCode(String surveyCode, String questionId);
}

+ 4 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyLabelInfoDao.java

@ -23,8 +23,11 @@ public interface SurveyLabelInfoDao extends PagingAndSortingRepository<SurveyLab
    @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 ")
    @Query("select t from SurveyLabelInfo s,SurveyTemplates t where t.del = 1 and s.relationCode = t.code and s.useType=0 and s.label = ?1 ")
    List<SurveyTemplates> findByLabel(int label);
    @Modifying
    @Query("update SurveyLabelInfo s set s.label=?2 where s.relationCode = ?1 ")
    void modifyLabel(String code,int label);
}

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

@ -17,4 +17,7 @@ public interface SurveyOptionAnswersDao extends PagingAndSortingRepository<Surve
    @Query("select  count(t.patient) from SurveyOptionAnswers t where t.optionComment is not null and t.surveyCode =?1 and t.questionCode=?2 and t.optionsCode=?3 ")
    int findByRelationCode(String id, String questionId, String optionId);
    @Query("select  count(distinct  t.patient) from SurveyOptionAnswers t where t.surveyCode =?1 and t.questionCode=?2 ")
    int countByRelationCode(String id, String questionId);
}

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

@ -11,9 +11,9 @@ 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 ")
    @Query("select  t from SurveyQuestions t where t.title like ?1 and t.del= 1 ")
    List<SurveyQuestions> findByTitle(String title, Pageable request);
    @Query("select  t from SurveyQuestions t ")
    @Query("select  t from SurveyQuestions t where t.del = 1 ")
    List<SurveyQuestions> findByTitle(Pageable request);
}

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

@ -17,7 +17,7 @@ public interface SurveyStatisticsDao extends PagingAndSortingRepository<SurveySt
    @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 ")
    @Query("select distinct 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 ")

+ 8 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateOptionsDao.java

@ -1,6 +1,7 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyTemplateOptions;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
@ -9,7 +10,12 @@ import java.util.List;
/**
 * Created by Reece on 2017/3/10.
 */
public interface SurveyTemplateOptionsDao extends PagingAndSortingRepository<SurveyTemplateOptions,Long>{
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);
    List<SurveyTemplateOptions> findById(String qstcode, String tempCode);
    @Modifying
    @Query("update SurveyTemplateOptions t set t.haveComment=?4,t.content=?5," +
            "t.questionCodeNext=?6,t.isRequired=?7,t.sort=?8 where  t.templateQuestionCode = ?1 and t.templateCode = ?2 and t.code=?3")
    void modifyOption(String tempCode, String qstcode, String optcode, int haveCommment, String content, String nextCode, int isRequired, int sort);
}

+ 8 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateQuestionsDao.java

@ -1,6 +1,7 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyTemplateQuestions;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
@ -14,5 +15,11 @@ public interface SurveyTemplateQuestionsDao extends PagingAndSortingRepository<S
    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);
    SurveyTemplateQuestions findById(String tempCode, String qstCode);
//String code, String title, String questionComment, Integer questionType, String templateCode, Integer isRequired, Integer minNum, Integer maxNum,
// Integer sort, String questionCodeNext, String questionSortNext, Integer del, Date createTime, Date updateTime
    @Modifying
    @Query("update SurveyTemplateQuestions t set t.title=?3,t.questionComment=?4,t.questionType=?5," +
            "t.isRequired=?6,t.minNum=?7,t.maxNum=?8,t.sort=?9,t.questionCodeNext=?10,t.questionSortNext=?11 where t.templateCode = ?1 and t.code = ?2 ")
    void modifyQuestion(String tempCode, String qstCode,String qstTitle, String qstComment, int qstType, int isRequired,int minNum,int  maxNum, int sort,String next);
}

+ 13 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplatesDao.java

@ -2,22 +2,34 @@ 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.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
/**
 * Created by Reece on 2017/3/9.
 */
public interface SurveyTemplatesDao extends PagingAndSortingRepository<SurveyTemplates, Long> {
    @Query("select  t from SurveyTemplates t")
    @Query("select  t from SurveyTemplates t where t.del = 1 ")
    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 count(t.id)  from SurveyTemplates t where t.title = ?1 ")
    int distinctByTitle(String title);
    @Query("select count(t.id)  from SurveyTemplates t where t.title like ?1 ")
    int distinctLikeTitle(String title);
    @Query("select  t from SurveyTemplates t where t.code = ?1 ")
    SurveyTemplates findById(String code);
    @Modifying
    @Query("update SurveyTemplates t set t.title=?2 ,t.templateComment=?3 where t.code=?1 ")
    void modifyTemplate(String templateCode, String title, String templateComment);
}

+ 266 - 52
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java

@ -9,11 +9,13 @@ import com.yihu.wlyy.entity.wechat.WechatTemplate;
import com.yihu.wlyy.entity.wechat.WechatTemplateData;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.repository.doctor.*;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.system.SystemDictService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.HttpUtil;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.web.doctor.survey.ManagerQuestionnaireController;
import com.yihu.wlyy.wechat.util.WeiXinTempMsgSendUtils;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
@ -81,9 +83,12 @@ public class ManagerQuestionnaireService extends BaseService {
    private SurveyDimensionDetailDao surveyDimensionDetailDao;
    @Autowired
    private DoctorDao doctorDao;
    @Autowired
    private PatientDao patientDao;
    public String createSurvey(String doctor, String accessToken, JSONObject jsonStr) throws Exception {
    public String createSurvey(String doctor, JSONObject jsonStr, String accessToken) throws Exception {
        System.out.println("=============>"+jsonStr);
//        问卷信息
        String surveyCode = getCode();
        String surveyName = jsonStr.getString("surveyName");
@ -105,13 +110,12 @@ public class ManagerQuestionnaireService extends BaseService {
        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  AND p.`openid`!=''  ";
        /*String str = "SELECT DISTINCT t.patient  " +
                "FROM `wlyy_sign_patient_label_info` t,wlyy_patient p,`wlyy_sign_family` f  " +
                "WHERE t.`patient` =  p.`code`  AND f.`patient`=t.`patient` AND f.`status` IN (1,2,3) AND p.`openid` IS NOT NULL AND p.`openid`!='' ";*/
        //      保存到维度详情表(不限不保存)  维度表(1性别 2疾病类型 3服务类型 4健康状况)
        if (sex != 0) {
            str += "AND(p.sex=" + sex + ")";
//            str += "AND(p.sex=" + sex + ")";
            String dimensionCode = surveyDimensionDao.findByName("性别");
            String dimensionDetailCode = getCode();
            SurveyDimensionDetail surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, sex == 1 ? "男" : "女", sex, "性别", 1, surveyCode);
@ -120,14 +124,14 @@ public class ManagerQuestionnaireService extends BaseService {
            SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
            surveyFilterDao.save(surveyFilter);
        }
        String ser = "";
        String servi = "";
//        String ser = "";
//        String servi = "";
        for (Object serv : service) {
            if ("0".equals(serv.toString())) {
                ser += ",";
//                ser += ",";
                break;
            } else {
                ser += serv.toString() + ",";
//                ser += serv.toString() + ",";
                //                ===================================
                String dimensionCode = surveyDimensionDao.findByName("服务类型");
                String dimensionDetailCode = getCode();
@ -151,18 +155,18 @@ public class ManagerQuestionnaireService extends BaseService {
                surveyFilterDao.save(surveyFilter);
            }
        }
        ser = ser.substring(0, ser.length() - 1);
        /*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 = "";
        }*/
//        String heal = "";
//        String healt = "";
        for (Object health : healthCondition) {
            if ("0".equals(health.toString())) {
                heal += ",";
//                heal += ",";
                break;
            } else {
                heal += health.toString() + ",";
//                heal += health.toString() + ",";
                String dimensionCode = surveyDimensionDao.findByName("健康状况");
                String dimensionDetailCode = getCode();
                String surveyFilterCode = getCode();
@ -189,18 +193,18 @@ public class ManagerQuestionnaireService extends BaseService {
            }
        }
        heal = heal.substring(0, heal.length() - 1);
       /* 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 = "";
        }*/
//        String dise = "";
//        String diseas = "";
        for (Object disea : disease) {
            if ("0".equals(disea.toString())) {
                dise += ",";
//                dise += ",";
                break;
            } else {
                dise += disea.toString() + ",";
//                dise += disea.toString() + ",";
//                ================================================================
                String dimensionCode = surveyDimensionDao.findByName("疾病类型");
                String dimensionDetailCode = getCode();
@ -220,7 +224,7 @@ public class ManagerQuestionnaireService extends BaseService {
                surveyFilterDao.save(surveyFilter);
            }
        }
        dise = dise.substring(0, dise.length() - 1);
        /*dise = dise.substring(0, dise.length() - 1);
        if (dise.length() != 0) {
            diseas = "(t.`label_type`=3 AND t.`label`IN(" + dise + "))";
        }
@ -238,30 +242,43 @@ public class ManagerQuestionnaireService extends BaseService {
            str += " AND " + healt;
        } else if (servi.length() == 0 & healt.length() == 0 & diseas.length() != 0) {
            str += " AND " + diseas;
        }
        }*/
       /* System.out.println("*****************str***********************" + str);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        sdf.format(new Date());
        String jsonData = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
        JSONObject json = new JSONObject(jsonData);
        List<Map<String, Object>> patients = jdbcTemplate.queryForList(str);
        int amount = patients.size();
        for (Map<String, Object> patient : patients) {
            String code = patient.get("patient").toString();
        json.put("survey_id", surveyCode);*/
//        List<Map<String, Object>> patients = jdbcTemplate.queryForList(str);
//        Map<String, Object> map = jdbcTemplate.queryForMap(str);
//        List<String> codes = jdbcTemplate.queryForList(str, String.class);
        List<String> codes = getCount(surveyTarget.toString());
        int amount = codes.size();
        for (String code : codes) {
//            String code = patient.get("patient").toString();
            SurveyUser user = new SurveyUser(surveyCode, code, 0, 1, new Date(), new Date());
            surveyUserDao.save(user);
//            发送居民模板 send=1发送
            if ("1".equals(send)) {
           /* if ("1".equals(send)) {
                String name = patient.get("name").toString();
                String openId = patient.get("openid").toString();
//                String openId = "orrOgwATDaljVunlAq_Tdx3imhYg";
//            String openId = "o7NFZw1QM4YR1O19mLjwfX1Hh11A";
                json.put("keyword2", sdf.format(new Date()));
                json.put("toUser", code);
                json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                System.out.println("*************************" + json + "******************");
                System.out.println("********name*********************" + name + "openId" + openId);
                PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
            }
            }*/
        }
        //            发送居民模板 send=1发送
//        ====================================================
        if ("1".equals(send)) {
            SendMessage sendMessage = new SendMessage(surveyCode, codes, accessToken);
            new Thread(sendMessage).start();
        }
//       =====================================================
//     获取标签数组
        JSONArray lables = jsonStr.getJSONArray("label");
//        标签保存到wlyy_survey_label_info
@ -625,6 +642,8 @@ public class ManagerQuestionnaireService extends BaseService {
                if (option.getQuestionCodeNext() != null) {
                    String next = option.getQuestionCodeNext();
                    SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
                    System.out.println("=============sq============== " + sq);
                    System.out.println("=============next============== " + next);
                    opt.put("nextQuestion", sq.getSort());
                }
                opt.put("content", conetent);
@ -679,11 +698,21 @@ public class ManagerQuestionnaireService extends BaseService {
            String qstcode = question.getCode();
            String title = question.getTitle();
            int type = question.getQuestionType();
            int amount = 0;
//            有效答了该题的人数
            /*int amount = 0;
            int[] sum = surveyStatisticsDao.findByIdAndQstId(id, qstcode);
            for (int count : sum) {
                amount += count;
            }*/
            int amount = 0;
            if (type == 2) {
//          问卷答案表有效(去重)答题人数
                amount = surveyAnswersDao.countByRelationCode(id, qstcode);
            } else {
//          问卷选项答案表有效(去重)答题人数
                amount = surveyOptionAnswersDao.countByRelationCode(id, qstcode);
            }
            qst.put("amount", amount);
            qst.put("qstcode", qstcode);
            qst.put("title", title);
@ -817,7 +846,6 @@ public class ManagerQuestionnaireService extends BaseService {
                String comment = question.getQuestionComment();
                map.put("comment", comment);
            }
            int isRequired = question.getIsRequired();
            int questionType = question.getQuestionType();
            if (questionType != 2) {
@ -837,7 +865,6 @@ public class ManagerQuestionnaireService extends BaseService {
            }
            map.put("code", code);
            map.put("title", qstTitle);
            map.put("isRequired", isRequired);
            map.put("questionType", questionType);
            list.add(map);
@ -857,7 +884,7 @@ public class ManagerQuestionnaireService extends BaseService {
        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 + "%'";
            String cql = "select  distinct t.* from wlyy_survey_templates t where t.del = 1 and t.title like '%" + name + "%' ";
            List<Map<String, Object>> surveyTemp = jdbcTemplate.queryForList(cql);
            for (Map<String, Object> temp : surveyTemp) {
                String create = temp.get("create_time").toString();
@ -962,6 +989,7 @@ public class ManagerQuestionnaireService extends BaseService {
                    " FROM wlyy_survey_templates t,wlyy_survey_label_info s  " +
                    " WHERE t.code = s.relation_code  " +
                    " AND s.use_type= 0 " +
                    " AND t.del = 1 " +
                    " AND s.label IN (" + labels +
                    ")  " +
                    " ORDER by t.create_time DESC " +
@ -1071,6 +1099,7 @@ public class ManagerQuestionnaireService extends BaseService {
            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) {
@ -1082,7 +1111,8 @@ public class ManagerQuestionnaireService extends BaseService {
                if (!StringUtils.isEmpty(option.getQuestionCodeNext())) {
                    String next = option.getQuestionCodeNext();
                    SurveyTemplateQuestions tempQst = surveyTemplateQuestionsDao.findById(id, next);
                    opt.put("nextQuestion", tempQst.getSort());
//                    跳题结束怎么办?
                    opt.put("nextQuestion", tempQst == null ? 0 : tempQst.getSort());
                }
                opt.put("isRequired", required);
@ -1098,11 +1128,16 @@ public class ManagerQuestionnaireService extends BaseService {
            question.put("type", type);
            question.put("options", optList);
            question.put("sort", sort);
            question.put("maxNum", questionnair.getMaxNum());
            question.put("minNum", questionnair.getMinNum());
            if (!StringUtils.isEmpty(questionnair.getQuestionCodeNext())) {
                String next = questionnair.getQuestionCodeNext();
                SurveyTemplateQuestions tempQst = surveyTemplateQuestionsDao.findById(id, next);
                question.put("nextQuestion", tempQst.getSort());
                question.put("nextQuestion", tempQst == null ? 0 : tempQst.getSort());
            }
            questions.add(question);
        }
@ -1113,10 +1148,11 @@ public class ManagerQuestionnaireService extends BaseService {
        jsonObject.put("comment", tempComment);
        jsonObject.put("label", labels);
        jsonObject.put("questions", questions);
        return jsonObject;
    }
    public void savaSurveyAsTemplate(String code) throws Exception {
    public int savaSurveyAsTemplate(String code) throws Exception {
        Survey survey = surveyDao.findById(code);
        String tempCode = getCode();
        String title = survey.getTitle();
@ -1124,6 +1160,12 @@ public class ManagerQuestionnaireService extends BaseService {
        String creater = survey.getCreater();
        Date createTime = survey.getCreateTime();
        Date updateTime = survey.getUpdateTime();
        //        查询问卷标题重复情况
        int number = surveyTemplatesDao.distinctByTitle(title);
        if (number!=0){
            int likeNum = surveyTemplatesDao.distinctLikeTitle(title+"%");
          return  likeNum;
        }
        SurveyTemplates surveyTemplates = new SurveyTemplates(tempCode, title, templateComment, creater, 1, createTime, updateTime);
//        保存模板信息
        surveyTemplatesDao.save(surveyTemplates);
@ -1147,14 +1189,14 @@ public class ManagerQuestionnaireService extends BaseService {
            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);
            SurveyTemplateQuestions surveyTemplateQuestions = new SurveyTemplateQuestions(qstCode, qstTitle, qstComment, qstType, tempCode, isRequired, minNum, maxNum, sort, next, null, de, createTiem, updateTiem);
            //            保存问题到模板问题表
            surveyTemplateQuestionsDao.save(surveyTemplateQuestions);
            if (qstType != 2) {
                List<SurveyQuestionnaireOptions> surveyQuestionnaireOptions = surveyQuestionnaireOptionsDao.findByIdAndQstCode(code, question.getCode());
                for (SurveyQuestionnaireOptions option : surveyQuestionnaireOptions) {
                    SurveyTemplateOptions surveyTemplateOptions = new SurveyTemplateOptions(getCode(), option.getHaveComment(), qstCode, question.getTitle(),
                            tempCode, question.getQuestionCodeNext(), question.getIsRequired(), question.getSort(), option.getDel());
                    SurveyTemplateOptions surveyTemplateOptions = new SurveyTemplateOptions(getCode(), option.getHaveComment(), qstCode, option.getContent(),
                            tempCode, option.getQuestionCodeNext(), null, option.getIsRequired(), option.getSort(), option.getDel());
                    //         保存到模板选项表   survey_template_options
                    surveyTemplateOptionsDao.save(surveyTemplateOptions);
                }
@ -1163,6 +1205,61 @@ public class ManagerQuestionnaireService extends BaseService {
        }
        return 0;
    }
    public int modifyTemplate(String code, String templateCode) throws Exception {
        Survey survey = surveyDao.findById(code);
        String title = survey.getTitle();
        String templateComment = survey.getSurveyComment();
//        查询问卷标题重复情况
        int number = surveyTemplatesDao.distinctByTitle(title);
        if (number!=0){
            int likeNum = surveyTemplatesDao.distinctLikeTitle(title+"%");
            return  likeNum;
        }
//        SurveyTemplates surveyTemplates = new SurveyTemplates(templateCode, title, templateComment, creater, 1, creater, updateTime);
//        更改模板信息
//        surveyTemplatesDao.save(surveyTemplates);
        surveyTemplatesDao.modifyTemplate(templateCode, title, templateComment);
        List<SurveyLabelInfo> surveyLabelInfos = surveyLabelInfoDao.findByCode(code);
        for (SurveyLabelInfo surveyLabelInfo : surveyLabelInfos) {
//        更改模板标签信息
//            SurveyLabelInfo surveyLabelInfo1 = new SurveyLabelInfo(getCode(), templateCode, 0, surveyLabelInfo.getLabel());
//            surveyLabelInfoDao.save(surveyLabelInfo1);
            surveyLabelInfoDao.modifyLabel(templateCode, surveyLabelInfo.getLabel());
        }
        List<SurveyQuestionnaire> surveyQuestionnaires = surveyQuestionnaireDao.findById(survey.getCode());
        for (SurveyQuestionnaire question : surveyQuestionnaires) {
            String qstCode = getCode();
            String qstTitle = question.getTitle();
            String qstComment = question.getQuestionComment();
            Integer qstType = question.getQuestionType();
            Integer isRequired = question.getIsRequired();
            Integer minNum = question.getMinNum();
            Integer maxNum = question.getMaxNum();
//            Date createTiem = question.getCreateTime();
//            Date updateTiem = question.getUpdateTime();
            Integer sort = question.getSort();
//            Integer de = question.getDel();
            String next = question.getQuestionCodeNext();
//            SurveyTemplateQuestions surveyTemplateQuestions = new SurveyTemplateQuestions(qstCode, qstTitle, qstComment, qstType, templateCode, isRequired, minNum, maxNum, sort, next, null, de, createTiem, updateTiem);
            //            更改问题到模板问题表
//            surveyTemplateQuestionsDao.save(surveyTemplateQuestions);
            surveyTemplateQuestionsDao.modifyQuestion(templateCode, qstCode, qstTitle, qstComment, qstType, isRequired, minNum, maxNum, sort, next);
            if (qstType != 2) {
                List<SurveyQuestionnaireOptions> surveyQuestionnaireOptions = surveyQuestionnaireOptionsDao.findByIdAndQstCode(code, question.getCode());
                for (SurveyQuestionnaireOptions option : surveyQuestionnaireOptions) {
                    SurveyTemplateOptions surveyTemplateOptions = new SurveyTemplateOptions(getCode(), option.getHaveComment(), qstCode, option.getContent(),
                            templateCode, option.getQuestionCodeNext(), null, option.getIsRequired(), option.getSort(), option.getDel());
                    //         更改到模板选项表   survey_template_options
//                    surveyTemplateOptionsDao.save(surveyTemplateOptions);
                    surveyTemplateOptionsDao.modifyOption(templateCode, qstCode, option.getCode(),
                            option.getHaveComment(), option.getContent(), option.getQuestionCodeNext(), option.getIsRequired(), option.getSort());
                }
            }
        }
        return 0;
    }
    public Map getFilter() {
@ -1208,16 +1305,95 @@ public class ManagerQuestionnaireService extends BaseService {
    }
    public int getAmount(String json) {
        return getCount(json).size();
    }
    public List<String> getCount(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();
        String str = "SELECT s.patient  FROM ( " +
                "SELECT t.patient,GROUP_CONCAT(t.label_name) label_name FROM wlyy_sign_patient_label_info t  " +
                "WHERE t.patient IN (SELECT a.patient FROM wlyy_sign_family a WHERE a.status IN(1,2,3)) AND t.patient IN (SELECT b.`code` FROM wlyy_patient b WHERE b.`openid` IS NOT NULL AND b.`openid`!='' ";
        if (!"0".equals(sex)) {
            str += "AND(p.sex=" + sex + ")";
            str += " AND b.sex= " + sex + " ) GROUP BY t.patient ) s WHERE 1=1 ";
        } else {
            str += " ) GROUP BY t.patient ) s WHERE 1=1 ";
        }
        JSONArray service = jsonObject.getJSONArray("service");
        String ser = "";
        service:
        for (Object serv : service) {
            String type = serv.toString();
            switch (type) {
//                AND (s.label_name LIKE '%普通人群%'OR s.label_name LIKE '%慢病人群%'OR s.label_name LIKE '%65岁以上人群%')
                case "0":
                    break service;
                case "1":
                    ser += " s.label_name LIKE '%普通人群%' ";
                    break;
                case "2":
                    ser += " s.label_name LIKE '%慢病人群%' ";
                    break;
                case "3":
                    ser += " s.label_name LIKE '%65岁以上人群%' ";
                    break;
            }
            ser += " OR ";
        }
        if (!StringUtils.isEmpty(ser)) {
            str += " AND ( " + ser.substring(0, ser.lastIndexOf("OR")) + " ) ";
        }
        JSONArray healthCondition = jsonObject.getJSONArray("healthCondition");
        String heal = "";
        health:
        for (Object health : healthCondition) {
            String type = health.toString();
            switch (type) {
//                AND (s.label_name LIKE '%普通人群%'OR s.label_name LIKE '%慢病人群%'OR s.label_name LIKE '%65岁以上人群%')
                case "0":
                    break health;
                case "1":
                    heal += " s.label_name LIKE '%健康人群%' ";
                    break;
                case "2":
                    heal += " s.label_name LIKE '%患病人群%' ";
                    break;
                case "3":
                    heal += " s.label_name LIKE '%高危人群%' ";
                    break;
                case "4":
                    heal += " s.label_name LIKE '%恢复期人群%' ";
                    break;
            }
            heal += " OR ";
        }
        if (!StringUtils.isEmpty(heal)) {
            str += " AND ( " + heal.substring(0, heal.lastIndexOf("OR")) + " ) ";
        }
        JSONArray disease = jsonObject.getJSONArray("disease");
        String dis = "";
        disea:
        for (Object disea : disease) {
            String type = disea.toString();
            switch (type) {
//                AND (s.label_name LIKE '%普通人群%'OR s.label_name LIKE '%慢病人群%'OR s.label_name LIKE '%65岁以上人群%')
                case "0":
                    break disea;
                case "1":
                    dis += " s.label_name LIKE '%糖尿病%' ";
                    break;
                case "2":
                    dis += " s.label_name LIKE '%高血压%' ";
                    break;
            }
            dis += " OR ";
        }
        if (!StringUtils.isEmpty(dis)) {
            str += " AND ( " + dis.substring(0, dis.lastIndexOf("OR")) + " ) ";
        }
      /*  if (Integer.parseInt(sex) != 0) {
            str += "and t.sex = " + sex;
        }
        JSONArray service = jsonObject.getJSONArray("service");
        String ser = "";
@ -1278,10 +1454,48 @@ public class ManagerQuestionnaireService extends BaseService {
            str += "AND " + healt;
        } else if (servi.length() == 0 & healt.length() == 0 & diseas.length() != 0) {
            str += "AND " + diseas;
        }*/
//        Map<String, Object> patients = jdbcTemplate.queryForMap(str);
        List<String> patients = jdbcTemplate.queryForList(str, String.class);
        return patients;
    }
    /**
     * 线程发送模板消息
     */
    class SendMessage implements Runnable {
        private String code;
        private List<String> codes;
        private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        private String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
        private String accessToken;
        private JSONObject json = new JSONObject(str);
        public SendMessage(String code, List<String> codes, String accessToken) {
            this.code = code;
            this.codes = codes;
            this.accessToken = accessToken;
        }
        @Override
        public void run() {
            synchronized (this) {
                json.put("survey_id", code);
                for (String cod : codes) {
                    Patient p = patientDao.findByCode(cod);
                    String name = p.getName();
                    String openId = p.getOpenid();
                /*String name = "吴俊杰";
                String openId = "o7NFZw1QM4YR1O19mLjwfX1Hh11A";
                cod = "jojojojpkpokpko";*/
                    json.put("keyword2", sdf.format(new Date()));
                    json.put("toUser", cod);
                    json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                    PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
                }
            }
        }
        Map<String, Object> patients = jdbcTemplate.queryForMap(str);
        int amount = Integer.parseInt(patients.get("amount").toString());
        return amount;
    }
}

+ 81 - 52
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/PatientQuestionnaireService.java

@ -78,42 +78,81 @@ public class PatientQuestionnaireService extends BaseService {
        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();
        if (!StringUtils.isEmpty(question.getQuestionComment())) {
            jsonObject.put("comment", question.getQuestionComment());
        }
        int type = question.getQuestionType();
//        int sorts = question.getSort();
        switch (type) {
            case 0:
                List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findByIdAndQstCode(id, qstCode);
                List list = new ArrayList();
                for (SurveyQuestionnaireOptions option : options) {
                    String content = option.getContent();
//                        可构造集合,返回选项特定值
                    Map<String, Object> map = new HashMap<>();
                    String content = option.getContent();
                    int optSort = option.getSort();
                    int required = option.getIsRequired();
                    String surCod = option.getSurveyCode();
                    int del = option.getDel();
                    int havaComment = option.getHaveComment();
                    String code = option.getCode();
                    String questionCode = option.getQuestionnaireCode();
                    long optid = option.getId();
                    map.put("content", content);
                    map.put("isRequired", required);
                    map.put("code", code);
                    map.put("del", del);
                    map.put("sort", optSort);
                    map.put("surveyCode", surCod);
                    map.put("havaComment", havaComment);
                    map.put("questionnaireCode", questionCode);
                    map.put("id", optid);
                    if (option.getQuestionCodeNext() != null) {
                        String next = option.getQuestionCodeNext();
                        SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
                        jsonObject.put("questionCodeNext", sq.getSort());
                        map.put("nextQuestion", sq.getSort());
                    }
                    list.add(map);
                }
                jsonObject.put("options", options);
                jsonObject.put("options", list);
                break;
            case 1:
                List<SurveyQuestionnaireOptions> optionss = surveyQuestionnaireOptionsDao.findByIdAndQstCode(id, qstCode);
                List lis = new ArrayList();
                for (SurveyQuestionnaireOptions option : optionss) {
//                        可构造集合,返回选项特定值
                    Map<String, Object> map = new HashMap<>();
                    String content = option.getContent();
                    int optSort = option.getSort();
                    int required = option.getIsRequired();
                    String surCod = option.getSurveyCode();
                    int del = option.getDel();
                    int havaComment = option.getHaveComment();
                    String code = option.getCode();
                    String questionCode = option.getQuestionnaireCode();
                    long optid = option.getId();
                    map.put("content", content);
                    map.put("isRequired", required);
                    map.put("code", code);
                    map.put("del", del);
                    map.put("sort", optSort);
                    map.put("surveyCode", surCod);
                    map.put("havaComment", havaComment);
                    map.put("questionnaireCode", questionCode);
                    map.put("id", optid);
                    if (option.getQuestionCodeNext() != null) {
                        String next = option.getQuestionCodeNext();
                        SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
                        jsonObject.put("questionCodeNext", sq.getSort());
                        map.put("nextQuestion", sq.getSort());
                    }
                    lis.add(map);
                }
                jsonObject.put("options", lis);
                Integer maxNum = question.getMaxNum();
                Integer minNum = question.getMinNum();
                jsonObject.put("maxNum", maxNum);
@ -124,7 +163,7 @@ public class PatientQuestionnaireService extends BaseService {
                if (question.getQuestionCodeNext() != null) {
                    String next = question.getQuestionCodeNext();
                    SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
                    jsonObject.put("questionCodeNext", sq.getSort());
                    jsonObject.put("nextQuestion", sq.getSort());
                }
                break;
        }
@ -203,6 +242,7 @@ public class PatientQuestionnaireService extends BaseService {
//    ======================================================================================
    public void saveAnswer(String patient, JSONObject jsonData) throws Exception {
        System.out.println("********jsonData********* " + jsonData);
        //解析json保存各种答案
        String surveyCode = jsonData.get("surveyCode").toString();
        Date createTime = new Date();
@ -215,56 +255,45 @@ public class PatientQuestionnaireService extends BaseService {
            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")) {
            if (type != 2) {
                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;
                    }
                    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);
                        SurveyOptionAnswers optionAnswer = new SurveyOptionAnswers(code, patient, surveyCode, qstCode, optionCode, comment, type, createTime);
                        surveyOptionAnswersDao.save(optionAnswer);
//                选择题修改统计表数量
                        surveyStatisticsDao.modifyAmount(surveyCode, qstCode, optionCode);
                    }
                }
            } else {
//               保存到问答题答案表
                String code = getCode();
                SurveyAnswers surveyAnswer = new SurveyAnswers(code, surveyCode, patient, qstCode, content, createTime);
                surveyAnswersDao.save(surveyAnswer);
                String content = question.get("content").toString();
                if (!StringUtils.isEmpty(content)) {
//                    保存到问答题答案表
                    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);
                    surveyStatisticsDao.modifyAmount(surveyCode, qstCode);
                }
            }
        }
//        更改调查对象表答题状态为已答
        surveyUserDao.modifyStatus(surveyCode,patient);
        surveyUserDao.modifyStatus(surveyCode, patient);
    }
}

+ 6 - 7
patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java

@ -200,13 +200,13 @@ public class PushMsgTask {
                String token_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token;
                String params = typeMsg(type, openid, name, json);
                if (params == "") {
                    logger.error("参数错误!");
                    logger.error("参数错误!error");
                    return false;
                }
                String result = HttpUtil.sendPost(token_url, params);
                JSONObject jsonResult = new JSONObject(result);
                if (Integer.parseInt(jsonResult.get("errcode").toString()) == 0) {
                    logger.info("微信信息推送成功!");
                    logger.info("微信信息推送成功!success");
                    return true;
                } else {
                    logger.error("错误编码:" + jsonResult.get("errcode").toString() + "  错误提示:" + jsonResult.get("errmsg").toString());
@ -335,7 +335,7 @@ public class PushMsgTask {
                keyword4.setValue(json.getString("date"));
                m.put("keyword4", keyword4);
            } else if (type == 6) {
                temp.setUrl(url + "wdyy/html/detail-appointment.html?openid=" + openid+ "&orgCode=" + json.get("orgCode")  + "&id=" + json.getString("id") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                temp.setUrl(url + "wdyy/html/detail-appointment.html?openid=" + openid + "&orgCode=" + json.get("orgCode") + "&id=" + json.getString("id") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                temp_id = SystemConf.getInstance().getSystemProperties().getProperty("template_appoint_success");
                temp.setTemplate_id(temp_id);
                WechatTemplateData keyword1 = new WechatTemplateData();
@ -438,12 +438,11 @@ public class PushMsgTask {
                m.put("keyword3", keyword3);
            } else if (type == 11) {
                temp.setUrl(url + "survey/html/survey_info.html?openid=" + openid + "&state=" + openid + "&survey_id=" + json.getString("survey_id")+"&toUser=" + json.getString("toUser") + "&toName=" + name );
                temp.setUrl(url + "survey/html/survey_info.html?openid=" + openid + "&state=" + openid + "&survey_id=" + json.getString("survey_id") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
//                temp.setTemplate_id("fgYiMntj1amEkE8_GLUPmAIyssUAroJrNSHqvydt-PQ");
                temp.setTemplate_id(SystemConf.getInstance().getSystemProperties()
                        .getProperty("template_doctor_survey"));
                System.out.println("templateID=====>"+SystemConf.getInstance().getSystemProperties()
                        .getProperty("template_doctor_survey"));
                WechatTemplateData keyword1 = new WechatTemplateData();
                keyword1.setColor("#000000");
                keyword1.setValue(json.getString("keyword1"));
@ -459,7 +458,7 @@ public class PushMsgTask {
            temp.setData(m);
            ObjectMapper mapper = new ObjectMapper();
            String strJson = mapper.writeValueAsString(temp);
            System.out.println("strJson=====>strJson " + strJson);
//            System.out.println("strJson=====>strJson " + strJson);
            return strJson;
        } catch (Exception e) {
            e.printStackTrace();

+ 57 - 10
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/ManagerQuestionnaireController.java

@ -47,8 +47,6 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
    private PatientDao patientDao;
    @Autowired
    private SurveyUserDao surveyUserDao;
    @Autowired
    private PushMsgTask pushMsgTask;
    /**
     * 获取问卷列表
@ -207,7 +205,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
//            获取医生信息(仅限市级管理员)
            String doctor = getUID();
            String accessToken = getAccessToken();
            String surveyCode = managerQuestionnaireService.createSurvey(doctor, accessToken, jsonStr);
            String surveyCode = managerQuestionnaireService.createSurvey(doctor, jsonStr, accessToken);
            return write(200, "创建成功!", "surveyCode", surveyCode);
        } catch (Exception e) {
            e.printStackTrace();
@ -375,7 +373,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
    /**
     * 新建问卷保存为模板
     *
     *引用模板新建问卷保存变更到模板
     * @param code
     * @return
     */
@ -384,10 +382,21 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
    @ResponseBody
    public String savaSurveyAsTemplate(
            @ApiParam(value = "新建问卷编码")
            @RequestParam String code) {
            @RequestParam String code,
            @ApiParam(value = "旧模板编码")
            @RequestParam(required = false) String templateCode) {
        try {
            managerQuestionnaireService.savaSurveyAsTemplate(code);
            return write(200, "保存成功!");
            int num=0;
            if (StringUtils.isEmpty(templateCode)){
                num = managerQuestionnaireService.savaSurveyAsTemplate(code);
            }else {
                num = managerQuestionnaireService.modifyTemplate(code,templateCode);
            }
            if (num==0){
                return write(200, "保存成功!");
            }else {
                return write(-1, "标题重复!","data",num);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "保存失败!");
@ -407,8 +416,8 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
            @ApiParam(value = "问卷编码")
            @RequestParam String code) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            sdf.format(new Date());
            /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//            sdf.format(new Date());
            String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
            String accessToken = getAccessToken();
            System.out.println("accessToken=====>" + accessToken);
@ -424,7 +433,10 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
                json.put("toUser", cod);
                json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                pushMsgTask.sendWeixinMessage(accessToken, 11, openId, name, json);
            }
            }*/
            List<String> codes = surveyUserDao.findBySurveyCodeAndStatus(code);
            SendMessage sendMessage = new SendMessage(code, codes, getAccessToken());
            new Thread(sendMessage).start();
            return write(200, "发送成功!");
        } catch (Exception e) {
            e.printStackTrace();
@ -453,5 +465,40 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
        }
    }
    /**
     * 线程发送模板消息
     */
    class SendMessage implements Runnable {
        private String code;
        private List<String> codes;
        private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        private String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
        private String accessToken;
        private JSONObject json = new JSONObject(str);
        public SendMessage(String code, List<String> codes, String accessToken) {
            this.code = code;
            this.codes = codes;
            this.accessToken = accessToken;
            System.out.println("============>" + accessToken);
        }
        @Override
        public void run() {
            synchronized (this) {
                json.put("survey_id", code);
                for (String cod : codes) {
                    Patient p = patientDao.findByCode(cod);
                    String name = p.getName();
                    String openId = p.getOpenid();
                    json.put("keyword2", sdf.format(new Date()));
                    json.put("toUser", cod);
                    json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                    PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
                }
            }
        }
    }
}

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

@ -63,50 +63,6 @@ public class PatientQuestionnaireController extends BaseController {
    @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();

+ 4 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/process/WeiXinEventProcess.java

@ -109,6 +109,10 @@ public class WeiXinEventProcess {
        // URL设置服务器URL、AppId
        urlBooking = urlBooking.replace("{server}", systemConf.getProperty("wechat_base_url"))
                .replace("{appId}", systemConf.getProperty("appId"));
        System.out.println("picUrlBooking ===>"+picUrlBooking);
        System.out.println("server_url ===>"+systemConf.getProperty("server_url"));
        //图片地址
        picUrlBooking = picUrlBooking.replace("{server}", systemConf.getProperty("server_url"));

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

@ -78,6 +78,7 @@ appSecret=2935b54b53a957d9516c920a544f2537
# 个人微信测试平台基本配置
#appId=wxb3827510b2e15012
#appSecret=c5bdedd909ded9c2ee08028487e6f50d
wechat_base_url=http%3a%2f%2fweixin.xmtyw.cn%2fwlyy-dev
wechat_token=27eb3bb24f149a7760cf1bb154b08040
@ -106,6 +107,7 @@ template_healthy_article=LA7erINJ0CSsG2G_ZCrgsDaX3krhsI4qg_NSHEyL_l4
template_doctor_change=TNIDMjduVKgVL4-k71umYLpHROvFB8K6mmm8aZC_EH8
#问卷调查
template_doctor_survey=IjQvzBy0PLeft2kN9mdBhACXPE9I_jyJywJ6B-JRxsY
#template_doctor_survey=fgYiMntj1amEkE8_GLUPmAIyssUAroJrNSHqvydt-PQ
#健康之路开放平台
yihu_OpenPlatform_url=http://ssotest.yihu.cn/OpenPlatform/cgiBin/1.0/