| 
					
				 | 
			
			
				@ -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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |