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.AnalyzeDownLog;
import com.phm.manage.service.IAnalyzeDownLogService;
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/analyzeDownLog")
public class AnalyzeDownLogController extends BaseController {
    @Autowired
    private IAnalyzeDownLogService analyzeDownLogService;

    /**
     * 查询数据解析下载日志列表
     */
    @PreAuthorize("@ss.hasPermi('manage:analyzeDownLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(AnalyzeDownLog analyzeDownLog) {
        startPage();
        List<AnalyzeDownLog> list = analyzeDownLogService.selectAnalyzeDownLogList(analyzeDownLog);
        return getDataTable(list);
    }

    /**
     * 导出数据解析下载日志列表
     */
    @PreAuthorize("@ss.hasPermi('manage:analyzeDownLog:export')")
    @Log(title = "数据解析下载日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AnalyzeDownLog analyzeDownLog) {
        List<AnalyzeDownLog> list = analyzeDownLogService.selectAnalyzeDownLogList(analyzeDownLog);
        ExcelUtil<AnalyzeDownLog> util = new ExcelUtil<AnalyzeDownLog>(AnalyzeDownLog.class);
        util.exportExcel(response, list, "数据解析下载日志数据");
    }

    /**
     * 获取数据解析下载日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:analyzeDownLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(analyzeDownLogService.selectAnalyzeDownLogById(id));
    }

    /**
     * 新增数据解析下载日志
     */
    @PreAuthorize("@ss.hasPermi('manage:analyzeDownLog:add')")
    @Log(title = "数据解析下载日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AnalyzeDownLog analyzeDownLog) {
        return toAjax(analyzeDownLogService.insertAnalyzeDownLog(analyzeDownLog));
    }

    /**
     * 修改数据解析下载日志
     */
    @PreAuthorize("@ss.hasPermi('manage:analyzeDownLog:edit')")
    @Log(title = "数据解析下载日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AnalyzeDownLog analyzeDownLog) {
        return toAjax(analyzeDownLogService.updateAnalyzeDownLog(analyzeDownLog));
    }

    /**
     * 删除数据解析下载日志
     */
    @PreAuthorize("@ss.hasPermi('manage:analyzeDownLog:remove')")
    @Log(title = "数据解析下载日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(analyzeDownLogService.deleteAnalyzeDownLogByIds(ids));
    }
}
