package com.persagy.server.dao

import org.apache.ibatis.jdbc.SQL


class EquipZoneTwoDao {

    fun selectEquipUnderSpace(projectId: String,zoneType : String?, zoneId : String?) : String{
        return object : SQL() {
            init {
                SELECT("equip_id")
                FROM("r_eq_in_sp_base")
                // 多个where条件之间是默认and连接
                WHERE("project_id = #{projectId} ")
                if(zoneType != null)
                    WHERE("object_type = #{zoneType}")
                if(zoneId != null)
                    WHERE("space_id = #{zoneId}")
            }
        }.toString()
    }



    fun similarityDegree(name: String,listStr:List<String>, total: Int): String{
        return object : SQL() {
            init {
                SELECT("public.rel_cilin_str_similar(#{name}," +
                        " ARRAY["+arrToString(listStr)+
                        "]" +
                        ", #{total})")

            }
        }.toString()
    }

    fun arrToString(listStr:List<String>): String{
        var str = ""
        for (ind in listStr.indices){

//            if (listStr.size-1==ind){
//                str+="'"+listStr[ind]+"'"
//            }else{
//                str+="'"+listStr[ind]+"'"+","
//            }
            if (listStr.size-1==ind){
                str+="#{listStr[${ind}]}"
            }else{
                str+="#{listStr[${ind}]}"+","
            }
        }
        return str
    }


//    object HelloWorld {
//        @JvmStatic
//        fun main(args: Array<String>) {
////            val list = ArrayList<String>()
////            list.add("北京")
////            list.add("田径")
////            val equipZoneDao = EquipZoneDao()
////            val arrToString = equipZoneDao.similarityDegree("北京",list,list.size,0.0f)
////
//            val str = "测试's"
//            val replace = str.replace("'", "\\\'")
//
//            println(replace)
//        }
//    }

}