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

package com.persagy.server.controllers.objects

import com.persagy.server.datacenter.models.entities.assistant.PointImage
import com.persagy.server.datacenter.models.entities.objects.LocationPoint
import com.persagy.server.services.objects.LocationPointServices
import com.persagy.base.extensions.toJson
import com.persagy.database.SFilter
import com.persagy.service.SPageContext
import com.persagy.service.models.requests.SCountRequest
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.SCountResponse
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 = ["012、点位标签信息"])
@RestController
@RequestMapping("/object/location-point")
open class LocationPointController {
    companion object {
        // 日志
        private val logger = LoggerFactory.getLogger(LocationPointController::class.java)
    } // Companion object

    /**
     * 批量创建点位标签信息
     *
     * @param   request      点位标签信息对象列表
     * @return                  创建结果信息
     */
    @ApiOperation(value = "创建点位标签信息", notes = "")
    @PostMapping(value = ["/create"])
    fun create(@RequestBody request: SCreateRequest<LocationPoint>): SCreateResponse<LocationPoint> {
        logger.debug("building =${request.toJson()}")
        return LocationPointServices.createList(request)
    } // Function create()

    /**
     * 根据id删除点位标签信息
     *
     * @param   entityList      点位标签信息数组
     * @return                  删除的结果信息
     */
    @ApiOperation(value = "批量删除点位标签信息", notes = "")
    @PostMapping(value = ["/delete"])
    fun delete(@RequestBody entityList: ArrayList<LocationPoint>): SBaseResponse {
        return LocationPointServices.deleteByKeysList(entityList)
    } // Function delete()

    /**
     * 更新点位标签信息
     *
     * @param   request     更新的内容对象
     * @return              更新的结果
     */
    @ApiOperation(value = "更新位标签信息", notes = "")
    @PostMapping(value = ["/update"])
    fun update(@RequestBody request: SUpdateRequest<LocationPoint>): SBaseResponse {
        return LocationPointServices.updateList(request)
    } // Function update()

    /**
     * 查询点位标签信息
     *
     * @param   request     查询信息条件
     * @return              查询结果
     */
    @ApiOperation(value = "查询点位标签信息", notes = "级联查询：点位的图片imageList")
    @PostMapping(value = ["/query"])
    fun query(@RequestBody request: SQueryRequest): SQueryResponse<LocationPoint> {
        return LocationPointServices.pageQuery(request,arrayListOf(SFilter.eq("projectId", SPageContext.getHeader("ProjectId").toString())))
    } // Function query()

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

    /**
     * 删除点位照片
     *
     * @param   entityList      点位标签照片列表
     * @return                  删除的结果信息
     */
    @ApiOperation(value = "删除点位照片", notes = "")
    @PostMapping(value = ["/delete-image"])
    fun deleteImage(@RequestBody entityList: ArrayList<PointImage>): SBaseResponse {
        return LocationPointServices.pointImageService.deleteByKeysList(entityList)
    } // Function delete()


} // Class LocationPointController