package com.cirs.biz.controller;

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

import com.cirs.biz.domain.TVerificationTask;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
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.TVerificationTaskDetail;
import com.cirs.biz.service.ITVerificationTaskDetailService;
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/detail")
public class TVerificationTaskDetailController extends BaseController
{
    @Autowired
    private ITVerificationTaskDetailService tVerificationTaskDetailService;

    /**
     * 查询验证任务详情列表
     */
    @PreAuthorize("@ss.hasPermi('biz:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(TVerificationTaskDetail tVerificationTaskDetail)
    {
        startPage();
        List<TVerificationTaskDetail> list = tVerificationTaskDetailService.selectTVerificationTaskDetailList(tVerificationTaskDetail);
        return getDataTable(list);
    }

    /**
     * 导出验证任务详情列表
     */
    @PreAuthorize("@ss.hasPermi('biz:detail:export')")
    @Log(title = "验证任务详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody List<Long> taskids)
    {
        List<TVerificationTaskDetail> list = tVerificationTaskDetailService.selectTVerificationTaskDetailByTaskIds(taskids);
        ExcelUtil<TVerificationTaskDetail> util = new ExcelUtil<TVerificationTaskDetail>(TVerificationTaskDetail.class);
        util.exportExcel(response, list, "验证任务详情数据");
    }

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

    /**
     * 新增验证任务详情
     */
    @PreAuthorize("@ss.hasPermi('biz:detail:add')")
    @Log(title = "验证任务详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TVerificationTaskDetail tVerificationTaskDetail)
    {
        return toAjax(tVerificationTaskDetailService.insertTVerificationTaskDetail(tVerificationTaskDetail));
    }

    /**
     * 修改验证任务详情
     */
    @PreAuthorize("@ss.hasPermi('biz:detail:edit')")
    @Log(title = "验证任务详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TVerificationTaskDetail tVerificationTaskDetail)
    {
        return toAjax(tVerificationTaskDetailService.updateTVerificationTaskDetail(tVerificationTaskDetail));
    }

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

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

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