package com.ruoyi.web.controller.oa;

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

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.oa.domain.vo.SysOaClaimVo;
import com.ruoyi.oa.domain.bo.SysOaClaimBo;
import com.ruoyi.oa.service.ISysOaClaimService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 差旅费报销
 *
 * @author ruoyi
 * @date 2025-02-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/oaClaim")
public class SysOaClaimController extends BaseController {

    private final ISysOaClaimService iSysOaClaimService;

    /**
     * 查询差旅费报销列表
     */
    @SaCheckPermission("system:oaClaim:list")
    @GetMapping("/list-claim")
    public TableDataInfo<SysOaClaimVo> listClaim(SysOaClaimBo bo, PageQuery pageQuery) {
        return iSysOaClaimService.queryPageListByClaim(bo, pageQuery);
    }

   /**
     * 查询差旅费报销列表
     */
    @SaCheckPermission("system:oaClaim:list")
    @GetMapping("/list-money")
    public TableDataInfo<SysOaClaimVo> listMoney(SysOaClaimBo bo, PageQuery pageQuery) {
        return iSysOaClaimService.queryPageListByMoney(bo, pageQuery);
    }

    /**
     * 导出差旅费报销列表
     */
    @SaCheckPermission("system:oaClaim:export")
    @Log(title = "差旅费报销", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysOaClaimBo bo, HttpServletResponse response) {
        List<SysOaClaimVo> list = iSysOaClaimService.queryList(bo);
        ExcelUtil.exportExcel(list, "差旅费报销", SysOaClaimVo.class, response);
    }

    /**
     * 获取差旅费报销详细信息
     *
     * @param claimId 主键
     */
    @SaCheckPermission("system:oaClaim:query")
    @GetMapping("/{claimId}")
    public R<SysOaClaimVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long claimId) {
        return R.ok(iSysOaClaimService.queryById(claimId));
    }

    /**
     * 通过实例id查询报销表单
     *
     * @param procInsId 主键
     */
    @SaCheckPermission("system:oaClaim:query")
    @GetMapping("/process/{procInsId}")
    public R<SysOaClaimVo> getInfoByProcInsId(@NotNull(message = "主键不能为空")
                                     @PathVariable String procInsId) {
        return R.ok(iSysOaClaimService.queryByProcInsId(procInsId));
    }

    /**
     * 新增差旅费报销
     */
    @SaCheckPermission("system:oaClaim:add")
    @Log(title = "差旅费报销", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysOaClaimBo bo) {
        return toAjax(iSysOaClaimService.insertByBo(bo));
    }

    /**
     * 修改差旅费报销
     */
    @SaCheckPermission("system:oaClaim:edit")
    @Log(title = "差旅费报销", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysOaClaimBo bo) {
        return toAjax(iSysOaClaimService.updateByBo(bo));
    }

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