package com.phm.manage.controller;

import com.phm.common.annotation.Log;
import com.phm.common.core.controller.BaseController;
import com.phm.common.core.domain.AjaxResult;
import com.phm.common.core.page.TableDataInfo;
import com.phm.common.enums.BusinessType;
import com.phm.common.utils.poi.ExcelUtil;
import com.phm.manage.domain.ImportExportLog;
import com.phm.manage.service.IImportExportLogService;
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 phm
 * @date 2023-08-22
 */
@RestController
@RequestMapping("/manage/importExportLog")
public class ImportExportLogController extends BaseController {
    @Autowired
    private IImportExportLogService importExportLogService;

    /**
     * 查询导入导出日志;列表
     */
    @PreAuthorize("@ss.hasPermi('manage:importExportLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImportExportLog importExportLog) {
        startPage();
        List<ImportExportLog> list = importExportLogService.selectImportExportLogList(importExportLog);
        return getDataTable(list);
    }

    /**
     * 导出导入导出日志;列表
     */
    @PreAuthorize("@ss.hasPermi('manage:importExportLog:export')")
    @Log(title = "导入导出日志;", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImportExportLog importExportLog) {
        List<ImportExportLog> list = importExportLogService.selectImportExportLogList(importExportLog);
        ExcelUtil<ImportExportLog> util = new ExcelUtil<ImportExportLog>(ImportExportLog.class);
        util.exportExcel(response, list, "导入导出日志;数据");
    }

    /**
     * 获取导入导出日志;详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:importExportLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(importExportLogService.selectImportExportLogById(id));
    }

    /**
     * 新增导入导出日志;
     */
    @PreAuthorize("@ss.hasPermi('manage:importExportLog:add')")
    @Log(title = "导入导出日志;", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImportExportLog importExportLog) {
        return toAjax(importExportLogService.insertImportExportLog(importExportLog));
    }

    /**
     * 修改导入导出日志;
     */
    @PreAuthorize("@ss.hasPermi('manage:importExportLog:edit')")
    @Log(title = "导入导出日志;", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImportExportLog importExportLog) {
        return toAjax(importExportLogService.updateImportExportLog(importExportLog));
    }

    /**
     * 删除导入导出日志;
     */
    @PreAuthorize("@ss.hasPermi('manage:importExportLog:remove')")
    @Log(title = "导入导出日志;", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(importExportLogService.deleteImportExportLogByIds(ids));
    }
}
