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

package com.persagy.server.controller.task

import com.persagy.database.SFilter
import com.persagy.database.functions.SLength
import com.persagy.server.datacenter.models.entities.task.CategoryStatistics
import com.persagy.server.datacenter.models.entities.task.ModelScanTask
import com.persagy.server.services.task.ScanTaskBaseService
import com.persagy.service.SPageContext
import com.persagy.service.models.requests.SCountRequest
import com.persagy.service.models.responses.SCountResponse
import com.persagy.service.models.responses.SQueryResponse
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.slf4j.LoggerFactory
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  邓婷婷
 */
@Api(tags = ["004、任务-总任务接口"])
@RestController
@RequestMapping("/task/aggregate")
open class ScanTaskBaseController {

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

    /**
     * 统计数量
     */
    @ApiOperation(value = "统计数量", notes = "查询总数量不传参数，查询已完成数量TaskState=0，查询未找到TaskState=-1，查询未验证TaskState=1")
    @PostMapping(value = ["/count"])
    fun count(@RequestBody request: SCountRequest): SCountResponse {
        val withFilterList = ArrayList<SFilter>()
        withFilterList.add(SFilter.eq("projectId", SPageContext.getHeader("ProjectId").toString()))
        withFilterList.add(SFilter.lt(SLength("category"), 6))

        return ScanTaskBaseService.count(request,withFilterList)
    } // Function count()

    /**
     * 查询设备任务下的部件类型及数量
     */
    @ApiOperation(value = "查询设备任务下的部件类型及数量",notes = "type 为model  是查询模型设备下的部件任务，默认是查设备台账任务  TaskId、EquipId 必填")
    @PostMapping(value = ["/category-count"])
    fun categoryCount(type: String?,@RequestBody equipScanTask: ModelScanTask): SQueryResponse<CategoryStatistics> {
        return ScanTaskBaseService.categoryCountsModel(type,equipScanTask)
    } // Fun


} // Class ScanTaskBaseController