package cn.sagacloud.server.scheduler.controllers

import cn.sagacloud.server.scheduler.models.TaskResultEntity
import cn.sagacloud.server.scheduler.service.BaseDataService
import com.sybotan.base.extensions.toJson
import com.sybotan.mybatis.SMybatisDao
import com.sybotan.service.SObjectService
import com.sybotan.service.models.requests.SCreateRequest
import com.sybotan.service.models.requests.SQueryRequest
import com.sybotan.service.models.requests.SUpdateRequest
import com.sybotan.service.models.responses.SBaseResponse
import com.sybotan.service.models.responses.SCreateResponse
import com.sybotan.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 jxing
 */
@Api(tags = ["Task 执行结果 接口"])
@RestController
@RequestMapping("/result")
class TaskResultController {
    companion object {
        // 日志
        private val logger = LoggerFactory.getLogger(TaskResultController::class.java)
    } // Companion object

    /**
     * 创建Task Result
     */
    @ApiOperation(value = "创建Task Result", notes = "")
    @PostMapping(value = ["/create"])
    fun create(@RequestBody taskEntity: SCreateRequest<TaskResultEntity>): SCreateResponse<TaskResultEntity> {
        logger.debug("result =${taskEntity.toJson()}")
//        val response = taskService.createList(taskEntity)
        return BaseDataService.taskResultService.createList(taskEntity)
    } // Function create()

    /**
     * 更新Task Result
     *
     * @param   request     更新请求
     * @return  更新结果应答信息
     */
    @ApiOperation(value="更新Task Result", notes="")
    @PostMapping(value = ["/update"])
    fun update(@RequestBody request: SUpdateRequest<TaskResultEntity>): SBaseResponse {
        return BaseDataService.taskResultService.updateList(request)
    } // Function update()

    /**
     * 查询Task Result
     *
     * @param   request     查询请求
     * @return  查询结果应答信息
     */
    @ApiOperation(value="查询Task Result", notes="")
    @PostMapping(value = ["/query"])
    fun query(@RequestBody request: SQueryRequest): SQueryResponse<TaskResultEntity> {
        return BaseDataService.taskResultService.pageQuery(request)
    } // Function query()


    /**
     * 删除Task Result
     *
     * @param   idList      TaskEntity ID列表
     * @return  删除结果应答信息
     */
    @ApiOperation(value = "删除Task Result", notes = "")
    @PostMapping(value = ["/delete"])
    fun delete(@RequestBody idList: ArrayList<TaskResultEntity>): SBaseResponse {
        return BaseDataService.taskResultService.deleteByKeysList(idList)
    } // Function delete()
}