package com.persagy.server.services.graphtype

import com.persagy.server.services.base.RService
import com.persagy.server.datacenter.models.entities.graphtype.block.ConnectedBlockSource
import com.persagy.server.datacenter.models.entities.graphtype.block.ConnectedBlockSourceRequest
import com.persagy.mybatis.SMybatisDao
import com.persagy.service.SPageContext
import com.persagy.service.models.enums.SResponseType
import com.persagy.service.models.requests.SCreateRequest
import com.persagy.service.models.responses.SCreateResponse
import org.slf4j.LoggerFactory

/**
 * 源末端
 *
 * @author  邓婷婷
 */
object ConnectedBlockSourceService : RService<ConnectedBlockSource>(SMybatisDao(ConnectedBlockSource::class.java))  {

    // 日志
    private val logger = LoggerFactory.getLogger(ConnectedBlockSourceService::class.java)

    /**
     * 覆盖源末端
     */
    fun replaceConnectedBlockSource(request: ConnectedBlockSourceRequest): SCreateResponse<ConnectedBlockSource> {
       return try {
            var projectId = SPageContext.getHeader("ProjectId")
            if(projectId.isNullOrEmpty()){
               projectId = request.projectId
            }
           if(request.buildingId == null){
               delete("projectId = '$projectId' and buildingId isnull and domain = '${request.domain}' and mepSystemType = '${request.mepSystemType}'")
           }else {
               delete("projectId = '$projectId' and  buildingId = '${request.buildingId}' and domain = '${request.domain}' and mepSystemType = '${request.mepSystemType}'")
           }
            val sCreateRequest = SCreateRequest<ConnectedBlockSource>()
            sCreateRequest.content = request.sourceList!!
            ConnectedBlockSourceService.createList(sCreateRequest)
        }catch (e: Exception) {
            e.printStackTrace()
            SCreateResponse(SResponseType.failure,e.message.toString())
        }
    } // Fun replaceConnectedBlockSource


} // Class ConnectedBlockSourceService