package com.fs.audit.controller;

import com.fs.audit.domain.AuditTemp;
import com.fs.audit.service.AuditTempService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 审核模板Controller
 *
 * @author fs
 * @date 2026-01-06
 */
@RestController
@RequestMapping("/audit/temp")
public class AuditTempController extends BaseController
{
    @Autowired
    private AuditTempService auditTempService;

    /**
     * 查询审核模板列表
     */
    @PreAuthorize("@ss.hasPermi('shop:temp:list')")
    @GetMapping("/list")
    public TableDataInfo list(AuditTemp auditTemp)
    {
        startPage();
        List<AuditTemp> list = auditTempService.selectAuditTempList(auditTemp);
        return getDataTable(list);
    }

    /**
     * 导出审核模板列表
     */
    @PreAuthorize("@ss.hasPermi('shop:temp:export')")
    @Log(title = "审核模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AuditTemp auditTemp)
    {
        List<AuditTemp> list = auditTempService.selectAuditTempList(auditTemp);
        ExcelUtil<AuditTemp> util = new ExcelUtil<AuditTemp>(AuditTemp.class);
        return util.exportExcel(list, "审核模板数据");
    }

    /**
     * 获取审核模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:temp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(auditTempService.getTemplate(id));
    }

    /**
     * 新增审核模板
     */
    @PreAuthorize("@ss.hasPermi('shop:temp:add')")
    @Log(title = "审核模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AuditTemp auditTemp)
    {
        return toAjax(auditTempService.insertAuditTemp(auditTemp));
    }

    /**
     * 修改审核模板
     */
    @PreAuthorize("@ss.hasPermi('shop:temp:edit')")
    @Log(title = "审核模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuditTemp auditTemp)
    {
        return toAjax(auditTempService.updateAuditTemp(auditTemp));
    }

    /**
     * 删除审核模板
     */
    @PreAuthorize("@ss.hasPermi('shop:temp:remove')")
    @Log(title = "审核模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(auditTempService.deleteAuditTempByIds(ids));
    }
}
