package com.xhpc.user.controller;

import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import com.xhpc.user.domain.XhpcOperatorInternetBlacklist;
import com.xhpc.user.service.IXhpcOperatorInternetBlacklistService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 运营商设置流量方黑名单
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/operator/internet")
public class XhpcOperatorInternetBlacklistController extends BaseController {

    @Autowired
    private IXhpcOperatorInternetBlacklistService xhpcOperatorInternetBlacklistService;

    /**
     * 新增运营商设置流量方黑名单
     */
    @Log(title = "运营商-设置流量方黑名单", businessType = BusinessType.INSERT)
    @ApiOperation("新增运营商设置流量方黑名单")
    //@PreAuthorize(hasPermi = "operator:internet:add")
    @PostMapping("/add")
    public AjaxResult add(@Valid @RequestBody List<XhpcOperatorInternetBlacklist> list) {
        if (null != list && list.size() > 0) {
            Long operatorId = list.get(0).getOperatorId();
            xhpcOperatorInternetBlacklistService.deleteByIds(operatorId);
            for (XhpcOperatorInternetBlacklist xhpcOperatorInternetBlacklist : list) {
                xhpcOperatorInternetBlacklistService.insert(xhpcOperatorInternetBlacklist);
            }
        }
        return AjaxResult.success();
    }

    /**
     * 通过运营商id查询流量方黑名单(包含已选择的黑名单)
     */
    @ApiOperation("通过运营商id查询流量方黑名单")
    //@PreAuthorize(hasPermi = "operator:internet:list")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam String operatorId) {
        startPage();
        List<Map<String, Object>> list = xhpcOperatorInternetBlacklistService.list(operatorId);
        return getDataTable(list);
    }
}
