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 org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 店员排行Controller
 *
 * @author admin
 * @since 2024-05-25
 */
@RestController
@RequestMapping("/clerk/ranking")
public class PlayClerkRankingInfoController {
    @Resource
    private IPlayClerkRankingInfoService playClerkRankingInfoService;

    /**
     * 查询店员排行列表
     */
    @PostMapping("/listByPage")
    public R list(@Validated @RequestBody IPlayClerkRankingInfoQueryVo vo) {
        IPage<IPlayClerkRankingInfoReturnVo> list = playClerkRankingInfoService.selectByPage(vo);
        return R.ok(list);
    }

    /**
     * 获取店员排行详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playClerkRankingInfoService.selectPlayClerkRankingInfoById(id));
    }

    /**
     * 新增店员排行
     */
    //@PreAuthorize("@customSs.hasPermission('clerk:ranking:add')")
    @Log(title = "店员排行", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayClerkRankingInfoEntity playClerkRankingInfo) {
        boolean success = playClerkRankingInfoService.create(playClerkRankingInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改店员排行
     */
    //@PreAuthorize("@customSs.hasPermission('clerk:ranking:update')")
    @Log(title = "店员排行", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayClerkRankingInfoEntity playClerkRankingInfo) {
        playClerkRankingInfo.setId(id);
        boolean success = playClerkRankingInfoService.update(playClerkRankingInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除店员排行
     */
    //@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));
    }
}
