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.OaExpressQuestionVo;
import com.ruoyi.oa.domain.bo.OaExpressQuestionBo;
import com.ruoyi.oa.service.IOaExpressQuestionService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 快递问题
 *
 * @author hdka
 * @date 2025-07-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/expressQuestion")
public class OaExpressQuestionController extends BaseController {

    private final IOaExpressQuestionService iOaExpressQuestionService;

    /**
     * 查询快递问题列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaExpressQuestionVo> list(OaExpressQuestionBo bo, PageQuery pageQuery) {
        return iOaExpressQuestionService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出快递问题列表
     */
    @Log(title = "快递问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaExpressQuestionBo bo, HttpServletResponse response) {
        List<OaExpressQuestionVo> list = iOaExpressQuestionService.queryList(bo);
        ExcelUtil.exportExcel(list, "快递问题", OaExpressQuestionVo.class, response);
    }

    /**
     * 获取快递问题详细信息
     *
     * @param questionId 主键
     */
    @GetMapping("/{questionId}")
    public R<OaExpressQuestionVo> getInfo(@NotNull(message = "主键不能为空")
                                          @PathVariable Long questionId) {
        return R.ok(iOaExpressQuestionService.queryById(questionId));
    }

    /**
     * 新增快递问题
     */
    @Log(title = "快递问题", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaExpressQuestionBo bo) {
        return toAjax(iOaExpressQuestionService.insertByBo(bo));
    }

    /**
     * 修改快递问题
     */
    @Log(title = "快递问题", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaExpressQuestionBo bo) {
        return toAjax(iOaExpressQuestionService.updateByBo(bo));
    }

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