package org.dromara.project.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.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.project.domain.dto.constructionblacklist.BusConstructionBlacklistCreateReq;
import org.dromara.project.domain.dto.constructionblacklist.BusConstructionBlacklistQueryReq;
import org.dromara.project.domain.vo.constructionblacklist.BusConstructionBlacklistVo;
import org.dromara.project.service.IBusConstructionBlacklistService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 黑名单
 *
 * @author lcj
 * @date 2025-03-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/project/constructionBlacklist")
public class BusConstructionBlacklistController extends BaseController {

    private final IBusConstructionBlacklistService busConstructionBlacklistService;

    /**
     * 查询黑名单列表
     */
    @SaCheckPermission("project:constructionBlacklist:list")
    @GetMapping("/list")
    public TableDataInfo<BusConstructionBlacklistVo> list(BusConstructionBlacklistQueryReq req, PageQuery pageQuery) {
        return busConstructionBlacklistService.queryPageList(req, pageQuery);
    }

    /**
     * 导出黑名单列表
     */
    @SaCheckPermission("project:constructionBlacklist:export")
    @Log(title = "黑名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BusConstructionBlacklistQueryReq req, HttpServletResponse response) {
        List<BusConstructionBlacklistVo> list = busConstructionBlacklistService.queryList(req);
        ExcelUtil.exportExcel(list, "黑名单", BusConstructionBlacklistVo.class, response);
    }

    /**
     * 获取黑名单详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("project:constructionBlacklist:query")
    @GetMapping("/{id}")
    public R<BusConstructionBlacklistVo> getInfo(@NotNull(message = "主键不能为空")
                                                 @PathVariable Long id) {
        return R.ok(busConstructionBlacklistService.queryById(id));
    }

    /**
     * 新增黑名单
     */
    @SaCheckPermission("project:constructionBlacklist:add")
    @Log(title = "黑名单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Long> add(@Validated(AddGroup.class) @RequestBody BusConstructionBlacklistCreateReq req) {
        return R.ok(busConstructionBlacklistService.insertByBo(req));
    }

    /**
     * 删除黑名单
     *
     * @param ids 主键串
     */
    @SaCheckPermission("project:constructionBlacklist:remove")
    @Log(title = "黑名单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(busConstructionBlacklistService.deleteWithValidByIds(List.of(ids), true));
    }
}
