|
|
|
@ -142,6 +142,15 @@ public class CourseInfoService extends CoreBaseService<CourseInfo>{
|
|
|
|
|
public CourseInfo add(CourseInfoQuery courseInfoQuery){
|
|
|
|
|
|
|
|
|
|
CourseInfo courseInfo = courseInfoQuery.pojo();
|
|
|
|
|
|
|
|
|
|
// 获取新的排序值
|
|
|
|
|
CourseInfo paras = new CourseInfo();
|
|
|
|
|
paras.setCourseInfoType(courseInfo.getCourseInfoType());
|
|
|
|
|
paras.setCourseInfoParentId(courseInfo.getCourseInfoParentId());
|
|
|
|
|
paras.setCourseInfoStatus(1);
|
|
|
|
|
BigDecimal bigDecimal = getFuncIncrement(paras, CourseInfo::getOrderIndex);
|
|
|
|
|
courseInfo.setOrderIndex(bigDecimal);
|
|
|
|
|
|
|
|
|
|
insert(courseInfo);
|
|
|
|
|
|
|
|
|
|
//删除以前的
|
|
|
|
@ -1091,6 +1100,9 @@ public class CourseInfoService extends CoreBaseService<CourseInfo>{
|
|
|
|
|
|
|
|
|
|
CourseInfo mergeCourseInfo = links.get(0);
|
|
|
|
|
|
|
|
|
|
// 定义排序值
|
|
|
|
|
Double calcedOrder = null;
|
|
|
|
|
|
|
|
|
|
switch (moveType) {
|
|
|
|
|
|
|
|
|
|
case MOVE_TOP: {
|
|
|
|
@ -1098,22 +1110,16 @@ public class CourseInfoService extends CoreBaseService<CourseInfo>{
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoType, mergeCourseInfo.getCourseInfoType())
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoStatus, 1)
|
|
|
|
|
.andNotEq(CourseInfo::getCourseInfoId, id)
|
|
|
|
|
.asc(CourseInfo::getCourseInfoOrder)
|
|
|
|
|
.asc(CourseInfo::getOrderIndex)
|
|
|
|
|
.limit(1, 1)
|
|
|
|
|
.select(CourseInfo::getCourseInfoOrder);
|
|
|
|
|
.select(CourseInfo::getOrderIndex);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result)) {
|
|
|
|
|
CourseInfo minOrderClientLink = result.get(0);
|
|
|
|
|
// 最小的排序值
|
|
|
|
|
BigDecimal minLinkOrder = minOrderClientLink.getCourseInfoOrder();
|
|
|
|
|
BigDecimal minLinkOrder = minOrderClientLink.getOrderIndex();
|
|
|
|
|
// 置顶就现有的最小值减1。但是需要确保结果小于0
|
|
|
|
|
BigDecimal calcedOrder = BigDecimal.valueOf(NumberUtil.sub(min(minLinkOrder.floatValue(), 0), 1));
|
|
|
|
|
|
|
|
|
|
// 改变排序记录值
|
|
|
|
|
CourseInfo updatePO = new CourseInfo();
|
|
|
|
|
updatePO.setCourseInfoId(mergeCourseInfo.getCourseInfoId());
|
|
|
|
|
updatePO.setCourseInfoOrder(calcedOrder);
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
|
|
calcedOrder = NumberUtil.sub(min(minLinkOrder.floatValue(), 0), 1);
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
@ -1121,33 +1127,26 @@ public class CourseInfoService extends CoreBaseService<CourseInfo>{
|
|
|
|
|
case MOVE_LEFT: {
|
|
|
|
|
List<CourseInfo> result = courseInfoDao.createLambdaQuery()
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoType, mergeCourseInfo.getCourseInfoType())
|
|
|
|
|
.andLess(CourseInfo::getCourseInfoOrder, mergeCourseInfo.getCourseInfoOrder())
|
|
|
|
|
.andLess(CourseInfo::getOrderIndex, mergeCourseInfo.getOrderIndex())
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoStatus, 1)
|
|
|
|
|
.andNotEq(CourseInfo::getCourseInfoId, id)
|
|
|
|
|
.desc(CourseInfo::getCourseInfoOrder)
|
|
|
|
|
.desc(CourseInfo::getOrderIndex)
|
|
|
|
|
.limit(1, 2)
|
|
|
|
|
.select(CourseInfo::getCourseInfoOrder);
|
|
|
|
|
.select(CourseInfo::getOrderIndex);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result)) {
|
|
|
|
|
// 找到应该安插的位置
|
|
|
|
|
BigDecimal LinkOrder0 = result.get(0).getCourseInfoOrder();
|
|
|
|
|
BigDecimal LinkOrder0 = result.get(0).getOrderIndex();
|
|
|
|
|
BigDecimal LinkOrder1 = LinkOrder0.subtract(BigDecimal.ONE);
|
|
|
|
|
if (result.size() == 2) {
|
|
|
|
|
LinkOrder1 = result.get(1).getCourseInfoOrder();
|
|
|
|
|
LinkOrder1 = result.get(1).getOrderIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BigDecimal min = NumberUtil.min(LinkOrder0, LinkOrder1);
|
|
|
|
|
BigDecimal max = NumberUtil.max(LinkOrder0, LinkOrder1);
|
|
|
|
|
|
|
|
|
|
// 左移位后的值
|
|
|
|
|
double calcedOrder = RandomUtil.randomDouble(min.doubleValue(), max.doubleValue(), 6, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
|
|
// 改变排序记录值
|
|
|
|
|
CourseInfo updatePO = new CourseInfo();
|
|
|
|
|
updatePO.setCourseInfoId(mergeCourseInfo.getCourseInfoId());
|
|
|
|
|
updatePO.setCourseInfoOrder(BigDecimal.valueOf(calcedOrder));
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
|
|
|
|
|
|
|
calcedOrder = RandomUtil.randomDouble(min.doubleValue(), max.doubleValue(), 6, RoundingMode.HALF_UP);
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
@ -1155,40 +1154,40 @@ public class CourseInfoService extends CoreBaseService<CourseInfo>{
|
|
|
|
|
case MOVE_RIGHT: {
|
|
|
|
|
List<CourseInfo> result = courseInfoDao.createLambdaQuery()
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoType, mergeCourseInfo.getCourseInfoType())
|
|
|
|
|
.andGreat(CourseInfo::getCourseInfoOrder, mergeCourseInfo.getCourseInfoOrder())
|
|
|
|
|
.andGreat(CourseInfo::getOrderIndex, mergeCourseInfo.getOrderIndex())
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoStatus, 1)
|
|
|
|
|
.andNotEq(CourseInfo::getCourseInfoId, id)
|
|
|
|
|
.asc(CourseInfo::getCourseInfoOrder)
|
|
|
|
|
.asc(CourseInfo::getOrderIndex)
|
|
|
|
|
.limit(1, 2)
|
|
|
|
|
.select(CourseInfo::getCourseInfoOrder);
|
|
|
|
|
.select(CourseInfo::getOrderIndex);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result)) {
|
|
|
|
|
// 找到应该安插的位置
|
|
|
|
|
BigDecimal LinkOrder0 = result.get(0).getCourseInfoOrder();
|
|
|
|
|
BigDecimal LinkOrder0 = result.get(0).getOrderIndex();
|
|
|
|
|
BigDecimal LinkOrder1 = LinkOrder0.add(BigDecimal.ONE);
|
|
|
|
|
if (result.size() == 2) {
|
|
|
|
|
LinkOrder1 = result.get(1).getCourseInfoOrder();
|
|
|
|
|
LinkOrder1 = result.get(1).getOrderIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BigDecimal min = NumberUtil.min(LinkOrder0, LinkOrder1);
|
|
|
|
|
BigDecimal max = NumberUtil.max(LinkOrder0, LinkOrder1);
|
|
|
|
|
|
|
|
|
|
// 右移位后的值
|
|
|
|
|
double calcedOrder = RandomUtil.randomDouble(min.doubleValue(), max.doubleValue(), 6, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
|
|
// 改变排序记录值
|
|
|
|
|
CourseInfo updatePO = new CourseInfo();
|
|
|
|
|
updatePO.setCourseInfoId(mergeCourseInfo.getCourseInfoId());
|
|
|
|
|
updatePO.setCourseInfoOrder(BigDecimal.valueOf(calcedOrder));
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
|
|
calcedOrder = RandomUtil.randomDouble(min.doubleValue(), max.doubleValue(), 6, RoundingMode.HALF_UP);
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
log.error("不支持的移动类型!");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (calcedOrder == null) {
|
|
|
|
|
// 改变排序记录值
|
|
|
|
|
CourseInfo updatePO = new CourseInfo();
|
|
|
|
|
updatePO.setCourseInfoId(mergeCourseInfo.getCourseInfoId());
|
|
|
|
|
updatePO.setOrderIndex(BigDecimal.valueOf(calcedOrder));
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -1243,7 +1242,7 @@ public class CourseInfoService extends CoreBaseService<CourseInfo>{
|
|
|
|
|
|
|
|
|
|
// 左移动,无法确定右侧边界,适用于置顶
|
|
|
|
|
if (hasLeft && !hasRight) {
|
|
|
|
|
BigDecimal leftOrder = defaultIfNull(leftElement.getCourseInfoOrder(), BigDecimal.ZERO);
|
|
|
|
|
BigDecimal leftOrder = defaultIfNull(leftElement.getOrderIndex(), BigDecimal.ZERO);
|
|
|
|
|
// 数据库里存小数点后六位的排序值
|
|
|
|
|
// 随机取值 0.0001 到 0.0005之间
|
|
|
|
|
BigDecimal randomNum = RandomUtil.randomBigDecimal(new BigDecimal("0.0001"), new BigDecimal("0.0005")).setScale(6, ROUND_HALF_UP);
|
|
|
|
@ -1253,7 +1252,7 @@ public class CourseInfoService extends CoreBaseService<CourseInfo>{
|
|
|
|
|
|
|
|
|
|
// 右移动,无法确定左侧边界,适用于置底
|
|
|
|
|
else if (!hasLeft && hasRight) {
|
|
|
|
|
BigDecimal rightOrder = defaultIfNull(rightElement.getCourseInfoOrder(), BigDecimal.ZERO);
|
|
|
|
|
BigDecimal rightOrder = defaultIfNull(rightElement.getOrderIndex(), BigDecimal.ZERO);
|
|
|
|
|
// 数据库里存小数点后六位的排序值
|
|
|
|
|
// 随机取值 0.0001 到 0.0005之间
|
|
|
|
|
BigDecimal randomNum = RandomUtil.randomBigDecimal(new BigDecimal("0.0001"), new BigDecimal("0.0005")).setScale(6, ROUND_HALF_UP);
|
|
|
|
@ -1264,8 +1263,8 @@ public class CourseInfoService extends CoreBaseService<CourseInfo>{
|
|
|
|
|
|
|
|
|
|
// 可以确定左右两侧边界,移动的比较精准
|
|
|
|
|
else if (hasLeft && hasRight) {
|
|
|
|
|
BigDecimal leftOrder = defaultIfNull(leftElement.getCourseInfoOrder(), BigDecimal.ZERO);
|
|
|
|
|
BigDecimal rightOrder = defaultIfNull(rightElement.getCourseInfoOrder(), BigDecimal.ONE);
|
|
|
|
|
BigDecimal leftOrder = defaultIfNull(leftElement.getOrderIndex(), BigDecimal.ZERO);
|
|
|
|
|
BigDecimal rightOrder = defaultIfNull(rightElement.getOrderIndex(), BigDecimal.ONE);
|
|
|
|
|
// 随机取值
|
|
|
|
|
BigDecimal randomNum = RandomUtil.randomBigDecimal(leftOrder, rightOrder).setScale(6, ROUND_HALF_UP);
|
|
|
|
|
// 计算后的排序值
|
|
|
|
@ -1276,7 +1275,7 @@ public class CourseInfoService extends CoreBaseService<CourseInfo>{
|
|
|
|
|
if (clacedOrder != null) {
|
|
|
|
|
CourseInfo updatePO = new CourseInfo();
|
|
|
|
|
updatePO.setCourseInfoId(selfElement.getCourseInfoId());
|
|
|
|
|
updatePO.setCourseInfoOrder(clacedOrder);
|
|
|
|
|
updatePO.setOrderIndex(clacedOrder);
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|