init
This commit is contained in:
@@ -9,8 +9,6 @@ public class RedisConstant {
|
||||
public static final String CODE_REDIS = REDIS_P + "code:%s:%s";
|
||||
public static final String USER_GREET_TOTAL_REDIS = REDIS_P + "userGreetTotal:%s:%s";
|
||||
public static final String USER_GREET_SEND_TIME_REDIS = REDIS_P + "userGreetSendTime:%s";
|
||||
public static final String BLACK_REDIS = REDIS_P + "black:%s";
|
||||
|
||||
public static final String FORBID_CACHE_REDIS = REDIS_P + "forbid:%s";
|
||||
public static final String LOVE_RANK_REDIS = REDIS_P + "loveRank:%s:%s";
|
||||
public static final String INVITE_RANK_REDIS = REDIS_P + "inviteRank:%s:%s";
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
package com.ruoyi.cai.controller.admin.back;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.cai.domain.Black;
|
||||
import com.ruoyi.cai.service.BlackService;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.annotation.RepeatSubmit;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.core.validate.AddGroup;
|
||||
import com.ruoyi.common.core.validate.EditGroup;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 黑名单
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-04
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/cai/black")
|
||||
@Deprecated
|
||||
public class BlackController extends BaseController {
|
||||
|
||||
private final BlackService blackService;
|
||||
|
||||
/**
|
||||
* 查询黑名单列表
|
||||
*/
|
||||
@SaCheckPermission("cai:black:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<Black> list(Black bo, PageQuery pageQuery) {
|
||||
Page<Black> page = blackService.page(pageQuery.build(), Wrappers.lambdaQuery(bo).orderByDesc(Black::getCreateTime));
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取黑名单详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@SaCheckPermission("cai:black:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<Black> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(blackService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增黑名单
|
||||
*/
|
||||
@SaCheckPermission("cai:black:add")
|
||||
@Log(title = "黑名单", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody Black bo) {
|
||||
return toAjax(blackService.addBlack(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改黑名单
|
||||
*/
|
||||
@SaCheckPermission("cai:black:edit")
|
||||
@Log(title = "黑名单", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody Black bo) {
|
||||
return toAjax(blackService.updateBlackStatus(bo.getId(),bo.getEnableStatus()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除黑名单
|
||||
*/
|
||||
@SaCheckPermission("cai:black:remove")
|
||||
@Log(title = "黑名单", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{id}")
|
||||
public R<Void> remove(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return toAjax(blackService.deleteBlack(id));
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.ruoyi.cai.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 黑名单对象 cai_black
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-04
|
||||
*/
|
||||
@Data
|
||||
@TableName("cai_black")
|
||||
public class Black implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
private Long id;
|
||||
/**
|
||||
* ip地址
|
||||
*/
|
||||
private String ipAddress;
|
||||
/**
|
||||
* 1-IP 2-MIC
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 启用状态 1-启用 0-关闭
|
||||
*/
|
||||
private Integer enableStatus;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private Long createById;
|
||||
/**
|
||||
* 创建人名
|
||||
*/
|
||||
private String createByName;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.ruoyi.cai.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.cai.domain.Black;
|
||||
|
||||
/**
|
||||
* 黑名单Mapper接口
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-04
|
||||
*/
|
||||
public interface BlackMapper extends BaseMapper<Black> {
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.ruoyi.cai.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.cai.domain.Black;
|
||||
|
||||
/**
|
||||
* 黑名单Service接口
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-04
|
||||
*/
|
||||
public interface BlackService extends IService<Black> {
|
||||
|
||||
boolean addBlack(Black black);
|
||||
|
||||
boolean updateBlackStatus(Long id, Integer enableStatus);
|
||||
|
||||
boolean deleteBlack(Long id);
|
||||
|
||||
boolean checkBlackIp(String ip);
|
||||
|
||||
boolean checkBlackMic(String ip);
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.ruoyi.cai.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.constant.RedisConstant;
|
||||
import com.ruoyi.cai.domain.Black;
|
||||
import com.ruoyi.cai.mapper.BlackMapper;
|
||||
import com.ruoyi.cai.service.BlackService;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.helper.LoginHelper;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 黑名单Service业务层处理
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-04
|
||||
*/
|
||||
@Service
|
||||
public class BlackServiceImpl extends ServiceImpl<BlackMapper,Black> implements BlackService {
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
private String getKey(Integer type){
|
||||
return String.format(RedisConstant.BLACK_REDIS,type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addBlack(Black black){
|
||||
black.setCreateById(LoginHelper.getUserId());
|
||||
black.setCreateByName(LoginHelper.getUsername());
|
||||
this.save(black);
|
||||
redisTemplate.opsForSet().add(getKey(black.getType()),black.getIpAddress());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateBlackStatus(Long id,Integer enableStatus){
|
||||
Black black = this.getById(id);
|
||||
if(black == null){
|
||||
throw new ServiceException("数据不存在");
|
||||
}
|
||||
this.update(Wrappers.lambdaUpdate(Black.class).set(Black::getEnableStatus,enableStatus).eq(Black::getId,id));
|
||||
if(enableStatus == 1){
|
||||
redisTemplate.opsForSet().add(getKey(black.getType()),black.getIpAddress());
|
||||
}else {
|
||||
redisTemplate.opsForSet().remove(getKey(black.getType()),black.getIpAddress());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteBlack(Long id){
|
||||
Black black = this.getById(id);
|
||||
if(black == null){
|
||||
throw new ServiceException("数据不存在");
|
||||
}
|
||||
this.removeById(id);
|
||||
redisTemplate.opsForSet().remove(getKey(black.getType()),black.getIpAddress());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkBlackIp(String ip){
|
||||
Boolean member = redisTemplate.opsForSet().isMember(getKey(1), ip);
|
||||
return BooleanUtils.isTrue(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkBlackMic(String ip){
|
||||
Boolean member = redisTemplate.opsForSet().isMember(getKey(2), ip);
|
||||
return BooleanUtils.isTrue(member);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.cai.mapper.BlackMapper">
|
||||
|
||||
<resultMap type="com.ruoyi.cai.domain.Black" id="BlackResult">
|
||||
<result property="id" column="id"/>
|
||||
<result property="ipAddress" column="ip_address"/>
|
||||
<result property="type" column="type"/>
|
||||
<result property="enableStatus" column="enable_status"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="createById" column="create_by_id"/>
|
||||
<result property="createByName" column="create_by_name"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user