package com.fs.task.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.task.domain.TaskInfo;
import com.fs.task.service.ITaskInfoService;
import com.fs.task.vo.TaskCreateAuditReqVO;
import com.fs.task.vo.TaskFinishAuditReqVO;
import com.fs.task.vo.TaskInfoCreateVO;
import com.fs.task.vo.TaskSpotCheckUpdateReqVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 任务信息Controller
 *
 * @author fs
 * @date 2026-01-04
 */
@RestController
@RequestMapping("/task/info")
public class TaskInfoController extends BaseController
{
    @Autowired
    private ITaskInfoService taskInfoService;



    /**
     * 查询任务信息列表
     */
    @PreAuthorize("@ss.hasPermi('task:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskInfo taskInfo)
    {
        startPage();
        List<TaskInfo> list = taskInfoService.selectTaskInfoList(taskInfo);
        return getDataTable(list);
    }

    /**
     * 导出任务信息列表
     */
    @PreAuthorize("@ss.hasPermi('task:info:export')")
    @Log(title = "任务信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TaskInfo taskInfo)
    {
        List<TaskInfo> list = taskInfoService.selectTaskInfoList(taskInfo);
        ExcelUtil<TaskInfo> util = new ExcelUtil<TaskInfo>(TaskInfo.class);
        return util.exportExcel(list, "任务信息数据");
    }

    /**
     * 获取任务信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('task:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(taskInfoService.selectTaskInfoById(id));
    }

    /**
     * 新增任务信息
     */
    @PreAuthorize("@ss.hasPermi('task:info:add')")
    @Log(title = "任务信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskInfoCreateVO vo)
    {
        return toAjax(taskInfoService.insertTaskInfo(vo));
    }

    /**
     * 修改任务信息
     */
    @PreAuthorize("@ss.hasPermi('task:info:edit')")
    @Log(title = "任务信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskInfo taskInfo)
    {
        return toAjax(taskInfoService.updateTaskInfo(taskInfo));
    }

    /**
     * 删除任务信息
     */
    @PreAuthorize("@ss.hasPermi('task:info:remove')")
    @Log(title = "任务信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(taskInfoService.deleteTaskInfoByIds(ids));
    }


    @Log(title = "创建审核处理", businessType = BusinessType.UPDATE)
    @PostMapping("doCreateAudit")
    @PreAuthorize("@ss.hasPermi('task:info:edit')")
    public void doCreateAudit(@RequestBody TaskCreateAuditReqVO taskCreateAuditReqVO){
        taskInfoService.doCreateAudit(taskCreateAuditReqVO);
    }


    @Log(title = "完成审核处理", businessType = BusinessType.UPDATE)
    @PostMapping("dofinishAudit")
    public void dofinishAudit(@RequestBody TaskFinishAuditReqVO taskFinishAuditReqVO){
        taskInfoService.dofinishAudit(taskFinishAuditReqVO);
    }

    @Log(title = "获取创建审核任务信息", businessType = BusinessType.UPDATE)
    @GetMapping("getTaskCreateAuditInfo")
    @PreAuthorize("@ss.hasPermi('task:info:query')")
    public AjaxResult getTaskCreateAuditInfo(@RequestParam Long taskId){
       return AjaxResult.success( taskInfoService.getTaskCreateAuditInfo(taskId));
    }


    @Log(title = "获取完成审核任务信息", businessType = BusinessType.UPDATE)
    @GetMapping("getTaskFinishAuditInfo")
    @PreAuthorize("@ss.hasPermi('task:info:query')")
    public AjaxResult getTaskFinishAuditInfo(@RequestParam Long taskId){
        return AjaxResult.success( taskInfoService.getTaskFinishAuditInfo(taskId));
    }



    @PutMapping("/spotCheck")
    public AjaxResult updateSpotCheck(@Valid @RequestBody TaskSpotCheckUpdateReqVO req) {

        int rows = taskInfoService.updateSpotCheck(req);
        return rows > 0 ? AjaxResult.success() : AjaxResult.error("更新失败");
    }




    }
