package com.persagy.server.services.rel

import com.persagy.server.synchronize.MessageHandler
import com.persagy.server.datacenter.models.entities.rel.RSp2Si
import com.persagy.mybatis.SMybatisDao
import com.persagy.service.SObjectService
import com.persagy.service.SPageContext
import com.persagy.service.utils.SSpringContextUtil
import org.json.JSONObject

/**
 * 业务空间和元空间的关系
 */
object RSp2SiService: SObjectService<RSp2Si>(SMybatisDao(RSp2Si::class.java)) {

    /** MQ消息对象 */
    val messageHandler by lazy {
        SSpringContextUtil.getBean(MessageHandler::class.java) as MessageHandler
    }

    override fun onDeleteSuccess(rEqInSpZoneLightingList: ArrayList<RSp2Si>) {
        val projectId = SPageContext.getHeader("ProjectId")
        for(rEqInSpZoneLighting in rEqInSpZoneLightingList){
            val jsonObject = JSONObject()
            jsonObject.put("type", "12")
            jsonObject.put("projectId", projectId)
            jsonObject.put("id", rEqInSpZoneLighting.id1)
            jsonObject.put("obj_type", "ElementSptoSpace")
            jsonObject.put("linkId",rEqInSpZoneLighting.id2)

            /** 发送消息 */
            messageHandler.sendMessage(jsonObject.toString())
//            kafkaService.sendNotice("datacenterrel", RelationNotice(projectId!!, "EquipinSpace", "12", IdUtils.uuidCreate(), rEqInSpZoneLighting.spaceId!!, rEqInSpZoneLighting.equipId),false)
        }
    } // Fun onDeleteSuccess

} //  Object REq2SpService