package com.persagy.server.service

import com.persagy.mybatis.SMybatisDao
import com.persagy.server.models.EquipORComponCategory
import com.persagy.server.service.base.RService
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

/**
 * 设备或部件的分类、分类名
 *
 * @author 张维新
 */
object EquipORComponCategoryService : RService<EquipORComponCategory>(SMybatisDao(EquipORComponCategory::class.java))  {


    /**
     * 查询当前设备下的部件分类数量
     *
     * @param   request     查询信息条件
     * @return              查询结果
     */
    fun getEquipORComponCategory(): SQueryResponse<EquipORComponCategory> {
        return try {
            val request = SQueryRequest()
            val projectId = SPageContext.getHeader("projectId")
            val queryBuilder = select(request.filters)
            queryBuilder.tableName = "public.f_equip_or_component_category('$projectId')"
            if (null != request.projection) {
                queryBuilder.projection(request.projection!!)
            }
            if (null != request.orders) {
                queryBuilder.order(request.orders!!)
            }
            val sPageQueryInfo = queryBuilder.pageQuery(1, 1000)
            SQueryResponse(sPageQueryInfo)
        } catch (e: Throwable) {
            e.printStackTrace()
            SQueryResponse(SResponseType.failure, e.message!!)
        }
    } // Function getEquipAssetComponent()
} // Object EquipORComponCategoryService