Browse Source

Merge branch 'dev' of liuwenbin/patient-co-management into dev

liuwenbin 7 years ago
parent
commit
0dedc23817

BIN
patient-co/patient-co-wlyy/doc/接口文档/对外接口文档/集美健康教育/集美健康教育对外接口文档.docx


+ 0 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/BaseController.java

@ -44,8 +44,6 @@ public class BaseController {
                userAgent = request.getHeader("User-Agent");
            }
            JSONObject json = new JSONObject(userAgent);
            logger.info("json:"+json.toString());
            System.out.println("json:"+json.toString());
            return json.getString("uid");
        } catch (Exception e) {

+ 0 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcDoctorController.java

@ -108,8 +108,6 @@ public class GcDoctorController extends BaseController {
    @ApiOperation("获取医生所属团队")
    public ResultListModel<AdminTeamModel> doctors(
    ) {
        logger.info("getUID:"+getUID());
        System.out.println("getUID:"+getUID());
        List<AdminTeam> teams = adminTeamService.getDoctorTeams(getUID());//hxmD201703150222"
        List<AdminTeamModel> adminTeamModelList = new ArrayList<>();
        if (teams != null && teams.size() > 0) {

+ 40 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcEduArticleController.java

@ -131,7 +131,8 @@ public class GcEduArticleController extends WeixinBaseController {
            @ApiParam(name = "articleType", value = "文章类别", required = true) @RequestParam(value = "articleType", required = true) String articleType,
            @ApiParam(name = "level1Type", value = "一级分类", required = true) @RequestParam(value = "level1Type", required = true) String level1Type,
            @ApiParam(name = "level2Type", value = "二级分类", required = true) @RequestParam(value = "level2Type", required = true) String level2Type,
            @ApiParam(name = "level", value = "等级", required = true) @RequestParam(value = "level", required = true) String level
            @ApiParam(name = "level", value = "等级", required = true) @RequestParam(value = "level", required = true) String level,
            @ApiParam(name = "articleUrl", value = "宣教文章获取url", required = true) @RequestParam(value = "articleUrl", required = true) String articleUrl
    ) {
        try {
            String[] patients = receiveCodes.split(",");//接收人的code
@ -141,7 +142,7 @@ public class GcEduArticleController extends WeixinBaseController {
            //得到需要发送的患者
            gcEduArticleService.initPatient(patientSet, patients, unPatients, labelType, labelCode, teamId);
            //获取保存发送记录
            List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = gcEduArticleService.getSaveArticle(patientSet, sendCode, sendName, sendType, sendMessage, teamId, articleId, articlePic, articleTitle, articleContent, articleType, level1Type, level2Type, level);
            List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = gcEduArticleService.getSaveArticle(patientSet, sendCode, sendName, sendType, sendMessage, teamId, articleId, articlePic, articleTitle, articleContent, articleType, level1Type, level2Type, level,articleUrl);
            //推送微信模板消息和发送im消息
            new Thread(() -> {
                //发送任务到redis
@ -172,4 +173,41 @@ public class GcEduArticleController extends WeixinBaseController {
        });
    }
    @RequestMapping(value = "sendPatients", method = RequestMethod.POST)
    @ApiOperation("文章群推送")
    public BaseResultModel sendPatients(
            @ApiParam(name = "sendType", value = "发送类型 1医生发送 2卫纪委发送", required = false) @RequestParam(value = "sendType", required = false,defaultValue = "2") Integer sendType,
            @ApiParam(name = "labelUnitType", value = "标签类型  1:下属单位,多个用逗号分隔", required = false) @RequestParam(value = "labelUnitType", required = false, defaultValue = "") String labelUnitType,
            @ApiParam(name = "labelSexType", value = "标签类型  2:性别,多个用逗号分隔", required = false) @RequestParam(value = "labelSexType", required = false, defaultValue = "") String labelSexType,
            @ApiParam(name = "labelServeType", value = "标签类型  3:服务类型,多个用逗号分隔", required = false) @RequestParam(value = "labelServeType", required = false, defaultValue = "") String labelServeType,
            @ApiParam(name = "labelDiseaseType", value = "标签类型  4:疾病类型,多个用逗号分隔", required = false) @RequestParam(value = "labelDiseaseType", required = false, defaultValue = "") String labelDiseaseType,
            @ApiParam(name = "labelHealthType", value = "标签类型  5:健康情况,多个用逗号分隔", required = false) @RequestParam(value = "labelHealthType", required = false, defaultValue = "") String labelHealthType,
            @ApiParam(name = "articleId", value = "文章ID", required = true) @RequestParam(value = "articleId", required = true) String articleId,
            @ApiParam(name = "articlePic", value = "文章封面", required = true) @RequestParam(value = "articlePic", required = true) String articlePic,
            @ApiParam(name = "articleTitle", value = "文章标题", required = true) @RequestParam(value = "articleTitle", required = true) String articleTitle,
            @ApiParam(name = "articleContent", value = "文章内容", required = true) @RequestParam(value = "articleContent", required = true) String articleContent,
            @ApiParam(name = "articleType", value = "文章类别", required = true) @RequestParam(value = "articleType", required = true) String articleType,
            @ApiParam(name = "level1Type", value = "一级分类", required = true) @RequestParam(value = "level1Type", required = true) String level1Type,
            @ApiParam(name = "level2Type", value = "二级分类", required = true) @RequestParam(value = "level2Type", required = true) String level2Type,
            @ApiParam(name = "level", value = "等级", required = true) @RequestParam(value = "level", required = true) String level,
            @ApiParam(name = "articleUrl", value = "宣教文章获取的url", required = true) @RequestParam(value = "articleUrl", required = true) String articleUrl
    ){
        try {
            Set<String> patientSet = new HashSet<>(); //放入set中可以去重复
            //得到需要发送的患者
            gcEduArticleService.initPatient(patientSet,labelUnitType,labelSexType,labelServeType,labelDiseaseType,labelHealthType);
            //获取保存发送记录
            List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = gcEduArticleService.getSaveArticle(patientSet, "", "", sendType, "", 0L, articleId, articlePic, articleTitle, articleContent, articleType, level1Type, level2Type, level,articleUrl);
            //推送微信模板消息和发送im消息
            new Thread(() -> {
                //发送任务到redis
                sender(healthEduArticlePatients);
            }).start();
            return new BaseResultModel();
        }catch (Exception e) {
            return new BaseResultModel(BaseResultModel.statusEm.opera_error.getCode(), BaseResultModel.statusEm.opera_error.getMessage() + ":" + e.getMessage());
        }
    }
}

+ 12 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcLableController.java

@ -122,5 +122,16 @@ public class GcLableController extends BaseController {
            return new ResultPageListModel(BaseResultModel.statusEm.find_error.getCode(), BaseResultModel.statusEm.find_error.getMessage() + "," + e.getMessage());
        }
    }
    @RequestMapping(value = "/unitLabels", method = RequestMethod.GET)
    @ApiOperation("根据地区查找卫计委下属单位标签")
    public ResultListModel<List<PatientLabelModel>> unitLabels(
            @ApiParam(name = "areas", value = "", required = true) @RequestParam(value = "areas", required = true) String areas
    ) {
        try {
            List<DictModel> dictModels = labelService.getUnitLabels(areas);
            return new ResultListModel(dictModels);
        } catch (Exception e) {
            return new ResultListModel(BaseResultModel.statusEm.find_error.getCode(), BaseResultModel.statusEm.find_error.getMessage() + "," + e.getMessage());
        }
    }
}

+ 7 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcMessageController.java

@ -101,4 +101,11 @@ public class GcMessageController {
            return new ResultBatchModel(BaseResultModel.statusEm.error_no_ip.getCode(), "获取IP失败", success, error, errorLiust);
        }
    }
    @RequestMapping(value = "/sendEduArticle", method = RequestMethod.POST)
    @ApiOperation("给手机号码发送短信消息")
    public ResultBatchModel sendEduArticle(){
        return null;
    }
}

+ 82 - 25
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/service/GcEduArticleService.java

@ -62,31 +62,52 @@ public class GcEduArticleService {
        StringBuffer sb = new StringBuffer();//sql
        //1 服务类型  2 健康情况 3 疾病类型 4 自定义标签
        if (!org.springframework.util.StringUtils.isEmpty(labelType)) {
//            switch (labelType) {
//                case "1": {
//                    sb.append(" SELECT " +
//                            "  w.patient " +
//                            "FROM " +
//                            "  wlyy_sign_family w " +
//                            " WHERE " +
//                            "  w.`status` > 0 " +
//                            " AND w.code in ( select sign_code from  " +
//                            "  wlyy_sign_family_server where server_type=? ) ");
//                    params.add(labelCode);
//
//                    if (teamId != null && teamId > 0) {
//                        sb.append(" and w.admin_team_code=? ");
//                        params.add(teamId);
//                    }
//                    break;
//                }
//                case "2":
//                case "3":
//                case "4": {
//                    sb.append("SELECT w.patient FROM wlyy_sign_family w " +
//                            "WHERE " +
//                            "  w.patient in (SELECT  l.patient FROM  wlyy_sign_patient_label_info l WHERE l.label_type = ? AND l.label = ? and l.status=1) " +
//                            "AND w.`status` > 0");
//                    params.add(labelType);
//                    params.add(labelCode);
//                    if (teamId != null && teamId > 0) {
//                        sb.append(" and w.admin_team_code=? ");
//                        params.add(teamId);
//                    }
//                    break;
//                }
//            }
            switch (labelType) {
                case "1": {
                    sb.append(" SELECT " +
                            "  w.patient " +
                            "FROM " +
                            "  wlyy_sign_family w " +
                            " WHERE " +
                            "  w.`status` > 0 " +
                            " AND w.code in ( select sign_code from  " +
                            "  wlyy_sign_family_server where server_type=? ) ");
                case "1":{
                    sb.append(" select w.patient FROM wlyy_sign_family w  left join wlyy_sign_family_server s on w.code=s.sign_code " +
                            "where w.`status` > 0 and s.server_type=? ");
                    params.add(labelCode);
                    if (teamId != null && teamId > 0) {
                        sb.append(" and w.admin_team_code=? ");
                        params.add(teamId);
                    }
                    break;
                }
                case "2":
                case "3":
                case "4": {
                    sb.append("SELECT w.patient FROM wlyy_sign_family w " +
                            "WHERE " +
                            "  w.patient in (SELECT  l.patient FROM  wlyy_sign_patient_label_info l WHERE l.label_type = ? AND l.label = ? and l.status=1) " +
                            "AND w.`status` > 0");
                case "4":{
                    sb.append(" SELECT w.patient FROM wlyy_sign_family w left join wlyy_sign_patient_label_info l on w.patient = l.patient " +
                            "where w.`status` > 0 and l.label_type = ? AND l.label = ? and l.status=1 ");
                    params.add(labelType);
                    params.add(labelCode);
                    if (teamId != null && teamId > 0) {
@ -138,7 +159,8 @@ public class GcEduArticleService {
                                                                        String articleType,
                                                                        String level1Type,
                                                                        String level2Type,
                                                                        String level) {
                                                                        String level,
                                                                        String articleUrl) {
        List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = new ArrayList<>();
        Doctor doctor = doctorDao.findByCode(sendCode);
@ -161,12 +183,12 @@ public class GcEduArticleService {
                healthEduArticlePatient.setHospitalName(doctor.getHospitalName());
                healthEduArticlePatient.setTown(doctor.getTown());
                healthEduArticlePatient.setTownName(doctor.getTownName());
                healthEduArticlePatient.setSendLevel(doctor.getLevel()!=null?String.valueOf(doctor.getLevel()):"");
                healthEduArticlePatient.setSendPic(doctor.getPhoto());
                healthEduArticlePatient.setSendSex(doctor.getSex()!=null?String.valueOf(doctor.getSex()):"");
            }
            healthEduArticlePatient.setBatchNo(batchNo);
            healthEduArticlePatient.setCreateTime(createTime);
            healthEduArticlePatient.setSendLevel(doctor.getLevel()!=null?String.valueOf(doctor.getLevel()):"");
            healthEduArticlePatient.setSendPic(doctor.getPhoto());
            healthEduArticlePatient.setSendSex(doctor.getSex()!=null?String.valueOf(doctor.getSex()):"");
            healthEduArticlePatient.setArticleId(articleId);
            healthEduArticlePatient.setAttachedTitle(articleTitle);
@ -178,7 +200,7 @@ public class GcEduArticleService {
            healthEduArticlePatient.setLevel1Type(level1Type);
            healthEduArticlePatient.setLevel2Type(level2Type);
            healthEduArticlePatient.setType("1");//文章
            healthEduArticlePatient.setArticleUrl(articleUrl);
            healthEduArticlePatients.add(healthEduArticlePatient);
        }
@ -268,4 +290,39 @@ public class GcEduArticleService {
    private String changeDate(String quotaDate) {
        return quotaDate + "T00:00:00+0800";
    }
    public void initPatient(Set<String> patientSet,String labelUnit,String labelSex,String labelServe,String labelDisease,String labelHealth){
        String tableSql = " select w.patient from wlyy_sign_family w ";
        String whereSql = " where w.status>0  ";
        if(!StringUtils.isEmpty(labelServe)){
            tableSql += " left join wlyy_sign_family_server s on w.code= s.sign_code ";
            whereSql += " and s.server_type in ("+labelServe+" ) ";
        }
        if(!StringUtils.isEmpty(labelHealth)||!StringUtils.isEmpty(labelDisease)){
            tableSql += " left join wlyy_sign_patient_label_info l on w.patient=l.patient ";
            whereSql += " and l.status=1 ";
            whereSql += " and ( ";
        }
        if(!StringUtils.isEmpty(labelHealth)){
            whereSql += " (l.label_type = 2 AND l.label in ("+labelHealth+")) ";
        }
        if(!StringUtils.isEmpty(labelDisease)){
            if(!whereSql.endsWith(" and ( ")) {
                whereSql += " or (l.label_type = 3 AND l.label in ("+labelDisease+"))) ";
            }else{
                whereSql += " (l.label_type = 1 AND l.label in ("+labelDisease+"))) ";
            }
        }
        if(!StringUtils.isEmpty(labelSex)){
            tableSql += " left join wlyy_patient p on p.code=w.patient ";
            whereSql += " and p.sex in ("+labelSex+") ";
        }
        if(!StringUtils.isEmpty(labelUnit)){
            whereSql += " and w.hospital in ("+labelUnit+") ";
        }
        List<String> groupPatient = jdbcTemplate.queryForList(tableSql+whereSql, String.class);
        patientSet.addAll(groupPatient);
    }
}

+ 106 - 22
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/service/GcLabelService.java

@ -87,6 +87,81 @@ public class GcLabelService {
            labels.add(labelNo);
        }
//        if (labels != null) {
//            for (SignPatientLabel label : labels) {
//                if (isAll) {//查询所有
//                    labelType = label.getLabelType();
//                }
//                JSONObject json = new JSONObject();
//
//                json.put("labelCode", label.getLabelCode());
//                json.put("labelName", label.getLabelName());
//                json.put("isSystem", label.getIsSystem());
//
//                int amount = 0;
//                String sql = "";
//                Object[] args;
//                if (label.getLabelCode().equals("0")) {
//                    sql = " SELECT " +
//                            "     count(DISTINCT t1.patient) count" +
//                            " FROM" +
//                            "     wlyy_sign_family t1 " +
//                            " left join " +
//                            "    (select repl.patient,repl.label,repl.label_type,repl.label_name from wlyy_sign_family repf left join wlyy_sign_patient_label_info repl on repf.patient = repl.patient where repf.admin_team_code = ? and repf.status > 0 and repl.label_type = ? and repl.status = 1) t2 " +
//                            " on t1.patient = t2.patient ," +
//                            " wlyy_patient t3 " +
//                            " WHERE" +
//                            "     t2.patient is null " +
//                            "    AND t1.patient = t3.code" +
//                            "     AND t1.status > 0 " +
//                            "     AND t1.admin_team_code = ? ";
//
//                    args = new Object[]{teamCode, labelType, teamCode};
//                } else {
//                    sql = " SELECT " +
//                            "     count(DISTINCT t1.patient) count" +
//                            " FROM" +
//                            "     wlyy_sign_family t1, " +
//                            "     wlyy_sign_patient_label_info t2, " +
//                            "     wlyy_patient t3 " +
//                            " WHERE" +
//                            "     t1.patient = t2.patient " +
//                            "     AND t1.patient = t3.code " +
//                            "     AND t2.label = ? " +
//                            "     AND t2.label_type = ? " +
//                            "     AND t2.status = 1 " +
//                            "     AND t1.status > 0 " +
//                            "    AND t1.admin_team_code = ? ";
//
//                    args = new Object[]{label.getLabelCode(), labelType, teamCode};
//                }
//
//
//                List<Map<String, Object>> count = jdbcTemplate.queryForList(sql, args);
//
//                if (count != null && count.size() > 0 && count.get(0).containsKey("count")) {
//                    amount = Integer.valueOf(String.valueOf(count.get(0).get("count")));
//                }
//
//                json.put("amount", amount);
//
//                int focusAmount = 0;
//                sql += labelType.equals("5") ? " AND LENGTH(TRIM(IFNULL(t3.openid,''))) > 0 " : " AND LENGTH(TRIM(IFNULL(t3.openid,''))) > 0 ";
//                List<Map<String, Object>> focusCount = jdbcTemplate.queryForList(sql, args);
//
//                if (focusCount != null && focusCount.size() > 0 && focusCount.get(0).containsKey("count")) {
//                    focusAmount = Integer.valueOf(String.valueOf(focusCount.get(0).get("count")));
//                }
//
//                json.put("focusAmount", focusAmount);
//
//                if (label.getLabelCode().equals("0") && labelType.equals("1") && amount < 1) {
//                    continue;
//                }
//                result.put(json);
//            }
//        }
        if (labels != null) {
            for (SignPatientLabel label : labels) {
                if (isAll) {//查询所有
@ -103,31 +178,34 @@ public class GcLabelService {
                Object[] args;
                if (label.getLabelCode().equals("0")) {
                    sql = " SELECT " +
                            "     count(DISTINCT t1.patient) count" +
                            "     t3.openid openid " +
                            " FROM" +
                            "     wlyy_sign_family t1 " +
                            " left join " +
                            "    (select repl.patient,repl.label,repl.label_type,repl.label_name from wlyy_sign_family repf left join wlyy_sign_patient_label_info repl on repf.patient = repl.patient where repf.admin_team_code = ? and repf.status > 0 and repl.label_type = ? and repl.status = 1) t2 " +
                            " on t1.patient = t2.patient ," +
                            " on t1.patient = t2.patient " +
                            " left join " +
                            " wlyy_patient t3 " +
                            " on t1.patient = t3.code " +
                            " WHERE" +
                            "     t2.patient is null " +
                            "    AND t1.patient = t3.code" +
                            "     AND t1.status > 0 " +
                            "     AND t1.admin_team_code = ? ";
                    args = new Object[]{teamCode, labelType, teamCode};
                } else {
                    sql = " SELECT " +
                            "     count(DISTINCT t1.patient) count" +
                            "     t3.openid openid " +
                            " FROM" +
                            "     wlyy_sign_family t1, " +
                            "     wlyy_sign_patient_label_info t2, " +
                            "     wlyy_patient t3 " +
                            "     wlyy_sign_family t1 " +
                            " LEFT JOIN " +
                            "     wlyy_sign_patient_label_info t2 " +
                            " ON t1.patient = t2.patient " +
                            " LEFT JOIN " +
                            " wlyy_patient t3 " +
                            " ON t1.patient = t3.code " +
                            " WHERE" +
                            "     t1.patient = t2.patient " +
                            "     AND t1.patient = t3.code " +
                            "     AND t2.label = ? " +
                            "      t2.label = ? " +
                            "     AND t2.label_type = ? " +
                            "     AND t2.status = 1 " +
                            "     AND t1.status > 0 " +
@ -137,23 +215,23 @@ public class GcLabelService {
                }
                List<Map<String, Object>> count = jdbcTemplate.queryForList(sql, args);
                List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, args);
                if (count != null && count.size() > 0 && count.get(0).containsKey("count")) {
                    amount = Integer.valueOf(String.valueOf(count.get(0).get("count")));
                }
//                if (count != null && count.size() > 0 && count.get(0).containsKey("count")) {
//                    amount = Integer.valueOf(String.valueOf(count.get(0).get("count")));
//                }
                amount = list.size();
                json.put("amount", amount);
                int focusAmount = 0;
                sql += labelType.equals("5") ? " AND LENGTH(TRIM(IFNULL(t3.openid,''))) > 0 " : " AND LENGTH(TRIM(IFNULL(t3.openid,''))) > 0 ";
                List<Map<String, Object>> focusCount = jdbcTemplate.queryForList(sql, args);
                List<Map<String, Object>> temp = new ArrayList<>();
                list.forEach(map-> {
                    if(map.get("openid")!=null&&String.valueOf(map.get("openid")).trim().length()>0){
                        temp.add(map);
                    }
                });
                if (focusCount != null && focusCount.size() > 0 && focusCount.get(0).containsKey("count")) {
                    focusAmount = Integer.valueOf(String.valueOf(focusCount.get(0).get("count")));
                }
                json.put("focusAmount", focusAmount);
                json.put("focusAmount", temp.size());
                if (label.getLabelCode().equals("0") && labelType.equals("1") && amount < 1) {
                    continue;
@ -163,4 +241,10 @@ public class GcLabelService {
        }
        return result;
    }
    public List<DictModel> getUnitLabels(String areas) {
        String sql = "select code, name  from dm_hospital  where level=2 and town in ("+areas+" ) " ;
        List<DictModel> returnList = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DictModel.class));
        return returnList;
    }
}