فهرست منبع

Merge branch 'dev' of zengmengkang/wlyy2.0 into dev

wangzhinan 5 سال پیش
والد
کامیت
ce338a3477

+ 154 - 0
business/base-service/src/main/java/com/yihu/jw/evaluate/score/service/BaseEvaluateScoreService.java

@ -0,0 +1,154 @@
package com.yihu.jw.evaluate.score.service;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.score.BaseEvaluateScoreDO;
import com.yihu.jw.evaluate.score.dao.BaseEvaluateScoreDao;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author zmk
 * @vsrsion 1.0
 * Created at 2019/12/6
 */
@Service
@Transactional
public class BaseEvaluateScoreService extends BaseJpaService<BaseEvaluateScoreDO, BaseEvaluateScoreDao> {
    @Autowired
    private BaseEvaluateScoreDao baseEvaluateScoreDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 计算总评分,周同比,日环比
     * @param area
     * @param level
     * @return
     */
    public Map<String, Object> getScoreAndPercentage(String area, int level){
        HashMap<String, Object> map = new HashMap<>();
        //今日凌晨、当前时间
        String startTime = DateUtil.getStringDateShort()+" 00:00:00";
        String nowTime = DateUtil.getStringDate();
        //昨日时间
        String oneDayAgo = DateUtil.getNextDay(startTime, -1);
        String oneStrTime = oneDayAgo + " 00:00:00";
        String oneEndTime = oneDayAgo + " 23:59:59";
        //七天之前时间
        String sevenDayAgo = DateUtil.getNextDay(startTime, -7);
        String sevenStrTime = sevenDayAgo + " 00:00:00";
        String sevenEndTime = sevenDayAgo + " 23:59:59";
        //服务总评分
        map.put("totalAvgScore",getAvgScore(null, null, area, level));
        //周同比
        map.put("weekJudge",judgeScore(getAvgScore(startTime, nowTime, area, level),getAvgScore(sevenStrTime, sevenEndTime, area, level)));
        //日环比
        map.put("dayJudge",judgeScore(getAvgScore(startTime, nowTime, area, level),getAvgScore(oneStrTime, oneEndTime, area, level)));
        return map;
    }
    /**
     * 计算平均分
     * @param startTime
     * @param endTime
     * @param area
     * @param level
     * @return
     */
    private Double getAvgScore(String startTime,String endTime,String area,int level){
        String sql = "select count(*) as total, sum(score) as score from base.base_evaluate_score o where";
        if (level == 4){
            sql += " o.doctor IN (SELECT doctor_code FROM `base_doctor_hospital` dh where dh.org_code ='"+area+"' and dh.del=1)";
        }else if (level == 5){
            sql += " o.doctor IN (SELECT doctor_code FROM `base_doctor_hospital` dh where dh.dept_code ='"+area+"' and dh.del=1)";
        }else if (level == 6){
            sql += " o.doctor ='"+area+"'";
        }
        if (startTime != null){
            sql += " and o.create_time >='" + startTime + "'";
        }
        if(endTime != null){
            sql += " and o.create_time <='" + endTime + "'";
        }
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
        double total = 0d;
        double score = 0d;
        if(rstotal != null && rstotal.size()>0){
            if (null == rstotal.get(0).get("score")){
                return 0.0;
            }
            total = Double.valueOf((rstotal.get(0).get("total")).toString());
            score = Double.valueOf((rstotal.get(0).get("score")).toString());
            if (0 == total || 0 == score){
                return 0.0;
            }
        }
        double avgScore = score / total;
        DecimalFormat df = new DecimalFormat("0.0");//格式化小数,不足的补0
        String filesize = df.format(avgScore);
        return Double.valueOf(filesize);
    }
    /**
     * 计算周同比和日环比
     * @param nowScore
     * @param oldScore
     */
    private Object judgeScore(Double nowScore, Double oldScore){
        JSONObject object = new JSONObject();
        if (nowScore > oldScore){
            if (oldScore == 0){
                object.put("trend",1);
                object.put("percentage","100%");
            }else {
                Double difScore = nowScore - oldScore;
                String percentage = getPercentage((float) (difScore.intValue()), (float) oldScore.intValue());
                object.put("trend",1);
                object.put("percentage",percentage);
            }
        }else if (nowScore < oldScore){
            Double difScore = oldScore - nowScore;
            String percentage = getPercentage((float) (difScore.intValue()), (float) oldScore.intValue());
            object.put("trend",-1);
            object.put("percentage",percentage);
        }else {
            String percentage = "0%";
            object.put("trend",0);
            object.put("percentage",percentage);
        }
        return object;
    }
    /**
     * 计算百分比
     * @param num1
     * @param num2
     * @return
     */
    private String getPercentage(float num1,float num2){
        //创建一个数值格式化对象
        NumberFormat format = NumberFormat.getInstance();
        //设置精确到小数点后两位
        format.setMaximumFractionDigits(2);
        String result = format.format(num1 / num2 * 100) + "%";
        return result;
    }
}

+ 16 - 3
business/es-service/src/main/java/com/yihu/jw/es/service/StatisticsEsService.java

