新增访问白名单管理
This commit is contained in:
@@ -20,4 +20,19 @@ public interface IpRegionWhiteAdminService {
|
||||
* @return
|
||||
*/
|
||||
Page<IpRegionWhiteAdminVo> page(String userErBanNo, String phone, Integer currentPage, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param userErBanNoStr
|
||||
* @param phone
|
||||
*/
|
||||
void save(String userErBanNoStr, String phone);
|
||||
|
||||
/**
|
||||
* 移除白名单
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void del(Long id);
|
||||
}
|
||||
|
@@ -1,13 +1,26 @@
|
||||
package com.accompany.admin.service.ip.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.accompany.admin.mapper.ip.IpRegionWhiteAdminMapper;
|
||||
import com.accompany.admin.service.ip.IpRegionWhiteAdminService;
|
||||
import com.accompany.admin.vo.ip.IpRegionWhiteAdminVo;
|
||||
import com.accompany.business.model.ip.IpRegionWhite;
|
||||
import com.accompany.business.service.ip.IpRegionWhiteService;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.service.user.UsersBaseService;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2023/11/20 15:27
|
||||
@@ -20,8 +33,71 @@ public class IpRegionWhiteAdminServiceImpl implements IpRegionWhiteAdminService
|
||||
@Autowired
|
||||
private IpRegionWhiteAdminMapper ipRegionWhiteAdminMapper;
|
||||
|
||||
@Autowired
|
||||
private UsersBaseService usersBaseService;
|
||||
|
||||
@Autowired
|
||||
private IpRegionWhiteService ipRegionWhiteService;
|
||||
|
||||
@Override
|
||||
public Page<IpRegionWhiteAdminVo> page(String userErBanNo, String phone, Integer currentPage, Integer pageSize) {
|
||||
return ipRegionWhiteAdminMapper.page(new Page<>(currentPage, pageSize), userErBanNo, phone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(String userErBanNoStr, String phone) {
|
||||
if (StrUtil.isEmpty(userErBanNoStr) && StrUtil.isEmpty(phone)) {
|
||||
throw new ServiceException(BusiStatus.PARAMERROR);
|
||||
}
|
||||
String[] userErBanNoArray = null;
|
||||
if (StrUtil.isNotEmpty(userErBanNoStr)) {
|
||||
userErBanNoArray = userErBanNoStr.split(StrUtil.COMMA);
|
||||
}
|
||||
Date now = new Date();
|
||||
if (userErBanNoArray != null) {
|
||||
for (String erBanNoStr : userErBanNoArray) {
|
||||
List<String> uidList = usersBaseService.getUidByErbanNo(Collections.singletonList(erBanNoStr));
|
||||
if (CollectionUtil.isEmpty(uidList)) {
|
||||
throw new ServiceException("[" + erBanNoStr + "]不存在");
|
||||
}
|
||||
String uidStr = uidList.get(0);
|
||||
int count = ipRegionWhiteService.count(Wrappers.<IpRegionWhite>lambdaQuery()
|
||||
.eq(IpRegionWhite::getUid, Long.valueOf(uidStr)));
|
||||
if (count == 0) {
|
||||
IpRegionWhite ipRegionWhite = new IpRegionWhite();
|
||||
ipRegionWhite.setUid(Long.valueOf(uidStr));
|
||||
ipRegionWhite.setCreateTime(now);
|
||||
ipRegionWhite.setSource(IpRegionWhite.Source.ADMIN.getSource());
|
||||
ipRegionWhiteService.save(ipRegionWhite);
|
||||
} else {
|
||||
throw new ServiceException("用户平台ID:[" + erBanNoStr + "]已添加");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotEmpty(phone)) {
|
||||
Long uid = null;
|
||||
Users users = usersBaseService.getUsersByPhone(phone);
|
||||
if (users != null) {
|
||||
uid = users.getUid();
|
||||
}
|
||||
int count = ipRegionWhiteService.count(Wrappers.<IpRegionWhite>lambdaQuery()
|
||||
.eq(uid != null, IpRegionWhite::getUid, uid)
|
||||
.eq(IpRegionWhite::getPhone, phone));
|
||||
if (count == 0) {
|
||||
IpRegionWhite ipRegionWhite = new IpRegionWhite();
|
||||
ipRegionWhite.setUid(uid);
|
||||
ipRegionWhite.setPhone(phone);
|
||||
ipRegionWhite.setSource(IpRegionWhite.Source.ADMIN.getSource());
|
||||
ipRegionWhite.setCreateTime(now);
|
||||
ipRegionWhiteService.save(ipRegionWhite);
|
||||
} else {
|
||||
throw new ServiceException("手机号码:[" + phone + "]已添加");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void del(Long id) {
|
||||
ipRegionWhiteService.removeById(id);
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,29 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.accompany.admin.mapper.ip.IpRegionWhiteAdminMapper">
|
||||
<select id="page" resultType="com.accompany.admin.vo.ip.IpRegionWhiteAdminVo">
|
||||
|
||||
select
|
||||
irw.id,
|
||||
irw.uid,
|
||||
irw.create_time as createTime,
|
||||
irw.last_check_time as lastCheckTime,
|
||||
irw.source,
|
||||
u.erban_no as erbanNo,
|
||||
u.nick,
|
||||
a.sign_time as signTime,
|
||||
if((u.uid is null), '未注册', if((h.owner_uid is not null), '公会会长', if((hm.uid is not null), '公会成员', '普通用户'))) as roleName
|
||||
from ip_region_white as irw
|
||||
left join account as a on a.uid = irw.uid
|
||||
left join users as u on u.uid = irw.uid
|
||||
left join hall_member as hm on hm.uid = irw.uid and hm.`status` = 1
|
||||
left join hall as h on h.owner_uid = irw.uid and h.`status` = 1
|
||||
<where>
|
||||
<if test="userErBanNo != null">
|
||||
and u.erban_no = #{userErBanNo}
|
||||
</if>
|
||||
<if test="phone != null and phone != ''">
|
||||
and irw.phone like concat('%', #{phone}, '%')
|
||||
</if>
|
||||
</where>
|
||||
order irw.create_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
|
@@ -5,17 +5,19 @@ import com.accompany.admin.vo.ip.IpRegionWhiteAdminVo;
|
||||
import com.accompany.common.model.PageReq;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2023/11/20 15:26
|
||||
* @description:
|
||||
*/
|
||||
@Api(tags = "访问白名单管理")
|
||||
@RestController
|
||||
@RequestMapping("/admin/ip/region/white")
|
||||
public class IpRegionWhiteAdminController {
|
||||
@@ -23,8 +25,48 @@ public class IpRegionWhiteAdminController {
|
||||
@Autowired
|
||||
private IpRegionWhiteAdminService ipRegionWhiteAdminService;
|
||||
|
||||
/**
|
||||
* 分页列表
|
||||
*
|
||||
* @param userErBanNo
|
||||
* @param phone
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "userErBanNo", value = "用户平台ID"),
|
||||
@ApiImplicitParam(name = "phone", value = "用户手机号"),
|
||||
@ApiImplicitParam(name = "page", value = "当前页", required = true),
|
||||
@ApiImplicitParam(name = "pageSize", value = "每页显示数", required = true),
|
||||
})
|
||||
@ApiOperation("分页列表")
|
||||
@GetMapping("page")
|
||||
public BusiResult<Page<IpRegionWhiteAdminVo>> page(String userErBanNo, String phone, PageReq req) {
|
||||
return BusiResult.success(ipRegionWhiteAdminService.page(userErBanNo, phone, req.getPage(), req.getPageSize()));
|
||||
}
|
||||
|
||||
@ApiOperation("添加")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "userErBanNoStr", value = "用户平台ID,多个逗号拼接"),
|
||||
@ApiImplicitParam(name = "phone", value = "用户手机号"),
|
||||
})
|
||||
@PostMapping("save")
|
||||
private BusiResult<Void> save(@RequestParam(name = "userErBanNoStr", required = false) String userErBanNoStr, @RequestParam(name = "phone", required = false) String phone) {
|
||||
ipRegionWhiteAdminService.save(userErBanNoStr, phone);
|
||||
return BusiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除白名单
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiImplicitParam(name = "id", value = "数据ID(主键)")
|
||||
@ApiOperation("移除白名单")
|
||||
@GetMapping("del")
|
||||
public BusiResult<Void> del(Long id) {
|
||||
ipRegionWhiteAdminService.del(id);
|
||||
return BusiResult.success();
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -28,6 +29,7 @@ public class IpRegionWhite {
|
||||
LIMIT((byte)3, "限制访问记录添加"),
|
||||
;
|
||||
|
||||
@Getter
|
||||
private Byte source;
|
||||
private String desc;
|
||||
|
||||
|
Reference in New Issue
Block a user