package com.persagy.server.controller.task

import com.persagy.base.extensions.toJson
import com.persagy.database.SFilter
import com.persagy.server.datacenter.models.entities.task.RecordProblems
import com.persagy.server.services.task.RecordProblemsService
import com.persagy.service.SPageContext
import com.persagy.service.models.requests.SCreateRequest
import com.persagy.service.models.requests.SQueryRequest
import com.persagy.service.models.responses.SCreateResponse
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 zhangweixin
 */
@Api(tags = ["007、记录问题"])
@RestController
@RequestMapping("/task/problems")
class RecordProblemsController {

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

    @ApiOperation(value = "创建记录", notes = "")
    @PostMapping(value = ["/create"])
    fun create(@RequestBody request: SCreateRequest<RecordProblems>): SCreateResponse<RecordProblems> {
        logger.debug("equip =${request.toJson()}")
        return RecordProblemsService.createList(request)
    } // Function create()

    @ApiOperation(value = "查询记录", notes = "")
    @PostMapping(value = ["/query"])
    fun pageQuery(@RequestBody request: SQueryRequest): SQueryResponse<RecordProblems> {
        logger.debug("EquipScanTaskQuery =${request.toJson()}")
        val projectId = SPageContext.getHeader("ProjectId")
        return RecordProblemsService.pageQuery(request, arrayListOf(SFilter.eq("projectId",projectId!!)))
    } // Function pageQuery()



} // class RecordProblemsController