package org.dromara.work.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.work.domain.bo.TpStaffPayBo;
import org.dromara.work.domain.vo.TpStaffPayVo;
import org.dromara.work.service.ITpStaffPayService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客服支出记录
 *
 * @author Maosw
 * @date 2024-08-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/work/staffPay")
public class TpStaffPayController extends BaseController {

    private final ITpStaffPayService tpStaffPayService;

    /**
     * 查询客服支出记录列表
     */
    @SaCheckPermission("work:staffPay:list")
    @GetMapping("/list")
    public TableDataInfo<TpStaffPayVo> list(TpStaffPayBo bo, PageQuery pageQuery) {
        return tpStaffPayService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出客服支出记录列表
     */
    @SaCheckPermission("work:staffPay:export")
    @Log(title = "客服支出记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TpStaffPayBo bo, HttpServletResponse response) {
        List<TpStaffPayVo> list = tpStaffPayService.queryList(bo);
        ExcelUtil.exportExcel(list, "客服支出记录", TpStaffPayVo.class, response);
    }

    /**
     * 获取客服支出记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("work:staffPay:query")
    @GetMapping("/{id}")
    public R<TpStaffPayVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tpStaffPayService.queryById(id));
    }

    /**
     * 新增客服支出记录
     */
    @SaCheckPermission("work:staffPay:add")
    @Log(title = "客服支出记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TpStaffPayBo bo) {
        return toAjax(tpStaffPayService.insertByBo(bo));
    }

    /**
     * 修改客服支出记录
     */
    @SaCheckPermission("work:staffPay:edit")
    @Log(title = "客服支出记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TpStaffPayBo bo) {
        return toAjax(tpStaffPayService.updateByBo(bo));
    }

    /**
     * 删除客服支出记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("work:staffPay:remove")
    @Log(title = "客服支出记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(tpStaffPayService.deleteWithValidByIds(List.of(ids), true));
    }
}
