package org.dromara.controller.blackManage;

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.domain.blackManage.bo.BlackManageBo;
import org.dromara.domain.blackManage.vo.BlackManageVo;
import org.dromara.service.IBlackManageService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 黑名单管理
 *
 * @author boman
 * @date 2025-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wuYe/blackManage")
public class BlackManageController extends BaseController {

    private final IBlackManageService blackManageService;

    /**
     * 查询黑名单管理列表
     */
    @SaCheckPermission("wuYe:blackManage:list")
    @GetMapping("/list")
    public TableDataInfo<BlackManageVo> list(BlackManageBo bo, PageQuery pageQuery) {
        return blackManageService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出黑名单管理列表
     */
    @SaCheckPermission("wuYe:blackManage:export")
    @Log(title = "黑名单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BlackManageBo bo, HttpServletResponse response) {
        List<BlackManageVo> list = blackManageService.queryList(bo);
        ExcelUtil.exportExcel(list, "黑名单管理", BlackManageVo.class, response);
    }

    /**
     * 获取黑名单管理详细信息
     *
     * @param blackManageId 主键
     */
    @SaCheckPermission("wuYe:blackManage:query")
    @GetMapping("/{blackManageId}")
    public R<BlackManageVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long blackManageId) {
        return R.ok(blackManageService.queryById(blackManageId));
    }

    /**
     * 新增黑名单管理
     */
    @SaCheckPermission("wuYe:blackManage:add")
    @Log(title = "黑名单管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BlackManageBo bo) {
        return toAjax(blackManageService.insertByBo(bo));
    }

    /**
     * 修改黑名单管理
     */
    @SaCheckPermission("wuYe:blackManage:edit")
    @Log(title = "黑名单管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BlackManageBo bo) {
        return toAjax(blackManageService.updateByBo(bo));
    }

    /**
     * 删除黑名单管理
     *
     * @param blackManageIds 主键串
     */
    @SaCheckPermission("wuYe:blackManage:remove")
    @Log(title = "黑名单管理", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{blackManageIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] blackManageIds) {
        return toAjax(blackManageService.deleteWithValidByIds(List.of(blackManageIds), true));
    }
}
