package com.ktg.iscs.controller;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.pojo.CommonResult;
import com.ktg.iscs.domain.IsBlacklist;
import com.ktg.iscs.domain.vo.user.WhiteUserVO;
import com.ktg.iscs.service.IIsBlacklistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 黑名单关联Controller
 *
 * @author cgj
 * @date 2025-01-10
 */
@Api(tags = "黑名单关联")
@RestController
@RequestMapping("/iscs/blacklist")
public class IsBlacklistController extends BaseController
{
    @Autowired
    private IIsBlacklistService isBlacklistService;

    @ApiOperation("查询黑名单关联-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isBlacklist", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:blacklist:list')")
    @GetMapping("/getIsBlacklistPage")
    public CommonResult<Page<IsBlacklist>> getIsBlacklistPage(Page<IsBlacklist> page, IsBlacklist isBlacklist)
    {
        Page<IsBlacklist> result = isBlacklistService.getIsBlacklistPage(page, isBlacklist);
        return CommonResult.success(result);
    }

    @ApiOperation("查询白名单-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isBlacklist", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:blacklist:list')")
    @GetMapping("/getWhiteUserPage")
    public CommonResult<Page<WhiteUserVO>> getWhiteUserPage(Page page, WhiteUserVO dto)
    {
        Page<WhiteUserVO> result = isBlacklistService.getWhiteUserPage(page, dto);
        return CommonResult.success(result);
    }


    @ApiOperation("新增黑名单关联")
    @PreAuthorize("@ss.hasPermi('iscs:blacklist:add')")
    @Log(title = "黑名单关联", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsBlacklist")
    public CommonResult<Boolean> insertIsBlacklist(@RequestBody @Parameter(name = "isBlacklist", description = "新增数据类,放到body") List<IsBlacklist> isBlacklist)
    {
        return CommonResult.success(isBlacklistService.insertIsBlacklist(isBlacklist));
    }

    @ApiOperation("删除黑名单关联")
    @PreAuthorize("@ss.hasPermi('iscs:blacklist:remove')")
    @Log(title = "黑名单关联", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsBlacklistByRecordIds")
    public CommonResult<Boolean> deleteIsBlacklistByRecordIds(String recordIds)
    {
        Assert.notBlank(recordIds, "请选择需要删除的数据!");
        Long[] longIds = Convert.toLongArray(recordIds);
        return CommonResult.success(isBlacklistService.remove(Wrappers.<IsBlacklist>lambdaQuery()
                .in(IsBlacklist::getRecordId, Arrays.asList(longIds))));
    }
}