@ -15,6 +15,7 @@ import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import com.yihu.jw.es.util.ElasticsearchUtil;
import com.yihu.jw.es.util.SaveModel;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.evaluate.score.service.BaseEvaluateScoreService;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.StringUtil;
import jdk.management.resource.internal.inst.FileOutputStreamRMHooks;
@ -46,6 +47,8 @@ public class StatisticsEsService {
    private BaseDoctorHospitalDao doctorHospitalDao;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private BaseEvaluateScoreService baseEvaluateScoreService;
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    /**
@ -62,13 +65,19 @@ public class StatisticsEsService {
    public JSONObject getTotalAmount(String startDate, String endDate, String area, int level, String index, String level2_type) throws Exception {
        //问诊量
        SaveModel saveModel = null;
        //开方量
        SaveModel saveModel1 = null;
        String[] indexes = index.split(",");
        if (StringUtils.isNotEmpty(level2_type)) {
            saveModel = elasticsearchUtil.findOneDateQuotaLevel1(endDate, endDate, area, level, index, SaveModel.timeLevel_DDL, level2_type);
            saveModel = elasticsearchUtil.findOneDateQuotaLevel1(endDate, endDate, area, level, indexes[0], SaveModel.timeLevel_DDL, level2_type);
            saveModel1 = elasticsearchUtil.findOneDateQuotaLevel1(endDate, endDate, area, level, indexes[1], SaveModel.timeLevel_DDL, level2_type);
        } else {
            saveModel = elasticsearchUtil.findOneDateQuotaLevel0(endDate, endDate, area, level, index, SaveModel.timeLevel_DDL);
            saveModel = elasticsearchUtil.findOneDateQuotaLevel0(endDate, endDate, area, level, indexes[0], SaveModel.timeLevel_DDL);
            saveModel1 = elasticsearchUtil.findOneDateQuotaLevel0(endDate, endDate, area, level, indexes[1], SaveModel.timeLevel_DDL);
        }
        JSONObject object = new JSONObject();
        object.put("outPatientCount",saveModel.getResult2().longValue());//问诊量
        object.put("prescriptionCount",saveModel1.getResult2().longValue());//开方量
        String startTime = DateUtil.getStringDateShort()+" 00:00:00";
        String endTime = DateUtil.getStringDateShort() +" 23:59:59";
        String sql = "select count(*) as total from base.wlyy_outpatient o where o.status=2 and o.create_time >='"+startTime+"' and o.create_time <='"+endTime+"'";
@ -84,7 +93,11 @@ public class StatisticsEsService {
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        object.put("TodayOutPatientCount",count);//今日问诊量
        object.put("todayOutPatientCount",count);//今日问诊量
        Map<String, Object> scoreAndPercentage = baseEvaluateScoreService.getScoreAndPercentage(area, level);
        object.put("totalAvgScore",scoreAndPercentage.get("totalAvgScore"));//服务总评分
        object.put("weekJudge",scoreAndPercentage.get("weekJudge"));//周同比
        object.put("dayJudge",scoreAndPercentage.get("dayJudge"));//日环比
        return object;
    }

+ 2 - 2
gateway/ag-basic/src/main/resources/application.yml

@ -66,7 +66,7 @@ zuul:
      serviceId: svr-base
    svr-authentication:
      path: /cityihealth/auth/**
      serviceId: svr-authentication-wangzhinan
      serviceId: svr-authentication
    svr-healthy-house:
      path: /cityihealth/healthyHouse/**
      serviceId: svr-healthy-house
@ -75,7 +75,7 @@ zuul:
      serviceId: svr-patient
    svr-internet-hospital:
      path: /hospital/**
      serviceId: svr-internet-hospital-wangzhinan
      serviceId: svr-internet-hospital
    svr-internet-hospital-entrance:
      path: /hospitalEntrance/**
      serviceId: svr-internet-hospital-entrance

+ 1 - 1
gateway/ag-basic/src/main/resources/bootstrap.yml

@ -1,6 +1,6 @@
spring:
  application:
    name: ag-basic-wangzhinan
    name: ag-basic
  cloud:
    config:
      failFast: true

+ 1 - 1
server/svr-authentication/src/main/resources/bootstrap.yml

@ -1,6 +1,6 @@
spring:
  application:
    name: svr-authentication-wangzhinan
    name: svr-authentication-lyx
  cloud:
    config:
      failFast: true

+ 1 - 1
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/base/BaseInfoEndpoint.java

@ -46,7 +46,7 @@ public class BaseInfoEndpoint extends EnvelopRestEndpoint {
    private BaseDoctorHosService baseDoctorHosService;
    @Autowired
    private BaseDoctorInfoService baseDoctorInfoService;
    private BaseDoctorService baseDoctorInfoService;
    @Autowired
    private BaseOrgInfoService baseOrgInfoService;

+ 1 - 1
svr/svr-internet-hospital/src/main/resources/bootstrap.yml

@ -1,6 +1,6 @@
spring:
  application:
    name:  svr-internet-hospital-wangzhinan
    name:  svr-internet-hospital
  cloud:
    config:
      failFast: true