///*
// * ********************************************************************************************************************
// *
// *               iFHS7.
// *              ;BBMBMBMc                  rZMBMBR              BMB
// *              MBEr:;PBM,               7MBMMEOBB:             BBB                       RBW
// *     XK:      BO     SB.     :SZ       MBM.       c;;     ir  BBM :FFr       :SSF:    ;xBMB:r   iuGXv.    i:. iF2;
// *     DBBM0r.  :D     S7   ;XMBMB       GMBMu.     MBM:   BMB  MBMBBBMBMS   WMBMBMBBK  MBMBMBM  BMBRBMBW  .MBMBMBMBB
// *      :JMRMMD  ..    ,  1MMRM1;         ;MBMBBR:   MBM  ;MB:  BMB:   MBM. RMBr   sBMH   BM0         UMB,  BMB.  KMBv
// *     ;.   XOW  B1; :uM: 1RE,   i           .2BMBs  rMB. MBO   MBO    JMB; MBB     MBM   BBS    7MBMBOBM:  MBW   :BMc
// *     OBRJ.SEE  MRDOWOR, 3DE:7OBM       .     ;BMB   RMR7BM    BMB    MBB. BMB    ,BMR  .BBZ   MMB   rMB,  BMM   rMB7
// *     :FBRO0D0  RKXSXPR. JOKOOMPi       BMBSSWBMB;    BMBB:    MBMB0ZMBMS  .BMBOXRBMB    MBMDE RBM2;SMBM;  MBB   xBM2
// *         iZGE  O0SHSPO. uGZ7.          sBMBMBDL      :BMO     OZu:BMBK,     rRBMB0;     ,EBMB  xBMBr:ER.  RDU   :OO;
// *     ,BZ, 1D0  RPSFHXR. xWZ .SMr                  . .BBB
// *      :0BMRDG  RESSSKR. 2WOMBW;                   BMBMR
// *         i0BM: SWKHKGO  MBDv
// *           .UB  OOGDM. MK,                                          Copyright (c) 2015-2019.  斯伯坦机器人
// *              ,  XMW  ..
// *                  r                                                                     All rights reserved.
// *
// * ********************************************************************************************************************
// */
//
//package cn.sagacloud.server.synchronize
//
//import cn.sagacloud.server.datacenter.models.entities.syncmessage.ObjectNoticeOther
//import cn.sagacloud.server.datacenter.models.entities.syncmessage.RelationNoticeOther
//import cn.sagacloud.server.dataplatform.entities.syncmessage.SynchronousMessageObj
//import cn.sagacloud.server.dataplatform.entities.syncmessage.SynchronousMessageRel
//import cn.sagacloud.server.synchronize.entities.ObjectNotice
//import cn.sagacloud.server.synchronize.entities.RelationNotice
//import com.google.gson.Gson
//import com.persagy.base.extensions.toJson
//import com.persagy.mybatis.SMybatisDao
//import com.persagy.service.SBaseService
//import com.persagy.service.kafka.SBaseNotice
//import com.persagy.service.kafka.SKafkaService
//import org.apache.kafka.clients.consumer.ConsumerRecord
//import org.springframework.beans.factory.annotation.Autowired
//import org.springframework.kafka.annotation.KafkaListener
//import org.springframework.kafka.core.KafkaTemplate
//import org.springframework.stereotype.Service
//
///**
// * Kafka 服务。用于连接 kafka, 收发 kafka 消息
// *
// * @author  庞利祥 <sybotan@126.com>
// */
//@Service
//open class KafkaService @Autowired constructor(template: KafkaTemplate<*, *>) : SKafkaService() {
//    init {
//        @Suppress("UNCHECKED_CAST")
//        kafkaTemplate = template as KafkaTemplate<Int, String>
//        this.delaySendTime = 5000
//    }
//
//    /** 消息存储服务 */
//    var synchronousMessageObjService = SBaseService(SMybatisDao(SynchronousMessageObj::class.java))
//    /** 关系 */
//    var synchronousMessageRelService = SBaseService(SMybatisDao(SynchronousMessageRel::class.java))
//
//
//
//    @KafkaListener(topics = ["datacenter"])
//    fun processMessage(record: ConsumerRecord<Int, String>) {
//        println("processMessage, topic = ${record.topic()}, msg = ${record.value()}")
//        val gson = Gson()
//        val objectNotice = gson.fromJson(record.value().toString(), ObjectNoticeOther::class.java)
//        val synchronousMessageObj = SynchronousMessageObj()
//        synchronousMessageObj.id = objectNotice.id
//        synchronousMessageObj.projectId = objectNotice.projectId
//        synchronousMessageObj.info = objectNotice
//        synchronousMessageObj.type = objectNotice.ops
//        synchronousMessageObj.objectType = objectNotice.type
//        synchronousMessageObjService.insert(synchronousMessageObj)
//        println("obj, topic = ${record.topic()}, msg = ${objectNotice.toJson()}")
//    } // Fun processMessage()
//
//    @KafkaListener(topics = ["datacenterrel"])
//    fun processMessageRel(record: ConsumerRecord<Int, String>) {
//        println("processMessagerel, topic = ${record.topic()}, msg = ${record.value()}")
//        val gson = Gson()
//        val relationNoticeOther = gson.fromJson(record.value().toString(), RelationNoticeOther::class.java)
//        val synchronousMessageRel = SynchronousMessageRel()
//        synchronousMessageRel.id = relationNoticeOther.id
//        synchronousMessageRel.projectId = relationNoticeOther.projectId
//        synchronousMessageRel.info = relationNoticeOther
//        synchronousMessageRel.type = relationNoticeOther.ops
//        synchronousMessageRel.objectType = relationNoticeOther.type
//        synchronousMessageRelService.insert(synchronousMessageRel)
////        println("obj, topic = ${record.topic()}, msg = ${objectNotice.toJson()}")
//    } // Fun processMessage()
//
//
//    override fun mergeNotice(lastNotice: SBaseNotice, notice: SBaseNotice): Boolean {
//        // 对象消息合并
//        if (notice is ObjectNotice) {
//            // 如果最后发送对象不是对象消息，则返回false
//            val last = lastNotice as? ObjectNotice ?: return false
//            // 操作不同，对象不同，项目不同的通知不合并
//            if (notice.ops != notice.ops || notice.type != last.type || notice.projectId != last.projectId) {
//                return false
//            }
//            // 合并消息
//            last.idList.addAll(notice.idList)
//            return true
//        } else if (notice is RelationNotice) {  // 关系消息合并
//            // TODO: 补 关系类型通知合并代码
//            return true
//        }
//        return false
//    } // Fun mergeNotice()
//} // Class KafkaService
