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

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wgz.bo.WgzScoreRecordQueryBo;
import com.ruoyi.wgz.domain.WgzScoreRecord;
import com.ruoyi.wgz.service.IWgzScoreRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 务工者评分记录Controller
 *
 * @author ruoyi
 * @date 2025-02-21
 */
@Api(value = "务工者评分记录控制器", tags = {"务工者评分记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wgz/record")
public class WgzScoreRecordController extends BaseController {

    private final IWgzScoreRecordService iWgzScoreRecordService;

    /**
     * 查询务工者评分记录列表
     */
    @ApiOperation("查询务工者评分记录列表")
    @PreAuthorize("@ss.hasPermi('wgz:record:list')")
    @GetMapping("/list")
    public TableDataInfo<WgzScoreRecord> list(@Validated WgzScoreRecordQueryBo bo) {
        return iWgzScoreRecordService.queryPageList(bo);
    }

    /**
     * 导出务工者评分记录列表
     */
    @ApiOperation("导出务工者评分记录列表")
    @PreAuthorize("@ss.hasPermi('wgz:record:export')")
    @Log(title = "务工者评分记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<WgzScoreRecord> export(@Validated WgzScoreRecordQueryBo bo) {
        List<WgzScoreRecord> list = iWgzScoreRecordService.queryList(bo);
        ExcelUtil<WgzScoreRecord> util = new ExcelUtil<WgzScoreRecord>(WgzScoreRecord.class);
        return util.exportExcel(list, "务工者评分记录");
    }

    /**
     * 获取务工者评分记录详细信息
     */
    @ApiOperation("获取务工者评分记录详细信息")
    @PreAuthorize("@ss.hasPermi('wgz:record:query')")
    @GetMapping("/{id}")
    public AjaxResult<WgzScoreRecord> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iWgzScoreRecordService.queryById(id));
    }

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

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

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