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.OaInsuranceTemplateVo;
import com.ruoyi.oa.domain.bo.OaInsuranceTemplateBo;
import com.ruoyi.oa.service.IOaInsuranceTemplateService;
import com.ruoyi.common.core.page.TableDataInfo;

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

    private final IOaInsuranceTemplateService iOaInsuranceTemplateService;

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

    @GetMapping("/list")
    public TableDataInfo<OaInsuranceTemplateVo> list(OaInsuranceTemplateBo bo, PageQuery pageQuery) {
        return iOaInsuranceTemplateService.queryPageList(bo, pageQuery);
    }

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

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

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

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

    /**
     * 新增社保/公积金模板主
     */

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

    /**
     * 修改社保/公积金模板主
     */

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

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

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