package com.persagy.server.controllers.labsl

import com.persagy.database.SFilter
import com.persagy.server.datacenter.models.entities.dictnew.DefClass
import com.persagy.server.datacenter.models.entities.objects.Building
import com.persagy.server.models.labsl.EquipTypeLabsl
import com.persagy.server.service.labsl.CustomSqlLabslService
import com.persagy.server.service.labsl.EquipTypeLabslService
import com.persagy.service.SPageContext
import com.persagy.service.models.requests.SQueryRequest
import com.persagy.service.models.responses.SQueryResponse
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
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 wx  <zhangweixin@sagacloud.com>
 * @date  2020/10/20 23:17
 */
@Api(tags = ["蜡笔森林"])
@RestController
@RequestMapping("/labsl")
class LabslController {
    /** 实例化 mapper 对象 */
    @Autowired
    lateinit var customSqlLabslService: CustomSqlLabslService

    /**
     * 查询项目下的设备类型
     */
    @ApiOperation(value = "查询项目下所有的设备类型", notes = "")
    @PostMapping(value = ["/category"])
    fun equipClassCode(): SQueryResponse<DefClass> {
        return customSqlLabslService.equipTypeStatistics()
    }

    /**
     * 项目下的空间类型
     */
    @ApiOperation(value = "查询项目下的空间类型", notes = "")
    @PostMapping(value = ["/zone/type"])
    fun spaceClassCode(): SQueryResponse<DefClass> {
        return customSqlLabslService.spaceTypeStatistics()
    }

    /**
     * 项目下的建筑楼层
     */
    @ApiOperation(value = "查询项目下的建筑楼层，包含未明确建筑和未明确楼层", notes = "")
    @PostMapping(value = ["/building/floor"])
    fun  buildingFloor(): SQueryResponse<Building> {
        return customSqlLabslService.buildingFloorStatistics()
    }

    /**
     * 查询设备包含设备类型
     */
    @ApiOperation(value = "查询设备包含设备类型", notes = "")
    @PostMapping(value = ["/query/equip"])
    fun query(@RequestBody request: SQueryRequest): SQueryResponse<EquipTypeLabsl> {
        val withFilterList = ArrayList<SFilter>()
        withFilterList.add(SFilter.eq("projectId", SPageContext.getHeader("projectId").toString()))
        return EquipTypeLabslService.pageQuery(request, withFilterList)
    } // Function query()

    /**
     * 根据设备 id 统计 设备所属的专业
     */
    @ApiOperation(value = "根据设备 id 统计 设备所属的专业", notes = " 设备 id 列表")
    @PostMapping(value = ["/major/category"])
    fun equipMajor(@RequestBody idList: ArrayList<String>): SQueryResponse<DefClass> {
        return EquipTypeLabslService.equipMajor(idList)
    }
}