高效能源监控管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

79 lines
2.3 KiB

package com.mh.common.utils;
import java.util.ArrayList;
import java.util.List;
/**
* @Author : Rainbow
* @date : 2023/7/10
*/
public class TableUtils {
/**
* 主机
*/
public final static String CHILLER = "chiller";
/**
* 电表等参数
*/
public final static String DEVICE = "device";
/**
* 返回表明列表
*
* @param dateType 分钟、小时、日月年
* @param dataType 主机参数、电表等参数
* @param startTime 开始时间
* @param endTime 结束时间
* @return 表名集合
*/
public static List<String> getTableName(String dateType, String dataType, String startTime, String endTime) {
int start = Integer.parseInt(startTime.substring(0, 4));
int end = Integer.parseInt(endTime.substring(0, 4));
if (end < start) {
throw new RuntimeException("时间不正确");
}
List<String> tabNames = new ArrayList<>();
StringBuilder tableName = new StringBuilder();
for (int i = start; i <= end; i++) {
//清空
tableName.setLength(0);
switch (dataType){
case CHILLER:
tableName.append("chillers_data_").append(dateType).append(i);
break;
case DEVICE:
tableName.append("data_").append(dateType).append(i);
break;
default:
break;
}
tabNames.add(tableName.toString());
}
return tabNames;
}
/**
* 返回表名字
*
* @param dateType 分钟、小时、日月年
* @param dataType 主机参数、电表等参数
* @param date 时间
* @return 一个表名
*/
public static String getTableName(String dateType, String dataType, String date) {
StringBuilder tableName = new StringBuilder();
switch (dataType) {
case CHILLER:
tableName.append("chillers_data_");
break;
case DEVICE:
tableName.append("data_");
break;
default:
break;
}
tableName.append(dateType).append(date.substring(0, 4));
return tableName.toString();
}
}