package com.hotwj.platform.driverManagement.inviteLog.controller;

import com.hotwj.platform.driverManagement.inviteLog.domain.bo.HotDriverInviteLogBo;
import com.hotwj.platform.driverManagement.inviteLog.domain.vo.HotDriverInviteLogVo;
import com.hotwj.platform.driverManagement.inviteLog.service.IHotDriverInviteLogService;
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.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 驾驶员邀请码使用记录
 *
 * @author shihongwei
 * @date 2025-12-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/driverManagement/driverInviteLog")
public class HotDriverInviteLogController extends BaseController {

    private final IHotDriverInviteLogService hotDriverInviteLogService;

    /**
     * 查询驾驶员邀请码使用记录列表
     */
    //@SaCheckPermission("driverManagement:driverInviteLog:list")
    @GetMapping("/list")
    public TableDataInfo<HotDriverInviteLogVo> list(HotDriverInviteLogBo bo, PageQuery pageQuery) {
        return hotDriverInviteLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出驾驶员邀请码使用记录列表
     */
    //@SaCheckPermission("driverManagement:driverInviteLog:export")
    @Log(title = "驾驶员邀请码使用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HotDriverInviteLogBo bo, HttpServletResponse response) {
        List<HotDriverInviteLogVo> list = hotDriverInviteLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "驾驶员邀请码使用记录", HotDriverInviteLogVo.class, response);
    }

    /**
     * 获取驾驶员邀请码使用记录详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("driverManagement:driverInviteLog:query")
    @GetMapping("/{id}")
    public R<HotDriverInviteLogVo> getInfo(@NotNull(message = "主键不能为空")
                                           @PathVariable Long id) {
        return R.ok(hotDriverInviteLogService.queryById(id));
    }

    /**
     * 新增驾驶员邀请码使用记录
     */
    //@SaCheckPermission("driverManagement:driverInviteLog:add")
    @Log(title = "驾驶员邀请码使用记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotDriverInviteLogBo bo) {
        return toAjax(hotDriverInviteLogService.insertByBo(bo));
    }

    /**
     * 修改驾驶员邀请码使用记录
     */
    //@SaCheckPermission("driverManagement:driverInviteLog:edit")
    @Log(title = "驾驶员邀请码使用记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotDriverInviteLogBo bo) {
        return toAjax(hotDriverInviteLogService.updateByBo(bo));
    }

    /**
     * 删除驾驶员邀请码使用记录
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("driverManagement:driverInviteLog:remove")
    @Log(title = "驾驶员邀请码使用记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(hotDriverInviteLogService.deleteWithValidByIds(List.of(ids), true));
    }
}
