| 
					
				 | 
			
			
				@ -2,6 +2,7 @@ package com.yihu.wlyy.service.survey; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.doctor.survey.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.doctor.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.questionnaire.QuestionnaireUsersDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.BaseService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.json.JSONArray; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -9,6 +10,7 @@ import org.json.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -34,6 +36,13 @@ public class PatientQuestionnaireService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private SurveyAnswersDao surveyAnswersDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    SurveyStatisticsDao surveyStatisticsDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private  SurveyTemplateQuestionsDao surveyTemplateQuestionsDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private SurveyTemplateOptionsDao surveyTemplateOptionsDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private QuestionnaireUsersDao questionnaireUsersDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private Logger logger = LoggerFactory.getLogger(this.getClass()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject getSurveySummary(String patient, String id) throws Exception { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -221,4 +230,73 @@ public class PatientQuestionnaireService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        surveyUserDao.modifyStatus(surveyCode, patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 抽奖问卷调查获取所有的问卷题目 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param surveyTemplateCode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject getAllQuestions(String surveyTemplateCode)throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject json = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<SurveyTemplateQuestions> questionList = surveyTemplateQuestionsDao.findById(surveyTemplateCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<SurveyTemplateOptions> optionsList = surveyTemplateOptionsDao.findByQuestionCode(surveyTemplateCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (SurveyTemplateQuestions surveyTemplateQuestions : questionList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String,Object> map = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String qusCode = surveyTemplateQuestions.getCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<SurveyTemplateOptions>  resultOptionList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (SurveyTemplateOptions option : optionsList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (option.getTemplateQuestionCode().equals(qusCode)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    resultOptionList.add(option); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("question",surveyTemplateQuestions); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("option",resultOptionList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put(surveyTemplateQuestions.getSort()+"",map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return  json; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String saveAnswerAndLotto(JSONObject jsonData) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        System.out.println("********jsonData********* " + jsonData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //解析json保存各种答案 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String surveyCode = jsonData.get("surveyCode").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String openId = jsonData.get("openId").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String userCode = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //userCode = questionnaireUsersDao.findByOpoenId(openId).getCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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 type = Integer.parseInt(question.get("type").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            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(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        String comment = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        int haveComment = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (option.has("comment")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            comment = option.get("comment").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            haveComment = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        //保存到选择题答案表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        SurveyOptionAnswers optionAnswer = new SurveyOptionAnswers(code, userCode, surveyCode, qstCode, optionCode, comment, type, createTime,openId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        surveyOptionAnswersDao.save(optionAnswer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        //选择题修改统计表数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        surveyStatisticsDao.modifyAmount(surveyCode, qstCode, optionCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return  UUID.randomUUID().toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |