回收站管理
# 短链接移至回收站
接口:
@RestController
@RequiredArgsConstructor
public class RecycleBinController {
private final RecycleBinService recycleBinService;
/**
* 保存回收站
*/
@PostMapping("/api/short-link/v1/recycle-bin/save")
public Result<Void> saveRecycleBin(@RequestBody RecycleBinSaveReqDTO requestParam) {
recycleBinService.saveRecycleBin(requestParam);
return Results.success();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@Service
@RequiredArgsConstructor
public class RecycleBinServiceImpl extends ServiceImpl<ShortLinkMapper, ShortLinkDO> implements RecycleBinService {
private final StringRedisTemplate stringRedisTemplate;
@Override
public void saveRecycleBin(RecycleBinSaveReqDTO requestParam) {
LambdaUpdateWrapper<ShortLinkDO> updateWrapper = Wrappers.lambdaUpdate(ShortLinkDO.class)
.eq(ShortLinkDO::getFullShortUrl, requestParam.getFullShortUrl())
.eq(ShortLinkDO::getGid, requestParam.getGid())
.eq(ShortLinkDO::getEnableStatus, 0)
.eq(ShortLinkDO::getDelFlag, 0);
ShortLinkDO shortLinkDO = ShortLinkDO.builder()
.enableStatus(1)
.build();
baseMapper.update(shortLinkDO, updateWrapper);
stringRedisTemplate.delete(String.format(GOTO_SHORT_LINK_KEY, requestParam.getFullShortUrl()));
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 回收站分页查询
后管先查询出用户所有分组得list,传给中台
中台接口:
@GetMapping("/api/short-link/v1/recycle-bin/page")
public Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {
return Results.success(recycleBinService.pageShortLink(requestParam));
}
1
2
3
4
2
3
4
@Override
public IPage<ShortLinkPageRespDTO> pageShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {
LambdaQueryWrapper<ShortLinkDO> queryWrapper = Wrappers.lambdaQuery(ShortLinkDO.class)
.in(ShortLinkDO::getGid, requestParam.getGidList())
.eq(ShortLinkDO::getEnableStatus, 1)
.eq(ShortLinkDO::getDelFlag, 0)
.orderByDesc(ShortLinkDO::getUpdateTime);
IPage<ShortLinkDO> resultPage = baseMapper.selectPage(requestParam, queryWrapper);
return resultPage.convert(each -> {
ShortLinkPageRespDTO result = BeanUtil.toBean(each, ShortLinkPageRespDTO.class);
result.setDomain("http://" + result.getDomain());
return result;
});
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
后管接口:
@GetMapping("/api/short-link/admin/v1/recycle-bin/page")
public Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {
return recycleBinService.pageRecycleBinShortLink(requestParam);
}
1
2
3
4
2
3
4
@Service
@RequiredArgsConstructor
public class RecycleBinServiceImpl implements RecycleBinService {
private final GroupMapper groupMapper;
/**
* 后续重构为 SpringCloud Feign 调用
*/
ShortLinkRemoteService shortLinkRemoteService = new ShortLinkRemoteService() {
};
@Override
public Result<IPage<ShortLinkPageRespDTO>> pageRecycleBinShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {
LambdaQueryWrapper<GroupDO> queryWrapper = Wrappers.lambdaQuery(GroupDO.class)
.eq(GroupDO::getUsername, UserContext.getUsername())
.eq(GroupDO::getDelFlag, 0);
List<GroupDO> groupDOList = groupMapper.selectList(queryWrapper);
if (CollUtil.isEmpty(groupDOList)) {
throw new ServiceException("用户无分组信息");
}
requestParam.setGidList(groupDOList.stream().map(GroupDO::getGid).toList());
return shortLinkRemoteService.pageRecycleBinShortLink(requestParam);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
default Result<IPage<ShortLinkPageRespDTO>> pageRecycleBinShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {
Map<String, Object> requestMap = new HashMap<>();
requestMap.put("gidList", requestParam.getGidList());
requestMap.put("current", requestParam.getCurrent());
requestMap.put("size", requestParam.getSize());
String resultPageStr = HttpUtil.get("http://127.0.0.1:8001/api/short-link/v1/recycle-bin/page", requestMap);
return JSON.parseObject(resultPageStr, new TypeReference<>() {
});
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 恢复短链接
接口:
@PostMapping("/api/short-link/v1/recycle-bin/recover")
public Result<Void> recoverRecycleBin(@RequestBody RecycleBinRecoverReqDTO requestParam) {
recycleBinService.recoverRecycleBin(requestParam);
return Results.success();
}
1
2
3
4
5
2
3
4
5
@Override
public void recoverRecycleBin(RecycleBinRecoverReqDTO requestParam) {
LambdaUpdateWrapper<ShortLinkDO> updateWrapper = Wrappers.lambdaUpdate(ShortLinkDO.class)
.eq(ShortLinkDO::getFullShortUrl, requestParam.getFullShortUrl())
.eq(ShortLinkDO::getGid, requestParam.getGid())
.eq(ShortLinkDO::getEnableStatus, 1)
.eq(ShortLinkDO::getDelFlag, 0);
ShortLinkDO shortLinkDO = ShortLinkDO.builder()
.enableStatus(0) // 使其恢复状态
.build();
baseMapper.update(shortLinkDO, updateWrapper);
stringRedisTemplate.delete(String.format(GOTO_IS_NULL_SHORT_LINK_KEY, requestParam.getFullShortUrl()));
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 移除短链接
接口:
@PostMapping("/api/short-link/v1/recycle-bin/remove")
public Result<Void> removeRecycleBin(@RequestBody RecycleBinRemoveReqDTO requestParam) {
recycleBinService.removeRecycleBin(requestParam);
return Results.success();
}
1
2
3
4
5
2
3
4
5
@Override
public void removeRecycleBin(RecycleBinRemoveReqDTO requestParam) {
LambdaUpdateWrapper<ShortLinkDO> updateWrapper = Wrappers.lambdaUpdate(ShortLinkDO.class)
.eq(ShortLinkDO::getFullShortUrl, requestParam.getFullShortUrl())
.eq(ShortLinkDO::getGid, requestParam.getGid())
.eq(ShortLinkDO::getEnableStatus, 1)
.eq(ShortLinkDO::getDelFlag, 0);
baseMapper.delete(updateWrapper);
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9