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

package com.persagy.server.controllers


import com.persagy.database.SFilter
import com.persagy.server.datacenter.models.response.EqpeDefferentReqponse
import com.persagy.server.datacenter.models.response.StatisticsCountResponse
import com.persagy.server.service.StatisticsService
import com.persagy.server.service.objects.EquipmentService
import com.persagy.server.service.objects.PropertyService
import com.persagy.service.SPageContext
import com.persagy.service.models.enums.SResponseType
import com.persagy.service.models.requests.SCountRequest
import com.persagy.service.models.responses.SCountResponse
import com.persagy.service.models.responses.SQueryResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
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  邓婷婷
 */
@Tag(name = "统计接口")
@RestController
@RequestMapping("/statistics")
open class StatisticsController {

    companion object {
        // 日志
        private val logger = LoggerFactory.getLogger(StatisticsController::class.java)
    } // Companion object

    /** 实例化  对象 */
    @Autowired
    lateinit var service: StatisticsService


    /**
     * 台账中待删除的对象
     */
    @Operation(summary = "台账中待删除的对象", description = "传入条件：taskState = -1")
    @PostMapping(value = ["/object-delete-count"])
    fun objectDeleteCount(@RequestBody request: SCountRequest): SCountResponse {
        val withFilterList = ArrayList<SFilter>()
        withFilterList.add(SFilter.eq("projectId", SPageContext.getHeader("projectId").toString()))
        val countResponse1 = EquipmentService.count(request, withFilterList)
        val countResponse2 = PropertyService.count(request, withFilterList)
        val count = countResponse1.count + countResponse2.count
        return SCountResponse(count)
    } // Function objectDeleteCount()


    /**
     * 不能同步到物理世界的关系数据
     */
    @Operation(summary = "不能同步到物理世界的关系数据", description = "")
    @PostMapping(value = ["/unsyn-relation-count"])
    fun unSynchronizeRelationCount(): SCountResponse {
        return service.unSynchronizeRelation()
    } // Function unSynchronizeRelation()

    /**
     * 岗位和关联的资产信息点值不一致
     */
    @Operation(summary = "岗位和关联的资产信息点值不一致", description = "")
    @PostMapping(value = ["/eq2pe-count"])
    fun eq2peCount(): SCountResponse {
        return service.eq2peCount()
    }

    /**
     * 岗位和关联的资产信息点值不一致的数据
     */
    @Operation(summary = "岗位和关联的资产信息点值不一致的数据", description = "")
    @PostMapping(value = ["/eq2pe-different"])
    fun eq2peDifferent(): SQueryResponse<ArrayList<EqpeDefferentReqponse>> {
        return service.eq2peDifferent()
    }

    /**
     * 设备-未关联资产的设备
     */
    @Operation(summary = "设备-未关联资产的设备", description = "")
    @PostMapping(value = ["/uneq2pe-count"])
    fun uneq2pe(): SCountResponse {
        return service.uneq2pe()
    }

    /**
     * 业务空间-各分区占比
     */
    @Operation(summary = "业务空间-各分区占比", description = "")
    @PostMapping(value = ["/sp-objecttype-count"])
    fun spObjectType(): SQueryResponse<StatisticsCountResponse> {
        return try {
            val sQueryResponse = SQueryResponse<StatisticsCountResponse>(SResponseType.success)
            sQueryResponse.content = service.spObjectTypeCount()
            sQueryResponse
        } catch (e: Exception) {
            e.printStackTrace()
            SQueryResponse(SResponseType.failure, e.message.toString())
        }
    }

    /**
     * 业务空间-默认分区功能类型占比
     */
    @Operation(summary = "业务空间-默认分区功能类型占比", description = "")
    @PostMapping(value = ["/general-sp-functype-count"])
    fun generalSpFuncTypeCount(): SQueryResponse<StatisticsCountResponse> {
        return try {
            val sQueryResponse = SQueryResponse<StatisticsCountResponse>(SResponseType.success)
            sQueryResponse.content = service.generalSpFuncTypeCount()
            sQueryResponse
        } catch (e: Exception) {
            e.printStackTrace()
            SQueryResponse(SResponseType.failure, e.message.toString())
        }
    }

    /**
     * 租户-关联业务空间完成度
     */
    @Operation(summary = "租户-关联业务空间完成度", description = "")
    @PostMapping(value = ["/tenant2sp-count"])
    fun tenant2SpCount(): SCountResponse {
        return service.tenant2SpCount()
    }

    /**
     * 竖井-关联业务空间完成度
     */
    @Operation(summary = "竖井-关联业务空间完成度", description = "")
    @PostMapping(value = ["/shaft2sp-count"])
    fun shaft2SpCount(): SCountResponse {
        return service.shaft2SpCount()
    }

    /**
     * 竖井-按功能类型占比
     */
    @Operation(summary = "竖井-按功能类型占比", description = "")
    @PostMapping(value = ["/shaft-functype-count"])
    fun shaftFuncTypeCount(): SQueryResponse<StatisticsCountResponse> {
       return try {
            val sQueryResponse = SQueryResponse<StatisticsCountResponse>(SResponseType.success)
            sQueryResponse.content = service.shaftFuncTypeCount()
            sQueryResponse
        } catch (e: Exception) {
            e.printStackTrace()
           SQueryResponse(SResponseType.failure,e.message.toString())
        }
    }


}