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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.clerk.module.entity.PlayClerkWagesDetailsInfoEntity;
import com.starry.admin.modules.clerk.service.IPlayClerkWagesDetailsInfoService;
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;

/**
 * 店员工资明细信息Controller
 *
 * @author admin
 * @since 2024-05-31
 */
@RestController
@RequestMapping("/wages/details")
public class PlayClerkWagesDetailsInfoController {
    @Resource
    private IPlayClerkWagesDetailsInfoService playClerkWagesDetailsInfoService;

    /**
     * 查询店员工资明细信息列表
     */
    @GetMapping("/list")
    public R list(PlayClerkWagesDetailsInfoEntity playClerkWagesDetailsInfo) {
        IPage<PlayClerkWagesDetailsInfoEntity> list = playClerkWagesDetailsInfoService.selectPlayClerkWagesDetailsInfoByPage(playClerkWagesDetailsInfo);
        return R.ok(list);
    }

    /**
     * 获取店员工资明细信息详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playClerkWagesDetailsInfoService.selectPlayClerkWagesDetailsInfoById(id));
    }

    /**
     * 新增店员工资明细信息
     */
    @Log(title = "店员工资明细信息", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayClerkWagesDetailsInfoEntity playClerkWagesDetailsInfo) {
        boolean success = playClerkWagesDetailsInfoService.create(playClerkWagesDetailsInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改店员工资明细信息
     */
    @Log(title = "店员工资明细信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayClerkWagesDetailsInfoEntity playClerkWagesDetailsInfo) {
        playClerkWagesDetailsInfo.setId(id);
        boolean success = playClerkWagesDetailsInfoService.update(playClerkWagesDetailsInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除店员工资明细信息
     */
    @Log(title = "店员工资明细信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playClerkWagesDetailsInfoService.deletePlayClerkWagesDetailsInfoByIds(ids));
    }
}
