package com.sundot.airport.web.controller.system;

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

import com.sundot.airport.common.domain.BaseRead;
import com.sundot.airport.common.service.IBaseReadService;
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.sundot.airport.common.annotation.Log;
import com.sundot.airport.common.core.controller.BaseController;
import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.enums.BusinessType;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import com.sundot.airport.common.core.page.TableDataInfo;

/**
 * 已读Controller
 *
 * @author ruoyi
 * @date 2025-09-09
 */
@RestController
@RequestMapping("/system/read")
public class BaseReadController extends BaseController {
    @Autowired
    private IBaseReadService baseReadService;

    /**
     * 查询已读列表
     */
    @PreAuthorize("@ss.hasPermi('system:read:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseRead baseRead) {
        startPage();
        List<BaseRead> list = baseReadService.selectBaseReadList(baseRead);
        return getDataTable(list);
    }

    /**
     * 导出已读列表
     */
    @PreAuthorize("@ss.hasPermi('system:read:export')")
    @Log(title = "已读", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseRead baseRead) {
        List<BaseRead> list = baseReadService.selectBaseReadList(baseRead);
        ExcelUtil<BaseRead> util = new ExcelUtil<BaseRead>(BaseRead.class);
        util.exportExcel(response, list, "已读数据");
    }

    /**
     * 获取已读详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:read:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(baseReadService.selectBaseReadById(id));
    }

    /**
     * 新增已读
     */
    @PreAuthorize("@ss.hasPermi('system:read:add')")
    @Log(title = "已读", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseRead baseRead) {
        baseRead.setCreateBy(getUsername());
        return toAjax(baseReadService.insertBaseRead(baseRead));
    }

    /**
     * 修改已读
     */
    @PreAuthorize("@ss.hasPermi('system:read:edit')")
    @Log(title = "已读", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseRead baseRead) {
        baseRead.setUpdateBy(getUsername());
        return toAjax(baseReadService.updateBaseRead(baseRead));
    }

    /**
     * 删除已读
     */
    @PreAuthorize("@ss.hasPermi('system:read:remove')")
    @Log(title = "已读", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseReadService.deleteBaseReadByIds(ids));
    }
}
