package com.starry.admin.modules.clerk.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.clerk.module.entity.IPlayClerkRankingInfoQueryVo;
import com.starry.admin.modules.clerk.module.entity.IPlayClerkRankingInfoReturnVo;
import com.starry.admin.modules.clerk.module.entity.PlayClerkRankingInfoEntity;
import com.starry.admin.modules.clerk.service.IPlayClerkRankingInfoService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 店员排行Controller
 *
 * @author admin
 * @since 2024-05-25
 */
@Api(tags = "店员排行管理", description = "店员排行榜信息管理相关接口，包括查询、新增、修改和删除等操作")
@RestController
@RequestMapping("/clerk/ranking")
public class PlayClerkRankingInfoController {
    @Resource
    private IPlayClerkRankingInfoService playClerkRankingInfoService;

    /**
     * 查询店员排行列表
     */
    @ApiOperation(value = "查询排行列表", notes = "分页查询店员排行信息列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = IPlayClerkRankingInfoReturnVo.class, responseContainer = "Page")})
    @PostMapping("/listByPage")
    public R list(@ApiParam(value = "查询条件", required = true) @Validated @RequestBody IPlayClerkRankingInfoQueryVo vo) {
        IPage<IPlayClerkRankingInfoReturnVo> list = playClerkRankingInfoService.selectByPage(vo);
        return R.ok(list);
    }

    /**
     * 获取店员排行详细信息
     */
    @ApiOperation(value = "获取排行详情", notes = "根据ID获取店员排行详细信息")
    @ApiImplicitParam(name = "id", value = "排行ID", required = true, paramType = "path", dataType = "String", example = "1")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功", response = PlayClerkRankingInfoEntity.class)})
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playClerkRankingInfoService.selectPlayClerkRankingInfoById(id));
    }

    /**
     * 新增店员排行
     */
    @ApiOperation(value = "新增排行", notes = "创建新的店员排行记录")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "添加失败")})
    // @PreAuthorize("@customSs.hasPermission('clerk:ranking:add')")
    @Log(title = "店员排行", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(
            @ApiParam(value = "排行信息", required = true) @RequestBody PlayClerkRankingInfoEntity playClerkRankingInfo) {
        boolean success = playClerkRankingInfoService.create(playClerkRankingInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改店员排行
     */
    @ApiOperation(value = "修改排行", notes = "根据ID修改店员排行信息")
    @ApiImplicitParam(name = "id", value = "排行ID", required = true, paramType = "path", dataType = "String", example = "1")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "修改失败")})
    // @PreAuthorize("@customSs.hasPermission('clerk:ranking:update')")
    @Log(title = "店员排行", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id,
            @ApiParam(value = "排行信息", required = true) @RequestBody PlayClerkRankingInfoEntity playClerkRankingInfo) {
        playClerkRankingInfo.setId(id);
        boolean success = playClerkRankingInfoService.update(playClerkRankingInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除店员排行
     */
    @ApiOperation(value = "删除排行", notes = "根据ID批量删除店员排行信息")
    @ApiImplicitParam(name = "ids", value = "排行ID数组", required = true, paramType = "path", dataType = "String[]", example = "1,2,3")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功", response = Integer.class)})
    // @PreAuthorize("@customSs.hasPermission('clerk:ranking:delete')")
    @Log(title = "店员排行", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playClerkRankingInfoService.deletePlayClerkRankingInfoByIds(ids));
    }
}
