Browse Source

咨询统计

trick9191 8 years ago
parent
commit
13e71f7b75

+ 87 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java

@ -1159,4 +1159,91 @@ public class StatisticsService extends BaseService {
        }
    }
    /**
     * 统计回复和未回复
     * @param level
     * @param code
     * @return
     * @throws Exception
     */
    public JSONObject getConsultingStatistics(int level ,String code)throws Exception{
        //获取总数
        String sqlTotal =  getConsultingStatisticsSQL(level,code,1);
        //获取已经回复
        String sqlReply =  getConsultingStatisticsSQL(level,code,2);
        //获取未回复
        String sqlnoReply =  getConsultingStatisticsSQL(level,code,3);
        JSONObject result = new JSONObject();
        Long total =  jdbcTemplate.queryForObject(sqlTotal,Long.class);
        Long reply =  jdbcTemplate.queryForObject(sqlReply,Long.class);
        Long noReply =  jdbcTemplate.queryForObject(sqlnoReply,Long.class);
        if(total == null||total == 0){
            result.put("total","0");
            result.put("replyCount","0");
            result.put("noReplyCount","0");
            result.put("replyRatio","0.00%");
            result.put("noReplyRatio","0.00%");
        }else{
            double rr = (double)reply/total*100;
            double nrr = (double)noReply/total*100;
            DecimalFormat df  = new DecimalFormat("###.00");
            result.put("total",total);
            result.put("replyCount",reply);
            result.put("noReplyCount",noReply);
            if(reply==0){
                result.put("replyRatio","0.00%");
            }else{
                result.put("replyRatio",df.format(rr)+"%");
            }
            if(noReply==0){
                result.put("noReplyRatio","0.00%");
            }else{
                result.put("noReplyRatio",df.format(nrr)+"%");
            }
        }
        return result;
    }
    public String getConsultingStatisticsSQL(int level,String code,int type){
        StringBuffer sql = new StringBuffer("SELECT count(1) " +
                "FROM ichat.topics t,ichat.participants p," +
                "(SELECT d1. CODE FROM " +
                " wlyy_admin_team t1," +
                " wlyy_admin_team_member m1," +
                " wlyy_doctor d1 " +
                " WHERE t1.id = m1.team_id AND d1.CODE = m1.doctor_code ");
        if (level == 4) {
            // 市级别
            sql.append(" AND d1.city = "+code);
        } else if (level == 3) {
            // 区、城镇级别
            sql.append(" AND d1.town = "+code);
        } else if (level == 2) {
            // 机构级别
            sql.append(" AND d1.hospital = "+code);
        } else if (level == 1) {
            // 机构团队级别
            sql.append(" AND t1.id = "+code);
        }
        sql.append(" GROUP BY T1.`name`,d1. CODE) dt " +
                "WHERE p.participant_id = dt.`CODE` AND p.session_id = t.session_id " +
                "AND t.create_time >= DATE_SUB(NOW(),INTERVAL -1 DAY) ");
        if(type == 1){
            //计算总数
        }else if(type == 2){
            //计算及时回复
            sql.append(" AND t.reply = 1 ");
        }else if(type == 3 ){
            //计算未回复
            sql.append(" AND t.reply = 0 ");
        }
        return sql.toString();
    }
}

+ 21 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -529,4 +529,25 @@ public class StatisticsController extends BaseController {
        }
    }
    /**
     * 咨询统计
     * 咨询分析页面具体交互与业务分析内一致,即按市、区、社区、机构有不同展示,可一级级进入查看
     * ①回复及时率------医生首次回复24小时内比例
     * ②未回复数(数、率)----------当前未回复咨询数、以及相应比例
     * ③处理咨询回复时间分布---------全部咨询的首次回复咨询时间分布
     * @param level 查询的等级,按市、区、机构
     * @param code  查询的等级对应Code
     * @return
     */
    @RequestMapping("/Consulting_Stat")
    @ResponseBody
    public String getConsultingStatistics(@RequestParam(required = true) Integer level,
                                          @RequestParam(required = true) String code){
        try{
            return write(200, "查询成功", "data", statisticsService.getConsultingStatistics(level,code));
        }catch (Exception e){
            return error(-1, "查询失败");
        }
    }
}