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.OaApplicationVo;
import com.ruoyi.oa.domain.bo.OaApplicationBo;
import com.ruoyi.oa.service.IOaApplicationService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应用集成
 *
 * @author ruoyi
 * @date 2025-06-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/application")
public class OaApplicationController extends BaseController {

    private final IOaApplicationService iOaApplicationService;

    /**
     * 查询应用集成列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaApplicationVo> list(OaApplicationBo bo, PageQuery pageQuery) {
        return iOaApplicationService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出应用集成列表
     */
    @Log(title = "应用集成", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaApplicationBo bo, HttpServletResponse response) {
        List<OaApplicationVo> list = iOaApplicationService.queryList(bo);
        ExcelUtil.exportExcel(list, "应用集成", OaApplicationVo.class, response);
    }

    /**
     * 获取应用集成详细信息
     *
     * @param applicationId 主键
     */
    @GetMapping("/{applicationId}")
    public R<OaApplicationVo> getInfo(@NotNull(message = "主键不能为空")
                                      @PathVariable Long applicationId) {
        return R.ok(iOaApplicationService.queryById(applicationId));
    }

    /**
     * 新增应用集成
     */
    @Log(title = "应用集成", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaApplicationBo bo) {
        return toAjax(iOaApplicationService.insertByBo(bo));
    }

    /**
     * 修改应用集成
     */
    @Log(title = "应用集成", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaApplicationBo bo) {
        return toAjax(iOaApplicationService.updateByBo(bo));
    }

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