|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.ibeetl.jlw.service;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
import cn.jlw.util.ToolUtils;
|
|
|
|
@ -191,108 +192,109 @@ public class StudentClientLinkService extends CoreBaseService<StudentClientLink>
|
|
|
|
|
*/
|
|
|
|
|
public void move(@NotNull(message = "ID不能为空!") Long id, @NotNull(message = "移动类型不能为空!") MoveEnum moveType) {
|
|
|
|
|
List<StudentClientLink> links = studentClientLinkDao.getByIds(id.toString());
|
|
|
|
|
if (CollectionUtil.isNotEmpty(links)) {
|
|
|
|
|
StudentClientLink studentClientLink = links.get(0);
|
|
|
|
|
|
|
|
|
|
switch (moveType) {
|
|
|
|
|
|
|
|
|
|
case MOVE_TOP: {
|
|
|
|
|
List<StudentClientLink> result = studentClientLinkDao.createLambdaQuery()
|
|
|
|
|
.andEq(StudentClientLink::getStudentClientLinkType, studentClientLink.getStudentClientLinkType())
|
|
|
|
|
.andEq(StudentClientLink::getStudentClientLinkStatus, 1)
|
|
|
|
|
.andNotEq(StudentClientLink::getStudentClientLinkId, id)
|
|
|
|
|
.asc(StudentClientLink::getStudentClientLinkOrder)
|
|
|
|
|
.limit(1, 1)
|
|
|
|
|
.select(StudentClientLink::getStudentClientLinkOrder);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result)) {
|
|
|
|
|
StudentClientLink minOrderClientLink = result.get(0);
|
|
|
|
|
// 最小的排序值
|
|
|
|
|
BigDecimal minLinkOrder = minOrderClientLink.getStudentClientLinkOrder();
|
|
|
|
|
// 置顶就现有的最小值减1。但是需要确保结果小于0
|
|
|
|
|
BigDecimal calcedOrder = BigDecimal.valueOf(NumberUtil.sub(min(minLinkOrder.floatValue(), 0), 1));
|
|
|
|
|
|
|
|
|
|
// 改变排序记录值
|
|
|
|
|
StudentClientLink updatePO = new StudentClientLink();
|
|
|
|
|
updatePO.setStudentClientLinkId(studentClientLink.getStudentClientLinkId());
|
|
|
|
|
updatePO.setStudentClientLinkOrder(calcedOrder);
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case MOVE_LEFT: {
|
|
|
|
|
List<StudentClientLink> result = studentClientLinkDao.createLambdaQuery()
|
|
|
|
|
.andEq(StudentClientLink::getStudentClientLinkType, studentClientLink.getStudentClientLinkType())
|
|
|
|
|
.andLess(StudentClientLink::getStudentClientLinkOrder, studentClientLink.getStudentClientLinkOrder())
|
|
|
|
|
.andEq(StudentClientLink::getStudentClientLinkStatus, 1)
|
|
|
|
|
.andNotEq(StudentClientLink::getStudentClientLinkId, id)
|
|
|
|
|
.desc(StudentClientLink::getStudentClientLinkOrder)
|
|
|
|
|
.limit(1, 2)
|
|
|
|
|
.select(StudentClientLink::getStudentClientLinkOrder);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result)) {
|
|
|
|
|
// 找到应该安插的位置
|
|
|
|
|
BigDecimal LinkOrder0 = result.get(0).getStudentClientLinkOrder();
|
|
|
|
|
BigDecimal LinkOrder1 = LinkOrder0.subtract(BigDecimal.ONE);
|
|
|
|
|
if (result.size() == 2) {
|
|
|
|
|
LinkOrder1 = result.get(1).getStudentClientLinkOrder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BigDecimal min = NumberUtil.min(LinkOrder0, LinkOrder1);
|
|
|
|
|
BigDecimal max = NumberUtil.max(LinkOrder0, LinkOrder1);
|
|
|
|
|
|
|
|
|
|
// 左移位后的值
|
|
|
|
|
double calcedOrder = RandomUtil.randomDouble(min.doubleValue(), max.doubleValue(), 6, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
|
|
// 改变排序记录值
|
|
|
|
|
StudentClientLink updatePO = new StudentClientLink();
|
|
|
|
|
updatePO.setStudentClientLinkId(studentClientLink.getStudentClientLinkId());
|
|
|
|
|
updatePO.setStudentClientLinkOrder(BigDecimal.valueOf(calcedOrder));
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(links, "未查询到要移动的元素!");
|
|
|
|
|
|
|
|
|
|
StudentClientLink studentClientLink = links.get(0);
|
|
|
|
|
|
|
|
|
|
switch (moveType) {
|
|
|
|
|
|
|
|
|
|
case MOVE_TOP: {
|
|
|
|
|
List<StudentClientLink> result = studentClientLinkDao.createLambdaQuery()
|
|
|
|
|
.andEq(StudentClientLink::getStudentClientLinkType, studentClientLink.getStudentClientLinkType())
|
|
|
|
|
.andEq(StudentClientLink::getStudentClientLinkStatus, 1)
|
|
|
|
|
.andNotEq(StudentClientLink::getStudentClientLinkId, id)
|
|
|
|
|
.asc(StudentClientLink::getStudentClientLinkOrder)
|
|
|
|
|
.limit(1, 1)
|
|
|
|
|
.select(StudentClientLink::getStudentClientLinkOrder);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result)) {
|
|
|
|
|
StudentClientLink minOrderClientLink = result.get(0);
|
|
|
|
|
// 最小的排序值
|
|
|
|
|
BigDecimal minLinkOrder = minOrderClientLink.getStudentClientLinkOrder();
|
|
|
|
|
// 置顶就现有的最小值减1。但是需要确保结果小于0
|
|
|
|
|
BigDecimal calcedOrder = BigDecimal.valueOf(NumberUtil.sub(min(minLinkOrder.floatValue(), 0), 1));
|
|
|
|
|
|
|
|
|
|
// 改变排序记录值
|
|
|
|
|
StudentClientLink updatePO = new StudentClientLink();
|
|
|
|
|
updatePO.setStudentClientLinkId(studentClientLink.getStudentClientLinkId());
|
|
|
|
|
updatePO.setStudentClientLinkOrder(calcedOrder);
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case MOVE_LEFT: {
|
|
|
|
|
List<StudentClientLink> result = studentClientLinkDao.createLambdaQuery()
|
|
|
|
|
.andEq(StudentClientLink::getStudentClientLinkType, studentClientLink.getStudentClientLinkType())
|
|
|
|
|
.andLess(StudentClientLink::getStudentClientLinkOrder, studentClientLink.getStudentClientLinkOrder())
|
|
|
|
|
.andEq(StudentClientLink::getStudentClientLinkStatus, 1)
|
|
|
|
|
.andNotEq(StudentClientLink::getStudentClientLinkId, id)
|
|
|
|
|
.desc(StudentClientLink::getStudentClientLinkOrder)
|
|
|
|
|
.limit(1, 2)
|
|
|
|
|
.select(StudentClientLink::getStudentClientLinkOrder);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result)) {
|
|
|
|
|
// 找到应该安插的位置
|
|
|
|
|
BigDecimal LinkOrder0 = result.get(0).getStudentClientLinkOrder();
|
|
|
|
|
BigDecimal LinkOrder1 = LinkOrder0.subtract(BigDecimal.ONE);
|
|
|
|
|
if (result.size() == 2) {
|
|
|
|
|
LinkOrder1 = result.get(1).getStudentClientLinkOrder();
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case MOVE_RIGHT: {
|
|
|
|
|
List<StudentClientLink> result = studentClientLinkDao.createLambdaQuery()
|
|
|
|
|
.andEq(StudentClientLink::getStudentClientLinkType, studentClientLink.getStudentClientLinkType())
|
|
|
|
|
.andGreat(StudentClientLink::getStudentClientLinkOrder, studentClientLink.getStudentClientLinkOrder())
|
|
|
|
|
.andEq(StudentClientLink::getStudentClientLinkStatus, 1)
|
|
|
|
|
.andNotEq(StudentClientLink::getStudentClientLinkId, id)
|
|
|
|
|
.asc(StudentClientLink::getStudentClientLinkOrder)
|
|
|
|
|
.limit(1, 2)
|
|
|
|
|
.select(StudentClientLink::getStudentClientLinkOrder);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result)) {
|
|
|
|
|
// 找到应该安插的位置
|
|
|
|
|
BigDecimal LinkOrder0 = result.get(0).getStudentClientLinkOrder();
|
|
|
|
|
BigDecimal LinkOrder1 = LinkOrder0.add(BigDecimal.ONE);
|
|
|
|
|
if (result.size() == 2) {
|
|
|
|
|
LinkOrder1 = result.get(1).getStudentClientLinkOrder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BigDecimal min = NumberUtil.min(LinkOrder0, LinkOrder1);
|
|
|
|
|
BigDecimal max = NumberUtil.max(LinkOrder0, LinkOrder1);
|
|
|
|
|
|
|
|
|
|
// 右移位后的值
|
|
|
|
|
double calcedOrder = RandomUtil.randomDouble(min.doubleValue(), max.doubleValue(), 6, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
|
|
// 改变排序记录值
|
|
|
|
|
StudentClientLink updatePO = new StudentClientLink();
|
|
|
|
|
updatePO.setStudentClientLinkId(studentClientLink.getStudentClientLinkId());
|
|
|
|
|
updatePO.setStudentClientLinkOrder(BigDecimal.valueOf(calcedOrder));
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
|
|
|
|
|
|
|
BigDecimal min = NumberUtil.min(LinkOrder0, LinkOrder1);
|
|
|
|
|
BigDecimal max = NumberUtil.max(LinkOrder0, LinkOrder1);
|
|
|
|
|
|
|
|
|
|
// 左移位后的值
|
|
|
|
|
double calcedOrder = RandomUtil.randomDouble(min.doubleValue(), max.doubleValue(), 6, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
|
|
// 改变排序记录值
|
|
|
|
|
StudentClientLink updatePO = new StudentClientLink();
|
|
|
|
|
updatePO.setStudentClientLinkId(studentClientLink.getStudentClientLinkId());
|
|
|
|
|
updatePO.setStudentClientLinkOrder(BigDecimal.valueOf(calcedOrder));
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case MOVE_RIGHT: {
|
|
|
|
|
List<StudentClientLink> result = studentClientLinkDao.createLambdaQuery()
|
|
|
|
|
.andEq(StudentClientLink::getStudentClientLinkType, studentClientLink.getStudentClientLinkType())
|
|
|
|
|
.andGreat(StudentClientLink::getStudentClientLinkOrder, studentClientLink.getStudentClientLinkOrder())
|
|
|
|
|
.andEq(StudentClientLink::getStudentClientLinkStatus, 1)
|
|
|
|
|
.andNotEq(StudentClientLink::getStudentClientLinkId, id)
|
|
|
|
|
.asc(StudentClientLink::getStudentClientLinkOrder)
|
|
|
|
|
.limit(1, 2)
|
|
|
|
|
.select(StudentClientLink::getStudentClientLinkOrder);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result)) {
|
|
|
|
|
// 找到应该安插的位置
|
|
|
|
|
BigDecimal LinkOrder0 = result.get(0).getStudentClientLinkOrder();
|
|
|
|
|
BigDecimal LinkOrder1 = LinkOrder0.add(BigDecimal.ONE);
|
|
|
|
|
if (result.size() == 2) {
|
|
|
|
|
LinkOrder1 = result.get(1).getStudentClientLinkOrder();
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
BigDecimal min = NumberUtil.min(LinkOrder0, LinkOrder1);
|
|
|
|
|
BigDecimal max = NumberUtil.max(LinkOrder0, LinkOrder1);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
log.error("不支持的移动类型!");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// 右移位后的值
|
|
|
|
|
double calcedOrder = RandomUtil.randomDouble(min.doubleValue(), max.doubleValue(), 6, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
|
|
// 改变排序记录值
|
|
|
|
|
StudentClientLink updatePO = new StudentClientLink();
|
|
|
|
|
updatePO.setStudentClientLinkId(studentClientLink.getStudentClientLinkId());
|
|
|
|
|
updatePO.setStudentClientLinkOrder(BigDecimal.valueOf(calcedOrder));
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
log.error("不支持的移动类型!");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|