package com.ruoyi.web.controller.oa;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.oa.domain.bo.SysOaClaimDetailBo;
import com.ruoyi.oa.domain.vo.SysOaClaimDetailVo;
import com.ruoyi.oa.service.ISysOaClaimDetailService;
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.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报销明细
 *
 * @author hdka
 * @date 2025-02-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/oaClaimDetail")
public class SysOaClaimDetailController extends BaseController {

    private final ISysOaClaimDetailService iSysOaClaimDetailService;

    /**
     * 查询报销明细列表
     */
    @SaCheckPermission("system:oaClaimDetail:list")
    @GetMapping("/list")
    public TableDataInfo<SysOaClaimDetailVo> list(SysOaClaimDetailBo bo, PageQuery pageQuery) {
        return iSysOaClaimDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出报销明细列表
     */
    @SaCheckPermission("system:oaClaimDetail:export")
    @Log(title = "报销明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysOaClaimDetailBo bo, HttpServletResponse response) {
        List<SysOaClaimDetailVo> list = iSysOaClaimDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "报销明细", SysOaClaimDetailVo.class, response);
    }

    /**
     * 获取报销明细详细信息
     *
     * @param claimDetailId 主键
     */
    @SaCheckPermission("system:oaClaimDetail:query")
    @GetMapping("/{claimDetailId}")
    public R<SysOaClaimDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long claimDetailId) {
        return R.ok(iSysOaClaimDetailService.queryById(claimDetailId));
    }

    /**
     * 新增报销明细
     */
    @SaCheckPermission("system:oaClaimDetail:add")
    @Log(title = "报销明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysOaClaimDetailBo bo) {
        return toAjax(iSysOaClaimDetailService.insertByBo(bo));
    }

    /**
     * 修改报销明细
     */
    @SaCheckPermission("system:oaClaimDetail:edit")
    @Log(title = "报销明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysOaClaimDetailBo bo) {
        return toAjax(iSysOaClaimDetailService.updateByBo(bo));
    }

    /**
     * 删除报销明细
     *
     * @param claimDetailIds 主键串
     */
    @SaCheckPermission("system:oaClaimDetail:remove")
    @Log(title = "报销明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{claimDetailIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] claimDetailIds) {
        return toAjax(iSysOaClaimDetailService.deleteWithValidByIds(Arrays.asList(claimDetailIds), true));
    }
}
