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.OaInsuranceTemplateDetailVo;
import com.ruoyi.oa.domain.bo.OaInsuranceTemplateDetailBo;
import com.ruoyi.oa.service.IOaInsuranceTemplateDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社保/公积金模板明细
 *
 * @author ruoyi
 * @date 2025-06-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/insuranceTemplateDetail")
public class OaInsuranceTemplateDetailController extends BaseController {

    private final IOaInsuranceTemplateDetailService iOaInsuranceTemplateDetailService;

    /**
     * 查询社保/公积金模板明细列表
     */

    @GetMapping("/list")
    public TableDataInfo<OaInsuranceTemplateDetailVo> list(OaInsuranceTemplateDetailBo bo, PageQuery pageQuery) {
        return iOaInsuranceTemplateDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出社保/公积金模板明细列表
     */

    @Log(title = "社保/公积金模板明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaInsuranceTemplateDetailBo bo, HttpServletResponse response) {
        List<OaInsuranceTemplateDetailVo> list = iOaInsuranceTemplateDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "社保/公积金模板明细", OaInsuranceTemplateDetailVo.class, response);
    }

    /**
     * 获取社保/公积金模板明细详细信息
     *
     * @param insuranceDetailId 主键
     */

    @GetMapping("/{insuranceDetailId}")
    public R<OaInsuranceTemplateDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long insuranceDetailId) {
        return R.ok(iOaInsuranceTemplateDetailService.queryById(insuranceDetailId));
    }

    /**
     * 新增社保/公积金模板明细
     */

    @Log(title = "社保/公积金模板明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaInsuranceTemplateDetailBo bo) {
        return toAjax(iOaInsuranceTemplateDetailService.insertByBo(bo));
    }

    /**
     * 修改社保/公积金模板明细
     */

    @Log(title = "社保/公积金模板明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaInsuranceTemplateDetailBo bo) {
        return toAjax(iOaInsuranceTemplateDetailService.updateByBo(bo));
    }

    /**
     * 删除社保/公积金模板明细
     *
     * @param insuranceDetailIds 主键串
     */

    @Log(title = "社保/公积金模板明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{insuranceDetailIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] insuranceDetailIds) {
        return toAjax(iOaInsuranceTemplateDetailService.deleteWithValidByIds(Arrays.asList(insuranceDetailIds), true));
    }
}
