ip隔离-更新白名单lastCheckTime

This commit is contained in:
khalil
2023-11-20 18:22:05 +08:00
parent 694108d501
commit 5399dd238e
3 changed files with 25 additions and 13 deletions

View File

@@ -8,8 +8,8 @@ import org.apache.ibatis.annotations.Param;
@Mapper
public interface IpRegionWhiteMapper extends BaseMapper<IpRegionWhite> {
boolean isInIpRegionWhileListByUidOrPhone(@Param("uid") Long uid, @Param("phone") String phone);
Long getIpRegionWhileListByUidOrPhone(@Param("uid") Long uid, @Param("phone") String phone);
boolean isInIpRegionWhileListByUid(@Param("uid") Long uid);
Long getIpRegionWhileListByUid(@Param("uid") Long uid);
}

View File

@@ -3,8 +3,10 @@ package com.accompany.business.service.ip;
import com.accompany.business.model.ip.IpRegionWhite;
import com.accompany.business.mybatismapper.ip.IpRegionWhiteMapper;
import com.accompany.common.utils.CommonUtil;
import com.accompany.core.base.SpringContextHolder;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.Date;
@@ -14,10 +16,22 @@ import java.util.Date;
public class IpRegionWhiteService extends ServiceImpl<IpRegionWhiteMapper, IpRegionWhite> {
public boolean isInWhileList(Long uid, String phone) {
if (CommonUtil.checkValidPhone(phone)) {
return baseMapper.isInIpRegionWhileListByUidOrPhone(uid, phone);
Long whiteId = CommonUtil.checkValidPhone(phone)?
baseMapper.getIpRegionWhileListByUidOrPhone(uid, phone):
baseMapper.getIpRegionWhileListByUid(uid);
if (null == whiteId){
return false;
}
return baseMapper.isInIpRegionWhileListByUid(uid);
SpringContextHolder.getBean(IpRegionWhiteService.class).updateLastCheckTime(whiteId);
return true;
}
@Async
public void updateLastCheckTime(Long id) {
lambdaUpdate()
.set(IpRegionWhite::getLastCheckTime, new Date())
.eq(IpRegionWhite::getId, id)
.update();
}
public void addIpRegionWhite(Long uid, String phone, Byte source) {

View File

@@ -1,15 +1,13 @@
<?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.accompany.business.mybatismapper.ip.IpRegionWhiteMapper">
<select id="isInIpRegionWhileListByUidOrPhone" resultType="java.lang.Boolean">
select count(*)
from (select id from ip_region_white where uid = #{uid}
union
select id from ip_region_white where phone = #{phone}
) a
<select id="getIpRegionWhileListByUidOrPhone" resultType="java.lang.Long">
select id from ip_region_white where uid = #{uid}
union
select id from ip_region_white where phone = #{phone}
</select>
<select id="isInIpRegionWhileListByUid" resultType="java.lang.Boolean">
select count(*) from ip_region_white where uid = #{uid}
<select id="getIpRegionWhileListByUid" resultType="java.lang.Long">
select id from ip_region_white where uid = #{uid}
</select>
</mapper>