package com.persagy.server.mappers

import org.apache.ibatis.jdbc.SQL

/**
 * 统计
 */
class StatisticsSQL {

    fun equipTypeCount(projectId: String,buildingId: String,floorId: String,listId: ArrayList<String>,listType: ArrayList<String>): String{
        val ids = concateStr(listId)
        val types = concateStr(listType)
        val sql = object: SQL() {
            init {
                //select eq.id equipId, deq.id revitUUID from revit.equipment eq inner join public.equipment deq on deq.bim_id = eq.bimid where eq.id in ('') and deq.project_id = ''
                SELECT("eq.id equipId, deq.id revitUUID")
                FROM("public.equipment eq")
                WHERE("eq.id in (${ids}) and eq.class_code = '${types}' and floorId = '${floorId}'     ")
            }
        }.toString()
        return sql
    }

    fun concateStr(arr : Collection<String>) : String{
        var stringBuilder = StringBuilder()
        arr.forEach {
            stringBuilder.append("\'").append(it).append("\',")
        }
        if(stringBuilder.endsWith(',')){
            stringBuilder.deleteCharAt(stringBuilder.length - 1) //.removeSuffix(",")
        }
        return stringBuilder.toString()
    }


}