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.OaJournalAccountVo;
import com.ruoyi.oa.domain.bo.OaJournalAccountBo;
import com.ruoyi.oa.service.IOaJournalAccountService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 日记账（绑定封账批次，未封账数据batch_id为NULL）
 *
 * @author Joshi
 * @date 2025-09-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/journalAccount")
public class OaJournalAccountController extends BaseController {

    private final IOaJournalAccountService iOaJournalAccountService;
    //需要一个接口用来批量修改batch_id字段，传入一个batch_id和多个journal_ids
    @Log(title = "日记账（绑定封账批次，未封账数据batch_id为NULL）", businessType = BusinessType.UPDATE)
    @PutMapping("/batchUpdate")
    public R<Void> batchUpdate(@RequestBody OaJournalAccountBo bo) {
        return toAjax(iOaJournalAccountService.batchUpdate(bo));
    }
    /**
     * 查询日记账（绑定封账批次，未封账数据batch_id为NULL）列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaJournalAccountVo> list(OaJournalAccountBo bo, PageQuery pageQuery) {
        return iOaJournalAccountService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出日记账（绑定封账批次，未封账数据batch_id为NULL）列表
     */
    @Log(title = "日记账（绑定封账批次，未封账数据batch_id为NULL）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaJournalAccountBo bo, HttpServletResponse response) {
        List<OaJournalAccountVo> list = iOaJournalAccountService.queryList(bo);
        ExcelUtil.exportExcel(list, "日记账（绑定封账批次，未封账数据batch_id为NULL）", OaJournalAccountVo.class, response);
    }

    /**
     * 获取日记账（绑定封账批次，未封账数据batch_id为NULL）详细信息
     *
     * @param journalId 主键
     */
    @GetMapping("/{journalId}")
    public R<OaJournalAccountVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long journalId) {
        return R.ok(iOaJournalAccountService.queryById(journalId));
    }

    /**
     * 新增日记账（绑定封账批次，未封账数据batch_id为NULL）
     */
    @Log(title = "日记账（绑定封账批次，未封账数据batch_id为NULL）", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaJournalAccountBo bo) {
        return toAjax(iOaJournalAccountService.insertByBo(bo));
    }

    /**
     * 修改日记账（绑定封账批次，未封账数据batch_id为NULL）
     */
    @Log(title = "日记账（绑定封账批次，未封账数据batch_id为NULL）", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaJournalAccountBo bo) {
        return toAjax(iOaJournalAccountService.updateByBo(bo));
    }

    /**
     * 删除日记账（绑定封账批次，未封账数据batch_id为NULL）
     *
     * @param journalIds 主键串
     */
    @Log(title = "日记账（绑定封账批次，未封账数据batch_id为NULL）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{journalIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] journalIds) {
        return toAjax(iOaJournalAccountService.deleteWithValidByIds(Arrays.asList(journalIds), true));
    }
}
