package com.ho.td.util;

import com.ho.common.tools.constant.CommonConstant;
import com.ho.datacollect.api.constant.DataCollectConstant;
import com.ho.td.api.entity.query.TdBaseTimeQuery;

public class TableUtil {

    /**
     * 根据参数获取表名
     * @param query
     * @return
     */
    public static String getTableName(TdBaseTimeQuery query) {
        String colFalg = query.getCol().substring(0, CommonConstant.TWO);
        String substring = query.getCol().substring(CommonConstant.TWO);
        int colNumber = Integer.parseInt(substring);
        int nameSuffix = 0;
        if (CommonConstant.YX.equals(colFalg)) {
            nameSuffix = colNumber / CommonConstant.FIVE_HUNDRED_AND_ONE;
        } else if (CommonConstant.YC.equals(colFalg)) {
            nameSuffix = colNumber / CommonConstant.THREETHOUSAND;
        }
        //将value拼接到表名后面进行查询
        StringBuffer tableName = new StringBuffer();
        tableName.append(query.getGroupId()).append(DataCollectConstant.TABLE_LINK)
                .append(query.getStationId()).append(DataCollectConstant.TABLE_LINK).append(query.getSrcId());
        if (nameSuffix != CommonConstant.ZERO) {
            tableName.append(DataCollectConstant.TABLE_LINK).append(nameSuffix);
        }
        return tableName.toString();
    }
}
