浏览代码

首页-修改

wangxingwang 6 年之前
父节点
当前提交
29f846ef43

+ 17 - 1
src/main/java/com/yihu/quota/controller/QuotaController.java

@ -265,7 +265,7 @@ public class QuotaController extends BaseController {
        return envelop;
    }
    @ApiOperation("根据条件到solr中获取记录数")
    /*@ApiOperation("根据条件到solr中获取记录数")
    @RequestMapping(value = "/report/searchSolrByParam", method = RequestMethod.POST)
    public Envelop searchSolrByParam(
            @ApiParam(name = "core", value = "solr core名称")
@ -317,6 +317,22 @@ public class QuotaController extends BaseController {
            envelop.setDetailModelList(yDate);
        }
        return envelop;
    }*/
    @ApiOperation("根据条件到solr中获取记录数,2018-11-09修改成到ES查询")
    @RequestMapping(value = "/report/searchSolrByParam", method = RequestMethod.POST)
    public Envelop searchSolrByParam(
            @ApiParam(name = "core", value = "solr core名称")
            @RequestParam(value = "core") String core,
            @ApiParam(name = "eventType", value = "就诊类型")
            @RequestParam(value = "eventType") String eventType,
            @ApiParam(name = "time", value = "过滤时间")
            @RequestParam(value = "time", required = false) String time,
            @ApiParam(name = "month", value = "获取几个月数据", defaultValue = "0")
            @RequestParam(value = "month", defaultValue = "0", required = false) Integer month) throws Exception {
        Envelop envelop = baseStatistsService.searchEsByParam(eventType, time, month);
        return envelop;
    }

+ 40 - 0
src/main/java/com/yihu/quota/service/quota/BaseStatistsService.java

@ -2,6 +2,7 @@ package com.yihu.quota.service.quota;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.util.datetime.DateUtil;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.quota.dao.jpa.TjQuotaDao;
import com.yihu.quota.dao.jpa.TjQuotaGovProvisionDao;
import com.yihu.quota.etl.extract.es.EsResultExtract;
@ -1967,4 +1968,43 @@ public class BaseStatistsService {
        });
        return map.get("result");
    }
    public Envelop searchEsByParam(String eventType, String time, Integer month) {
        Envelop envelop = new Envelop();
        String start = "", end = "";
        StringBuffer sb = new StringBuffer();
        List<String> xData = new ArrayList<>(); // x轴坐标
        List<String> yData = new ArrayList<>(); // x轴坐标对应的值
        // 设置查询时间范围
        if (StringUtils.isNotEmpty(time)) {
            SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd'T'23:59:59'Z'");
            Date dateTime = DateUtil.strToDate(time);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(dateTime);
            calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
            end = dfs.format(calendar.getTime());
            calendar.add(Calendar.MONTH, -(month - 1));
            calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
            start = DateUtil.utcToDate(calendar.getTime());
        }
        if ("0".equals(eventType)) {
            sb.append("SELECT count(*) FROM medical_service_index where quotaCode='HC041100' and slaveKey1=0 and quotaDate>='")
                    .append(start).append("' and quotaDate<='").append(end).append("' group by date_histogram(field='quotaDate', 'interval'='month')");
        } else if ("1".equals(eventType)) {
            sb.append("SELECT count(*) FROM medical_service_index where quotaCode='HC041103' and quotaDate>='")
                    .append(start).append("' and quotaDate<='").append(end).append("' group by date_histogram(field='quotaDate', 'interval'='month')");
        }
        log.info(sb.toString());
        List<Map<String, Object>> list = elasticsearchUtil.excuteDataModel(sb.toString());
        list.forEach(one -> {
            xData.add((one.get("date_histogram(field=quotaDate,interval=month)") + "").substring(0,7));
            yData.add(one.get("COUNT(*)") + "");
        });
        envelop.setSuccessFlg(true);
        envelop.setObj(xData);
        envelop.setDetailModelList(yData);
        return envelop;
    }
}