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.OaSupplierVo;
import com.ruoyi.oa.domain.bo.OaSupplierBo;
import com.ruoyi.oa.service.IOaSupplierService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商信息
 *
 * @author ruoyi
 * @date 2025-11-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/supplier")
public class OaSupplierController extends BaseController {

    private final IOaSupplierService iOaSupplierService;

    /**
     * 查询供应商信息列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaSupplierVo> list(OaSupplierBo bo, PageQuery pageQuery) {
        return iOaSupplierService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出供应商信息列表
     */
    @Log(title = "供应商信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaSupplierBo bo, HttpServletResponse response) {
        List<OaSupplierVo> list = iOaSupplierService.queryList(bo);
        ExcelUtil.exportExcel(list, "供应商信息", OaSupplierVo.class, response);
    }

    /**
     * 获取供应商信息详细信息
     *
     * @param supplierId 主键
     */
    @GetMapping("/{supplierId}")
    public R<OaSupplierVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long supplierId) {
        return R.ok(iOaSupplierService.queryById(supplierId));
    }

    /**
     * 新增供应商信息
     */
    @Log(title = "供应商信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaSupplierBo bo) {
        return toAjax(iOaSupplierService.insertByBo(bo));
    }

    /**
     * 修改供应商信息
     */
    @Log(title = "供应商信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaSupplierBo bo) {
        return toAjax(iOaSupplierService.updateByBo(bo));
    }

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