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

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

import com.ruoyi.wgz.domain.WgzUser;
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.WgzUserQueryBo;
import com.ruoyi.wgz.service.IWgzUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * PC务工者Controller
 *
 * @author ruoyi
 * @date 2025-02-14
 */
@Api(value = "PC务工者控制器", tags = {"PC务工者管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController

@RequestMapping("/wgz/user")
public class WgzUserController extends BaseController {

    private final IWgzUserService iWgzUserService;

    /**
     * 查询PC务工者列表
     */
    @ApiOperation("查询PC务工者列表")
    @PreAuthorize("@ss.hasPermi('wgz:user:list')")
    @GetMapping("/list")
    public TableDataInfo<WgzUser> list(@Validated WgzUserQueryBo bo) {
        return iWgzUserService.queryPageList(bo);
    }

    /**
     * 导出PC务工者列表
     */
    @ApiOperation("导出PC务工者列表")
    @PreAuthorize("@ss.hasPermi('wgz:user:export')")
    @Log(title = "PC务工者", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<WgzUser> export(@Validated WgzUserQueryBo bo) {
        List<WgzUser> list = iWgzUserService.queryList(bo);
        ExcelUtil<WgzUser> util = new ExcelUtil<WgzUser>(WgzUser.class);
        return util.exportExcel(list, "PC务工者");
    }

    /**
     * 获取PC务工者详细信息
     */
    @ApiOperation("获取PC务工者详细信息")
    @PreAuthorize("@ss.hasPermi('wgz:user:query')")
    @GetMapping("/{id}")
    public AjaxResult<WgzUser> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") String id) {
        return AjaxResult.success(iWgzUserService.queryById(id));
    }

    /**
     * 新增PC务工者
     */
    @ApiOperation("新增PC务工者")
    @PreAuthorize("@ss.hasPermi('wgz:user:add')")
    @Log(title = "PC务工者", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody WgzUser bo) {
        return toAjax(iWgzUserService.insert(bo) ? 1 : 0);
    }

    /**
     * 修改PC务工者
     */
    @ApiOperation("修改PC务工者")
    @PreAuthorize("@ss.hasPermi('wgz:user:edit')")
    @Log(title = "PC务工者", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody WgzUser bo) {
        return toAjax(iWgzUserService.update(bo) ? 1 : 0);
    }

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