|
|
|
@ -1,7 +1,11 @@
|
|
|
|
|
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.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
import cn.jlw.Interceptor.GetFile;
|
|
|
|
|
import cn.jlw.util.ToolUtils;
|
|
|
|
|
import com.beust.jcommander.internal.Maps;
|
|
|
|
@ -14,7 +18,9 @@ import com.ibeetl.admin.core.web.JsonResult;
|
|
|
|
|
import com.ibeetl.jlw.dao.CourseInfoDao;
|
|
|
|
|
import com.ibeetl.jlw.dao.ResourcesApplicationCourseDao;
|
|
|
|
|
import com.ibeetl.jlw.entity.*;
|
|
|
|
|
import com.ibeetl.jlw.enums.MoveEnum;
|
|
|
|
|
import com.ibeetl.jlw.web.query.CourseInfoQuery;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
|
|
|
|
import org.apache.poi.openxml4j.opc.PackagePartName;
|
|
|
|
@ -30,12 +36,17 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
|
|
|
|
|
import static cn.jlw.util.ConvertM3U8.booleanMap;
|
|
|
|
|
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUserId;
|
|
|
|
|
import static java.lang.Math.min;
|
|
|
|
|
import static java.math.BigDecimal.ROUND_HALF_UP;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -43,6 +54,7 @@ import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUserId;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Transactional
|
|
|
|
|
public class CourseInfoService extends CoreBaseService<CourseInfo>{
|
|
|
|
|
|
|
|
|
@ -856,25 +868,6 @@ public class CourseInfoService extends CoreBaseService<CourseInfo>{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 系统课程排序实现
|
|
|
|
|
* @param moveDTO
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public void move(MoveDTO moveDTO) {
|
|
|
|
|
moveDTO.getMoveType();
|
|
|
|
|
moveDTO.getId();
|
|
|
|
|
moveDTO.getNum();
|
|
|
|
|
|
|
|
|
|
switch(moveDTO.getMoveType()) {
|
|
|
|
|
case MOVE_TOP:
|
|
|
|
|
|
|
|
|
|
case MOVE_LEFT:
|
|
|
|
|
|
|
|
|
|
case MOVE_RIGHT:
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//线程处理 根据章节分割word
|
|
|
|
|
private class TaskCallable2Split implements Callable<Boolean> {
|
|
|
|
|
File file;
|
|
|
|
@ -1081,4 +1074,210 @@ public class CourseInfoService extends CoreBaseService<CourseInfo>{
|
|
|
|
|
|
|
|
|
|
return courseInfoDao.getCourseInfoPageByUniversitiesCollegesId(pageQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 位置移动
|
|
|
|
|
* 小于0的数字,是代表置顶。大于0代表非置顶
|
|
|
|
|
* @param id
|
|
|
|
|
* @param moveType
|
|
|
|
|
*/
|
|
|
|
|
public void move(@NotNull(message = "ID不能为空!") Long id, @NotNull(message = "移动类型不能为空!") MoveEnum moveType) {
|
|
|
|
|
|
|
|
|
|
List<CourseInfo> links = courseInfoDao.createLambdaQuery().andIn(CourseInfo::getCourseInfoId, Arrays.asList(id))
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoStatus, 1)
|
|
|
|
|
.select();
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(links, "未查询到要移动的元素!");
|
|
|
|
|
|
|
|
|
|
CourseInfo mergeCourseInfo = links.get(0);
|
|
|
|
|
|
|
|
|
|
switch (moveType) {
|
|
|
|
|
|
|
|
|
|
case MOVE_TOP: {
|
|
|
|
|
List<CourseInfo> result = courseInfoDao.createLambdaQuery()
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoType, mergeCourseInfo.getCourseInfoType())
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoStatus, 1)
|
|
|
|
|
.andNotEq(CourseInfo::getCourseInfoId, id)
|
|
|
|
|
.asc(CourseInfo::getCourseInfoOrder)
|
|
|
|
|
.limit(1, 1)
|
|
|
|
|
.select(CourseInfo::getCourseInfoOrder);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result)) {
|
|
|
|
|
CourseInfo minOrderClientLink = result.get(0);
|
|
|
|
|
// 最小的排序值
|
|
|
|
|
BigDecimal minLinkOrder = minOrderClientLink.getCourseInfoOrder();
|
|
|
|
|
// 置顶就现有的最小值减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);
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case MOVE_LEFT: {
|
|
|
|
|
List<CourseInfo> result = courseInfoDao.createLambdaQuery()
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoType, mergeCourseInfo.getCourseInfoType())
|
|
|
|
|
.andLess(CourseInfo::getCourseInfoOrder, mergeCourseInfo.getCourseInfoOrder())
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoStatus, 1)
|
|
|
|
|
.andNotEq(CourseInfo::getCourseInfoId, id)
|
|
|
|
|
.desc(CourseInfo::getCourseInfoOrder)
|
|
|
|
|
.limit(1, 2)
|
|
|
|
|
.select(CourseInfo::getCourseInfoOrder);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result)) {
|
|
|
|
|
// 找到应该安插的位置
|
|
|
|
|
BigDecimal LinkOrder0 = result.get(0).getCourseInfoOrder();
|
|
|
|
|
BigDecimal LinkOrder1 = LinkOrder0.subtract(BigDecimal.ONE);
|
|
|
|
|
if (result.size() == 2) {
|
|
|
|
|
LinkOrder1 = result.get(1).getCourseInfoOrder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case MOVE_RIGHT: {
|
|
|
|
|
List<CourseInfo> result = courseInfoDao.createLambdaQuery()
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoType, mergeCourseInfo.getCourseInfoType())
|
|
|
|
|
.andGreat(CourseInfo::getCourseInfoOrder, mergeCourseInfo.getCourseInfoOrder())
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoStatus, 1)
|
|
|
|
|
.andNotEq(CourseInfo::getCourseInfoId, id)
|
|
|
|
|
.asc(CourseInfo::getCourseInfoOrder)
|
|
|
|
|
.limit(1, 2)
|
|
|
|
|
.select(CourseInfo::getCourseInfoOrder);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result)) {
|
|
|
|
|
// 找到应该安插的位置
|
|
|
|
|
BigDecimal LinkOrder0 = result.get(0).getCourseInfoOrder();
|
|
|
|
|
BigDecimal LinkOrder1 = LinkOrder0.add(BigDecimal.ONE);
|
|
|
|
|
if (result.size() == 2) {
|
|
|
|
|
LinkOrder1 = result.get(1).getCourseInfoOrder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
log.error("不支持的移动类型!");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能描述: <br>
|
|
|
|
|
* 拖动
|
|
|
|
|
* 只传左元素ID,表示:拖动元素 在 左元素的左侧;
|
|
|
|
|
* 只传右元素ID,表示:拖动元素 在 右元素的右侧;
|
|
|
|
|
* 左右元素ID都传,则拖动元素放置在两个元素的中间。
|
|
|
|
|
*
|
|
|
|
|
* @param id 拖动元素的ID
|
|
|
|
|
* @param leftId 左元素ID 偏小数值对应的元素ID
|
|
|
|
|
* @param rightId 右元素ID 偏大数值对应的元素ID
|
|
|
|
|
*
|
|
|
|
|
* 左侧(上) ==> 右侧(下)
|
|
|
|
|
* 小数值 ==> 大数值
|
|
|
|
|
*
|
|
|
|
|
* 数值越小,越靠前
|
|
|
|
|
*
|
|
|
|
|
* @Author: 87966
|
|
|
|
|
* @Date: 2023/1/9 16:44
|
|
|
|
|
*/
|
|
|
|
|
public void drag(@NotNull(message = "要移动的元素 ID不能为空!") final Long id, final Long leftId, final Long rightId) {
|
|
|
|
|
|
|
|
|
|
// 查询出来所有元素
|
|
|
|
|
List<CourseInfo> allElement = courseInfoDao.createLambdaQuery().andIn(CourseInfo::getCourseInfoId, Arrays.asList(id, leftId, rightId))
|
|
|
|
|
.andEq(CourseInfo::getCourseInfoStatus, 1)
|
|
|
|
|
.select();
|
|
|
|
|
|
|
|
|
|
// 自身ID是否存在
|
|
|
|
|
boolean hasSelf = allElement.stream().anyMatch(item -> item.getCourseInfoId().equals(id));
|
|
|
|
|
// 是否有左元素
|
|
|
|
|
boolean hasLeft = allElement.stream().anyMatch(item -> item.getCourseInfoId().equals(leftId));
|
|
|
|
|
// 是否有元素
|
|
|
|
|
boolean hasRight = allElement.stream().anyMatch(item -> item.getCourseInfoId().equals(rightId));
|
|
|
|
|
|
|
|
|
|
// 断言
|
|
|
|
|
Assert.isTrue(hasSelf, "未查询到要移动的元素!");
|
|
|
|
|
Assert.isFalse(!hasLeft && !hasRight, "左右元素ID不能同时为空!");
|
|
|
|
|
|
|
|
|
|
// 自身元素
|
|
|
|
|
CourseInfo selfElement = allElement.stream()
|
|
|
|
|
.filter(item -> item.getCourseInfoId().equals(id)).findFirst().get();
|
|
|
|
|
// 左侧元素
|
|
|
|
|
CourseInfo leftElement = allElement.stream()
|
|
|
|
|
.filter(item -> item.getCourseInfoId().equals(leftId)).findFirst().orElse(null);
|
|
|
|
|
// 右侧元素
|
|
|
|
|
CourseInfo rightElement = allElement.stream()
|
|
|
|
|
.filter(item -> item.getCourseInfoId().equals(rightId)).findFirst().orElse(null);
|
|
|
|
|
|
|
|
|
|
// 定义排序值
|
|
|
|
|
BigDecimal clacedOrder = null;
|
|
|
|
|
|
|
|
|
|
// 左移动,无法确定右侧边界,适用于置顶
|
|
|
|
|
if (hasLeft && !hasRight) {
|
|
|
|
|
BigDecimal leftOrder = defaultIfNull(leftElement.getCourseInfoOrder(), BigDecimal.ZERO);
|
|
|
|
|
// 数据库里存小数点后六位的排序值
|
|
|
|
|
// 随机取值 0.0001 到 0.0005之间
|
|
|
|
|
BigDecimal randomNum = RandomUtil.randomBigDecimal(new BigDecimal("0.0001"), new BigDecimal("0.0005")).setScale(6, ROUND_HALF_UP);
|
|
|
|
|
// 计算后的排序值
|
|
|
|
|
clacedOrder = leftOrder.subtract(randomNum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 右移动,无法确定左侧边界,适用于置底
|
|
|
|
|
else if (!hasLeft && hasRight) {
|
|
|
|
|
BigDecimal rightOrder = defaultIfNull(rightElement.getCourseInfoOrder(), BigDecimal.ZERO);
|
|
|
|
|
// 数据库里存小数点后六位的排序值
|
|
|
|
|
// 随机取值 0.0001 到 0.0005之间
|
|
|
|
|
BigDecimal randomNum = RandomUtil.randomBigDecimal(new BigDecimal("0.0001"), new BigDecimal("0.0005")).setScale(6, ROUND_HALF_UP);
|
|
|
|
|
// 计算后的排序值
|
|
|
|
|
clacedOrder = rightOrder.add(randomNum);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 可以确定左右两侧边界,移动的比较精准
|
|
|
|
|
else if (hasLeft && hasRight) {
|
|
|
|
|
BigDecimal leftOrder = defaultIfNull(leftElement.getCourseInfoOrder(), BigDecimal.ZERO);
|
|
|
|
|
BigDecimal rightOrder = defaultIfNull(rightElement.getCourseInfoOrder(), BigDecimal.ONE);
|
|
|
|
|
// 随机取值
|
|
|
|
|
BigDecimal randomNum = RandomUtil.randomBigDecimal(leftOrder, rightOrder).setScale(6, ROUND_HALF_UP);
|
|
|
|
|
// 计算后的排序值
|
|
|
|
|
clacedOrder = rightOrder.add(randomNum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 最后更新排序值
|
|
|
|
|
if (clacedOrder != null) {
|
|
|
|
|
CourseInfo updatePO = new CourseInfo();
|
|
|
|
|
updatePO.setCourseInfoId(selfElement.getCourseInfoId());
|
|
|
|
|
updatePO.setCourseInfoOrder(clacedOrder);
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|