package com.ruoyi.web.controller.wgz.controller;

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

import com.ruoyi.wgz.domain.WgzPayCalculationFiles;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wgz.bo.WgzPayCalculationFilesQueryBo;
import com.ruoyi.wgz.service.IWgzPayCalculationFilesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 工资结算附件Controller
 *
 * @author ruoyi
 * @date 2025-02-22
 */
@Api(value = "工资结算附件控制器", tags = {"工资结算附件管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wgz/files")
public class WgzPayCalculationFilesController extends BaseController {

    private final IWgzPayCalculationFilesService iWgzPayCalculationFilesService;

    /**
     * 查询工资结算附件列表
     */
    @ApiOperation("查询工资结算附件列表")
    @PreAuthorize("@ss.hasPermi('wgz:files:list')")
    @GetMapping("/list")
    public TableDataInfo<WgzPayCalculationFiles> list(@Validated WgzPayCalculationFilesQueryBo bo) {
        return iWgzPayCalculationFilesService.queryPageList(bo);
    }

    /**
     * 导出工资结算附件列表
     */
    @ApiOperation("导出工资结算附件列表")
    @PreAuthorize("@ss.hasPermi('wgz:files:export')")
    @Log(title = "工资结算附件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<WgzPayCalculationFiles> export(@Validated WgzPayCalculationFilesQueryBo bo) {
        List<WgzPayCalculationFiles> list = iWgzPayCalculationFilesService.queryList(bo);
        ExcelUtil<WgzPayCalculationFiles> util = new ExcelUtil<WgzPayCalculationFiles>(WgzPayCalculationFiles.class);
        return util.exportExcel(list, "工资结算附件");
    }

    /**
     * 获取工资结算附件详细信息
     */
    @ApiOperation("获取工资结算附件详细信息")
    @PreAuthorize("@ss.hasPermi('wgz:files:query')")
    @GetMapping("/{id}")
    public AjaxResult<WgzPayCalculationFiles> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iWgzPayCalculationFilesService.queryById(id));
    }

    /**
     * 新增工资结算附件
     */
    @ApiOperation("新增工资结算附件")
    @PreAuthorize("@ss.hasPermi('wgz:files:add')")
    @Log(title = "工资结算附件", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody WgzPayCalculationFiles bo) {
        return toAjax(iWgzPayCalculationFilesService.insert(bo) ? 1 : 0);
    }

    /**
     * 修改工资结算附件
     */
    @ApiOperation("修改工资结算附件")
    @PreAuthorize("@ss.hasPermi('wgz:files:edit')")
    @Log(title = "工资结算附件", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody WgzPayCalculationFiles bo) {
        return toAjax(iWgzPayCalculationFilesService.update(bo) ? 1 : 0);
    }

    /**
     * 删除工资结算附件
     */
    @ApiOperation("删除工资结算附件")
    @PreAuthorize("@ss.hasPermi('wgz:files:remove')")
    @Log(title = "工资结算附件" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iWgzPayCalculationFilesService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
