LAPTOP-KB9HII50\70708 před 11 měsíci
rodič
revize
fbb4416608

+ 74 - 133
business/es-service/src/main/java/com/yihu/jw/es/service/StatisticsEsService.java

@ -7141,15 +7141,14 @@ public class StatisticsEsService {
        //查询人数
        String patientCountSql = "SELECT count(DISTINCT p.patient) 'count' FROM  wlyy_outpatient p  WHERE `p`.`pay_status` in (1,2) AND p.`create_time`>='" + qvo.getStartDate() + "' AND p.`create_time`<='" + qvo.getEndDate() + " 23:59:59' ";
        //全部问诊量
        String indexSql = "SELECT count(ct.id) FROM wlyy_consult_outpatient_info ct WHERE " +
                " ct.type IN (1, 9, 12, 15, 16,17) AND ct.create_time <'"+qvo.getEndDate()+" 23:59:59' AND ct.create_time >='"+qvo.getStartDate()+"' ";
        CompletableFuture<Void> future01 = CompletableFuture.runAsync(() -> {
            try {
                //全部问诊量
                SaveModel saveModel = elasticsearchUtil.findOneDateQuotaLevel0(qvo.getEndDate(), qvo.getEndDate(), qvo.getArea(), qvo.getLevel(), qvo.getIndex(), SaveModel.timeLevel_DDL);
                if (saveModel != null) {
                    map.put("allConsultCount", saveModel.getResult2().longValue());
                } else {
                    map.put("allConsultCount", 0);
                }
                Integer allConsultCount = jdbcTemplate.queryForObject(indexSql, Integer.class);
                map.put("allConsultCount", allConsultCount);
            } catch (Exception e) {
                e.printStackTrace();
            }
@ -7268,58 +7267,23 @@ public class StatisticsEsService {
        // 服务评分
        String scoreSql = "SELECT ROUND(AVG(score),2) 'score' FROM base_evaluate_score ";
        String index2Sql = "SELECT COUNT(a.id) FROM wlyy_prescription a where a.status>=30  AND a.create_time <'"+qvo.getEndDate()+" 23:59:59' AND a.create_time >='"+qvo.getStartDate()+"' ";
        //开方量
        Integer num = jdbcTemplate.queryForObject(index2Sql, Integer.class);
        resultMap.put("kfl", num);
        CompletableFuture<Void> future01 = CompletableFuture.runAsync(() -> {
            //开方量
            try {
                SaveModel model = elasticsearchUtil.findOneDateQuotaLevel0(qvo.getEndDate(), qvo.getEndDate(), qvo.getArea(), qvo.getLevel(), "2", SaveModel.timeLevel_DDL);
                if (model != null) {
                    resultMap.put("kfl", model.getResult2().longValue());//赋值开发量
                } else {
                    resultMap.put("kfl", 0);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, execute);
        CompletableFuture<List<SaveModel>> future02 = CompletableFuture.supplyAsync(() -> {
            //接诊量
            List<SaveModel> model = null;
            try {
                model = elasticsearchUtil.findListDateQuotaLevel2(qvo.getStartDate(), qvo.getEndDate(), qvo.getArea(), qvo.getLevel(), "12,14,16", SaveModel.timeLevel_ZL, null, "9,16,12,1,17", "1");
            } catch (Exception e) {
                e.printStackTrace();
            }
            return model;
        }, execute);
        CompletableFuture<SaveModel> future03 = CompletableFuture.supplyAsync(() -> {
            SaveModel model = null;
            try {
                //接诊量
                model = elasticsearchUtil.findOneDateQuotaLevel0(qvo.getEndDate(), qvo.getEndDate(), qvo.getArea(), qvo.getLevel(), "5", SaveModel.timeLevel_DDL);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return model;
        }, execute);
        //指标12,14,16
        //接诊量
        String indexSql = "SELECT COUNT(ct.id)  FROM wlyy_consult_outpatient_info ct " +
                "WHERE  ct.type IN(1,9,12,15,16,17) and ct.visite_status=1 AND ct.create_time <'"+qvo.getEndDate()+" 23:59:59' AND ct.create_time >='"+qvo.getStartDate()+"' ";
        CompletableFuture<Void> future04 = CompletableFuture.runAsync(() -> {
            String score = jdbcTemplate.queryForObject(scoreSql, String.class);
            resultMap.put("score", score);//赋值评分
        }, execute);
        CompletableFuture.allOf(future01, future02, future03, future04).get();
        List<SaveModel> jzModelList = future02.get();
        SaveModel model = future03.get();
        String index5Sql = "SELECT COUNT(ct.id)  FROM wlyy_consult_outpatient_info ct " +
                "WHERE  ct.type IN(1,9,12,15,16,17) AND ct.create_time <'"+qvo.getEndDate()+" 23:59:59' AND ct.create_time >='"+qvo.getStartDate()+"' ";
        int patientVolume = countListTotal(jzModelList);
        int allConsultCount = 0;
        if (model != null) {
            allConsultCount = model.getResult2().intValue();
        }
        String score = jdbcTemplate.queryForObject(scoreSql, String.class);
        resultMap.put("score", score);//赋值评分
        int patientVolume = jdbcTemplate.queryForObject(indexSql, Integer.class);
        int allConsultCount = jdbcTemplate.queryForObject(index5Sql, Integer.class);
        resultMap.put("jzCount", patientVolume);//赋值接诊量
        resultMap.put("wzAllCount", allConsultCount);//赋值问诊量
@ -7328,13 +7292,13 @@ public class StatisticsEsService {
        return resultMap;
    }
    /**
     * 【总收入】= 诊查费(21) + 处方费(3)
     * 查询诊查费、药品费、平均门诊费用 、总收入
     * 今日新增、本月新增
     */
    public HashMap<String, Object> getFreeDetailCount(ScreenQvo qvo) throws Exception {
        DecimalFormat df = new DecimalFormat("#.00");
        HashMap<String, Object> resultMap = new HashMap<>();
        String[] dateList = getFirstAndEndDay(qvo.getEndDate());
        //今天的
@ -7360,86 +7324,63 @@ public class StatisticsEsService {
                "		AND bop.pay_price IS NOT NULL AND bop.pay_price>0\n" +
                "		AND o.create_time  >='" + qvo.getEndDate() + "'  AND o.create_time <='" + qvo.getEndDate() + " 23:59:59' \n" +
                ") q ";
        CompletableFuture<SaveModel> future01 = CompletableFuture.supplyAsync(() -> {
            SaveModel model = null;
            try {
                //处方费
                model = elasticsearchUtil.findOneDateQuotaLevel0(qvo.getEndDate(), qvo.getEndDate(), qvo.getArea(), qvo.getLevel(), "3", SaveModel.timeLevel_DDL);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return model;
        }, execute);
        CompletableFuture<SaveModel> future02 = CompletableFuture.supplyAsync(() -> {
            SaveModel model = null;
            try {
                //检查费
                model = elasticsearchUtil.findOneDateQuotaLevel0(qvo.getEndDate(), qvo.getEndDate(), qvo.getArea(), qvo.getLevel(), "21", SaveModel.timeLevel_DDL);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return model;
        }, execute);
        CompletableFuture<SaveModel> future03 = CompletableFuture.supplyAsync(() -> {
            SaveModel model = null;
            try {
                //本月新增[处方费+检查费]
                model = elasticsearchUtil.findOneDateQuotaLevel0(dateList[0], dateList[1], qvo.getArea(), qvo.getLevel(), "3,21", SaveModel.timeLevel_ZL);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return model;
        }, execute);
        CompletableFuture<String> future04 = CompletableFuture.supplyAsync(() -> {
            String todayFree = jdbcTemplate.queryForObject(sql, String.class);
            return todayFree;
        }, execute);
        CompletableFuture.allOf(future01, future02, future03, future04).get();
        SaveModel model01 = future01.get();//处方费
        SaveModel model02 = future02.get(); //检查费
        SaveModel monthModel = future03.get();
        String todayFree = future04.get();
        long checkFree = 0;
        long prescriptionFee = 0;
        long allCount;
        if (model01 != null) {
            prescriptionFee = model01.getResult2().longValue();
        }
        if (model02 != null) {
            checkFree = model02.getResult2().longValue();
        }
        allCount = prescriptionFee + checkFree;
        if (checkFree == 0) {
            resultMap.put("checkFree", "0.00");//检查费
        } else {
            resultMap.put("checkFree", checkFree);//检查费
        }
        if (prescriptionFee == 0) {
            resultMap.put("prescriptionFee", "0.00");//处方费
        } else {
            resultMap.put("prescriptionFee", prescriptionFee);//处方费
        }
        if (allCount == 0) {
            resultMap.put("allCount", "0.00");//总费用
        } else {
            resultMap.put("allCount", allCount);//总费用
        }
        if (allCount == 0) {
        Double checkFree = 0.00D;
        Double prescriptionFee = 0.00D;
        Double allCount = 0.00D;
        Double monthAdd = 0.00D;//本月新增
        //处方费
        String index3Sql = "SELECT SUM(p.drug_fee) as num " +
                "FROM wlyy_prescription p, wlyy_outpatient o " +
                "WHERE p.outpatient_id = o.id AND p.status >=30 AND p.create_time <'"+qvo.getEndDate()+" 23:59:59'  AND p.create_time  >='"+qvo.getStartDate()+"' ";
        List<Map<String,Object>> index3SqlList = jdbcTemplate.queryForList(index3Sql);
        if(index3SqlList.size()>0){
            String num = index3SqlList.get(0).get("num")+"";
            if(!"null".equals(num)){
                prescriptionFee = Double.valueOf(num);
            }
        }
        //检查费
        String index21Sql = "SELECT sum(bop.pay_price) as num FROM wlyy_outpatient o " +
                "LEFT JOIN base_business_order_pay bop ON o.id = bop.relation_code " +
                "WHERE o.pay_status=1 and o.`status` IN(1,2,3) AND o.create_time <'"+qvo.getEndDate()+" 23:59:59'  AND o.create_time  >='"+qvo.getStartDate()+"' ";
        List<Map<String,Object>> index21SqlList = jdbcTemplate.queryForList(index21Sql);
        if(index21SqlList.size()>0){
            String num = index21SqlList.get(0).get("num")+"";
            if(!"null".equals(num)){
                checkFree = Double.valueOf(num);
            }
        }
        //本月新增[处方费+检查费]
        String index321Sql = "SELECT SUM(num) num from( SELECT " +
                " SUM(p.drug_fee) as num FROM  wlyy_prescription p, wlyy_outpatient o " +
                "WHERE p.outpatient_id = o.id AND p.status >=30 AND p.create_time <'"+dateList[1]+" 23:59:59'  AND p.create_time  >='"+dateList[0]+"' "+
                "UNION all " +
                "SELECT sum(bop.pay_price) as num FROM wlyy_outpatient o " +
                "LEFT JOIN base_business_order_pay bop ON o.id = bop.relation_code " +
                "WHERE o.pay_status=1 and o.`status` IN(1,2,3)  AND o.create_time <'"+dateList[1]+" 23:59:59'  AND o.create_time  >='"+dateList[0]+"' "+
                " ) t ";
        List<Map<String,Object>> index321SqlList = jdbcTemplate.queryForList(index321Sql);
        if(index321SqlList.size()>0){
            String num = index321SqlList.get(0).get("num")+"";
            if(!"null".equals(num)){
                monthAdd = Double.valueOf(num);
            }
        }
        String todayFree = jdbcTemplate.queryForObject(sql, String.class);
        allCount = checkFree+prescriptionFee;
        resultMap.put("checkFree", df.format(checkFree));//检查费
        resultMap.put("prescriptionFee", df.format(prescriptionFee));//处方费
        resultMap.put("allCount", df.format(allCount));//总费用
        resultMap.put("todayFree", todayFree);//今日新增
        if (allCount==0) {
            resultMap.put("avgFree", "0.00");
        } else {
            resultMap.put("avgFree", allCount / 2.0);//平均费用
        }
        if (monthModel != null && monthModel.getResult2().longValue() != 0) {
            resultMap.put("monthFree", monthModel.getResult2().longValue());//本月新增
        } else {
            resultMap.put("monthFree", "0.00");
        }
        if ("0".equals(todayFree)) {
            resultMap.put("todayFree", "0.00");
        } else {
            resultMap.put("todayFree", todayFree);//今日新增
            resultMap.put("avgFree", df.format( (allCount / 2.0))+"");//平均费用
        }
        resultMap.put("monthFree", df.format(monthAdd));//本月新增
        System.out.println("结果===>" + JSON.toJSONString(resultMap));
        return resultMap;
    }