Browse Source

问卷调查居民标签表更新

wujunjie 7 years ago
parent
commit
d62ff9fd54

+ 200 - 47
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java

@ -279,14 +279,14 @@ public class ManagerQuestionnaireService extends BaseService {
//                            }
//                        }
                        //发送代理人
                        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
                        if(jsonArray!=null&&jsonArray.length()>0){
                            for (int i = 0;i<jsonArray.length();i++){
                                JSONObject j  = jsonArray.getJSONObject(i);
                        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                        if (jsonArray != null && jsonArray.length() > 0) {
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject j = jsonArray.getJSONObject(i);
                                Patient member = (Patient) j.get("member");
                                if(StringUtils.isNotBlank(member.getOpenid())){
                                if (StringUtils.isNotBlank(member.getOpenid())) {
                                    json.remove("toUser");
                                    json.put("toUser",member.getCode());
                                    json.put("toUser", member.getCode());
                                    json.remove("first");
                                    try {
                                        json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
@ -1346,7 +1346,7 @@ public class ManagerQuestionnaireService extends BaseService {
            }
            if (qstType != 2) {
                List<SurveyQuestionnaireOptions> surveyQuestionnaireOptions = surveyQuestionnaireOptionsDao.findByIdAndQstCode(code, question.getCode());
                List<SurveyTemplateOptions> templateOption = surveyTemplateOptionsDao.findById(qstCode,templateCode);
                List<SurveyTemplateOptions> templateOption = surveyTemplateOptionsDao.findById(qstCode, templateCode);
                List options = new ArrayList();
                for (SurveyTemplateOptions opt : templateOption) {
                    options.add(opt.getCode());
@ -1375,19 +1375,20 @@ public class ManagerQuestionnaireService extends BaseService {
                    }
                }
//               删除选项更改选项状态
                for (Object opt:options) {
                for (Object opt : options) {
                    surveyTemplateOptionsDao.modifyOption(templateCode, qstCode, opt.toString());
                }
            }
        }
//            删除问题更改问题状态
        for (Object qst:questions) {
            surveyTemplateQuestionsDao.modifyQuestion(templateCode,qst.toString());
        for (Object qst : questions) {
            surveyTemplateQuestionsDao.modifyQuestion(templateCode, qst.toString());
        }
        return 0;
    }
    public Map getFilter() {
    /*public Map getFilter() {
        JSONObject jsonObject = new JSONObject();
//        List lis = new ArrayList();
        Iterable<SurveyDimension> surveyDimension = surveyDimensionDao.findAll();
@ -1426,24 +1427,186 @@ public class ManagerQuestionnaireService extends BaseService {
            map.put(name, subLabel);
//            lis.add(map);
        }
        return map;
    }*/
    /**
     * 居民标签变更,前端展示所有标签
     * modify by wjj 2017.7.21
     *
     * @return
     */
    public Map getFilter() {
        JSONObject jsonObject = new JSONObject();
//        居民标签类型 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 = ?";
        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' ";
        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());
            map1.put("label", label);
            map1.put("labelName", labelName);
            healthCodition.add(map1);
        }
        List disease = new ArrayList();
        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());
            map1.put("label", label);
            map1.put("labelName", labelName);
            disease.add(map1);
        }
        List service = new ArrayList();
        for (Map<String, Object> li : servi) {
            Map<String, Object> map1 = new HashMap<>();
            String labelName = li.get("name").toString();
            int label = Integer.parseInt(li.get("code").toString());
            map1.put("label", label);
            map1.put("labelName", labelName);
            service.add(map1);
        }
        List sex = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        map1.put("label", 1);
        map1.put("labelName", "男");
        Map<String, Object> map2 = new HashMap<>();
        map2.put("label", 2);
        map2.put("labelName", "女");
        sex.add(map1);
        sex.add(map2);
        map.put("healthCondition", healthCodition);
        map.put("disease", disease);
        map.put("sex", sex);
        map.put("service", service);
        return map;
    }
    public int getAmount(String json) {
        return getCount(json).size();
    }
    /* public List<String> getCount(String json) {
 //        1.服务 2.健康 3疾病
         JSONObject jsonObject = new JSONObject(json);
         String sex = jsonObject.get("sex").toString();
         String str = "SELECT DISTINCT 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.status = 1 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 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")) + " ) ";
         }
         System.out.println("=====query sql =======>>>>" + str);
         List<String> patients = jdbcTemplate.queryForList(str, String.class);
         return patients;
     }*/
    /**
     * 表变更 由筛选条件获取人数
     *
     * @param json
     * @return
     */
    public List<String> getCount(String json) {
//        1.服务 2.健康 3疾病
        JSONObject jsonObject = new JSONObject(json);
        String sex = jsonObject.get("sex").toString();
        String str = "SELECT DISTINCT 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.status = 1 AND t.patient IN (SELECT b.`code` FROM wlyy_patient b WHERE b.`openid` IS NOT NULL AND b.`openid`!='' ";
        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 ";
        if (!"0".equals(sex)) {
            str += " AND b.sex= " + sex + " ) GROUP BY t.patient ) s WHERE 1=1 ";
            str += " AND p.sex=  " + sex +
                    " AND f.STATUS>0 AND p.`openid` IS NOT NULL AND p.`openid`!='')ff WHERE ff.CODE=s.sign_code ";
        } else {
            str += " ) GROUP BY t.patient ) s WHERE 1=1 ";
            str += " AND f.STATUS>0 AND p.`openid`IS NOT NULL AND p.`openid`!='')ff WHERE ff.CODE=s.sign_code ";
        }
        JSONArray service = jsonObject.getJSONArray("service");
        String ser = "";
@ -1451,17 +1614,10 @@ public class ManagerQuestionnaireService extends BaseService {
        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岁以上人群%' ";
                default:
                    ser += " s.server_type= " + type;
                    break;
            }
            ser += " OR ";
@ -1469,32 +1625,23 @@ public class ManagerQuestionnaireService extends BaseService {
        if (!StringUtils.isEmpty(ser)) {
            str += " AND ( " + ser.substring(0, ser.lastIndexOf("OR")) + " ) ";
        }
        str += " )tt WHERE lb.patient=tt.patient ";
        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 '%恢复期人群%' ";
                default:
                    heal += " lb.label= " + type;
                    break;
            }
            heal += " OR ";
        }
        if (!StringUtils.isEmpty(heal)) {
            str += " AND ( " + heal.substring(0, heal.lastIndexOf("OR")) + " ) ";
            str += " AND ( (lb.label_type =2 AND ( " + heal.substring(0, heal.lastIndexOf("OR")) + " ) " + " ) ";
        }
        JSONArray disease = jsonObject.getJSONArray("disease");
        String dis = "";
@ -1502,25 +1649,31 @@ public class ManagerQuestionnaireService extends BaseService {
        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 '%糖尿病%' ";
                default:
                    dis += " lb.label= "+type;
                    break;
            }
            dis += " OR ";
        }
        if (!StringUtils.isEmpty(dis)) {
            str += " AND ( " + dis.substring(0, dis.lastIndexOf("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 += " )";
            }
        }
        System.out.println("=====query sql =======>>>>" + str);
        List<String> patients = jdbcTemplate.queryForList(str, String.class);
        return patients;
    }
}

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

@ -541,6 +541,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
            @ApiParam(value = "筛选条件")
            @RequestParam String json) {
        try {
            json = "{\"sex\":1,\"disease\":[1],\"healthCondition\":[1,2,3],\"service\":[1,2]}";
            int amount = managerQuestionnaireService.getAmount(json);
            return write(200, "查询成功!", "amount", amount);
        } catch (Exception e) {