package com.ruoyi.web.controller.workTecket;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.worktecket.domain.WorkTicketSignatureTemplate;
import com.ruoyi.worktecket.dto.WorkTicketSignatureTemplateDTO;
import com.ruoyi.worktecket.service.IWorkTicketSignatureTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 作业票签字模板Controller
 *
 * @author ruoyi
 * @date 2023-08-04
 */
@Api(tags = "作业票签字模板")
@RestController
@RequestMapping("/worktecket/sign/template")
public class WorkTicketSignatureTemplateController extends BaseController
{
    @Autowired
    private IWorkTicketSignatureTemplateService workTicketSignatureTemplateService;

    /**
     * 查询作业票签字模板列表
     */
    @ApiOperation("查询作业票签字模板列表")
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('worktecket:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkTicketSignatureTemplateDTO workTicketSignatureTemplate)
    {
        startPage();
        List<WorkTicketSignatureTemplate> list = workTicketSignatureTemplateService.selectList(workTicketSignatureTemplate);
        return getDataTable(list);
    }

    /**
     * 导出作业票签字模板列表
     */
    @ApiOperation("导出作业票签字模板列表")
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('worktecket:template:export')")
    @Log(title = "作业票签字模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkTicketSignatureTemplateDTO workTicketSignatureTemplate)
    {
        List<WorkTicketSignatureTemplateDTO> list = workTicketSignatureTemplateService.selectWorkTicketSignatureTemplateList(workTicketSignatureTemplate);
        ExcelUtil<WorkTicketSignatureTemplateDTO> util = new ExcelUtil<WorkTicketSignatureTemplateDTO>(WorkTicketSignatureTemplateDTO.class);
        util.exportExcel(response, list, "作业票签字模板数据");
    }

    /**
     * 获取作业票签字模板详细信息
     */
    @ApiOperation("获取作业票签字模板详细信息")
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('worktecket:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(workTicketSignatureTemplateService.selectWorkTicketSignatureTemplateById(id));
    }

    /**
     * 新增作业票签字模板
     */
    @ApiOperation("新增作业票签字模板")
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('worktecket:template:add')")
    @Log(title = "作业票签字模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkTicketSignatureTemplateDTO workTicketSignatureTemplate)
    {
        return toAjax(workTicketSignatureTemplateService.insertWorkTicketSignatureTemplate(workTicketSignatureTemplate));
    }

    /**
     * 修改作业票签字模板
     */
    @ApiOperation("修改作业票签字模板")
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('worktecket:template:edit')")
    @Log(title = "作业票签字模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkTicketSignatureTemplateDTO workTicketSignatureTemplate)
    {
        return toAjax(workTicketSignatureTemplateService.updateWorkTicketSignatureTemplate(workTicketSignatureTemplate));
    }

    /**
     * 删除作业票签字模板
     */
    @ApiOperation("删除作业票签字模板")
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('worktecket:template:remove')")
    @Log(title = "作业票签字模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workTicketSignatureTemplateService.deleteWorkTicketSignatureTemplateByIds(ids));
    }
}
