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

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

import com.ruoyi.wgz.domain.WgzPayCalculation;
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.WgzPayCalculationQueryBo;
import com.ruoyi.wgz.service.IWgzPayCalculationService;
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-21
 */
@Api(value = "工资结算控制器", tags = {"工资结算管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wgz/calculation")
public class WgzPayCalculationController extends BaseController {

    private final IWgzPayCalculationService iWgzPayCalculationService;

    /**
     * 查询工资结算列表
     */
    @ApiOperation("查询工资结算列表")
    @PreAuthorize("@ss.hasPermi('wgz:calculation:list')")
    @GetMapping("/list")
    public TableDataInfo<WgzPayCalculation> list(@Validated WgzPayCalculationQueryBo bo) {
        return iWgzPayCalculationService.queryPageList(bo);
    }

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

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

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

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

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