|  | @ -23,6 +23,7 @@ import org.springframework.data.domain.Sort;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | import springfox.documentation.spring.web.json.Json;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
	
		
			
				|  | @ -101,28 +102,44 @@ public class ManagerQuestionnaireService extends BaseService {
 | 
	
		
			
				|  |  | //      获取调查对象
 | 
	
		
			
				|  |  |         JSONObject surveyTarget = jsonStr.getJSONObject("surveyTarget");
 | 
	
		
			
				|  |  |         //            0不限 1男 2女
 | 
	
		
			
				|  |  |         int sex = Integer.parseInt(surveyTarget.get("sex").toString());
 | 
	
		
			
				|  |  | //        int sex = Integer.parseInt(surveyTarget.get("sex").toString());
 | 
	
		
			
				|  |  |         JSONArray sex = surveyTarget.getJSONArray("sex");
 | 
	
		
			
				|  |  |         JSONArray disease = surveyTarget.getJSONArray("disease");
 | 
	
		
			
				|  |  |         JSONArray service = surveyTarget.getJSONArray("service");
 | 
	
		
			
				|  |  |         JSONArray healthCondition = surveyTarget.getJSONArray("healthCondition");
 | 
	
		
			
				|  |  |         if (sex != 0) {
 | 
	
		
			
				|  |  |             String dimensionCode = surveyDimensionDao.findByName("性别");
 | 
	
		
			
				|  |  |             String dimensionDetailCode = getCode();
 | 
	
		
			
				|  |  |             SurveyDimensionDetail surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, sex == 1 ? "男" : "女", sex, "性别", 1, surveyCode);
 | 
	
		
			
				|  |  |             surveyDimensionDetailDao.save(surveyDimensionDetail);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         int sexList = 0;
 | 
	
		
			
				|  |  |         for (Object se : sex) {
 | 
	
		
			
				|  |  |             JSONObject sexJson = new JSONObject(se.toString());
 | 
	
		
			
				|  |  |             int label = sexJson.getInt("label");
 | 
	
		
			
				|  |  |             sexList = label;
 | 
	
		
			
				|  |  |             if (label != 0) {
 | 
	
		
			
				|  |  |                 String dimensionCode = surveyDimensionDao.findByName("性别");
 | 
	
		
			
				|  |  |                 String dimensionDetailCode = getCode();
 | 
	
		
			
				|  |  | //            SurveyDimensionDetail surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, sex == 1 ? "男" : "女", sex, "性别", 1, surveyCode);
 | 
	
		
			
				|  |  | //            modify by wjj 2017.7.24 居民标签更改
 | 
	
		
			
				|  |  |                 SurveyDimensionDetail surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, sexJson.getString("labelName"), label, "性别", 1, surveyCode);
 | 
	
		
			
				|  |  |                 surveyDimensionDetailDao.save(surveyDimensionDetail);
 | 
	
		
			
				|  |  | //          保存到筛选表
 | 
	
		
			
				|  |  |             SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
 | 
	
		
			
				|  |  |             surveyFilterDao.save(surveyFilter);
 | 
	
		
			
				|  |  |                 SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
 | 
	
		
			
				|  |  |                 surveyFilterDao.save(surveyFilter);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List servList = new ArrayList();
 | 
	
		
			
				|  |  |         for (Object serv : service) {
 | 
	
		
			
				|  |  |             if ("0".equals(serv.toString())) {
 | 
	
		
			
				|  |  |             JSONObject servJson = new JSONObject(serv.toString());
 | 
	
		
			
				|  |  |             int label = servJson.getInt("label");
 | 
	
		
			
				|  |  |             servList.add(label);
 | 
	
		
			
				|  |  |             if (label == 0) {
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  | //                       ===================================
 | 
	
		
			
				|  |  |                 String dimensionCode = surveyDimensionDao.findByName("服务类型");
 | 
	
		
			
				|  |  |                 String dimensionDetailCode = getCode();
 | 
	
		
			
				|  |  |                 SurveyDimensionDetail surveyDimensionDetail = null;
 | 
	
		
			
				|  |  |                 switch (Integer.parseInt(serv.toString())) {
 | 
	
		
			
				|  |  |                 surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, servJson.getString("labelName"), label, "服务类型", 3, surveyCode);
 | 
	
		
			
				|  |  |                /* switch (Integer.parseInt(serv.toString())) {
 | 
	
		
			
				|  |  | //                1.普通人群 2.慢病人群 3.65岁以上人群
 | 
	
		
			
				|  |  |                     case 1:
 | 
	
		
			
				|  |  |                         surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "普通人群", 1, "服务类型", 3, surveyCode);
 | 
	
	
		
			
				|  | @ -134,22 +151,29 @@ public class ManagerQuestionnaireService extends BaseService {
 | 
	
		
			
				|  |  |                         surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "65岁以上人群", 3, "服务类型", 3, surveyCode);
 | 
	
		
			
				|  |  |                         break;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | */
 | 
	
		
			
				|  |  |                 surveyDimensionDetailDao.save(surveyDimensionDetail);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
 | 
	
		
			
				|  |  |                 surveyFilterDao.save(surveyFilter);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List healthList = new ArrayList();
 | 
	
		
			
				|  |  |         for (Object health : healthCondition) {
 | 
	
		
			
				|  |  |             if ("0".equals(health.toString())) {
 | 
	
		
			
				|  |  |             JSONObject healthJson = new JSONObject(health.toString());
 | 
	
		
			
				|  |  |             int label = healthJson.getInt("label");
 | 
	
		
			
				|  |  |             healthList.add(label);
 | 
	
		
			
				|  |  |             if (label == 0) {
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 String dimensionCode = surveyDimensionDao.findByName("健康状况");
 | 
	
		
			
				|  |  |                 String dimensionDetailCode = getCode();
 | 
	
		
			
				|  |  |                 String surveyFilterCode = getCode();
 | 
	
		
			
				|  |  |                 SurveyDimensionDetail surveyDimensionDetail = null;
 | 
	
		
			
				|  |  |                 switch (Integer.parseInt(health.toString())) {
 | 
	
		
			
				|  |  |                 surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, healthJson.getString("labelName"), label, "健康状况", 4, surveyCode);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 /*switch (Integer.parseInt(health.toString())) {
 | 
	
		
			
				|  |  | //                1.健康人群 2.患病人群 3.高危人群 4.恢复期人群
 | 
	
		
			
				|  |  |                     case 1:
 | 
	
		
			
				|  |  |                         surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "健康人群", 1, "健康状况", 4, surveyCode);
 | 
	
	
		
			
				|  | @ -163,7 +187,7 @@ public class ManagerQuestionnaireService extends BaseService {
 | 
	
		
			
				|  |  |                     case 4:
 | 
	
		
			
				|  |  |                         surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "恢复期人群", 4, "健康状况", 4, surveyCode);
 | 
	
		
			
				|  |  |                         break;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 }*/
 | 
	
		
			
				|  |  |                 surveyDimensionDetailDao.save(surveyDimensionDetail);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 SurveyFilter surveyFilter = new SurveyFilter(surveyFilterCode, surveyCode, dimensionDetailCode);
 | 
	
	
		
			
				|  | @ -171,15 +195,22 @@ public class ManagerQuestionnaireService extends BaseService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List diseaList = new ArrayList();
 | 
	
		
			
				|  |  |         for (Object disea : disease) {
 | 
	
		
			
				|  |  |             if ("0".equals(disea.toString())) {
 | 
	
		
			
				|  |  |             JSONObject diseaJson = new JSONObject(disea.toString());
 | 
	
		
			
				|  |  |             int label = diseaJson.getInt("label");
 | 
	
		
			
				|  |  |             diseaList.add(label);
 | 
	
		
			
				|  |  |             if (label == 0) {
 | 
	
		
			
				|  |  | //                dise += ",";
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 String dimensionCode = surveyDimensionDao.findByName("疾病类型");
 | 
	
		
			
				|  |  |                 String dimensionDetailCode = getCode();
 | 
	
		
			
				|  |  |                 SurveyDimensionDetail surveyDimensionDetail = null;
 | 
	
		
			
				|  |  |                 switch (Integer.parseInt(disea.toString())) {
 | 
	
		
			
				|  |  |                 surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, diseaJson.getString("labelName"), label, "疾病类型", 2, surveyCode);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 /*switch (Integer.parseInt(disea.toString())) {
 | 
	
		
			
				|  |  | //                  1.高血压 2糖尿病 3.高血压+糖尿病
 | 
	
		
			
				|  |  |                     case 1:
 | 
	
		
			
				|  |  |                         surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "高血压", 1, "疾病类型", 2, surveyCode);
 | 
	
	
		
			
				|  | @ -187,14 +218,20 @@ public class ManagerQuestionnaireService extends BaseService {
 | 
	
		
			
				|  |  |                     case 2:
 | 
	
		
			
				|  |  |                         surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "糖尿病", 2, "疾病类型", 2, surveyCode);
 | 
	
		
			
				|  |  |                         break;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 }*/
 | 
	
		
			
				|  |  |                 surveyDimensionDetailDao.save(surveyDimensionDetail);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
 | 
	
		
			
				|  |  |                 surveyFilterDao.save(surveyFilter);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<String> codes = getCount(surveyTarget.toString());
 | 
	
		
			
				|  |  | //        List<String> codes = getCount(surveyTarget.toString());
 | 
	
		
			
				|  |  |         JSONObject countJson = new JSONObject();
 | 
	
		
			
				|  |  |         countJson.put("sex", sexList);
 | 
	
		
			
				|  |  |         countJson.put("disease", diseaList);
 | 
	
		
			
				|  |  |         countJson.put("healthCondition", healthList);
 | 
	
		
			
				|  |  |         countJson.put("service", servList);
 | 
	
		
			
				|  |  |         List<String> codes = getCount(countJson.toString());
 | 
	
		
			
				|  |  |         int amount = codes.size();
 | 
	
		
			
				|  |  |         for (String code : codes) {
 | 
	
		
			
				|  |  | //            String code = patient.get("patient").toString();
 | 
	
	
		
			
				|  | @ -1441,20 +1478,20 @@ public class ManagerQuestionnaireService extends BaseService {
 | 
	
		
			
				|  |  | //        居民标签类型 2健康人群 3疾病类型
 | 
	
		
			
				|  |  |         int lableType = 0;
 | 
	
		
			
				|  |  |         Map<String, Object> map = new HashMap<>();
 | 
	
		
			
				|  |  |         String sql = " SELECT DISTINCT t.label_name ,t.label " +
 | 
	
		
			
				|  |  |                 " from wlyy_sign_patient_label_info t " +
 | 
	
		
			
				|  |  |                 " where t.label_type = ?";
 | 
	
		
			
				|  |  |         String sql = " SELECT DISTINCT t.label_name ,t.label_code " +
 | 
	
		
			
				|  |  |                 " from wlyy_sign_patient_label t " +
 | 
	
		
			
				|  |  |                 " where t.status = 1 and t.label_type = ? ORDER BY t.label_code ";
 | 
	
		
			
				|  |  |         List<Map<String, Object>> health = jdbcTemplate.queryForList(sql, 2);
 | 
	
		
			
				|  |  |         List<Map<String, Object>> disea = jdbcTemplate.queryForList(sql, 3);
 | 
	
		
			
				|  |  |         String querySql = " SELECT DISTINCT t.code,t.name from wlyy_sign_dict t " +
 | 
	
		
			
				|  |  |                 " where t.type=1 and `year`='2017' ";
 | 
	
		
			
				|  |  |                 " where `year`='2017' ORDER BY t.code  ";
 | 
	
		
			
				|  |  |         List<Map<String, Object>> servi = jdbcTemplate.queryForList(querySql);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List healthCodition = new ArrayList();
 | 
	
		
			
				|  |  |         for (Map<String, Object> li : health) {
 | 
	
		
			
				|  |  |             Map<String, Object> map1 = new HashMap<>();
 | 
	
		
			
				|  |  |             String labelName = li.get("label_name").toString();
 | 
	
		
			
				|  |  |             int label = Integer.parseInt(li.get("label").toString());
 | 
	
		
			
				|  |  |             int label = Integer.parseInt(li.get("label_code").toString());
 | 
	
		
			
				|  |  |             map1.put("label", label);
 | 
	
		
			
				|  |  |             map1.put("labelName", labelName);
 | 
	
		
			
				|  |  |             healthCodition.add(map1);
 | 
	
	
		
			
				|  | @ -1463,7 +1500,7 @@ public class ManagerQuestionnaireService extends BaseService {
 | 
	
		
			
				|  |  |         for (Map<String, Object> li : disea) {
 | 
	
		
			
				|  |  |             Map<String, Object> map1 = new HashMap<>();
 | 
	
		
			
				|  |  |             String labelName = li.get("label_name").toString();
 | 
	
		
			
				|  |  |             int label = Integer.parseInt(li.get("label").toString());
 | 
	
		
			
				|  |  |             int label = Integer.parseInt(li.get("label_code").toString());
 | 
	
		
			
				|  |  |             map1.put("label", label);
 | 
	
		
			
				|  |  |             map1.put("labelName", labelName);
 | 
	
		
			
				|  |  |             disease.add(map1);
 | 
	
	
		
			
				|  | @ -1598,6 +1635,8 @@ public class ManagerQuestionnaireService extends BaseService {
 | 
	
		
			
				|  |  |     public List<String> getCount(String json) {
 | 
	
		
			
				|  |  | //        1.服务 2.健康 3疾病
 | 
	
		
			
				|  |  |         JSONObject jsonObject = new JSONObject(json);
 | 
	
		
			
				|  |  |         String sql = "";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sex = jsonObject.get("sex").toString();
 | 
	
		
			
				|  |  |         String str = "SELECT DISTINCT lb.patient FROM wlyy_sign_patient_label_info lb,(SELECT DISTINCT ff.patient FROM wlyy_sign_family_server s, " +
 | 
	
		
			
				|  |  |                 " (SELECT f.`code`,f.patient FROM wlyy_sign_family f,wlyy_patient p WHERE p.CODE=f.patient ";
 | 
	
	
		
			
				|  | @ -1622,11 +1661,13 @@ public class ManagerQuestionnaireService extends BaseService {
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             ser += " OR ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (!StringUtils.isEmpty(ser)) {
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(ser)) {
 | 
	
		
			
				|  |  |             str += " AND ( " + ser.substring(0, ser.lastIndexOf("OR")) + " ) ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         str += " )tt WHERE lb.patient=tt.patient ";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONArray healthCondition = jsonObject.getJSONArray("healthCondition");
 | 
	
		
			
				|  |  |         String healSql = "";
 | 
	
		
			
				|  |  |         String heal = "";
 | 
	
		
			
				|  |  |         health:
 | 
	
		
			
				|  |  |         for (Object health : healthCondition) {
 | 
	
	
		
			
				|  | @ -1640,10 +1681,12 @@ public class ManagerQuestionnaireService extends BaseService {
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             heal += " OR ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (!StringUtils.isEmpty(heal)) {
 | 
	
		
			
				|  |  |             str += " AND ( (lb.label_type =2 AND ( " + heal.substring(0, heal.lastIndexOf("OR")) + " ) " + " ) ";
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(heal)) {
 | 
	
		
			
				|  |  |             healSql = " (lb.label_type =2 AND ( " + heal.substring(0, heal.lastIndexOf("OR")) + " )  )";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONArray disease = jsonObject.getJSONArray("disease");
 | 
	
		
			
				|  |  |         String disSql = "";
 | 
	
		
			
				|  |  |         String dis = "";
 | 
	
		
			
				|  |  |         disea:
 | 
	
		
			
				|  |  |         for (Object disea : disease) {
 | 
	
	
		
			
				|  | @ -1652,27 +1695,27 @@ public class ManagerQuestionnaireService extends BaseService {
 | 
	
		
			
				|  |  |                 case "0":
 | 
	
		
			
				|  |  |                     break disea;
 | 
	
		
			
				|  |  |                 default:
 | 
	
		
			
				|  |  |                     dis += " lb.label= "+type;
 | 
	
		
			
				|  |  |                     dis += " lb.label= " + type;
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             dis += " OR ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isEmpty(heal)){
 | 
	
		
			
				|  |  |             if (!StringUtils.isEmpty(dis)) {
 | 
	
		
			
				|  |  |                 str += " AND ( lb.label_type =3 AND ( " + dis.substring(0, dis.lastIndexOf("OR")) + " ) " + " )";
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 str += " )";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             if (!StringUtils.isEmpty(dis)) {
 | 
	
		
			
				|  |  |                 str += " OR ( lb.label_type =3 AND ( " + dis.substring(0, dis.lastIndexOf("OR")) + " ) " + " ) )";
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 str += " )";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(dis)) {
 | 
	
		
			
				|  |  |             disSql= " (lb.label_type =3 AND ( " + dis.substring(0, dis.lastIndexOf("OR")) + " )  )";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (StringUtils.isEmpty(heal) && StringUtils.isEmpty(dis)) {
 | 
	
		
			
				|  |  |             sql = str;
 | 
	
		
			
				|  |  |         } else if (StringUtils.isEmpty(heal) && StringUtils.isNotEmpty(dis)) {
 | 
	
		
			
				|  |  |             sql = str + " AND " +disSql;
 | 
	
		
			
				|  |  |         } else if (StringUtils.isNotEmpty(heal) && StringUtils.isEmpty(dis)) {
 | 
	
		
			
				|  |  |             sql = str + " AND " +healSql;
 | 
	
		
			
				|  |  |         } else if (StringUtils.isNotEmpty(heal) && StringUtils.isNotEmpty(dis)) {
 | 
	
		
			
				|  |  |             sql = str + " AND ( " + disSql +" OR " +healSql +" ) ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         System.out.println("=====query sql =======>>>>" + str);
 | 
	
		
			
				|  |  |         List<String> patients = jdbcTemplate.queryForList(str, String.class);
 | 
	
		
			
				|  |  |         System.out.println("=====query sql =======>>>>" + sql);
 | 
	
		
			
				|  |  |         List<String> patients = jdbcTemplate.queryForList(sql, String.class);
 | 
	
		
			
				|  |  |         return patients;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 |