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.OaUserActiveVo;
import com.ruoyi.oa.domain.bo.OaUserActiveBo;
import com.ruoyi.oa.service.IOaUserActiveService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户活跃统计
 *
 * @author ruoyi
 * @date 2025-10-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/userActive")
public class OaUserActiveController extends BaseController {

    private final IOaUserActiveService iOaUserActiveService;

    /**
     * 查询用户活跃统计列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaUserActiveVo> list(OaUserActiveBo bo, PageQuery pageQuery) {
        return iOaUserActiveService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户活跃统计列表
     */
    @Log(title = "用户活跃统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaUserActiveBo bo, HttpServletResponse response) {
        List<OaUserActiveVo> list = iOaUserActiveService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户活跃统计", OaUserActiveVo.class, response);
    }

    /**
     * 获取用户活跃统计详细信息
     *
     * @param activeId 主键
     */
    @GetMapping("/{activeId}")
    public R<OaUserActiveVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long activeId) {
        return R.ok(iOaUserActiveService.queryById(activeId));
    }

    /**
     * 新增用户活跃统计
     */
    @Log(title = "用户活跃统计", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaUserActiveBo bo) {
        return toAjax(iOaUserActiveService.insertByBo(bo));
    }

    /**
     * 修改用户活跃统计
     */
    @Log(title = "用户活跃统计", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaUserActiveBo bo) {
        return toAjax(iOaUserActiveService.updateByBo(bo));
    }

    /**
     * 删除用户活跃统计
     *
     * @param activeIds 主键串
     */
    @Log(title = "用户活跃统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{activeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] activeIds) {
        return toAjax(iOaUserActiveService.deleteWithValidByIds(Arrays.asList(activeIds), true));
    }
}
