package cn.sagacloud.server.algorithm.controllers.modelEntity

import cn.sagacloud.server.algorithm.models.entities.PipeDuctComp
import com.sybotan.database.SFilter
import com.sybotan.mybatis.SMybatisDao
import com.sybotan.service.SObjectService
import com.sybotan.service.models.requests.SCountRequest
import com.sybotan.service.models.requests.SCreateRequest
import com.sybotan.service.models.requests.SQueryRequest
import com.sybotan.service.models.requests.SUpdateRequest
import com.sybotan.service.models.responses.SBaseResponse
import com.sybotan.service.models.responses.SCountResponse
import com.sybotan.service.models.responses.SCreateResponse
import com.sybotan.service.models.responses.SQueryResponse
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 *
 * @author  Cainga
 * @date  2021/1/26 16:39
 */
@Api(tags = ["管道映射接口"])
@RestController
@RequestMapping("/pdComp")
class PdCompController {

    companion object {
        // 日志
        private val logger = LoggerFactory.getLogger(PdCompController::class.java)
    } // Companion object
    
    val pipeDuctCompService = SObjectService(SMybatisDao(PipeDuctComp::class.java))  // 管道映射

    /**
     * 创建管道映射
     *
     * @param   entity     管道映射实体
     * @return  创建结果应答信息
     */
    @ApiOperation(value = "创建管道映射", notes = "")
    @PostMapping(value = ["/create"])
    fun create(@RequestBody entity: SCreateRequest<PipeDuctComp>): SCreateResponse<PipeDuctComp> {
        return pipeDuctCompService.createList(entity)
    } // Function create()

    /**
     * 删除管道映射
     *
     * @param   idList      管道映射ID列表
     * @return  删除结果应答信息
     */
    @ApiOperation(value = "删除管道映射", notes = "")
    @PostMapping(value = ["/delete"])
    fun delete(@RequestBody idList: ArrayList<PipeDuctComp>): SBaseResponse {
        return pipeDuctCompService.deleteByKeysList(idList)
    } // Function delete()

    /**
     * 更新管道映射
     *
     * @param   request     更新请求
     * @return  更新结果应答信息
     */
    @ApiOperation(value = "更新管道映射", notes = "")
    @PostMapping(value = ["/update"])
    fun update(@RequestBody request: SUpdateRequest<PipeDuctComp>): SBaseResponse {
        return pipeDuctCompService.updateList(request)
    } // Function update()

    /**
     * 查询管道映射
     *
     * @param   request     查询请求
     * @return  查询结果应答信息
     */
    @ApiOperation(value = "查询管道映射", notes = "")
    @PostMapping(value = ["/query"])
    fun query(@RequestBody request: SQueryRequest): SQueryResponse<PipeDuctComp> {
        val queryResult = pipeDuctCompService.pageQuery(request)
        if(queryResult.total ==0L){
            request.filters = "projectId ='0'"
            return pipeDuctCompService.pageQuery(request)
        }
        return queryResult
    } // Function query()

    /**
     * 根据条件查询统计数量
     */
    @ApiOperation(value = "根据条件查询统计数量", notes = "")
    @PostMapping(value = ["/count"])
    fun count(@RequestBody request: SCountRequest): SCountResponse {
        return pipeDuctCompService.count(request)
    } // Function count()
}