package com.cirs.biz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cirs.biz.domain.TEvaluation;
import com.cirs.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cirs.common.annotation.Log;
import com.cirs.common.core.controller.BaseController;
import com.cirs.common.core.domain.AjaxResult;
import com.cirs.common.enums.BusinessType;
import com.cirs.biz.domain.TVerificationTask;
import com.cirs.biz.service.ITVerificationTaskService;
import com.cirs.common.utils.poi.ExcelUtil;
import com.cirs.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 验证任务Controller
 * 
 * @author allen
 * @date 2023-11-03
 */
@RestController
@RequestMapping("/biz/task")
public class TVerificationTaskController extends BaseController
{
    @Autowired
    private ITVerificationTaskService tVerificationTaskService;

    /**
     * 查询验证任务列表
     */
    @PreAuthorize("@ss.hasPermi('biz:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(TVerificationTask tVerificationTask)
    {
        startPage();
        List<TVerificationTask> list = tVerificationTaskService.selectTVerificationTaskList(tVerificationTask);
        return getDataTable(list);
    }

    /**
     * 导出验证任务列表
     */
    @PreAuthorize("@ss.hasPermi('biz:task:export')")
    @Log(title = "验证任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TVerificationTask tVerificationTask)
    {
        List<TVerificationTask> list = tVerificationTaskService.selectTVerificationTaskList(tVerificationTask);
        ExcelUtil<TVerificationTask> util = new ExcelUtil<TVerificationTask>(TVerificationTask.class);
        util.exportExcel(response, list, "验证任务数据");
    }

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

    /**
     * 新增验证任务
     */
    @PreAuthorize("@ss.hasPermi('biz:task:add')")
    @Log(title = "验证任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TVerificationTask tVerificationTask)
    {
        return toAjax(tVerificationTaskService.insertTVerificationTask(tVerificationTask));
    }

    /**
     * 修改验证任务
     */
    @PreAuthorize("@ss.hasPermi('biz:task:edit')")
    @Log(title = "验证任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TVerificationTask tVerificationTask)
    {
        return toAjax(tVerificationTaskService.updateTVerificationTask(tVerificationTask));
    }

    /**
     * 删除验证任务
     */
    @PreAuthorize("@ss.hasPermi('biz:task:remove')")
    @Log(title = "验证任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tVerificationTaskService.deleteTVerificationTaskByIds(ids));
    }

    /**
     * 导入验证任务 wangruilin
     */
    @PreAuthorize("@ss.hasPermi('biz:task:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<TVerificationTask> util = new ExcelUtil<TVerificationTask>(TVerificationTask.class);
        List<TVerificationTask> taskList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = tVerificationTaskService.importTask(taskList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<TVerificationTask> util = new ExcelUtil<TVerificationTask>(TVerificationTask.class);
        util.importTemplateExcel(response, "任务数据");
    }

    @GetMapping("/last")
    public AjaxResult getLastTask(){
        return success(tVerificationTaskService.getLastTask());
    }
}
