package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.vo.SysOaWarehouseLogVo;
import com.ruoyi.oa.domain.bo.SysOaWarehouseLogBo;
import com.ruoyi.oa.service.ISysOaWarehouseLogService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 日志
 *
 * @author ruoyi
 * @date 2025-06-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/oaWarehouseLog")
public class SysOaWarehouseLogController extends BaseController {

    private final ISysOaWarehouseLogService iSysOaWarehouseLogService;

    /**
     * 查询日志列表
     */
    @GetMapping("/list")
    public TableDataInfo<SysOaWarehouseLogVo> list(SysOaWarehouseLogBo bo, PageQuery pageQuery) {
        return iSysOaWarehouseLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出日志列表
     */
    @Log(title = "日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysOaWarehouseLogBo bo, HttpServletResponse response) {
        List<SysOaWarehouseLogVo> list = iSysOaWarehouseLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "日志", SysOaWarehouseLogVo.class, response);
    }

    /**
     * 获取日志详细信息
     *
     * @param logId 主键
     */
    @GetMapping("/{logId}")
    public R<SysOaWarehouseLogVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long logId) {
        return R.ok(iSysOaWarehouseLogService.queryById(logId));
    }

    /**
     * 新增日志
     */
    @Log(title = "日志", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysOaWarehouseLogBo bo) {
        return toAjax(iSysOaWarehouseLogService.insertByBo(bo));
    }

    /**
     * 修改日志
     */
    @Log(title = "日志", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysOaWarehouseLogBo bo) {
        return toAjax(iSysOaWarehouseLogService.updateByBo(bo));
    }

    /**
     * 删除日志
     *
     * @param logIds 主键串
     */
    @Log(title = "日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{logIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] logIds) {
        return toAjax(iSysOaWarehouseLogService.deleteWithValidByIds(Arrays.asList(logIds), true));
    }
}
