/*
 * ********************************************************************************************************************
 *
 *                     :*$@@%$*:                         ;:                ;;    ;;
 *                   :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
 *                  :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
 *                  =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
 *                  =@*                                  %!              @ $= % %@=   =%@!      %=
 *             *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
 *           %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
 *         ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
 *         $@*   ;@@@%=!:                *@*
 *         =@$    ;;;!=%@@@@=!           =@!
 *          %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
 *           ;%@@$=$@@%*       *@@@$=%@@%;
 *              ::;::             ::;::                                              All rights reserved.
 *
 * ********************************************************************************************************************
 */

package com.persagy.server.controllers.objects

import com.persagy.server.datacenter.models.entities.objects.Floor
import com.persagy.server.services.objects.FloorService
import com.persagy.base.extensions.toJson
import com.persagy.database.SFilter
import com.persagy.service.SPageContext
import com.persagy.service.models.requests.SCreateRequest
import com.persagy.service.models.requests.SQueryRequest
import com.persagy.service.models.requests.SUpdateRequest
import com.persagy.service.models.responses.SBaseResponse
import com.persagy.service.models.responses.SCreateResponse
import com.persagy.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 张维新
 */
@Api(tags = ["003、楼层"])
@RestController
@RequestMapping("/object/floor")
open class FloorController {
    companion object {
        // 日志
        private val logger = LoggerFactory.getLogger(FloorController::class.java)
    } // Companion object

    /**
     * 创建楼层
     *
     * @param   request     楼层对象
     * @return              创建结果信息
     */
    @ApiOperation(value = "创建楼层", notes = "")
    @PostMapping(value = ["/create"])
    fun create(@RequestBody request: SCreateRequest<Floor>): SCreateResponse<Floor> {
        logger.debug("floor =${request.toJson()}")
        return FloorService.createList(request)
    } // Function create()

    /**
     * 根据id删除楼层
     *
     * @param   idList  id数组
     * @return          删除的结果信息
     */
    @ApiOperation(value = "根据id删除楼层", notes = "")
    @PostMapping(value = ["/delete"])
    fun delete(@RequestBody idList: ArrayList<Floor>): SBaseResponse {
        return FloorService.deleteByKeysList( idList)
    } // Function delete()

    /**
     * 更新楼层信息
     *
     *
     * @param   request     更新的内容对象
     * @return              更新的结果
     */
    @ApiOperation(value = "更新楼层信息", notes = "")
    @PostMapping(value = ["/update"])
    fun update(@RequestBody request: SUpdateRequest<Floor>): SBaseResponse {
        logger.debug("floorUpdate =${request.toJson()}")
        return FloorService.updateList(request)
    } // Function update()

    /**
     * 更新楼层信息-Outline
     *
     *
     * @param   request     更新楼层信息-Outline
     * @return              更新的结果
     */
    @ApiOperation(value = "更新楼层信息-Outline", notes = "")
    @PostMapping(value = ["/update-outline"])
    fun updateOutlines(@RequestBody request: SUpdateRequest<Floor>): SBaseResponse {
        logger.debug("floorUpdate =${request.toJson()}")
        return FloorService.updateOutline(request)
    } // Function update()

    /**
     * 查询楼层信息
     *
     * @param   request     查询信息条件
     * @return              查询结果
     */
    @ApiOperation(value = "查询楼层信息", notes = "级联对象：建筑（building）、项目（project）、楼层贯通关系（floorThroughList）")
    @PostMapping(value = ["/query-outline"])
    fun queryOutline(@RequestBody request: SQueryRequest): SQueryResponse<Floor> {
        logger.debug("floorQuery =${request.toJson()}")
        if (!request.projection.isNullOrEmpty()){
            request.projection!!.clear()
        }
        val list = ArrayList<String>()
        list.add("FloorID")
        list.add("FloorName")
        list.add("FloorLocalID")
        list.add("FloorLocalName")
        list.add("Outline")
        list.add("StructureInfo")
        list.add("ModelId")
        request.projection = list
        return FloorService.pageQuery(request, arrayListOf(SFilter.eq("projectId", SPageContext.getHeader("ProjectId").toString())))
    } // Function query()


    /**
     * 查询楼层信息
     *
     * @param   request     查询信息条件
     * @return              查询结果
     */
    @ApiOperation(value = "查询楼层信息", notes = "级联对象：建筑（building）、项目（project）、楼层贯通关系（floorThroughList）")
    @PostMapping(value = ["/query"])
    fun query(@RequestBody request: SQueryRequest): SQueryResponse<Floor> {
        logger.debug("floorQuery =${request.toJson()}")
        return FloorService.pageQuery(request, arrayListOf(SFilter.eq("projectId", SPageContext.getHeader("ProjectId").toString())))
    } // Function query()
} // Class FloorController