package com.persagy.server.services.task

import com.persagy.database.SFilter
import com.persagy.database.functions.SLength
import com.persagy.mybatis.SMybatisDao
import com.persagy.server.datacenter.models.entities.task.ModelScanTaskQuery
import com.persagy.server.services.base.RService
import com.persagy.service.SPageContext
import com.persagy.service.models.requests.SQueryRequest
import com.persagy.service.models.responses.SQueryResponse


/**
 * 模型任务
 *
 * @author  邓婷婷
 */
object ModelScanTaskQueryService : RService<ModelScanTaskQuery>(SMybatisDao(ModelScanTaskQuery::class.java))  {

    fun pageQuerys(request: SQueryRequest): SQueryResponse<ModelScanTaskQuery> {
        val withFilterList = ArrayList<SFilter>()
        withFilterList.add(SFilter.eq("projectId", SPageContext.getHeader("ProjectId").toString()))
        withFilterList.add(SFilter.lt(SLength("category"), 6))
        val pageQuery = pageQuery(request, withFilterList)
        if (!pageQuery.content.isNullOrEmpty()&&pageQuery.content!!.size>0){
            for (content in pageQuery.content!!){
                val exec = select(SFilter.eq("parentId", content.equipId!!),SFilter.eq("taskParentId", content.id!!)).exec()
                if (exec.size>0){
                    content.component = exec
                }
            }
        }
        return pageQuery
    } // Fun


} // Class ModelScanTaskService