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

import com.hotwj.platform.driverManagement.driverGroup.domain.bo.HotDriverGroupBo;
import com.hotwj.platform.driverManagement.driverGroup.domain.vo.HotDriverGroupVo;
import com.hotwj.platform.driverManagement.driverGroup.service.IHotDriverGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
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-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/driverManagement/driverGroup")
@Tag(name = "驾驶员分组", description = "分组管理")
public class HotDriverGroupController extends BaseController {

    private final IHotDriverGroupService hotDriverGroupService;

    /**
     * 查询驾驶员分组列表
     */
    //@SaCheckPermission("driverManagement:driverGroup:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询驾驶员分组列表")
    public TableDataInfo<HotDriverGroupVo> list(HotDriverGroupBo bo, PageQuery pageQuery) {
        return hotDriverGroupService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出驾驶员分组列表
     */
    //@SaCheckPermission("driverManagement:driverGroup:export")
    @Log(title = "驾驶员分组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出驾驶员分组列表")
    public void export(HotDriverGroupBo bo, HttpServletResponse response) {
        List<HotDriverGroupVo> list = hotDriverGroupService.queryList(bo);
        ExcelUtil.exportExcel(list, "驾驶员分组", HotDriverGroupVo.class, response);
    }

    /**
     * 获取驾驶员分组详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("driverManagement:driverGroup:query")
    @GetMapping("/{id}")
    @Operation(summary = "查询驾驶员分组详情")
    public R<HotDriverGroupVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable Long id) {
        return R.ok(hotDriverGroupService.queryById(id));
    }

    /**
     * 新增驾驶员分组
     */
    //@SaCheckPermission("driverManagement:driverGroup:add")
    @Log(title = "驾驶员分组", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增驾驶员分组")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotDriverGroupBo bo) {
        return toAjax(hotDriverGroupService.insertByBo(bo));
    }

    /**
     * 修改驾驶员分组
     */
    //@SaCheckPermission("driverManagement:driverGroup:edit")
    @Log(title = "驾驶员分组", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改驾驶员分组")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotDriverGroupBo bo) {
        return toAjax(hotDriverGroupService.updateByBo(bo));
    }

    /**
     * 删除驾驶员分组
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("driverManagement:driverGroup:remove")
    @Log(title = "驾驶员分组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除驾驶员分组")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(hotDriverGroupService.deleteWithValidByIds(List.of(ids), true));
    }
}
