public R sort(Long tid, String type) {
try {
Courescatalog a = getById(tid);
if (type.equals("up")) {
LambdaQueryWrapper<Courescatalog> qw1 = new LambdaQueryWrapper<>();
qw1.and(it -> it.eq(Courescatalog::getCid, a.getCid()).eq(Courescatalog::getSort, a.getSort() - 1));
Courescatalog b = getOne(qw1);
Courescatalog m = getById(b.getTid());
m.setSort(m.getSort() + 1);
updateById(m);
a.setSort(a.getSort() - 1);
updateById(a);
return R.ok(null);
} else {
LambdaQueryWrapper<Courescatalog> qw1 = new LambdaQueryWrapper<>();
qw1.and(it -> it.eq(Courescatalog::getCid, a.getCid()).eq(Courescatalog::getSort, a.getSort() + 1));
Courescatalog b = getOne(qw1);
Courescatalog m = getById(b.getTid());
m.setSort(m.getSort() - 1);
updateById(m);
a.setSort(a.getSort() + 1);
updateById(a);
return R.ok(null);
}
} catch (Exception e) {
return R.error("排序失败:已达到后一级。");
}
}
点击上下箭头对数据排序
最新推荐文章于 2024-10-14 09:02:11 发布