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

package com.persagy.server.service


import com.persagy.database.SPageQueryInfo
import com.persagy.database.SQueryBuilder
import com.persagy.mybatis.SMybatisDao
import com.persagy.server.models.PointPorperty
import com.persagy.server.models.PropertyFamily
import com.persagy.server.service.base.Service
import com.persagy.service.SObjectService
import com.persagy.service.SPageContext
import com.persagy.service.models.enums.SResponseType
import com.persagy.service.models.requests.SQueryRequest
import com.persagy.service.models.responses.SQueryResponse
import org.slf4j.LoggerFactory

/**
 * 资产关联设备信息服务
 *
 * @author 张维新
 */
object PropertyFamilyService : Service<PropertyFamily>(SMybatisDao(PropertyFamily::class.java)) {
    /** 日志 */
    private val logger = LoggerFactory.getLogger(PropertyFamilyService::class.java)


   val pointPorpertyService = SObjectService(SMybatisDao(PointPorperty::class.java))

    /**
     * 查询之前的操作
     */
    override fun onQueryBefore(queryBuilder: SQueryBuilder<PropertyFamily>) {
        val projectId = SPageContext.getHeader("ProjectId").toString()
        queryBuilder.tableName = "f_project_family('$projectId')"
        return
    } // Function onQueryBefore()

    /**
     * 查询项目下的设备族分类
     *
     * @param   buildingId      建筑id
     * @param   floorId         楼层id
     * @param   startTime       开始时间
     * @param   endingTime      结束时间
     * @param   pointId         点位标签id
     * @param   checked         是否修订
     */
    fun queryFamily(buildingId: String?, floorId: String?,startTime: String?, endingTime: String?,pointId: String?, checked: String?): SQueryResponse<PropertyFamily> {
        val pageQuery: SPageQueryInfo<PropertyFamily>
        return try {
            var request = SQueryRequest()
            val projectId = SPageContext.getHeader("ProjectId").toString()
            val queryBuilder = select(request.filters)
            queryBuilder.tableName = "f_project_family('$projectId','$buildingId','$floorId','$startTime','$endingTime','$pointId','$checked')"
            pageQuery = queryBuilder.pageQuery(1, 1000)
            SQueryResponse(pageQuery)
        } catch (e: Exception) {
            e.printStackTrace()
            SQueryResponse(SResponseType.failure, e.message!!)
        }
    } // Function queryFamily()

    /**
     * 查询项目下的设备族分类
     *
     * @param   buildingId      建筑id
     * @param   floorId         楼层id
     * @param   startTime       开始时间
     * @param   endingTime      结束时间
     */
    fun queryPointPorperty(buildingId: String?, floorId: String?,startTime: String?, endingTime: String?): SQueryResponse<PointPorperty>{
        val pageQuery: SPageQueryInfo<PointPorperty>
        return try {
            var request = SQueryRequest()
            val projectId = SPageContext.getHeader("ProjectId").toString()
            val queryBuilder = pointPorpertyService.select(request.filters)
            queryBuilder.tableName = "f_point_poroerty('$projectId','$buildingId','$floorId','$startTime','$endingTime')"
            pageQuery = queryBuilder.pageQuery(1, 1000)
            SQueryResponse(pageQuery)
        } catch (e: Exception) {
            e.printStackTrace()
            SQueryResponse(SResponseType.failure, e.message!!)
        }
    } // Function queryPointPorperty()


} // Object PropertyService
