package com.ruoyi.member.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.member.domain.MemberApply;
import com.ruoyi.member.vo.MemberApplyVO;
import com.ruoyi.member.vo.MemberBlacklistVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.member.domain.MemberBlacklist;
import com.ruoyi.member.service.IMemberBlacklistService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 黑名单Controller
 *
 * @author pqz
 * @date 2025-03-17
 */
@RestController
@RequestMapping("/member/blacklist")
public class MemberBlacklistController extends BaseController {
    @Autowired
    private IMemberBlacklistService memberBlacklistService;


    /**
     * 分页查询黑名单
     *
     * @param blacklist {@link MemberBlacklist}
     * @param pageNum   分页参数
     * @param pageSize  分页参数
     * @return com.ruoyi.common.core.domain.AjaxResult
     * @author PQZ
     * @date 17:27 2025/4/14
     **/
    @GetMapping("/list")
    public AjaxResult list(MemberBlacklist blacklist,
                           @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<MemberBlacklist> page = new Page<>(pageNum, pageSize);
        IPage<MemberBlacklistVO> list = memberBlacklistService.queryListPage(blacklist, page);
        return success(list);
    }

    /**
     * 导出黑名单列表
     */
    @PreAuthorize("@ss.hasPermi('member:blacklist:export')")
    @Log(title = "黑名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberBlacklist memberBlacklist) {
        List<MemberBlacklist> list = memberBlacklistService.list();
        ExcelUtil<MemberBlacklist> util = new ExcelUtil<MemberBlacklist>(MemberBlacklist.class);
        util.exportExcel(response, list, "黑名单数据");
    }

    /**
     * 获取黑名单详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:blacklist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(memberBlacklistService.getById(id));
    }

    /**
     * 新增黑名单
     *
     * @param memberBlacklist {@link MemberBlacklist}
     * @return com.ruoyi.common.core.domain.AjaxResult
     * @author PQZ
     * @date 15:05 2025/4/23
     **/
    @Log(title = "黑名单", businessType = BusinessType.INSERT)
    @PostMapping("/saveBlack")
    public AjaxResult add(@RequestBody MemberBlacklist memberBlacklist) {
        memberBlacklistService.save(memberBlacklist);
        return success();
    }

    /**
     * 修改黑名单
     */
    @PreAuthorize("@ss.hasPermi('member:blacklist:edit')")
    @Log(title = "黑名单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberBlacklist memberBlacklist) {
        return toAjax(memberBlacklistService.updateById(memberBlacklist));
    }

    /**
     * 移除黑名单
     *
     * @param id id
     * @return com.ruoyi.common.core.domain.AjaxResult
     * @author PQZ
     * @date 11:04 2025/4/15
     **/
    @Log(title = "黑名单", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeById")
    public AjaxResult remove(@RequestParam("id") String id) {
        memberBlacklistService.removeById(id);
        return success();
    }
}
