package hw.tagApi.web.controller.system;

import hw.tagApi.common.annotation.Log;
import hw.tagApi.common.core.controller.BaseController;
import hw.tagApi.common.core.domain.AjaxResult;
import hw.tagApi.common.core.page.TableDataInfo;
import hw.tagApi.common.enums.BusinessType;
import hw.tagApi.common.utils.poi.ExcelUtil;
import hw.tagApi.system.domain.SysAttachInfo;
import hw.tagApi.system.service.ISysAttachInfoService;
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.List;

/**
 * 附件信息Controller
 * 
 * @author Yinq
 * @date 2025-04-22
 */
@RestController
@RequestMapping("/system/attachInfo")
public class SysAttachInfoController extends BaseController
{
    @Autowired
    private ISysAttachInfoService sysAttachInfoService;

    /**
     * 查询附件信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:attachInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAttachInfo sysAttachInfo)
    {
        startPage();
        List<SysAttachInfo> list = sysAttachInfoService.selectSysAttachInfoList(sysAttachInfo);
        return getDataTable(list);
    }

    /**
     * 导出附件信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:attachInfo:export')")
    @Log(title = "附件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAttachInfo sysAttachInfo)
    {
        List<SysAttachInfo> list = sysAttachInfoService.selectSysAttachInfoList(sysAttachInfo);
        ExcelUtil<SysAttachInfo> util = new ExcelUtil<SysAttachInfo>(SysAttachInfo.class);
        util.exportExcel(response, list, "附件信息数据");
    }

    /**
     * 获取附件信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:attachInfo:query')")
    @GetMapping(value = "/{attachId}")
    public AjaxResult getInfo(@PathVariable("attachId") Long attachId)
    {
        return success(sysAttachInfoService.selectSysAttachInfoByAttachId(attachId));
    }

    /**
     * 新增附件信息
     */
    @PreAuthorize("@ss.hasPermi('system:attachInfo:add')")
    @Log(title = "附件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAttachInfo sysAttachInfo)
    {
        return toAjax(sysAttachInfoService.insertSysAttachInfo(sysAttachInfo));
    }

    /**
     * 修改附件信息
     */
    @PreAuthorize("@ss.hasPermi('system:attachInfo:edit')")
    @Log(title = "附件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAttachInfo sysAttachInfo)
    {
        return toAjax(sysAttachInfoService.updateSysAttachInfo(sysAttachInfo));
    }

    /**
     * 删除附件信息
     */
    @PreAuthorize("@ss.hasPermi('system:attachInfo:remove')")
    @Log(title = "附件信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attachIds}")
    public AjaxResult remove(@PathVariable Long[] attachIds)
    {
        return toAjax(sysAttachInfoService.deleteSysAttachInfoByAttachIds(attachIds));
    }
}
