Переглянути джерело

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

huangwenjie 7 роки тому
батько
коміт
853dfa67ee

+ 206 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statisticsES/StatisticsESService.java

@ -20,6 +20,7 @@ import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.web.quota.vo.SaveModel;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.type.StringClobType;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -6202,7 +6203,7 @@ public class StatisticsESService {
        return rsJs;
    }*/
    public JSONArray getDeviceLowLevelTotal(String date, String area, int level, String index, int sort, String lowLevel, String year) throws Exception {
    /*public JSONArray getDeviceLowLevelTotal(String date, String area, int level, String index, int sort, String lowLevel, String year) throws Exception {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String low_level = String.valueOf(org.springframework.util.StringUtils.isEmpty(lowLevel) ? (level + 1) : lowLevel);
        List<Map<String, Object>> resultList = new ArrayList<>();
@ -6212,7 +6213,8 @@ public class StatisticsESService {
        List<SaveModel> esModelList = new ArrayList<>();
        if ((level == 2 && "5".equals(lowLevel)) || (level == 4) || (level == 3 && "5".equals(lowLevel))) {
            String time = DateUtil.getStringDateShort();
            //String time = DateUtil.getStringDateShort();
            String time= elasticsearchUtil.getQuotaTime();
            String sql ="SELECT" +
                    " pd.doctor team," +
                    " pd.doctor_name teamName," +
@ -6225,7 +6227,7 @@ public class StatisticsESService {
                    " AND pd.del = 0" +
                    " AND pd.category_code IN (1, 2)" +
                    " AND pd.czrq>='2018-06-30 17:00:00'"+
                    " AND pd.czrq < '"+time+" 17:00:00'" +
                    " AND pd.czrq <= '"+time+"'" +
                    " AND LEFT(pd.czrq,4)= '"+year+"' AND grant_admin_team NOT IN(SELECT id FROM wlyy_admin_team WHERE LENGTH(org_code)!=10)";
            if(level==3){
                sql +=" AND LEFT(dw.grant_org_code,6)= '"+area+"'";
@ -6266,6 +6268,131 @@ public class StatisticsESService {
            }
        }
        // 结果为空时,自建结果集
        *//*if (resultList == null || resultList.size() < 1) {
            resultList = getLowLevelMapKey(level, low_level, area);
        }*//*
        if (resultList != null) {
            DecimalFormat df = new DecimalFormat("0.0000");
            for (Map<String, Object> map : resultList) {
                map.put("amount", map.get("amount") != null ? Long.valueOf(map.get("amount").toString()) : 0L);
                if (!low_level.equals("5")) {
                    PopulationBase peopleNum = getPopulationBase(area, year);
                    if (peopleNum != null) {
                        map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getNum() * 100));
                        map.put("taskRate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getTaskNum() * 100));
                        map.put("targetRate", df.format(peopleNum.getTaskNum() * 1.0000 / peopleNum.getNum() * 100));
                        map.put("rateString", map.get("amount") + "/" + peopleNum.getNum());
                        map.put("taskRateString", map.get("amount") + "/" + peopleNum.getTaskNum());
                        map.put("targetRateString", peopleNum.getTaskNum() + "/" + peopleNum.getNum());
                        map.put("num", peopleNum.getNum());
                        map.put("task", peopleNum.getTaskNum());
                    }
                }
            }
            *//*if ((level == 2 && "5".equals(lowLevel)) || (level == 4) || (level == 3 && "5".equals(lowLevel))) {
                translateTeamLeaderName(resultList);
            }*//*
            Collections.sort(resultList, new Comparator<Map<String, Object>>() {
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    long map1value = (long) o1.get("amount");
                    long map2value = (long) o2.get("amount");
                    if (map1value - map2value > 0) {
                        return sort == 1 ? -1 : 1;
                    } else if (map1value - map2value < 0) {
                        return sort == 1 ? 1 : -1;
                    } else {
                        return 0;
                    }
                }
            });
            return new JSONArray(resultList);
        } else {
            return new JSONArray();
        }
    }*/
    public JSONArray getDeviceLowLevelTotal(String date, String area, int level, String index, int sort, String lowLevel, String year) throws Exception {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String low_level = String.valueOf(org.springframework.util.StringUtils.isEmpty(lowLevel) ? (level + 1) : lowLevel);
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (date.compareTo(dateFormat.format(new Date())) >= 0) {
            date = elasticsearchUtil.getQuotaTime();
        }
        List<SaveModel> esModelList = new ArrayList<>();
        List<Map<String,Object>> sqlList = new ArrayList<>();
        if ((level == 2 && "5".equals(lowLevel)) || (level == 4) || (level == 3 && "5".equals(lowLevel))) {
            //String time = DateUtil.getStringDateShort();
            String time=  redisTemplate.opsForValue().get("quota:date");
            String sql ="SELECT" +
                    " d.device_code," +
                    " pd.doctor," +
                    " pd.doctor_name," +
                    " pd.user_type" +
                    " FROM" +
                    " device.wlyy_devices d" +
                    " LEFT JOIN wlyy.wlyy_patient_device pd ON d.device_code = pd.device_sn" +
                    " WHERE" +
                    " d.is_binding IN (1, 2)" +
                    " AND pd.category_code IN ('1', '2')" +
                    " AND d.grant_time <= '"+time+"'" +
                    " AND d.grant_admin_team NOT IN(SELECT id FROM wlyy_admin_team WHERE LENGTH(org_code)!=10)"+
                    " ";
            if(level==3){
                sql +=" AND d.grant_admin_team IN(SELECT id FROM wlyy_admin_team WHERE LEFT(org_code,6) = '"+area+"'AND available = 1) AND LEFT(d.grant_org_code,6)= '"+area+"'";
            }else if (level==4){
                sql +=" AND d.grant_admin_team IN(SELECT id FROM wlyy_admin_team WHERE org_code = '"+area+"'AND available = 1) AND d.grant_org_code = '"+area+"'";
            }else if (level==2){
                sql +=" AND d.grant_admin_team IN(SELECT id FROM wlyy_admin_team WHERE available = 1)";
            }
            sqlList = jdbcTemplate.queryForList(sql);
        }else {
            esModelList = (List<SaveModel>) elasticsearchUtil.findListDateQuotaLevel0(year+"-07-01",date, area, level, index, SaveModel.timeLevel_ZL, low_level);
        }
        esModelList = getDeviceBindToTeam(sqlList);
        //到绑定人的封装数据
        if (esModelList != null && esModelList.size() > 0) {
            for (SaveModel one : esModelList) {
                Map<String, Object> maps = new HashMap<String, Object>();
                maps.put("amount", one.getResult1().intValue());
                if (low_level.equals("3")) {
                    maps.put("code", one.getTown());
                    maps.put("name", one.getTownName());
                } else if (low_level.equals("4")) {
                    maps.put("code", one.getHospital());
                    maps.put("name", one.getHospitalName());
                } else if (low_level.equals("5")) {
                    if (StringUtils.isNotEmpty(one.getTeam())){
                        maps.put("code", one.getTeam());
                        if (StringUtils.isEmpty(one.getTeamName())){
                            Doctor doctor = doctorDao.findByCode(one.getTeam());
                            if (doctor!=null){
                                maps.put("name", doctor.getName());
                            }
                        }else {
                            maps.put("name", one.getTeamName());
                        }
                    }
                    if (StringUtils.isEmpty(one.getTeam())){
                        maps.put("code","0");
                        maps.put("name", "其他");
                    }
                }
                resultList.add(maps);
            }
        }
        // 结果为空时,自建结果集
        /*if (resultList == null || resultList.size() < 1) {
            resultList = getLowLevelMapKey(level, low_level, area);
@ -6315,4 +6442,80 @@ public class StatisticsESService {
            return new JSONArray();
        }
    }
    public List<SaveModel> getDeviceBindToTeam(List<Map<String,Object>> dataList) throws Exception{
        if (dataList==null && dataList.size()==0){
            return  null;
        }
        Map<String,Object> resultMap = new HashedMap();
        List<SaveModel> resultList = new ArrayList<>();
        //如果有两个键,则取a键
        for (Map<String,Object> map : dataList){
            String deviceSn = String.valueOf(map.get("device_code"));
            List<Map<String,Object>> deviceList =  null;
            if (resultMap.containsKey(deviceSn)){
                deviceList = (List<Map<String,Object>>)resultMap.get(deviceSn);
                String userType = String.valueOf(deviceList.get(0).get("user_type"));
                if (Integer.parseInt(String.valueOf(map.get("user_type")))<Integer.parseInt(userType)){
                    deviceList.clear();
                    deviceList.add(map);
                }
            }else {
                deviceList = new ArrayList<>();
                deviceList.add(map);
            }
            resultMap.put(deviceSn,deviceList);
        }
        //遍历map
        List<Map<String,Object>> mapList = new ArrayList<>();
        resultMap.forEach((key, value) -> {
            mapList.addAll((List<Map<String,Object>>)value);
        });
        //根据医生code聚合返回页面所需要结果
         Map<String,Object> doctorMap = new HashedMap();
         for (Map<String,Object> map2 : mapList){
             String key = "";
             String doctor = "";
             String doctorName = "";
             if (map2.get("doctor")!= null){
                 doctor = String.valueOf(map2.get("doctor"));
             }
             if (map2.get("doctor_name")!=null){
                 doctorName = String.valueOf(map2.get("doctor_name"));
             }
             if (StringUtils.isEmpty(doctor)){
                 key ="qita,";
             }else if (StringUtils.isNotBlank(doctor)){
                 key =doctor+","+doctorName;
             }
             int count = 0;
             if (doctorMap.containsKey(key)){
                 count = Integer.valueOf(String.valueOf(doctorMap.get(key)));
             }
             count++;
             doctorMap.put(key,count);
         }
         //遍历map
        for (Map.Entry<String,Object> entry : doctorMap.entrySet()){
             SaveModel saveModel = new SaveModel();
             String key = entry.getKey();
             String[] keyStr = key.split(",");
             if(keyStr[0].equals("qita")){
                 saveModel.setTeam("");
             }else {
                 saveModel.setTeam(keyStr[0]);
             }
             if (keyStr.length>1){
                 saveModel.setTeamName(keyStr[1]);
             }
             saveModel.setResult1(Double.valueOf(String.valueOf(entry.getValue())));
             resultList.add(saveModel);
        }
        return  resultList;
    }
}

+ 10 - 8
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/EsStatisticsController.java

@ -517,6 +517,11 @@ public class EsStatisticsController extends BaseController {
                    if ("13".equals(idx)) {
                        idx = "1";
                    }
                    //20指标一个键绑定一条数据 2018年开始所以改用86指标. 2018-08-27 zd
                    String thisYear = Constant.getNowYearByDate(endDate);
                    if ("20".equals(idx) && Integer.valueOf(thisYear)>=2018){
                        idx="86";
                    }
                    JSONObject json = statisticsESService.getDateTotal(startDate, endDate, interval, area, level, idx, lowCode, year,SaveModel.timeLevel_DDL);
                    result.put("index_" + idx, json);
                }
@ -592,7 +597,8 @@ public class EsStatisticsController extends BaseController {
                    } else if (idx.equals("72")) {
                        result.put("index_" + idx, statisticsESService.getLowLevelTotalOnlineTeamLeader(date, area, level, idx, sort, lowLevel, year, ""));
                    }else if (idx.equals("20") && Integer.valueOf(year)>=2018){
                        result.put("index_" + idx, statisticsESService.getDeviceLowLevelTotal(date, area, level, idx, sort, lowLevel, year));
                        //20指标是一个键绑定一条数据 所以2018年开始使用86指标 2018-08-27 zd
                        result.put("index_" + idx, statisticsESService.getDeviceLowLevelTotal(date, area, level, "86", sort, lowLevel, year));
                    }else {
                        result.put("index_" + idx, statisticsESService.getLowLevelTotal(date, area, level, idx, sort, lowLevel, year));
                    }
@ -659,14 +665,10 @@ public class EsStatisticsController extends BaseController {
            JSONObject result = new JSONObject();
            for (String idx : indexes) {
                Long total = 0L;
                if ("20".equals(idx)){
                    endDate = elasticsearchUtil.changeTime(endDate);
                    SaveModel saveModel = elasticsearchUtil.findOneDateQuotaLevel0("2018-07-01",endDate, area, level, index, "1");
                    total =  saveModel.getResult2().longValue();
                }else {
                    total=statisticsESService.getIndexTotal(endDate, area, level, idx, "2");
                if ("20".equals(idx) && Integer.valueOf(year)>=2018){
                    idx = "86";
                }
                Long total=statisticsESService.getIndexTotal(endDate, area, level, idx, "2");
                result.put("index_" + idx, total);
            }