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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.clerk.module.entity.PlayClerkPkEntity;
import com.starry.admin.modules.clerk.service.IPlayClerkPkService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 店员pkController
 *
 * @author admin
 * @since 2024-08-02
 */
@RestController
@RequestMapping("/play/pk")
public class PlayClerkPkController {
    @Resource
    private IPlayClerkPkService playClerkPkService;

    /**
     * 查询店员pk列表
     */
    @GetMapping("/list")
    public R list(PlayClerkPkEntity playClerkPk) {
        IPage<PlayClerkPkEntity> list = playClerkPkService.selectPlayClerkPkByPage(playClerkPk);
        return R.ok(list);
    }

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

    /**
     * 新增店员pk
     */
    @Log(title = "店员pk", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayClerkPkEntity playClerkPk) {
        boolean success = playClerkPkService.create(playClerkPk);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改店员pk
     */
    @Log(title = "店员pk", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayClerkPkEntity playClerkPk) {
        playClerkPk.setId(id);
        boolean success = playClerkPkService.update(playClerkPk);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除店员pk
     */
    @Log(title = "店员pk", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playClerkPkService.deletePlayClerkPkByIds(ids));
    }
}
