package com.my.bus.controller;

import com.my.bus.service.ISysOperationLogService;
import com.my.bus.cache.BusCache;
import com.my.bus.domain.SysOperationLog;
import com.my.common.annotation.Log;
import com.my.common.core.controller.BaseController;
import com.my.common.core.domain.AjaxResult;
import com.my.common.core.page.TableDataInfo;
import com.my.common.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 日志Controller
 *
 * @author my
 * @date 2024-12-23
 */
@RestController
@RequestMapping("/bus/busSysOperationLog")
@RequiredArgsConstructor
public class SysOperationLogController extends BaseController {

    private final ISysOperationLogService sysOperationLogService;

    private final BusCache busCache;

    /**
     * 查询日志列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysOperationLog sysOperationLog) {
        startPage();
        List<SysOperationLog> list = sysOperationLogService.selectList(sysOperationLog);
        return getDataTable(list);
    }


    /**
     * 获取日志详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysOperationLogService.selectById(id));
    }

    /**
     * 新增日志
     */
    @Log(title = "日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysOperationLog sysOperationLog) {
        return toAjax(sysOperationLogService.insert(sysOperationLog));
    }

    /**
     * 修改日志
     */
    @Log(title = "日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysOperationLog sysOperationLog) {
        return toAjax(sysOperationLogService.update(sysOperationLog));
    }

    /**
     * 删除日志
     */
    @Log(title = "日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysOperationLogService.deleteByIds(ids));
    }

}
