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.OaFurnitureTableVo;
import com.ruoyi.oa.domain.bo.OaFurnitureTableBo;
import com.ruoyi.oa.service.IOaFurnitureTableService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家具
 *
 * @author liujingchao
 * @date 2025-07-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/furnitureTable")
public class OaFurnitureTableController extends BaseController {

    private final IOaFurnitureTableService iOaFurnitureTableService;

    /**
     * 查询家具列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaFurnitureTableVo> list(OaFurnitureTableBo bo, PageQuery pageQuery) {
        return iOaFurnitureTableService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出家具列表
     */
    @Log(title = "家具", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaFurnitureTableBo bo, HttpServletResponse response) {
        List<OaFurnitureTableVo> list = iOaFurnitureTableService.queryList(bo);
        ExcelUtil.exportExcel(list, "家具", OaFurnitureTableVo.class, response);
    }

    /**
     * 获取家具详细信息
     *
     * @param furnitureId 主键
     */
    @GetMapping("/{furnitureId}")
    public R<OaFurnitureTableVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long furnitureId) {
        return R.ok(iOaFurnitureTableService.queryById(furnitureId));
    }

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

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

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