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 cn.dev33.satoken.annotation.SaCheckPermission;
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.SysOaTaskUserVo;
import com.ruoyi.oa.domain.bo.SysOaTaskUserBo;
import com.ruoyi.oa.service.ISysOaTaskUserService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件共享表
 *
 * @author hdka
 * @date 2025-03-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/oaTaskUser")
public class SysOaTaskUserController extends BaseController {

    private final ISysOaTaskUserService iSysOaTaskUserService;

    /**
     * 查询文件共享表列表
     */
    @SaCheckPermission("oa:oaTaskUser:list")
    @GetMapping("/list")
    public TableDataInfo<SysOaTaskUserVo> list(SysOaTaskUserBo bo, PageQuery pageQuery) {
        return iSysOaTaskUserService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出文件共享表列表
     */
    @SaCheckPermission("oa:oaTaskUser:export")
    @Log(title = "文件共享表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysOaTaskUserBo bo, HttpServletResponse response) {
        List<SysOaTaskUserVo> list = iSysOaTaskUserService.queryList(bo);
        ExcelUtil.exportExcel(list, "文件共享表", SysOaTaskUserVo.class, response);
    }

    /**
     * 获取文件共享表详细信息
     *
     * @param taskUserId 主键
     */
    @GetMapping("/{taskUserId}")
    public R<SysOaTaskUserVo> getInfo(@NotNull(message = "主键不能为空")
                                      @PathVariable Long taskUserId) {
        return R.ok(iSysOaTaskUserService.queryById(taskUserId));
    }

    /**
     * 新增文件共享表
     */
    @Log(title = "文件共享表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysOaTaskUserBo bo) {
        return toAjax(iSysOaTaskUserService.insertByBo(bo));
    }

    /**
     * 修改文件共享表
     */
    @Log(title = "文件共享表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysOaTaskUserBo bo) {
        return toAjax(iSysOaTaskUserService.updateByBo(bo));
    }

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