潘志宝
2024-11-15 4be7d863a161b64f8592a789d699e807545e7dc6
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/collection/PlanItemCollector.java
@@ -34,8 +34,6 @@
    public List<PlanItemValueVO> queryValue(String itemNo, Date startTime, Date endTime) {
        List<PlanItemValueVO> result = new ArrayList<>();
        PlanItemEntity itemEntity = planItemService.getInfoByNo(itemNo);
        Map<String, Object> params = new HashMap<String, Object>();
        PlanDataSetEntity dataSet = planDataSetService.get(itemEntity.getDataSet());
        if (dataSet == null) {
            log.warn("数据集不能为空");
@@ -45,24 +43,14 @@
            log.warn("数据源不能为空");
            return null;
        }
        Map<String, Object> params = getSqlParams(dataSet, startTime, endTime);
        DataContextHolder.setDataSourceId(Long.valueOf(dataSet.getDataSource()));
        params.put("selectSql", " plan_t.start_time, plan_t.end_time");
        params.put("viewSql", dataSet.getQuerySql());
        StringBuilder whereSql = new StringBuilder();
        String startStr = DateUtils.format(startTime, DateUtils.DATE_NUMBER_PATTERN);
        String endStr = DateUtils.format(endTime, DateUtils.DATE_NUMBER_PATTERN);
        whereSql.append(" plan_t.start_time <= " )
                .append(endStr)
                .append(" and plan_t.end_time >= ")
                .append(startStr);
        params.put("whereSql", whereSql.toString());
        List<PlanItemDataVO> dataList = planItemService.getSourceValue(params);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startTime);
        int dataLength = (int)((endTime.getTime() - startTime.getTime()) / (1000 * 60)) + 1;
        for (int i = 0; i < dataLength; i ++) {
        int dataLength = (int) ((endTime.getTime() - startTime.getTime()) / (1000 * 60)) + 1;
        for (int i = 0; i < dataLength; i++) {
            PlanItemValueVO itemValue = new PlanItemValueVO();
            Date dataTime = calendar.getTime();
            itemValue.setDataTime(dataTime);
@@ -82,4 +70,36 @@
        }
        return result;
    }
    public List<PlanItemDataVO> getSourceValue(String itemNo, Date startTime, Date endTime) {
        PlanItemEntity itemEntity = planItemService.getInfoByNo(itemNo);
        PlanDataSetEntity dataSet = planDataSetService.get(itemEntity.getDataSet());
        if (dataSet == null) {
            log.warn("数据集不能为空");
            return null;
        }
        if (StringUtils.isEmpty(dataSet.getDataSource())) {
            log.warn("数据源不能为空");
            return null;
        }
        Map<String, Object> params = getSqlParams(dataSet, startTime, endTime);
        return planItemService.getSourceValue(params);
    }
    private Map<String, Object> getSqlParams(PlanDataSetEntity dataSet, Date startTime, Date endTime) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("selectSql", " plan_t.start_time, plan_t.end_time");
        params.put("viewSql", dataSet.getQuerySql());
        StringBuilder whereSql = new StringBuilder();
        String startStr = DateUtils.format(startTime, DateUtils.DATE_NUMBER_PATTERN);
        String endStr = DateUtils.format(endTime, DateUtils.DATE_NUMBER_PATTERN);
        whereSql.append(" plan_t.start_time <= '")
                .append(endStr)
                .append("'")
                .append(" and plan_t.end_time >= '")
                .append(startStr)
                .append("'");
        params.put("whereSql", whereSql.toString());
        return params;
    }
}