package com.persagy.server.service

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.persagy.base.extensions.toJson
import com.persagy.server.dao.mappers.CustomSql
import com.persagy.server.dao.mappers.EquipmentZoneMapper
import com.persagy.server.models.SimilarityDegree
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.lang.reflect.Type

@Service
class EquipmentZoneService {

    companion object {
        /** 日志 */
        private val logger = LoggerFactory.getLogger(EquipmentZoneService::class.java)

    } // Companion object


    @Autowired
    lateinit var equipZoneMapper : EquipmentZoneMapper

    @Autowired
    lateinit var mapperCustomSql : CustomSql

    fun getEquipIdUnderSpace(projectId : String, zoneType : String?, zoneId : String?) : ArrayList<String>{
        return equipZoneMapper.selectEquipUnderSpace(projectId, zoneType, zoneId)
    }



    fun selectAllEquipsUnderSpace(projectId : String) : ArrayList<String>{
        return equipZoneMapper.selectAllEquipsUnderSpace(projectId)

    }


    fun similars(){
        try {
            val list = ArrayList<String>()
            list.add("北京市")
            list.add("上海-市")
            list.add("田径 是")
            val similarList = equipZoneMapper.similar("北 京", list,2,0.9f)
            val gson = Gson()
            val type: Type = object : TypeToken<List<SimilarityDegree>>() {}.getType()
            val lists: List<SimilarityDegree> = gson.fromJson(similarList, type)

                logger.debug("数据输出=${lists.toJson()}")

            val map = HashMap<String,String>()
            map.put("name","435")
            logger.debug("数据输出000=${map.toJson()}")
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }



}