✨ 定时删除未使用的分组.
This commit is contained in:
@@ -74,4 +74,13 @@ public interface DataGroupApi {
|
||||
*/
|
||||
Integer deleteDataGroupById(Long id);
|
||||
|
||||
/**
|
||||
* 删除数据分组
|
||||
*
|
||||
* @param type type
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteDataGroupByIdList(DataGroupTypeEnum type, List<Long> idList);
|
||||
|
||||
}
|
||||
|
||||
@@ -43,4 +43,14 @@ public interface DataGroupUserApi {
|
||||
*/
|
||||
List<DataGroupDTO> getDataGroupTree(DataGroupTypeEnum type, Long userId);
|
||||
|
||||
/**
|
||||
* 删除数据分组
|
||||
*
|
||||
* @param type type
|
||||
* @param userId userId
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteDataGroupByIdList(DataGroupTypeEnum type, Long userId, List<Long> idList);
|
||||
|
||||
}
|
||||
|
||||
@@ -88,4 +88,9 @@ public class DataGroupApiImpl implements DataGroupApi {
|
||||
return dataGroupService.deleteDataGroupById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteDataGroupByIdList(DataGroupTypeEnum type, List<Long> idList) {
|
||||
return dataGroupService.deleteDataGroupByIdList(type.name(), Const.SYSTEM_USER_ID, idList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,4 +50,9 @@ public class DataGroupUserApiImpl implements DataGroupUserApi {
|
||||
return DataGroupProviderConvert.MAPPER.toList(rows);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteDataGroupByIdList(DataGroupTypeEnum type, Long userId, List<Long> idList) {
|
||||
return dataGroupService.deleteDataGroupByIdList(type.name(), userId, idList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,6 +66,16 @@ public interface DataGroupService {
|
||||
*/
|
||||
Integer deleteDataGroupById(Long id);
|
||||
|
||||
/**
|
||||
* 通过 id 删除数据分组
|
||||
*
|
||||
* @param type type
|
||||
* @param userId userId
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteDataGroupByIdList(String type, Long userId, List<Long> idList);
|
||||
|
||||
/**
|
||||
* 通过 userId 删除数据分组
|
||||
*
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -66,7 +67,7 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
Long id = record.getId();
|
||||
log.info("DataGroupService-createDataGroup id: {}, effect: {}", id, effect);
|
||||
// 删除缓存
|
||||
this.deleteCache(record.getUserId(), request.getType());
|
||||
this.deleteCache(request.getType(), record.getUserId());
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
// 更新
|
||||
int effect = dataGroupDAO.updateById(updateRecord);
|
||||
// 删除缓存
|
||||
this.deleteCache(record.getUserId(), record.getType());
|
||||
this.deleteCache(record.getType(), record.getUserId());
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -144,7 +145,7 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
effect = dataGroupDAO.updateById(update);
|
||||
}
|
||||
// 删除缓存
|
||||
this.deleteCache(moveRecord.getUserId(), type);
|
||||
this.deleteCache(type, moveRecord.getUserId());
|
||||
// 添加日志参数
|
||||
OperatorLogs.add(OperatorLogs.SOURCE, moveRecord.getName());
|
||||
OperatorLogs.add(OperatorLogs.TARGET, targetRecord.getName());
|
||||
@@ -219,12 +220,34 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
dataGroupRelService.deleteByGroupIdList(type, record.getUserId(), deleteIdList);
|
||||
log.info("DataGroupService-deleteDataGroupById id: {}, effect: {}", id, effect);
|
||||
// 删除缓存
|
||||
this.deleteCache(record.getUserId(), type);
|
||||
this.deleteCache(type, record.getUserId());
|
||||
// 添加日志参数
|
||||
OperatorLogs.add(OperatorLogs.GROUP_NAME, record.getName());
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer deleteDataGroupByIdList(String type, Long userId, List<Long> idList) {
|
||||
log.info("DataGroupService-deleteDataGroupByIdList idList: {}", idList);
|
||||
// 检查数据是否存在
|
||||
List<DataGroupDO> records = dataGroupDAO.selectBatchIds(idList);
|
||||
if (records.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
// 查询子级
|
||||
List<Long> deleteIdList = new ArrayList<>(idList);
|
||||
this.flatChildrenId(idList, deleteIdList);
|
||||
// 删除分组
|
||||
int effect = dataGroupDAO.deleteBatchIds(deleteIdList);
|
||||
// 删除组内数据
|
||||
dataGroupRelService.deleteByGroupIdList(type, userId, deleteIdList);
|
||||
log.info("DataGroupService-deleteDataGroupByIdList id: {}, effect: {}", idList, effect);
|
||||
// 删除缓存
|
||||
this.deleteCache(type, userId);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteDataGroupByUserId(Long userId) {
|
||||
// 删除分组
|
||||
@@ -283,10 +306,10 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
/**
|
||||
* 删除缓存
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @param userId userId
|
||||
*/
|
||||
private void deleteCache(Long userId, String type) {
|
||||
private void deleteCache(String type, Long userId) {
|
||||
RedisStrings.delete(DataGroupCacheKeyDefine.DATA_GROUP_LIST.format(type, userId),
|
||||
DataGroupCacheKeyDefine.DATA_GROUP_TREE.format(type, userId));
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class TagAutoClearTask {
|
||||
/**
|
||||
* 分布式锁名称
|
||||
*/
|
||||
private static final String LOCK_KEY = "tag:clear:lock";
|
||||
private static final String LOCK_KEY = "clear:tag:lock";
|
||||
|
||||
@Resource
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
Reference in New Issue
Block a user