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.ExternalInterfaceLog;
import com.phm.manage.service.IExternalInterfaceLogService;
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/externalInterfaceLog")
public class ExternalInterfaceLogController extends BaseController {
    @Autowired
    private IExternalInterfaceLogService externalInterfaceLogService;

    /**
     * 查询外部接口日志列表
     */
    @PreAuthorize("@ss.hasPermi('manage:externalInterfaceLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExternalInterfaceLog externalInterfaceLog) {
        startPage();
        List<ExternalInterfaceLog> list = externalInterfaceLogService.selectExternalInterfaceLogList(externalInterfaceLog);
        return getDataTable(list);
    }

    /**
     * 导出外部接口日志列表
     */
    @PreAuthorize("@ss.hasPermi('manage:externalInterfaceLog:export')")
    @Log(title = "外部接口日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExternalInterfaceLog externalInterfaceLog) {
        List<ExternalInterfaceLog> list = externalInterfaceLogService.selectExternalInterfaceLogList(externalInterfaceLog);
        ExcelUtil<ExternalInterfaceLog> util = new ExcelUtil<ExternalInterfaceLog>(ExternalInterfaceLog.class);
        util.exportExcel(response, list, "外部接口日志数据");
    }

    /**
     * 获取外部接口日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:externalInterfaceLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(externalInterfaceLogService.selectExternalInterfaceLogById(id));
    }

    /**
     * 新增外部接口日志
     */
    @PreAuthorize("@ss.hasPermi('manage:externalInterfaceLog:add')")
    @Log(title = "外部接口日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExternalInterfaceLog externalInterfaceLog) {
        return toAjax(externalInterfaceLogService.insertExternalInterfaceLog(externalInterfaceLog));
    }

    /**
     * 修改外部接口日志
     */
    @PreAuthorize("@ss.hasPermi('manage:externalInterfaceLog:edit')")
    @Log(title = "外部接口日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExternalInterfaceLog externalInterfaceLog) {
        return toAjax(externalInterfaceLogService.updateExternalInterfaceLog(externalInterfaceLog));
    }

    /**
     * 删除外部接口日志
     */
    @PreAuthorize("@ss.hasPermi('manage:externalInterfaceLog:remove')")
    @Log(title = "外部接口日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(externalInterfaceLogService.deleteExternalInterfaceLogByIds(ids));
    }
}
