package com.dcs.hnyz.api;


import com.dcs.common.annotation.Log;
import com.dcs.common.core.domain.AjaxResult;
import com.dcs.common.enums.BusinessType;
import com.dcs.hnyz.domain.DcsRequestTask;
import com.dcs.hnyz.service.IDcsRequestTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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;

@Api(tags = "任务接口")
@RestController
@RequestMapping("/hnyz/api")
public class ApiController {
    @Autowired
    private IDcsRequestTaskService requestTaskService;

    @Log(title = "发送任务请求", businessType = BusinessType.INSERT)
    @PostMapping("/requestTask")
    @ApiOperation(value = "发送任务请求")
    public AjaxResult requestTask(@RequestBody DcsRequestTask requestTask)
    {
        try {
            int i = requestTaskService.insertDcsRequestTask(requestTask);
            if (i == 0) {
                throw new Exception("任务请求失败");
            }
            return AjaxResult.success(requestTask);
        }catch (Exception ex){
            return AjaxResult.success(ex.getMessage());
        }
    }

    @Log(title = "查询任务请求", businessType = BusinessType.OTHER)
    @PostMapping("/searchTask")
    @ApiOperation(value = "发送任务请求")
    public AjaxResult searchTask(@RequestBody DcsRequestTask requestTask)
    {
        try {
            requestTask = requestTaskService.selectDcsRequestTaskByRequestId(requestTask.getRequestId());
            return AjaxResult.success(requestTask);
        }catch (Exception ex){
            return AjaxResult.success(ex.getMessage());
        }
    }
}
