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

package com.persagy.server.controller


import com.persagy.base.extensions.toJson
import com.persagy.database.SFilter
import com.persagy.mybatis.SMybatisDao
import com.persagy.server.scanbuilding.UserLog
import com.persagy.service.SObjectService
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 = ["009、用户日志接口"])
@RestController
@RequestMapping("/user-log")
open class UserLogController {
    companion object {
        // 日志
        private val logger = LoggerFactory.getLogger(UserLogController::class.java)
    } // Companion object

    private var baseService = SObjectService(SMybatisDao(UserLog::class.java))

    /**
     * 批量创建用户日志
     *
     * @param   request      用户日志对象列表
     * @return                  创建结果信息
     */
    @ApiOperation(value = "创建用户日志", notes = "")
    @PostMapping(value = ["/create"])
    fun create(@RequestBody request: SCreateRequest<UserLog>): SCreateResponse<UserLog> {
        logger.debug("userlog =${request.toJson()}")
        return baseService.createList(request)
    } // Function create()

    /**
     * 根据id删除用户日志
     *
     * @param   entityList  用户日志数组
     * @return              删除的结果信息
     */
    @ApiOperation(value = "根据id删除用户日志", notes = "")
    @PostMapping(value = ["/delete"])
    fun delete(@RequestBody entityList: ArrayList<UserLog>): SBaseResponse {
        return baseService.deleteByKeysList(entityList)
    } // Function delete()

    /**
     * 更新用户日志
     *
     * @param   request     更新的内容对象
     * @return              更新的结果
     */
    @ApiOperation(value = "更新用户日志", notes = "")
    @PostMapping(value = ["/update"])
    fun update(@RequestBody request: SUpdateRequest<UserLog>): SBaseResponse {
        return baseService.updateList(request)
    } // Function update()

    /**
     * 查询用户日志
     *
     * @param   request     查询信息条件
     * @return              查询结果
     */
    @ApiOperation(value = "查询用户日志", notes = "")
    @PostMapping(value = ["/query"])
    fun query(@RequestBody request: SQueryRequest): SQueryResponse<UserLog> {
        return baseService.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 baseService.count(request)
    } // Function count()

} // Class UserLogController